From 84f77fb044dfbc62d208584ed8e74018fe59306f Mon Sep 17 00:00:00 2001 From: yuye-aws Date: Thu, 14 Sep 2023 10:43:25 +0800 Subject: [PATCH] remove clone for dashboard Signed-off-by: yuye-aws --- .../__snapshots__/clone_modal.test.js.snap | 63 ----- .../top_nav/clone_modal.test.js | 79 ------ .../dashboard_top_nav/top_nav/clone_modal.tsx | 225 ------------------ .../top_nav/get_top_nav_config.ts | 18 -- .../dashboard_top_nav/top_nav/index.ts | 2 - .../top_nav/show_clone_modal.tsx | 80 ------- .../dashboard_top_nav/top_nav/top_nav_ids.ts | 1 - .../application/utils/get_nav_actions.tsx | 28 --- 8 files changed, 496 deletions(-) delete mode 100644 src/plugins/dashboard/public/application/components/dashboard_top_nav/top_nav/__snapshots__/clone_modal.test.js.snap delete mode 100644 src/plugins/dashboard/public/application/components/dashboard_top_nav/top_nav/clone_modal.test.js delete mode 100644 src/plugins/dashboard/public/application/components/dashboard_top_nav/top_nav/clone_modal.tsx delete mode 100644 src/plugins/dashboard/public/application/components/dashboard_top_nav/top_nav/show_clone_modal.tsx diff --git a/src/plugins/dashboard/public/application/components/dashboard_top_nav/top_nav/__snapshots__/clone_modal.test.js.snap b/src/plugins/dashboard/public/application/components/dashboard_top_nav/top_nav/__snapshots__/clone_modal.test.js.snap deleted file mode 100644 index 1e029e6960cd..000000000000 --- a/src/plugins/dashboard/public/application/components/dashboard_top_nav/top_nav/__snapshots__/clone_modal.test.js.snap +++ /dev/null @@ -1,63 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`renders DashboardCloneModal 1`] = ` - - - - - - - - -

- -

-
- - -
- - - - - - - - -
-`; diff --git a/src/plugins/dashboard/public/application/components/dashboard_top_nav/top_nav/clone_modal.test.js b/src/plugins/dashboard/public/application/components/dashboard_top_nav/top_nav/clone_modal.test.js deleted file mode 100644 index 2529f146e2b0..000000000000 --- a/src/plugins/dashboard/public/application/components/dashboard_top_nav/top_nav/clone_modal.test.js +++ /dev/null @@ -1,79 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * The OpenSearch Contributors require contributions made to - * this file be licensed under the Apache-2.0 license or a - * compatible open source license. - * - * Any modifications Copyright OpenSearch Contributors. See - * GitHub history for details. - */ - -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import React from 'react'; -import sinon from 'sinon'; -import { shallowWithI18nProvider, mountWithI18nProvider } from 'test_utils/enzyme_helpers'; -import { findTestSubject } from '@elastic/eui/lib/test'; - -import { DashboardCloneModal } from './clone_modal'; - -let onClone; -let onClose; - -beforeEach(() => { - onClone = sinon.spy(); - onClose = sinon.spy(); -}); - -test('renders DashboardCloneModal', () => { - const component = shallowWithI18nProvider( - - ); - expect(component).toMatchSnapshot(); // eslint-disable-line -}); - -test('onClone', () => { - const component = mountWithI18nProvider( - - ); - findTestSubject(component, 'cloneConfirmButton').simulate('click'); - sinon.assert.calledWith(onClone, 'dash title'); - sinon.assert.notCalled(onClose); -}); - -test('onClose', () => { - const component = mountWithI18nProvider( - - ); - findTestSubject(component, 'cloneCancelButton').simulate('click'); - sinon.assert.calledOnce(onClose); - sinon.assert.notCalled(onClone); -}); - -test('title', () => { - const component = mountWithI18nProvider( - - ); - const event = { target: { value: 'a' } }; - component.find('input').simulate('change', event); - findTestSubject(component, 'cloneConfirmButton').simulate('click'); - sinon.assert.calledWith(onClone, 'a'); -}); diff --git a/src/plugins/dashboard/public/application/components/dashboard_top_nav/top_nav/clone_modal.tsx b/src/plugins/dashboard/public/application/components/dashboard_top_nav/top_nav/clone_modal.tsx deleted file mode 100644 index f56a1e5be14a..000000000000 --- a/src/plugins/dashboard/public/application/components/dashboard_top_nav/top_nav/clone_modal.tsx +++ /dev/null @@ -1,225 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * The OpenSearch Contributors require contributions made to - * this file be licensed under the Apache-2.0 license or a - * compatible open source license. - * - * Any modifications Copyright OpenSearch Contributors. See - * GitHub history for details. - */ - -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import React, { Fragment } from 'react'; -import { i18n } from '@osd/i18n'; -import { FormattedMessage } from '@osd/i18n/react'; - -import { - EuiButton, - EuiButtonEmpty, - EuiFieldText, - EuiModal, - EuiModalBody, - EuiModalFooter, - EuiModalHeader, - EuiModalHeaderTitle, - EuiSpacer, - EuiText, - EuiCallOut, -} from '@elastic/eui'; - -interface Props { - onClone: ( - newTitle: string, - isTitleDuplicateConfirmed: boolean, - onTitleDuplicate: () => void - ) => Promise; - onClose: () => void; - title: string; -} - -interface State { - newDashboardName: string; - isTitleDuplicateConfirmed: boolean; - hasTitleDuplicate: boolean; - isLoading: boolean; -} - -export class DashboardCloneModal extends React.Component { - private isMounted = false; - - constructor(props: Props) { - super(props); - - this.state = { - newDashboardName: props.title, - isTitleDuplicateConfirmed: false, - hasTitleDuplicate: false, - isLoading: false, - }; - } - componentDidMount() { - this.isMounted = true; - } - - componentWillUnmount() { - this.isMounted = false; - } - - onTitleDuplicate = () => { - this.setState({ - isTitleDuplicateConfirmed: true, - hasTitleDuplicate: true, - }); - }; - - cloneDashboard = async () => { - this.setState({ - isLoading: true, - }); - - await this.props.onClone( - this.state.newDashboardName, - this.state.isTitleDuplicateConfirmed, - this.onTitleDuplicate - ); - - if (this.isMounted) { - this.setState({ - isLoading: false, - }); - } - }; - - onInputChange = (event: any) => { - this.setState({ - newDashboardName: event.target.value, - isTitleDuplicateConfirmed: false, - hasTitleDuplicate: false, - }); - }; - - renderDuplicateTitleCallout = () => { - if (!this.state.hasTitleDuplicate) { - return; - } - - return ( - - - -

- - - - ), - }} - /> -

