From 52a8e335a3d46144a8d5ea3e6490cfaa121f1624 Mon Sep 17 00:00:00 2001 From: Shailesh Parmar Date: Fri, 2 Dec 2022 13:04:28 +0530 Subject: [PATCH] Fixed: [UI] Add support for renaming glossary #8733 (#9105) * Fixed: [UI] Add support for renaming glossary #8733 * Addressing comments --- .../Glossary/GlossaryV1.component.tsx | 1 + .../GlossaryPage/GlossaryPageV1.component.tsx | 52 +++++++++++++------ 2 files changed, 36 insertions(+), 17 deletions(-) diff --git a/openmetadata-ui/src/main/resources/ui/src/components/Glossary/GlossaryV1.component.tsx b/openmetadata-ui/src/main/resources/ui/src/components/Glossary/GlossaryV1.component.tsx index d65ce7d31ea..58debd16f9e 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/Glossary/GlossaryV1.component.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/Glossary/GlossaryV1.component.tsx @@ -250,6 +250,7 @@ const GlossaryV1 = ({ updatedDetails = { ...selectedData, displayName: displayName?.trim(), + name: displayName?.trim() || selectedData.name, }; if ( diff --git a/openmetadata-ui/src/main/resources/ui/src/pages/GlossaryPage/GlossaryPageV1.component.tsx b/openmetadata-ui/src/main/resources/ui/src/pages/GlossaryPage/GlossaryPageV1.component.tsx index 613388409b9..417956e37a4 100644 --- a/openmetadata-ui/src/main/resources/ui/src/pages/GlossaryPage/GlossaryPageV1.component.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/pages/GlossaryPage/GlossaryPageV1.component.tsx @@ -21,6 +21,7 @@ import { LoadingState, } from 'Models'; import React, { useCallback, useEffect, useState } from 'react'; +import { useTranslation } from 'react-i18next'; import { useHistory, useParams } from 'react-router-dom'; import { deleteGlossary, @@ -62,6 +63,7 @@ export type ModifiedGlossaryData = Glossary & { const GlossaryPageV1 = () => { const { glossaryName } = useParams>(); + const { t } = useTranslation(); const history = useHistory(); const [isLoading, setIsLoading] = useState(true); @@ -482,6 +484,28 @@ const GlossaryPageV1 = () => { return patchGlossaries(selectedData?.id as string, jsonPatch); }; + /** + * Handle the redirection to glossary page via FQN. + * @param fqn for redirecting to glossary page + */ + const handleRedirection = (fqn?: string) => { + // If no FQN provided it will redirect to previous parent of selected glossaryTerm. + // mainly use for after delete effect + const redirectFqn = fqn + ? fqn + : selectedKey.split('.').slice(0, -1).join('.'); + + if (isEmpty(redirectFqn)) { + setGlossariesList([]); + setIsLoading(true); + history.push(getGlossaryPath()); + fetchGlossaryList(); + } else { + history.push(getGlossaryPath(redirectFqn)); + fetchGlossaryList(redirectFqn); + } + }; + /** * To update glossary * @param updatedData glossary with new values @@ -514,8 +538,13 @@ const GlossaryPageV1 = () => { } }); }); + if (selectedData?.name !== updatedData.name) { + handleRedirection(response.fullyQualifiedName); + } } else { - throw jsonData['api-error-messages']['update-description-error']; + throw t('server.entity-updating-error', { + entity: updateGlossary.name, + }); } } catch (error) { showErrorToast(error as AxiosError); @@ -544,6 +573,9 @@ const GlossaryPageV1 = () => { const response = await saveUpdatedGlossaryTermData(updatedData); if (response) { setSelectedData(response); + if (selectedData?.name !== updatedData.name) { + handleRedirection(response.fullyQualifiedName); + } } else { throw jsonData['api-error-messages']['update-glossary-term-error']; } @@ -552,20 +584,6 @@ const GlossaryPageV1 = () => { } }; - const afterDeleteAction = () => { - const redirectFqn = selectedKey.split('.').slice(0, -1).join('.'); - - if (isEmpty(redirectFqn)) { - setGlossariesList([]); - setIsLoading(true); - history.push(getGlossaryPath()); - fetchGlossaryList(); - } else { - history.push(getGlossaryPath(redirectFqn)); - fetchGlossaryList(redirectFqn); - } - }; - /** * To delete glossary by id * @param id glossary id @@ -578,7 +596,7 @@ const GlossaryPageV1 = () => { showSuccessToast( jsonData['api-success-messages']['delete-glossary-success'] ); - afterDeleteAction(); + handleRedirection(); }) .catch((err: AxiosError) => { showErrorToast( @@ -601,7 +619,7 @@ const GlossaryPageV1 = () => { showSuccessToast( jsonData['api-success-messages']['delete-glossary-term-success'] ); - afterDeleteAction(); + handleRedirection(); }) .catch((err: AxiosError) => { showErrorToast(