Skip to content

Commit

Permalink
Disable input in edit data source when data_source.manageableBy is no…
Browse files Browse the repository at this point in the history
…ne (#7307)

* Disable input in edit data source when data_source.manageableBy is none

Signed-off-by: Eemi Juntunen <eemijun@amazon.com>

* Changeset file for PR #7307 created/updated

* Removed unnecessary canManageDataSource check

Signed-off-by: Eemi Juntunen <eemijun@amazon.com>

* Fix lint issue

Signed-off-by: Eemi Juntunen <eemijun@amazon.com>

* Update snapshot

Signed-off-by: Eemi Juntunen <eemijun@amazon.com>

---------

Signed-off-by: Eemi Juntunen <eemijun@amazon.com>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
  • Loading branch information
1 parent 2c6e78e commit ddc26fc
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 2 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/7307.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
feat:
- Disable inputs in edit data source screen when data_source.manageableBy is none ([#7307](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7307))
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,7 @@ export class EditDataSourceForm extends React.Component<EditDataSourceProps, Edi
<>
<EuiButton
onClick={this.onClickUpdatePassword}
disabled={!this.props.canManageDataSource}
data-test-subj="editDatasourceUpdatePasswordBtn"
>
{
Expand All @@ -601,6 +602,7 @@ export class EditDataSourceForm extends React.Component<EditDataSourceProps, Edi
username={this.state.auth?.credentials?.username || ''}
handleUpdatePassword={this.updatePassword}
closeUpdatePasswordModal={this.closePasswordModal}
canManageDataSource={this.props.canManageDataSource}
/>
) : null}
</>
Expand All @@ -613,6 +615,7 @@ export class EditDataSourceForm extends React.Component<EditDataSourceProps, Edi
<EuiButton
onClick={this.onClickUpdateAwsCredential}
data-test-subj="editDatasourceUpdateAwsCredentialBtn"
disabled={!this.props.canManageDataSource}
>
{
<FormattedMessage
Expand All @@ -628,6 +631,7 @@ export class EditDataSourceForm extends React.Component<EditDataSourceProps, Edi
service={this.state.auth.credentials!.service}
handleUpdateAwsCredential={this.updateAwsCredential}
closeUpdateAwsCredentialModal={this.closeAwsCredentialModal}
canManageDataSource={this.props.canManageDataSource}
/>
) : null}
</>
Expand Down Expand Up @@ -725,6 +729,7 @@ export class EditDataSourceForm extends React.Component<EditDataSourceProps, Edi
isInvalid={!!this.state.formErrorsByField.title.length}
onChange={this.onChangeTitle}
onBlur={this.validateTitle}
disabled={!this.props.canManageDataSource}
/>
</EuiFormRow>
{/* Description */}
Expand All @@ -745,6 +750,7 @@ export class EditDataSourceForm extends React.Component<EditDataSourceProps, Edi
}
)}
onChange={this.onChangeDescription}
disabled={!this.props.canManageDataSource}
/>
</EuiFormRow>
</EuiDescribedFormGroup>
Expand Down Expand Up @@ -837,7 +843,7 @@ export class EditDataSourceForm extends React.Component<EditDataSourceProps, Edi
options={this.authOptions}
valueOfSelected={this.state.auth.type}
onChange={(value) => this.onChangeAuthType(value)}
disabled={this.authOptions.length <= 1}
disabled={this.authOptions.length <= 1 || !this.props.canManageDataSource}
name="Credential"
data-test-subj="editDataSourceSelectAuthType"
/>
Expand Down Expand Up @@ -883,6 +889,7 @@ export class EditDataSourceForm extends React.Component<EditDataSourceProps, Edi
value={this.state.auth.credentials?.region || ''}
onChange={this.onChangeRegion}
onBlur={this.validateRegion}
disabled={!this.props.canManageDataSource}
data-test-subj="editDataSourceFormRegionField"
name="dataSourceRegion"
/>
Expand All @@ -895,6 +902,7 @@ export class EditDataSourceForm extends React.Component<EditDataSourceProps, Edi
<EuiSuperSelect
options={sigV4ServiceOptions}
valueOfSelected={this.state.auth.credentials?.service}
disabled={!this.props.canManageDataSource}
onChange={(value) => this.onChangeSigV4ServiceName(value)}
name="ServiceName"
data-test-subj="editDataSourceFormSigV4ServiceTypeSelect"
Expand Down Expand Up @@ -989,6 +997,7 @@ export class EditDataSourceForm extends React.Component<EditDataSourceProps, Edi
isInvalid={!!this.state.formErrorsByField.createCredential?.username?.length}
onChange={this.onChangeUsername}
onBlur={this.validateUsername}
disabled={!this.props.canManageDataSource}
/>
</EuiFormRow>

