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

fix(ui): expand invalid state upon glossary term add #18968

Merged
merged 7 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@ const GlossaryTermTab = ({
useGlossaryStore();
const { t } = useTranslation();

const glossaryTerms = (glossaryChildTerms as ModifiedGlossaryTerm[]) ?? [];
const glossaryTerms = useMemo(
() => (glossaryChildTerms as ModifiedGlossaryTerm[]) ?? [],
[glossaryChildTerms]
);

const [movedGlossaryTerm, setMovedGlossaryTerm] =
useState<MoveGlossaryTermType>();
Expand Down Expand Up @@ -141,6 +144,9 @@ const GlossaryTermTab = ({
}, [isGlossary, activeGlossary]);

const expandableKeys = useMemo(() => {
// clean expandedRowKey upon glossaryTerm change
setExpandedRowKeys([]);

return findExpandableKeysForArray(glossaryTerms);
}, [glossaryTerms]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,9 @@ const GlossaryV1 = ({
const { data } = await getFirstLevelGlossaryTerms(
params?.glossary ?? params?.parent ?? ''
);
const children = data.map((data) =>
data.childrenCount ?? 0 > 0 ? { ...data, children: [] } : data
);

setGlossaryChildTerms(children as ModifiedGlossary[]);
// We are considering childrenCount fot expand collapse state
// Hence don't need any intervention to list response here
setGlossaryChildTerms(data as ModifiedGlossary[]);
} catch (error) {
showErrorToast(error as AxiosError);
} finally {
Expand Down Expand Up @@ -232,7 +230,11 @@ const GlossaryV1 = ({
entity: t('label.glossary-term'),
});
} else {
updateGlossaryTermInStore(response);
updateGlossaryTermInStore({
...response,
// Since patch didn't respond with childrenCount preserve it from currentData
childrenCount: currentData.childrenCount,
});
setIsEditModalOpen(false);
}
} catch (error) {
Expand Down
Loading