-
-
- ); - }; - - render() { - return ( - - - - - - - - - -

- -

-
- - - - - - {this.renderDuplicateTitleCallout()} -
- - - - - - - - - - -
- ); - } -} diff --git a/src/plugins/dashboard/public/application/components/dashboard_top_nav/top_nav/get_top_nav_config.ts b/src/plugins/dashboard/public/application/components/dashboard_top_nav/top_nav/get_top_nav_config.ts index 8ae04eb6e6d6..26317e45f6ae 100644 --- a/src/plugins/dashboard/public/application/components/dashboard_top_nav/top_nav/get_top_nav_config.ts +++ b/src/plugins/dashboard/public/application/components/dashboard_top_nav/top_nav/get_top_nav_config.ts @@ -54,7 +54,6 @@ export function getTopNavConfig( : [ getFullScreenConfig(actions[TopNavIds.FULL_SCREEN]), getShareConfig(actions[TopNavIds.SHARE]), - getCloneConfig(actions[TopNavIds.CLONE]), getDuplicateConfig(actions[TopNavIds.DUPLICATE]), getEditConfig(actions[TopNavIds.ENTER_EDIT_MODE]), ]; @@ -142,23 +141,6 @@ function getViewConfig(action: NavAction) { }; } -/** - * @returns {osdTopNavConfig} - */ -function getCloneConfig(action: NavAction) { - return { - id: 'clone', - label: i18n.translate('dashboard.topNave.cloneButtonAriaLabel', { - defaultMessage: 'clone', - }), - description: i18n.translate('dashboard.topNave.cloneConfigDescription', { - defaultMessage: 'Create a copy of your dashboard', - }), - testId: 'dashboardClone', - run: action, - }; -} - /** * @returns {osdTopNavConfig} */ diff --git a/src/plugins/dashboard/public/application/components/dashboard_top_nav/top_nav/index.ts b/src/plugins/dashboard/public/application/components/dashboard_top_nav/top_nav/index.ts index 468db7035856..828692abd066 100644 --- a/src/plugins/dashboard/public/application/components/dashboard_top_nav/top_nav/index.ts +++ b/src/plugins/dashboard/public/application/components/dashboard_top_nav/top_nav/index.ts @@ -3,11 +3,9 @@ * SPDX-License-Identifier: Apache-2.0 */ -export * from './clone_modal'; export * from './get_top_nav_config'; export * from './options'; export * from './save_modal'; -export * from './show_clone_modal'; export * from './show_duplicate_modal'; export * from './show_options_popover'; export * from './top_nav_ids'; diff --git a/src/plugins/dashboard/public/application/components/dashboard_top_nav/top_nav/show_clone_modal.tsx b/src/plugins/dashboard/public/application/components/dashboard_top_nav/top_nav/show_clone_modal.tsx deleted file mode 100644 index 42f07ebe1569..000000000000 --- a/src/plugins/dashboard/public/application/components/dashboard_top_nav/top_nav/show_clone_modal.tsx +++ /dev/null @@ -1,80 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * The OpenSearch Contributors require contributions made to - * this file be licensed under the Apache-2.0 license or a - * compatible open source license. - * - * Any modifications Copyright OpenSearch Contributors. See - * GitHub history for details. - */ - -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import React from 'react'; -import ReactDOM from 'react-dom'; -import { i18n } from '@osd/i18n'; -import { I18nProvider } from '@osd/i18n/react'; -import { DashboardCloneModal } from './clone_modal'; - -export function showCloneModal( - onClone: ( - newTitle: string, - isTitleDuplicateConfirmed: boolean, - onTitleDuplicate: () => void - ) => Promise<{ id?: string } | { error: Error }>, - title: string -) { - const container = document.createElement('div'); - const closeModal = () => { - ReactDOM.unmountComponentAtNode(container); - document.body.removeChild(container); - }; - - const onCloneConfirmed = async ( - newTitle: string, - isTitleDuplicateConfirmed: boolean, - onTitleDuplicate: () => void - ) => { - onClone(newTitle, isTitleDuplicateConfirmed, onTitleDuplicate).then( - (response: { id?: string } | { error: Error }) => { - // The only time you don't want to close the modal is if it's asking you - // to confirm a duplicate title, in which case there will be no error and no id. - if ((response as { error: Error }).error || (response as { id?: string }).id) { - closeModal(); - } - } - ); - }; - document.body.appendChild(container); - const element = ( - - - - ); - ReactDOM.render(element, container); -} diff --git a/src/plugins/dashboard/public/application/components/dashboard_top_nav/top_nav/top_nav_ids.ts b/src/plugins/dashboard/public/application/components/dashboard_top_nav/top_nav/top_nav_ids.ts index 240fbd9ea8b1..8ed9ac315afb 100644 --- a/src/plugins/dashboard/public/application/components/dashboard_top_nav/top_nav/top_nav_ids.ts +++ b/src/plugins/dashboard/public/application/components/dashboard_top_nav/top_nav/top_nav_ids.ts @@ -34,7 +34,6 @@ export const TopNavIds = { SAVE: 'save', EXIT_EDIT_MODE: 'exitEditMode', ENTER_EDIT_MODE: 'enterEditMode', - CLONE: 'clone', DUPLICATE: 'duplicate', FULL_SCREEN: 'fullScreenMode', VISUALIZE: 'visualize', diff --git a/src/plugins/dashboard/public/application/utils/get_nav_actions.tsx b/src/plugins/dashboard/public/application/utils/get_nav_actions.tsx index 75c6c20ff1c9..1699ebb02427 100644 --- a/src/plugins/dashboard/public/application/utils/get_nav_actions.tsx +++ b/src/plugins/dashboard/public/application/utils/get_nav_actions.tsx @@ -17,7 +17,6 @@ import { DashboardAppStateContainer, DashboardServices, NavAction } from '../../ import { DashboardSaveModal, TopNavIds, - showCloneModal, showDuplicateModal, showOptionsPopover, UrlParams, @@ -150,33 +149,6 @@ export const getNavActions = ( showSaveModal(dashboardSaveModal, I18nContext); }; - navActions[TopNavIds.CLONE] = () => { - const currentTitle = appState.title; - const onClone = ( - newTitle: string, - isTitleDuplicateConfirmed: boolean, - onTitleDuplicate: () => void - ) => { - savedDashboard.copyOnSave = true; - stateContainer.transitions.set('title', newTitle); - const saveOptions = { - confirmOverwrite: false, - isTitleDuplicateConfirmed, - onTitleDuplicate, - }; - return save(saveOptions).then((response: { id?: string } | { error: Error }) => { - // If the save wasn't successful, put the original title back. - if ((response as { error: Error }).error) { - stateContainer.transitions.set('title', currentTitle); - } - // updateNavBar(); - return response; - }); - }; - - showCloneModal(onClone, currentTitle); - }; - navActions[TopNavIds.DUPLICATE] = () => { const getDuplicateWorkspaces = async (): Promise => { let result;