Skip to content

Commit

Permalink
optimize the code
Browse files Browse the repository at this point in the history
Signed-off-by: yubonluo <[email protected]>
  • Loading branch information
yubonluo committed Jul 23, 2024
1 parent 0ef48c3 commit b850070
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.

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 @@ -112,7 +112,7 @@ describe('DuplicateModal', () => {
expect(options[1].label).toEqual('bar');
});

it('should display the suffix (current) in target workspace options when in workspace1', async () => {
it('should display the suffix (current) in target workspace options when it is the current workspace', async () => {
workspaces.workspaceList$.next(workspaceList);
workspaces.currentWorkspaceId$.next('workspace1');
workspaces.currentWorkspace$.next({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,17 @@ export class SavedObjectsDuplicateModal extends React.Component<ShowDuplicateMod
}

duplicateSavedObjects = async (savedObjects: DuplicateObject[]) => {
const selectedWorkspace = this.state.targetWorkspaceOption[0];
if (!selectedWorkspace) {
return;

Check warning on line 76 in src/plugins/saved_objects_management/public/management_section/objects_table/components/duplicate_modal.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/saved_objects_management/public/management_section/objects_table/components/duplicate_modal.tsx#L76

Added line #L76 was not covered by tests
}
const targetWorkspace = selectedWorkspace.key;
const targetWorkspaceName = selectedWorkspace.label;

this.setState({
isLoading: true,
});

const targetWorkspace = this.state.targetWorkspaceOption[0].key;
const targetWorkspaceName = this.state.targetWorkspaceOption[0].label;

await this.props.onDuplicate(
savedObjects,
this.state.isIncludeReferencesDeepChecked,
Expand All @@ -98,10 +102,10 @@ export class SavedObjectsDuplicateModal extends React.Component<ShowDuplicateMod
});
};

changeIncludeReferencesDeep = () => {
this.setState((state) => ({
isIncludeReferencesDeepChecked: !state.isIncludeReferencesDeepChecked,
}));
changeIncludeReferencesDeep = (e: React.ChangeEvent<HTMLInputElement>) => {
this.setState({
isIncludeReferencesDeepChecked: e.target.checked,
});
};

render() {
Expand Down Expand Up @@ -137,7 +141,7 @@ export class SavedObjectsDuplicateModal extends React.Component<ShowDuplicateMod
<EuiFormRow
fullWidth
label={i18n.translate(
'savedObjectsManagement.objectsTable.duplicateModal.targetWorkspacelabel',
'savedObjectsManagement.objectsTable.duplicateModal.targetWorkspaceLabel',
{ defaultMessage: 'Workspace' }
)}
>
Expand Down Expand Up @@ -210,9 +214,6 @@ export class SavedObjectsDuplicateModal extends React.Component<ShowDuplicateMod
<FormattedMessage
id="savedObjectsManagement.objectsTable.duplicateModal.confirmButtonLabel"
defaultMessage="Copy"
values={{
objectCount: allSelectedObjects.length,
}}
/>
</EuiButton>
</EuiModalFooter>
Expand Down

0 comments on commit b850070

Please sign in to comment.