Skip to content

Commit

Permalink
Simplify dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
kmcginnes committed Aug 9, 2024
1 parent e6ca97a commit 364cbf5
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions packages/graph-explorer/src/hooks/usePrefixesUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,29 @@ const usePrefixesUpdater = () => {
const setSchema = useSetRecoilState(schemaAtom);
const { enqueueNotification } = useNotification();

const supportsPrefixes = config?.connection?.queryEngine === "sparql"
const existingPrefixes = config?.schema?.prefixes
const activeConfigId = config?.id;

return useCallback(
(ids: Array<string>) => {
if (config?.connection?.queryEngine !== "sparql" || ids.length === 0) {
if (supportsPrefixes || ids.length === 0) {
return;
}

const genPrefixes = generatePrefixes(ids, config?.schema?.prefixes);
const genPrefixes = generatePrefixes(ids, existingPrefixes);
if (!genPrefixes?.length) {
return;
}

setSchema(prevSchemaMap => {
if (!config?.id) {
if (!activeConfigId) {
return prevSchemaMap;
}

const updatedSchema = new Map(prevSchemaMap);
const schema = updatedSchema.get(config.id);
updatedSchema.set(config.id, {
const schema = updatedSchema.get(activeConfigId);
updatedSchema.set(activeConfigId, {
// Update prefixes does not affect to sync last update date
lastUpdate: schema?.lastUpdate,
vertices: schema?.vertices || [],
Expand All @@ -40,11 +44,11 @@ const usePrefixesUpdater = () => {
return updatedSchema;
});

const oldPrefixesSize = config?.schema?.prefixes?.length || 0;
const newPrefixesSize = genPrefixes.length || 0;
const oldPrefixesSize = existingPrefixes?.length ?? 0;
const newPrefixesSize = genPrefixes.length;
if (
genPrefixes.length &&
config?.schema?.prefixes?.length !== genPrefixes.length
existingPrefixes?.length !== genPrefixes.length
) {
const addedCount = newPrefixesSize - oldPrefixesSize;
enqueueNotification({
Expand All @@ -58,13 +62,7 @@ const usePrefixesUpdater = () => {
});
}
},
[
config?.id,
config?.connection?.queryEngine,
config?.schema?.prefixes,
enqueueNotification,
setSchema,
]
[supportsPrefixes, existingPrefixes, setSchema, activeConfigId, enqueueNotification]
);
};

Expand Down

0 comments on commit 364cbf5

Please sign in to comment.