Set queryLabel after query on page first load
This commit is contained in:
@@ -12,6 +12,7 @@ const GraphLabels = () => {
|
|||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const label = useSettingsStore.use.queryLabel()
|
const label = useSettingsStore.use.queryLabel()
|
||||||
const allDatabaseLabels = useGraphStore.use.allDatabaseLabels()
|
const allDatabaseLabels = useGraphStore.use.allDatabaseLabels()
|
||||||
|
const labelsFetchAttempted = useGraphStore.use.labelsFetchAttempted()
|
||||||
|
|
||||||
// Remove initial label fetch effect as it's now handled by fetchGraph based on lastSuccessfulQueryLabel
|
// Remove initial label fetch effect as it's now handled by fetchGraph based on lastSuccessfulQueryLabel
|
||||||
|
|
||||||
@@ -56,22 +57,25 @@ const GraphLabels = () => {
|
|||||||
[getSearchEngine]
|
[getSearchEngine]
|
||||||
)
|
)
|
||||||
|
|
||||||
// Validate if current queryLabel exists in allDatabaseLabels
|
// Show queryLabel validation status
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Only update label when all conditions are met:
|
|
||||||
// 1. allDatabaseLabels is loaded (length > 1, as it has at least '*' by default)
|
if (labelsFetchAttempted) {
|
||||||
// 2. Current label is not the default '*'
|
if (allDatabaseLabels.length > 1) {
|
||||||
// 3. Current label doesn't exist in allDatabaseLabels
|
if (label && label !== '*' && !allDatabaseLabels.includes(label)) {
|
||||||
if (
|
console.log(`Label "${label}" not in available labels`);
|
||||||
allDatabaseLabels.length > 1 &&
|
// useSettingsStore.getState().setQueryLabel('*');
|
||||||
label &&
|
} else {
|
||||||
label !== '*' &&
|
console.log(`Label "${label}" is valid`);
|
||||||
!allDatabaseLabels.includes(label)
|
}
|
||||||
) {
|
} else if (allDatabaseLabels.length <= 1 && label && label !== '*') {
|
||||||
console.log(`Label "${label}" not found in available labels, resetting to default`);
|
console.log('Available labels list is empty');
|
||||||
useSettingsStore.getState().setQueryLabel('*');
|
// useSettingsStore.getState().setQueryLabel('');
|
||||||
|
}
|
||||||
|
useGraphStore.getState().setLabelsFetchAttempted(false)
|
||||||
}
|
}
|
||||||
}, [allDatabaseLabels, label]);
|
|
||||||
|
}, [allDatabaseLabels, label, labelsFetchAttempted]);
|
||||||
|
|
||||||
const handleRefresh = useCallback(() => {
|
const handleRefresh = useCallback(() => {
|
||||||
// Reset fetch status flags
|
// Reset fetch status flags
|
||||||
|
@@ -120,6 +120,10 @@ const fetchGraph = async (label: string, maxDepth: number, maxNodes: number) =>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Trigger GraphLabels component to check if the label is valid
|
||||||
|
// console.log('Setting labelsFetchAttempted to true');
|
||||||
|
useGraphStore.getState().setLabelsFetchAttempted(true)
|
||||||
|
|
||||||
// If label is empty, use default label '*'
|
// If label is empty, use default label '*'
|
||||||
const queryLabel = label || '*';
|
const queryLabel = label || '*';
|
||||||
|
|
||||||
@@ -339,6 +343,7 @@ const useLightrangeGraph = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Only fetch data when graphDataFetchAttempted is false (avoids re-fetching on vite dev mode)
|
// Only fetch data when graphDataFetchAttempted is false (avoids re-fetching on vite dev mode)
|
||||||
|
// GraphDataFetchAttempted must set to false when queryLabel is changed
|
||||||
if (!isFetching && !useGraphStore.getState().graphDataFetchAttempted) {
|
if (!isFetching && !useGraphStore.getState().graphDataFetchAttempted) {
|
||||||
// Set flags
|
// Set flags
|
||||||
fetchInProgressRef.current = true
|
fetchInProgressRef.current = true
|
||||||
@@ -445,6 +450,13 @@ const useLightrangeGraph = () => {
|
|||||||
state.setRawGraph(data);
|
state.setRawGraph(data);
|
||||||
state.setGraphIsEmpty(false);
|
state.setGraphIsEmpty(false);
|
||||||
|
|
||||||
|
// ensusre GraphLabels show the current label on first load
|
||||||
|
const lastSuccessfulQueryLabel = useGraphStore.getState().lastSuccessfulQueryLabel;
|
||||||
|
if (!lastSuccessfulQueryLabel){
|
||||||
|
useSettingsStore.getState().setQueryLabel('');
|
||||||
|
useSettingsStore.getState().setQueryLabel(queryLabel);
|
||||||
|
console.log('Set queryLabel after query on page first load');
|
||||||
|
}
|
||||||
// Update last successful query label
|
// Update last successful query label
|
||||||
state.setLastSuccessfulQueryLabel(currentQueryLabel);
|
state.setLastSuccessfulQueryLabel(currentQueryLabel);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user