Skip to content

Commit

Permalink
f-4140/update: enable type operator in type filter in mydata page
Browse files Browse the repository at this point in the history
  • Loading branch information
bilalesi committed Aug 15, 2023
1 parent 2c944f4 commit 949c96f
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 12 deletions.
5 changes: 5 additions & 0 deletions src/shared/canvas/MyData/MyData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const HomeMyData: React.FC<{}> = () => {
locate,
issuer,
types,
typeOperator,
},
setFilterOptions,
] = React.useReducer(
Expand All @@ -51,6 +52,7 @@ const HomeMyData: React.FC<{}> = () => {
locate: false,
issuer: 'createdBy',
types: [],
typeOperator: 'OR',
}
);

Expand Down Expand Up @@ -88,13 +90,15 @@ const HomeMyData: React.FC<{}> = () => {
issuer,
date,
order,
typeOperator,
types: resourceTypes,
},
],
retry: false,
queryFn: () =>
nexus.Resource.list(undefined, undefined, {
size,
typeOperator,
from: offset,
[issuer]: issuerUri,
...(locate && query.trim().length
Expand Down Expand Up @@ -144,6 +148,7 @@ const HomeMyData: React.FC<{}> = () => {
locate,
issuer,
setFilterOptions,
typeOperator,
}}
/>
<MyDataTable
Expand Down
3 changes: 2 additions & 1 deletion src/shared/canvas/MyData/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export type TFilterOptions = {
sort: string[];
locate: boolean;
issuer: TIssuer;
typeOperator: 'AND' | 'OR';
};
export type TCurrentDate = Pick<
TFilterOptions,
Expand All @@ -34,7 +35,7 @@ export type TTitleProps = {
};
export type THeaderFilterProps = Pick<
THeaderProps,
'types' | 'dateField' | 'setFilterOptions'
'types' | 'dateField' | 'setFilterOptions' | 'typeOperator'
>;
export type THeaderTitleProps = Pick<
THeaderProps,
Expand Down
2 changes: 2 additions & 0 deletions src/shared/molecules/MyDataHeader/MyDataHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const MyDataHeader: React.FC<THeaderProps> = ({
setFilterOptions,
locate,
issuer,
typeOperator,
}) => {
return (
<div className="my-data-header">
Expand All @@ -32,6 +33,7 @@ const MyDataHeader: React.FC<THeaderProps> = ({
locate,
setFilterOptions,
issuer,
typeOperator,
}}
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const MyDataHeaderTitle = ({

const MyDataHeaderFilters = ({
types,
typeOperator,
dateField,
setFilterOptions,
}: THeaderFilterProps) => {
Expand All @@ -47,6 +48,7 @@ const MyDataHeaderFilters = ({
<TypeSelector
{...{
types,
typeOperator,
updateOptions: setFilterOptions,
styles: {
container: { width: '300px' },
Expand Down
41 changes: 31 additions & 10 deletions src/shared/molecules/TypeSelector/TypeSelector.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import React, { useCallback, useRef, useState, ReactElement } from 'react';
import { NexusClient } from '@bbp/nexus-sdk';
import { useNexusContext } from '@bbp/react-nexus';
import { Checkbox, Col, Input, Radio, Row, Select } from 'antd';
import {
Checkbox,
Col,
Input,
Radio,
RadioChangeEvent,
Row,
Select,
} from 'antd';
import { isString, startCase } from 'lodash';
import { useQuery } from 'react-query';
import { prettifyNumber } from '../../../utils/formatNumber';
Expand All @@ -15,6 +23,11 @@ import {
import isValidUrl from '../../../utils/validUrl';
import './style.less';

const typesOperatorOptions = [
{ label: 'AND', value: 'AND' },
{ label: 'OR', value: 'OR' },
];

const getTypesByAggregation = async ({
nexus,
orgLabel,
Expand Down Expand Up @@ -105,6 +118,7 @@ const TypeSelector = ({
project,
types,
styles,
typeOperator,
updateOptions,
defaultValue,
afterUpdate,
Expand Down Expand Up @@ -165,15 +179,19 @@ const TypeSelector = ({
e.preventDefault();
e.stopPropagation();
const newTypes = types?.find((item: TType) => item.value === type.value)
? []
: [type];
? types.filter((item: TType) => item.value !== type.value)
: [...(types ? types : []), type];
updateOptions({
types: newTypes,
});
afterUpdate?.(newTypes);
};
const renderedTypes = typeSearchValue ? typesOptionsArray : typeOptions ?? [];

const onTypeOperatorChange = ({ target: { value } }: RadioChangeEvent) => {
updateOptions({
typeOperator: value,
});
};
return (
<div className="types-selector" style={styles?.container}>
<div className="types-selector-wrapper">
Expand All @@ -197,12 +215,15 @@ const TypeSelector = ({
aria-label="type-filter"
dropdownRender={() => (
<>
<div className=''>
<label htmlFor="typeOperator">Select Type Operator</label>
<Radio.Group name='typeOperator'>
<Radio.Button value="AND">AND</Radio.Button>
<Radio.Button value="OR">OR</Radio.Button>
</Radio.Group>
<div className="type-operator-selector">
<div>Select Type Operator</div>
<Radio.Group
value={typeOperator}
optionType="default"
name="typeOperator"
options={typesOperatorOptions}
onChange={onTypeOperatorChange}
/>
</div>
<div className="types-selector-search-container">
<Input.Search
Expand Down
8 changes: 8 additions & 0 deletions src/shared/molecules/TypeSelector/style.less
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
&::placeholder {
color: @fusion-daybreak-10 !important;
}

.ant-select-selector {
background-color: var(--types-background-color) !important;
}
Expand All @@ -21,6 +22,13 @@
padding: 0 !important;
}

.type-operator-selector {
padding: 10px 5px;
display: flex;
flex-direction: column;
gap: 3px;
}

.types-selector-search-container {
padding: 10px 5px;
display: flex;
Expand Down
6 changes: 5 additions & 1 deletion src/shared/molecules/TypeSelector/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ export type TTypeSelectorProps = {
types?: TType[];
styles?: TTypeSelectorStyle;
defaultValue?: TType[];
updateOptions: (options: { types?: TType[] }) => void;
typeOperator?: 'AND' | 'OR';
updateOptions(options: {
types?: TType[];
typeOperator?: 'AND' | 'OR';
}): void;
afterUpdate?: (types?: TType[]) => void;
};

0 comments on commit 949c96f

Please sign in to comment.