2025-04-16 16:55:38 -07:00
|
|
|
import EntityRegistry from '@app/entity/EntityRegistry';
|
|
|
|
import { GenericEntityProperties } from '@app/entity/shared/types';
|
|
|
|
|
|
|
|
import { Entity, EntityType } from '@types';
|
2023-03-06 12:05:45 -05:00
|
|
|
|
|
|
|
export const ROOT_NODES = 'rootNodes';
|
|
|
|
export const ROOT_TERMS = 'rootTerms';
|
|
|
|
|
|
|
|
export function getGlossaryRootToUpdate(entityType: EntityType) {
|
|
|
|
return entityType === EntityType.GlossaryTerm ? ROOT_TERMS : ROOT_NODES;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the urns or special constants for root nodes or terms (above) that need to be refreshed in the Glossary
|
|
|
|
// sidebar when making updates (edit name, create term/term group, delete term/term group, move entity)
|
|
|
|
export function getParentNodeToUpdate(entityData: GenericEntityProperties | null, entityType: EntityType) {
|
2024-12-12 20:49:25 +05:30
|
|
|
return entityData?.parentNodes?.nodes?.length
|
|
|
|
? entityData?.parentNodes?.nodes[0]?.urn
|
2023-03-06 12:05:45 -05:00
|
|
|
: getGlossaryRootToUpdate(entityType);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add the parent nodes that need to refetch from the glossary sidebar to `urnsToUpdate` state.
|
|
|
|
// This could also include ROOT_NODES or ROOT_TERMS if the item(s) that need updating don't have parents.
|
|
|
|
export function updateGlossarySidebar(
|
|
|
|
parentNodesToUpdate: string[],
|
|
|
|
urnsToUpdate: string[],
|
|
|
|
setUrnsToUpdate: (updatdUrns: string[]) => void,
|
|
|
|
) {
|
|
|
|
setUrnsToUpdate([...urnsToUpdate, ...parentNodesToUpdate]);
|
|
|
|
}
|
2024-01-29 15:26:14 +05:30
|
|
|
|
|
|
|
export function getParentGlossary<T extends Entity>(node: T, entityRegistry: EntityRegistry) {
|
|
|
|
const props = entityRegistry.getGenericEntityProperties(EntityType.GlossaryNode, node);
|
|
|
|
return props?.parentNodes?.nodes ?? [];
|
|
|
|
}
|