-
Notifications
You must be signed in to change notification settings - Fork 233
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Make exact table search result auto show up (#1106)
* feat: Make exact table search result auto show up * do not let user double select * Mix exact match and user selected table together * also incorporate filters into logic
- Loading branch information
Showing
3 changed files
with
81 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { useShallowSelector } from 'hooks/redux/useShallowSelector'; | ||
import { useMemo } from 'react'; | ||
import { IStoreState } from 'redux/store/types'; | ||
|
||
export function useExactMatchTableId() { | ||
const { dataTables, searchString, searchFilters } = useShallowSelector( | ||
(state: IStoreState) => ({ | ||
dataTables: state.dataTableSearch.results, | ||
searchString: state.dataTableSearch.searchString, | ||
searchFilters: state.dataTableSearch.searchFilters, | ||
}) | ||
); | ||
|
||
const [searchStringSchema, searchStringTable] = useMemo(() => { | ||
const trimmedStr = searchString.trim(); | ||
const separatedStrs = trimmedStr.split('.'); | ||
|
||
if (separatedStrs.length > 2) { | ||
return [null, null]; | ||
} | ||
|
||
if (separatedStrs.length === 1) { | ||
return [searchFilters.schema, separatedStrs[0]]; | ||
} else if (separatedStrs.length === 2) { | ||
return separatedStrs; | ||
} | ||
}, [searchString, searchFilters]); | ||
|
||
const exactMatchTableId = useMemo(() => { | ||
if (!searchStringSchema || !searchStringTable) { | ||
return null; | ||
} | ||
|
||
return dataTables.find( | ||
(table) => | ||
table.name === searchStringTable && | ||
table.schema === searchStringSchema | ||
)?.id; | ||
}, [searchStringSchema, searchStringTable, dataTables]); | ||
|
||
return exactMatchTableId; | ||
} |