Skip to content

Commit

Permalink
[MD] new UX changes for password fields and update password modal in …
Browse files Browse the repository at this point in the history
…data source management (opensearch-project#2532)

* nex ux changes for password fields and update password modal in data source management

Signed-off-by: mpabba3003 <amazonmanideep@gmail.com>

* update change log

Signed-off-by: mpabba3003 <amazonmanideep@gmail.com>

Signed-off-by: mpabba3003 <amazonmanideep@gmail.com>
  • Loading branch information
mpabba3003 authored Oct 10, 2022
1 parent ac07159 commit 9f6bfc0
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
* [Viz Builder] Create a new wizard directly on a dashboard ([#2384](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2384))
* [Multi DataSource] UX enhacement on index pattern management stack ([#2505](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2505))
* [Multi DataSource] UX enhancement on Data source management stack ([#2521](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2521))
* [Multi DataSource] UX enhancement on Update stored password modal for Data source management stack ([#2532](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2532))

### 🐛 Bug Fixes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
EuiButton,
EuiButtonEmpty,
EuiDescribedFormGroup,
EuiFieldPassword,
EuiFieldText,
EuiFlexGroup,
EuiFlexItem,
Expand Down Expand Up @@ -459,8 +460,9 @@ export class EditDataSourceForm extends React.Component<EditDataSourceProps, Edi
>
<EuiFlexGroup>
<EuiFlexItem>
<EuiFieldText
<EuiFieldPassword
placeholder={DATA_SOURCE_PASSWORD_PLACEHOLDER}
type={'dual'}
value={
this.props.existingDataSource.auth.type !== AuthType.NoAuth
? '********'
Expand All @@ -470,6 +472,7 @@ export class EditDataSourceForm extends React.Component<EditDataSourceProps, Edi
onChange={this.onChangePassword}
onBlur={this.validatePassword}
disabled={this.props.existingDataSource.auth.type !== AuthType.NoAuth}
data-test-subj="updateDataSourceFormPasswordField"
/>
</EuiFlexItem>
{this.props.existingDataSource.auth.type !== AuthType.NoAuth ? (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,18 @@ import {
EuiModalFooter,
EuiModalHeader,
EuiModalHeaderTitle,
EuiSpacer,
EuiText,
} from '@elastic/eui';
import { NEW_PASSWORD_TEXT, UPDATE_STORED_PASSWORD, USERNAME } from '../../../text_content';
import {
CANCEL_TEXT,
CONFIRM_NEW_PASSWORD_TEXT,
NEW_PASSWORD_TEXT,
PASSWORD_NO_MATCH,
UPDATE_STORED_PASSWORD,
UPDATE_STORED_PASSWORD_DESCRIPTION,
USERNAME,
} from '../../../text_content';

export interface UpdatePasswordModalProps {
username: string;
Expand All @@ -32,13 +41,34 @@ export const UpdatePasswordModal = ({
}: UpdatePasswordModalProps) => {
/* State Variables */
const [newPassword, setNewPassword] = useState<string>('');
const [confirmNewPassword, setConfirmNewPassword] = useState<string>('');
const [isNewPasswordValid, setIsNewPasswordValid] = useState<boolean>(true);
const [isConfirmNewPasswordValid, setIsConfirmNewPasswordValid] = useState<string[]>([]);

const onClickUpdatePassword = () => {
if (!!newPassword) {
if (isFormValid()) {
handleUpdatePassword(newPassword);
}
};

const isFormValid = () => {
return !!(newPassword && confirmNewPassword && confirmNewPassword === newPassword);
};

const validateNewPassword = () => {
setIsNewPasswordValid(!!newPassword);
};

const validateConfirmNewPassword = () => {
const invalidReason: string[] = [];
if (!confirmNewPassword) {
invalidReason.push('');
} else if (confirmNewPassword !== newPassword) {
invalidReason.push(PASSWORD_NO_MATCH);
}
setIsConfirmNewPasswordValid(invalidReason);
};

const renderUpdatePasswordModal = () => {
return (
<EuiModal onClose={closeUpdatePasswordModal}>
Expand All @@ -49,33 +79,59 @@ export const UpdatePasswordModal = ({
</EuiModalHeader>

<EuiModalBody>
<EuiFormRow>
<EuiText size="m" style={{ fontWeight: 300 }}>
{UPDATE_STORED_PASSWORD_DESCRIPTION}
</EuiText>
</EuiFormRow>
<EuiSpacer size="m" />

<EuiForm data-test-subj="data-source-update-password">
{/* Username */}
<EuiFormRow label={USERNAME}>
<EuiText size="s">{username}</EuiText>
</EuiFormRow>
{/* Password */}
<EuiFormRow label={NEW_PASSWORD_TEXT}>
{/* updated Password */}
<EuiFormRow label={NEW_PASSWORD_TEXT} isInvalid={!isNewPasswordValid}>
<EuiFieldPassword
name="updatedPassword"
placeholder={NEW_PASSWORD_TEXT}
type={'dual'}
value={newPassword}
isInvalid={!isNewPasswordValid}
onChange={(e) => setNewPassword(e.target.value)}
onBlur={validateNewPassword}
/>
</EuiFormRow>
{/* Password */}
<EuiFormRow
label={CONFIRM_NEW_PASSWORD_TEXT}
isInvalid={!!isConfirmNewPasswordValid.length}
error={isConfirmNewPasswordValid}
>
<EuiFieldPassword
name="confirmUpdatedPassword"
placeholder={CONFIRM_NEW_PASSWORD_TEXT}
type={'dual'}
value={confirmNewPassword}
isInvalid={!!isConfirmNewPasswordValid.length}
onChange={(e) => setConfirmNewPassword(e.target.value)}
onBlur={validateConfirmNewPassword}
/>
</EuiFormRow>
</EuiForm>
</EuiModalBody>

<EuiModalFooter>
<EuiButtonEmpty onClick={closeUpdatePasswordModal}>Cancel</EuiButtonEmpty>
<EuiButtonEmpty onClick={closeUpdatePasswordModal}>{CANCEL_TEXT}</EuiButtonEmpty>
<EuiButton
type="submit"
form="modalFormId"
onClick={onClickUpdatePassword}
fill={!!newPassword}
disabled={!newPassword}
fill={isFormValid()}
disabled={!isFormValid()}
>
Update
{UPDATE_STORED_PASSWORD}
</EuiButton>
</EuiModalFooter>
</EuiModal>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,19 @@ export const DELETE_THIS_DATA_SOURCE = i18n.translate(
export const NEW_PASSWORD_TEXT = i18n.translate(
'dataSourcesManagement.editDataSource.newPassword',
{
defaultMessage: 'New password',
defaultMessage: 'Updated password',
}
);
export const CONFIRM_NEW_PASSWORD_TEXT = i18n.translate(
'dataSourcesManagement.editDataSource.confirmNewPassword',
{
defaultMessage: 'Confirm Updated password',
}
);
export const PASSWORD_NO_MATCH = i18n.translate(
'dataSourcesManagement.editDataSource.passwordNoMatch',
{
defaultMessage: 'Passwords do not match',
}
);
export const UPDATE_STORED_PASSWORD = i18n.translate(
Expand All @@ -172,6 +184,13 @@ export const UPDATE_STORED_PASSWORD = i18n.translate(
defaultMessage: 'Update stored password',
}
);
export const UPDATE_STORED_PASSWORD_DESCRIPTION = i18n.translate(
'dataSourcesManagement.editDataSource.updateStoredPasswordDescription',
{
defaultMessage:
'Update credential password to reflect accurate password to gain access to the endpoint.',
}
);
export const CONNECTION_DETAILS_TITLE = i18n.translate(
'dataSourcesManagement.editDataSource.connectionDetailsText',
{
Expand Down

0 comments on commit 9f6bfc0

Please sign in to comment.