grafana/public/app/features/datasources/utils/passwordHandlers.ts
Diana Payton 1399b49c16
UI text edits (#32524)
* 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>
2021-03-31 16:07:37 -07:00

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;
};