Skip to content
This repository has been archived by the owner on Dec 20, 2024. It is now read-only.

Commit

Permalink
make use of a Field label
Browse files Browse the repository at this point in the history
  • Loading branch information
shelldandy committed Dec 12, 2024
1 parent 8ebe5ac commit 3431089
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions src/ConfigEditor/Auth/auth-method/AuthMethodSettings.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React, { ReactElement, useMemo, useState } from 'react';
import { css } from '@emotion/css';
import { useTheme2, Select } from '@grafana/ui';
import { useTheme2, Select, Field } from '@grafana/ui';
import { SelectableValue } from '@grafana/data';
import { BasicAuth, Props as BasicAuthProps } from './BasicAuth';
import { ConfigSubSection } from '../../ConfigSection';
import { AuthMethod, CustomMethod, CustomMethodId , AuthMethodSelectOption } from '../types';
import { AuthMethod, CustomMethod, CustomMethodId, AuthMethodSelectOption } from '../types';

const defaultOptions: Record<AuthMethod, SelectableValue<AuthMethod>> = {
[AuthMethod.BasicAuth]: {
Expand Down Expand Up @@ -83,7 +83,7 @@ export const AuthMethodSettings = ({
preparedDefaultOptions[k] = {
...defaultOptions[k],
...defaultOptionsOverrides?.[k],
}
};
}

const allOptions: Record<AuthMethod | CustomMethodId, SelectableValue<AuthMethod | CustomMethodId>> = {
Expand Down Expand Up @@ -119,11 +119,11 @@ export const AuthMethodSettings = ({
AuthFieldsComponent = customMethods?.find((m) => m.id === selected)?.component ?? null;
}

const title = hasSelect ? 'Authentication methods' : preparedOptions[0].label ?? '';
const title = hasSelect ? 'Authentication methods' : (preparedOptions[0].label ?? '');

const description = hasSelect
? 'Choose an authentication method to access the data source'
: preparedOptions[0].description ?? '';
: (preparedOptions[0].description ?? '');

const styles = {
authMethods: css({
Expand All @@ -142,15 +142,18 @@ export const AuthMethodSettings = ({
<ConfigSubSection title={title} description={description}>
<div className={styles.authMethods}>
{hasSelect && (
<Select
options={preparedOptions}
value={selected}
onChange={(option) => {
setAuthMethodChanged(true);
onAuthMethodSelect(option.value!);
}}
disabled={readOnly}
/>
<Field label="Authentication method">
<Select
inputId="auth-method-select"
options={preparedOptions}
value={selected}
onChange={(option) => {
setAuthMethodChanged(true);
onAuthMethodSelect(option.value!);
}}
disabled={readOnly}
/>
</Field>
)}
{AuthFieldsComponent && <div className={styles.selectedMethodFields}>{AuthFieldsComponent}</div>}
</div>
Expand Down

0 comments on commit 3431089

Please sign in to comment.