Expand Down Expand Up @@ -1018,7 +1027,10 @@ export class EditDataSourceForm extends React.Component<EditDataSourceProps, Edi
spellCheck={false}
onChange={this.onChangePassword}
onBlur={this.validatePassword}
disabled={this.props.existingDataSource.auth.type === AuthType.UsernamePasswordType}
disabled={
this.props.existingDataSource.auth.type === AuthType.UsernamePasswordType ||
!this.props.canManageDataSource
}
data-test-subj="updateDataSourceFormPasswordField"
/>
</EuiFlexItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ describe('UpdateAwsCredentialModal', () => {
service: SigV4ServiceName.OpenSearch,
handleUpdateAwsCredential: mockHandleUpdateAwsCredential,
closeUpdateAwsCredentialModal: mockCloseUpdateAwsCredentialModal,
canManageDataSource: true,
};

it('updates new access key state on input change', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ export interface UpdateAwsCredentialModalProps {
service: SigV4ServiceName;
handleUpdateAwsCredential: (accessKey: string, secretKey: string) => void;
closeUpdateAwsCredentialModal: () => void;
canManageDataSource: boolean;
}

export const UpdateAwsCredentialModal = ({
region,
service,
handleUpdateAwsCredential,
closeUpdateAwsCredentialModal,
canManageDataSource,
}: UpdateAwsCredentialModalProps) => {
/* State Variables */
const [newAccessKey, setNewAccessKey] = useState<string>('');
Expand Down Expand Up @@ -134,6 +136,7 @@ export const UpdateAwsCredentialModal = ({
spellCheck={false}
onChange={(e) => setNewAccessKey(e.target.value)}
onBlur={validateNewAccessKey}
disabled={!canManageDataSource}
/>
</EuiFormRow>

Expand All @@ -159,6 +162,7 @@ export const UpdateAwsCredentialModal = ({
spellCheck={false}
onChange={(e) => setNewSecretKey(e.target.value)}
onBlur={validateNewSecretKey}
disabled={!canManageDataSource}
/>
</EuiFormRow>
</EuiForm>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ describe('Datasource Management: Update Stored Password Modal', () => {
username={mockUserName}
handleUpdatePassword={mockFn}
closeUpdatePasswordModal={mockFn}
canManageDataSource={true}
/>
),
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ export interface UpdatePasswordModalProps {
username: string;
handleUpdatePassword: (password: string) => void;
closeUpdatePasswordModal: () => void;
canManageDataSource: boolean;
}

export const UpdatePasswordModal = ({
username,
handleUpdatePassword,
closeUpdatePasswordModal,
canManageDataSource,
}: UpdatePasswordModalProps) => {
/* State Variables */
const [newPassword, setNewPassword] = useState<string>('');
Expand Down Expand Up @@ -128,6 +130,7 @@ export const UpdatePasswordModal = ({
spellCheck={false}
onChange={(e) => setNewPassword(e.target.value)}
onBlur={validateNewPassword}
disabled={!canManageDataSource}
/>
</EuiFormRow>
{/* Password */}
Expand All @@ -153,6 +156,7 @@ export const UpdatePasswordModal = ({
spellCheck={false}
onChange={(e) => setConfirmNewPassword(e.target.value)}
onBlur={validateConfirmNewPassword}
disabled={!canManageDataSource}
/>
</EuiFormRow>
</EuiForm>
Expand Down

0 comments on commit ddc26fc

Please sign in to comment.