Skip to content
Merged
Show file tree
Hide file tree
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
38 changes: 21 additions & 17 deletions vesta/vesta_ui/src/components/project-explorer/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,32 +98,36 @@ export function ProjectExplorerContextProvider({projectData, children}:{
const updateFilterItemSet = React.useCallback(
(filterItemSet: FilterSet) => {
setState( (prevState) => ({ ...prevState, filterItemSet }) );
}, [ state ]
}, [ ]
)

const updateFilterItems = React.useCallback(
(filterName: string, filterItems: FilterItem['value'][]|null) => {
let newState = { ...state };
newState.filterItemSet = {
...state.filterItemSet,
[ filterName ]: filterItems
}
setState(prevState => {
let newState = { ...prevState };
newState.filterItemSet = {
...prevState.filterItemSet,
[ filterName ]: filterItems
}

if (!filterItems || filterItems.length == 0) {
delete newState.filterItemSet[filterName];
}
setState(newState);
}, [ state ]
if (!filterItems || filterItems.length == 0) {
delete newState.filterItemSet[filterName];
}
return newState
});
}, []
);

const clearFilterItems = React.useCallback(
() => {
let newState = { ...state };
newState.filterItemSet = {
...defaultProjectExplorerState.filterItemSet
}
setState(newState);
}, [ state ]
setState(prevState => {
let newState = { ...prevState };
newState.filterItemSet = {
...defaultProjectExplorerState.filterItemSet
}
return newState
});
}, [ ]
);

const filteredProjectData = projectData.filter(
Expand Down
22 changes: 8 additions & 14 deletions vesta/vesta_ui/src/components/project-explorer/filter-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,11 @@ const Filter = ({title, highlight, children}:{

type FilterFunction = (filterItem:FilterItem['value'], project:Project, matchAllFilters:boolean) => boolean;

const BasicFilter = ({title, filter, items, render, id}:{
const BasicFilter = ({title, filter, items, render}:{
title: string;
items: (p:Project) => any;
filter: FilterFunction,
render: (params:any) => any;
id: (item:FilterItem['value']) => any;
}) => {
const {
state: { projectData, filters, filterItemSet },
Expand Down Expand Up @@ -203,8 +202,8 @@ const BasicFilter = ({title, filter, items, render, id}:{
};

const handleClickRemoveFilterItem = React.useCallback(
(filterItem:FilterItem['value']) => {
handleChangeFilterItems(filterItems.filter((f:FilterItem['value']) => f !== filterItem))
(filterItem:string) => {
handleChangeFilterItems(filterItems.filter((f:string) => f !== filterItem))
}, [filterItemSet]
);

Expand All @@ -216,7 +215,7 @@ const BasicFilter = ({title, filter, items, render, id}:{
icon={searchDarkIcon}
options={itemNames}
// @ts-ignore
onChange={(_, value:FilterItem['value'][] | null, reason) => {
onChange={(_, value:string[] | null, reason) => {
if (reason === 'removeOption') return;
handleChangeFilterItems(value);
}}
Expand All @@ -241,10 +240,10 @@ const BasicFilter = ({title, filter, items, render, id}:{
pt: '16px'
}}
>
{filterItems.map(((item:FilterItem['value']) => (
{filterItems.map(((item:string) => (
<FilterPill
key={id(item)}
label={id(item)}
key={item}
label={item}
removeable
onClickRemove={() => handleClickRemoveFilterItem(item)}
/>
Expand Down Expand Up @@ -305,8 +304,7 @@ const InvestigatorsFilter = () => {
variant='filled'
/>
)
}
id={ (pi:FilterItem['value']) => (pi as PrincipalInvestigator).name }/>
} />
}

const DEFAULT_RANGE=[0,500];
Expand All @@ -324,7 +322,6 @@ const DataTypesFilter = () => {
render={
projectItems => (params:any) => <Typography variant='pBodyMediumWt' key={params.option}>{params.option}</Typography>
}
id={ (item:FilterItem['value']) => item as ProjectDataType }
/>
}

Expand All @@ -342,7 +339,6 @@ const ThemeFilter = () => {
<Typography variant='pMedium'>{projectItems[params.option].name}</Typography>
)
}
id={ (item:FilterItem['value']) => (item as ThemeData).name }
/>
}

Expand Down Expand Up @@ -403,7 +399,6 @@ const TypeFilter = () => {
<Typography variant='pMedium'>{params.option}</Typography>
)
}
id={ (item:FilterItem['value']) => item }
/>
}

Expand All @@ -421,7 +416,6 @@ const PhaseFilter = () => {
<Typography variant='pMedium'>{params.option}</Typography>
)
}
id={ (item:FilterItem['value']) => item }
/>
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ function _ProjectExplorer({ }) {
}, []);

const handleChangeFilterItems = React.useCallback(
([ filterItem, ...others ]: FilterItem[]) => {
if (!(filterItem.type in filterItemSet) || !filterItemSet[filterItem.type].includes(filterItem.value))
updateFilterItems(filterItem.type, (filterItemSet[filterItem.type] || []).concat(filterItem.value))
(filterItem: FilterItem) => {
if (!(filterItem.type in filterItemSet) || !filterItemSet[filterItem.type].includes(filterItem.label))
updateFilterItems(filterItem.type, (filterItemSet[filterItem.type] || []).concat(filterItem.label))
setCurrentPage(0)
}, [ filterItemSet, updateFilterItems ]
);
Expand Down Expand Up @@ -173,13 +173,13 @@ function _ProjectExplorer({ }) {
/>

<Autocomplete
multiple
icon={searchDarkIcon}
placeholder={searchPlaceholder}
options={[...searchOptions].sort((a, b) => a.type.localeCompare(b.type))}
showResultsOnEmpty={false}
// @ts-ignore
inputValue={inputValue}
value={null}
onInputChange={ (_, value: string, reason) => setInputValue(value) }
onKeyDown={
(e) => {
Expand All @@ -193,11 +193,12 @@ function _ProjectExplorer({ }) {
}
}
// @ts-ignore
onChange={(_, value: FilterItem[], reason) => {
onChange={(_, value: FilterItem, reason) => {
// disables removing options with backspace
if (reason === 'removeOption') return

handleChangeFilterItems(value)
setInputValue('');
}}
// @ts-ignore
getOptionKey={(option: FilterItem) => option.key}
Expand Down
Loading