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

fix: schema filtering in table search modal #1348

Merged
merged 3 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions querybook/webapp/components/Search/SearchOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,7 @@ export const SearchOverview: React.FC<ISearchOverviewProps> = ({
<SearchSchemaSelect
updateSearchFilter={updateSearchFilter}
schema={searchFilters?.schema}
metastoreId={metastoreId}
/>
</div>
{queryMetastoreHasDataElements && (
Expand Down
38 changes: 20 additions & 18 deletions querybook/webapp/components/Search/SearchSchemaSelect.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import React, { useMemo, useCallback } from 'react';
import React, { useMemo, useCallback, useState } from 'react';
import AsyncSelect from 'react-select/async';
import { useSelector } from 'react-redux';
import { IStoreState } from 'redux/store/types';
import {
makeReactSelectStyle,
asyncReactSelectStyles,
Expand All @@ -10,6 +8,7 @@ import {
import { SearchSchemaResource } from 'resource/search';

interface ISearchSchemaSelectProps {
metastoreId: number;
schema?: string[];
updateSearchFilter: (key: string, value: string[]) => void;
}
Expand All @@ -22,10 +21,9 @@ const tableReactSelectStyle = makeReactSelectStyle(
export const SearchSchemaSelect: React.FC<ISearchSchemaSelectProps> = ({
updateSearchFilter,
schema,
metastoreId,
}) => {
const currentMetastoreId = useSelector(
(state: IStoreState) => state.environment.currentEnvironmentId
);
const [searchText, setSearchText] = useState('');

const handleUpdateSearchFilter = useCallback((option: IOptions<string>) => {
updateSearchFilter(
Expand All @@ -34,17 +32,20 @@ export const SearchSchemaSelect: React.FC<ISearchSchemaSelectProps> = ({
);
}, []);

const loadOptions = useCallback(async (value) => {
const searchRequest = await SearchSchemaResource.getMore({
metastore_id: currentMetastoreId,
name: value,
});
const loadOptions = useCallback(
async (value) => {
const searchRequest = await SearchSchemaResource.getMore({
metastore_id: metastoreId,
name: value,
});

return searchRequest.data.results.map((schema) => ({
label: schema.name,
value: schema.name,
}));
}, []);
return searchRequest.data.results.map((schema) => ({
label: schema.name,
value: schema.name,
}));
},
[metastoreId, schema]
);

const selectedSchemaItems = useMemo(
() =>
Expand All @@ -58,11 +59,12 @@ export const SearchSchemaSelect: React.FC<ISearchSchemaSelectProps> = ({
<AsyncSelect
styles={tableReactSelectStyle}
placeholder={'search schema name'}
value={selectedSchemaItems}
onChange={handleUpdateSearchFilter}
loadOptions={loadOptions}
defaultOptions={[]}
noOptionsMessage={() => 'No schema found.'}
inputValue={searchText}
onInputChange={(text) => setSearchText(text)}
adamstruck marked this conversation as resolved.
Show resolved Hide resolved
noOptionsMessage={() => (searchText ? 'No schema found.' : null)}
isMulti
/>
);
Expand Down