Skip to content

Commit

Permalink
feat: Auth: enable customizing label and placeholder for user/passwor…
Browse files Browse the repository at this point in the history
…d inputs (#128)
  • Loading branch information
cletter7 authored Aug 8, 2024
1 parent 1b8c624 commit 701bcd8
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to this project will be documented in this file.

## v1.8.0

- Auth: add ability to customize labels and placeholders for user/password fields

## v1.7.13

- Switched from "react-beautiful-dnd" to "@hello-pangea/dnd"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@grafana/experimental",
"version": "1.7.13",
"version": "1.8.0",
"description": "Experimental Grafana components and APIs",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down
13 changes: 13 additions & 0 deletions src/ConfigEditor/Auth/auth-method/BasicAuth.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,17 @@ describe('<BasicAuth />', () => {
expect(screen.getByPlaceholderText('User')).toBeDisabled();
expect(screen.getByPlaceholderText('Password')).toBeDisabled();
});

it('should render custom username and password labels and placeholders', () => {
const props = getProps({
userLabel: 'user-test-label',
userPlaceholder: 'user-test-placeholder',
passwordLabel: 'pwd-test-label',
passwordPlaceholder: 'pwd-test-placeholder',
});
render(<BasicAuth {...props} />);

expect(screen.getByLabelText('user-test-label *')).toHaveAttribute('placeholder', 'user-test-placeholder');
expect(screen.getByLabelText('pwd-test-label *')).toHaveAttribute('placeholder', 'pwd-test-placeholder');
});
});
16 changes: 12 additions & 4 deletions src/ConfigEditor/Auth/auth-method/BasicAuth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ import { useCommonStyles } from '../styles';
export type Props = {
user?: string;
passwordConfigured: boolean;
userLabel?: string;
userTooltip?: PopoverContent;
userPlaceholder?: string;
passwordLabel?: string;
passwordTooltip?: PopoverContent;
passwordPlaceholder?: string;
onUserChange: (user: string) => void;
onPasswordChange: (password: string) => void;
onPasswordReset: () => void;
Expand All @@ -17,8 +21,12 @@ export type Props = {
export const BasicAuth: React.FC<Props> = ({
user,
passwordConfigured,
userLabel = 'User',
userTooltip = 'The username of the data source account',
userPlaceholder = 'User',
passwordLabel = 'Password',
passwordTooltip = 'The password of the data source account',
passwordPlaceholder = 'Password',
onUserChange,
onPasswordChange,
onPasswordReset,
Expand All @@ -34,7 +42,7 @@ export const BasicAuth: React.FC<Props> = ({
<>
<InlineField
className={commonStyles.inlineFieldNoMarginRight}
label="User"
label={userLabel}
labelWidth={24}
tooltip={userTooltip}
required
Expand All @@ -45,7 +53,7 @@ export const BasicAuth: React.FC<Props> = ({
>
<Input
id="basic-auth-user-input"
placeholder="User"
placeholder={userPlaceholder}
value={user}
onChange={(e) => onUserChange(e.currentTarget.value)}
required
Expand All @@ -57,7 +65,7 @@ export const BasicAuth: React.FC<Props> = ({
commonStyles.inlineFieldWithSecret,
styles.lastInlineField
)}
label="Password"
label={passwordLabel}
labelWidth={24}
tooltip={passwordTooltip}
required
Expand All @@ -70,7 +78,7 @@ export const BasicAuth: React.FC<Props> = ({
id="basic-auth-password-input"
isConfigured={passwordConfigured}
onReset={readOnly ? () => {} : onPasswordReset}
placeholder="Password"
placeholder={passwordPlaceholder}
onChange={(e) => onPasswordChange(e.currentTarget.value)}
required
/>
Expand Down

0 comments on commit 701bcd8

Please sign in to comment.