mirror of
https://github.com/grafana/grafana.git
synced 2025-02-12 16:45:43 -06:00
* Update TeamSettings.tsx * Update navModel.ts * Update ChangePasswordForm.tsx * Update UserProfileEditForm.tsx * Update DashboardImportPage.tsx * Update uploadDashboardDirective.ts * Update ImportDashboardForm.tsx * Update ImportDashboardOverview.tsx * Update validation.ts * Update PlaylistEditPage.tsx * ui text edits * text edits * Update buildCategories.ts * text edits * text edits * Fix formatting * Update test snapshots Co-authored-by: dsotirakis <sotirakis.dim@gmail.com>
46 lines
1.3 KiB
TypeScript
46 lines
1.3 KiB
TypeScript
/**
|
|
* Set of handlers for secure password field in Angular components. They handle backward compatibility with
|
|
* passwords stored in plain text fields.
|
|
*/
|
|
|
|
import { SyntheticEvent } from 'react';
|
|
|
|
export enum PasswordFieldEnum {
|
|
Password = 'password',
|
|
BasicAuthPassword = 'basicAuthPassword',
|
|
}
|
|
|
|
/**
|
|
* Basic shape for settings controllers in at the moment mostly angular data source plugins.
|
|
*/
|
|
export type Ctrl = {
|
|
current: {
|
|
secureJsonFields: {
|
|
[key: string]: boolean;
|
|
};
|
|
secureJsonData?: {
|
|
[key: string]: string;
|
|
};
|
|
password?: string;
|
|
basicAuthPassword?: string;
|
|
};
|
|
};
|
|
|
|
export const createResetHandler = (ctrl: Ctrl, field: PasswordFieldEnum) => (
|
|
event: SyntheticEvent<HTMLInputElement>
|
|
) => {
|
|
event.preventDefault();
|
|
// Reset also normal plain text password to remove it and only save it in secureJsonData.
|
|
ctrl.current[field] = undefined;
|
|
ctrl.current.secureJsonFields[field] = false;
|
|
ctrl.current.secureJsonData = ctrl.current.secureJsonData || {};
|
|
ctrl.current.secureJsonData[field] = '';
|
|
};
|
|
|
|
export const createChangeHandler = (ctrl: any, field: PasswordFieldEnum) => (
|
|
event: SyntheticEvent<HTMLInputElement>
|
|
) => {
|
|
ctrl.current.secureJsonData = ctrl.current.secureJsonData || {};
|
|
ctrl.current.secureJsonData[field] = event.currentTarget.value;
|
|
};
|