Skip to content

Commit

Permalink
f-4096/update: enable type operator in type filter in data explorer
Browse files Browse the repository at this point in the history
  • Loading branch information
bilalesi committed Aug 15, 2023
1 parent 949c96f commit 01df800
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/shared/canvas/MyData/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { MenuProps } from 'antd';
import { TType } from '../../molecules/TypeSelector/types';
import { TType, TTypeOperator } from '../../molecules/TypeSelector/types';

export type TIssuer = 'createdBy' | 'updatedBy';
export type TDateField = 'createdAt' | 'updatedAt';
Expand All @@ -18,7 +18,7 @@ export type TFilterOptions = {
sort: string[];
locate: boolean;
issuer: TIssuer;
typeOperator: 'AND' | 'OR';
typeOperator: TTypeOperator;
};
export type TCurrentDate = Pick<
TFilterOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const MyDataHeaderFilters = ({
<DateFieldSelector {...{ dateField, setFilterOptions }} />
<DateSelector {...{ dateField, setFilterOptions }} />
<TypeSelector
key={'my-data-type-selector'}
{...{
types,
typeOperator,
Expand Down
11 changes: 7 additions & 4 deletions src/shared/molecules/TypeSelector/TypeSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ const TypeSelector = ({
project,
types,
styles,
typeOperator,
updateOptions,
defaultValue,
afterUpdate,
typeOperator = 'OR',
}: TTypeSelectorProps) => {
const nexus = useNexusContext();
const originTypes = useRef<TType[]>([]);
Expand Down Expand Up @@ -161,15 +161,17 @@ const TypeSelector = ({
const onDeselectTypesChange = (value: any) => {
const newTypes = types?.filter((item: TType) => item.value !== value);
updateOptions({
typeOperator,
types: newTypes,
});
afterUpdate?.(newTypes);
afterUpdate?.(typeOperator, newTypes);
};
const onClearTypesChange = () => {
updateOptions({
typeOperator,
types: [],
});
afterUpdate?.([]);
afterUpdate?.('OR', []);
};

const handleOnCheckType = (
Expand All @@ -182,9 +184,10 @@ const TypeSelector = ({
? types.filter((item: TType) => item.value !== type.value)
: [...(types ? types : []), type];
updateOptions({
typeOperator,
types: newTypes,
});
afterUpdate?.(newTypes);
afterUpdate?.(typeOperator, newTypes);
};
const renderedTypes = typeSearchValue ? typesOptionsArray : typeOptions ?? [];
const onTypeOperatorChange = ({ target: { value } }: RadioChangeEvent) => {
Expand Down
7 changes: 4 additions & 3 deletions src/shared/molecules/TypeSelector/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,17 @@ type TTypeSelectorStyle = {
container?: React.CSSProperties;
selector?: React.CSSProperties;
};
export type TTypeOperator = 'AND' | 'OR';
export type TTypeSelectorProps = {
org?: string;
project?: string;
types?: TType[];
styles?: TTypeSelectorStyle;
defaultValue?: TType[];
typeOperator?: 'AND' | 'OR';
typeOperator: TTypeOperator;
updateOptions(options: {
types?: TType[];
typeOperator?: 'AND' | 'OR';
typeOperator: TTypeOperator;
}): void;
afterUpdate?: (types?: TType[]) => void;
afterUpdate?: (typeOperator: TTypeOperator, types?: TType[]) => void;
};
22 changes: 16 additions & 6 deletions src/subapps/dataExplorer/DataExplorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@ import {
sortColumns,
usePaginatedExpandedResources,
} from './DataExplorerUtils';
import {
TType,
TTypeOperator,
} from '../../shared/molecules/TypeSelector/types';
import TypeSelector from '../../shared/molecules/TypeSelector/TypeSelector';
import { ProjectSelector } from './ProjectSelector';
import { PredicateSelector } from './PredicateSelector';
import { DatasetCount } from './DatasetCount';
import { DataExplorerCollapsibleHeader } from './DataExplorerCollapsibleHeader';
import DateExplorerScrollArrows from './DateExplorerScrollArrows';
import { RootState } from '../../shared/store/reducers';
import { UpdateDataExplorerOrigin } from '../../shared/store/reducers/data-explorer';
import { TType } from '../../shared/molecules/TypeSelector/types';
import ColumnsSelector, { TColumn } from './ColumnsSelector';
import TypeSelector from '../../shared/molecules/TypeSelector/TypeSelector';
import './styles.less';

const $update = <T,>(
Expand All @@ -42,6 +43,7 @@ export interface DataExplorerConfiguration {
selectedPath: string | null;
deprecated: boolean;
columns: TColumn[];
typeOperator: TTypeOperator;
}
const SELECTED_COLUMNS_CACHED_KEY = 'data-explorer-selected-columns';
const SELECTED_FILTERS_CACHED_KEY = 'data-explorer-selected-filters';
Expand Down Expand Up @@ -83,6 +85,7 @@ const getSelectedFiltersCached = () => {
showEmptyCells: parsed.showEmptyCells ?? true,
pageSize: parsed.pageSize ?? 50,
offset: parsed.offset ?? 0,
typeOperator: parsed.typeOperator ?? 'OR',
};
} catch (e) {
return null;
Expand Down Expand Up @@ -133,6 +136,7 @@ const DataExplorer: React.FC<{}> = () => {
selectedPath,
deprecated,
columns,
typeOperator,
},
updateTableConfiguration,
] = useReducer(
Expand All @@ -152,6 +156,7 @@ const DataExplorer: React.FC<{}> = () => {
selectedPath: null,
deprecated: false,
columns: [],
typeOperator: 'OR',
}
);

Expand All @@ -160,6 +165,7 @@ const DataExplorer: React.FC<{}> = () => {
offset,
orgAndProject,
deprecated,
typeOperator,
types: types?.map(t => t.value),
});

Expand Down Expand Up @@ -225,6 +231,7 @@ const DataExplorer: React.FC<{}> = () => {
: undefined,
types: selectedFilters.types,
deprecated: selectedFilters.deprecated ?? deprecated,
typeOperator: selectedFilters.typeOperator ?? typeOperator,
});
setShowMetadataColumns(
selectedFilters.showMetadata ?? showMetadataColumns
Expand Down Expand Up @@ -312,21 +319,24 @@ const DataExplorer: React.FC<{}> = () => {
}}
/>
<TypeSelector
key={'data-explorer-type-selector'}
defaultValue={types}
org={orgAndProject?.[0]}
project={orgAndProject?.[1]}
types={types}
typeOperator={typeOperator}
updateOptions={updateTableConfiguration}
styles={{
container: { width: '250px' },
selector: {
'--types-background-color': 'white',
} as React.CSSProperties,
}}
afterUpdate={types => {
updateTableConfiguration({ types });
afterUpdate={(typeOperator, types) => {
updateTableConfiguration({ types, typeOperator });
clearSelectedColumnsCached();
updateSelectedFiltersCached({
typeOperator,
types: types && types.length > 0 ? types : undefined,
});
}}
Expand Down
19 changes: 13 additions & 6 deletions src/subapps/dataExplorer/DataExplorerUtils.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
import { useEffect } from 'react';
import { Resource } from '@bbp/nexus-sdk';
import { useQuery } from 'react-query';
import { useNexusContext } from '@bbp/react-nexus';
import PromisePool from '@supercharge/promise-pool';
import { notification } from 'antd';
import { useQuery } from 'react-query';
import { makeOrgProjectTuple } from '../../shared/molecules/MyDataTable/MyDataTable';
import { isString } from 'lodash';
import { useEffect } from 'react';
import PromisePool from '@supercharge/promise-pool';
import { makeOrgProjectTuple } from '../../shared/molecules/MyDataTable/MyDataTable';
import { TTypeOperator } from '../../shared/molecules/TypeSelector/types';

export const usePaginatedExpandedResources = ({
pageSize,
offset,
orgAndProject,
deprecated,
types,
typeOperator,
}: PaginatedResourcesParams) => {
const nexus = useNexusContext();
return useQuery({
queryKey: ['data-explorer', { pageSize, offset, orgAndProject, types }],
queryKey: [
'data-explorer',
{ pageSize, offset, orgAndProject, types, typeOperator },
],
retry: false,
queryFn: async () => {
const resultWithPartialResources = await nexus.Resource.list(
Expand All @@ -25,8 +30,9 @@ export const usePaginatedExpandedResources = ({
{
deprecated,
// @ts-ignore
typeOperator,
// @ts-ignore
type: types,
typeOperator: 'or',
from: offset,
size: pageSize,
}
Expand Down Expand Up @@ -186,6 +192,7 @@ interface PaginatedResourcesParams {
orgAndProject?: string[];
deprecated: boolean;
types?: string[];
typeOperator: TTypeOperator;
}

export const useTimeoutMessage = ({
Expand Down

0 comments on commit 01df800

Please sign in to comment.