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

Enchancing the Structure search #1709

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all 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 @@ -21,25 +21,30 @@ export default function useStructure() {
const [datasetFieldFieldsCount] = useAtom(datasetFieldFieldsCountAtom);
const [datasetVersions] = useAtom(datasetVersionsAtom);

// Create a filtered dataset structure based on the search query
const filteredDatasetStructureRoot = useMemo(() => {
if (!searchQuery) return datasetStructureRoot;
return datasetStructureRoot.filter(item =>
item.name.toLowerCase().includes(searchQuery.toLowerCase()) ||
item.internalName?.toLowerCase().includes(searchQuery.toLowerCase())
);
}, [searchQuery, datasetStructureRoot]);

const idxToScroll = useMemo(
() => datasetStructureRoot.findIndex(field => field.id === selectedFieldId),
[selectedFieldId, datasetStructureRoot]
() =>
filteredDatasetStructureRoot.findIndex(
field => field.id === selectedFieldId
),
[selectedFieldId, filteredDatasetStructureRoot]
);

// Update the search query state
const handleSearch = useCallback(
(query: string) => {
const itemIdx = datasetStructureRoot?.findIndex(
item =>
item.name.toLowerCase().includes(query.toLowerCase()) ||
item.internalName?.toLowerCase().includes(query.toLowerCase())
);

if (itemIdx !== undefined && itemIdx > -1) {
setSelectedFieldId(datasetStructureRoot?.[itemIdx].id);
setIsSearchUpdated(prev => !prev);
}
setSearchQuery(query);
setIsSearchUpdated(prev => !prev);
},
[datasetStructureRoot]
[setSearchQuery, setIsSearchUpdated]
);

return useMemo(
Expand All @@ -51,7 +56,8 @@ export default function useStructure() {
isSearchUpdated,
setIsSearchUpdated,
handleSearch,
datasetStructureRoot,
// filtered dataset structure
datasetStructureRoot: filteredDatasetStructureRoot,
idxToScroll,
datasetFieldRowsCount,
datasetFieldTypesCount,
Expand All @@ -63,12 +69,12 @@ export default function useStructure() {
selectedFieldId,
isSearchUpdated,
handleSearch,
datasetStructureRoot,
filteredDatasetStructureRoot,
idxToScroll,
datasetFieldRowsCount,
datasetFieldTypesCount,
datasetFieldFieldsCount,
datasetVersions,
]
);
}
}
Loading