Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MD] new UX changes for password fields and update password modal in data source management #2532

Merged
merged 3 commits into from
Oct 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ive called this out in some of the other MD PR's, but lets move the translate functions into the react components. That way we have realtime translations instead of static translations that only run during compile time.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood, I will resolve it today in a different PR as many PRs will have conflicts if I do it now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @mpabba3003!

'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