From b31afd11684d5cb6b7b05e8c5cb050d97b3a7bac Mon Sep 17 00:00:00 2001 From: jasquat Date: Tue, 1 Nov 2022 17:00:59 -0400 Subject: [PATCH] filter is working for status and process model w/ burnettk --- .../src/routes/ProcessInstanceList.tsx | 204 +++++++----------- 1 file changed, 74 insertions(+), 130 deletions(-) diff --git a/spiffworkflow-frontend/src/routes/ProcessInstanceList.tsx b/spiffworkflow-frontend/src/routes/ProcessInstanceList.tsx index 498ca9168..b6f87262a 100644 --- a/spiffworkflow-frontend/src/routes/ProcessInstanceList.tsx +++ b/spiffworkflow-frontend/src/routes/ProcessInstanceList.tsx @@ -24,7 +24,6 @@ import { InputGroup } from 'react-bootstrap'; // @ts-expect-error TS(7016) FIXME: Could not find a declaration file for module 'reac... Remove this comment to see the full error message import DatePicker from 'react-datepicker'; import { Typeahead } from 'react-bootstrap-typeahead'; -import { Option } from 'react-bootstrap-typeahead/types/types'; import { PROCESS_STATUSES, DATE_FORMAT } from '../config'; import { convertDateToSeconds, @@ -61,10 +60,11 @@ export default function ProcessInstanceList() { const setErrorMessage = (useContext as any)(ErrorContext)[1]; - const [processStatusSelectionOptions, setProcessStatusSelectionOptions] = - useState([]); + const [processStatusAllOptions, setProcessStatusAllOptions] = useState( + [] + ); const [processStatusSelection, setProcessStatusSelection] = useState< - Option[] + string[] >([]); const [processModelAvailableItems, setProcessModelAvailableItems] = useState< ProcessModel[] @@ -72,9 +72,8 @@ export default function ProcessInstanceList() { const [processModelFilteredItems, setProcessModelFilteredItems] = useState< ProcessModel[] >([]); - const [processModelSelection, setProcessModelSelection] = useState( - [] - ); + const [processModelSelection, setProcessModelSelection] = + useState(null); const parametersToAlwaysFilterBy = useMemo(() => { return { @@ -138,25 +137,25 @@ export default function ProcessInstanceList() { const label = `${item.process_group_id}/${item.id}`; Object.assign(item, { label }); if (label === processModelFullIdentifier) { - setProcessModelSelection([item]); + setProcessModelSelection(item); } return item; }); setProcessModelAvailableItems(selectionArray); setProcessModelFilteredItems(selectionArray); - const processStatusSelectedArray: Option[] = []; - const processStatusSelectionArray = PROCESS_STATUSES.map( + const processStatusSelectedArray: string[] = []; + const processStatusAllOptionsArray = PROCESS_STATUSES.map( (processStatusOption: any) => { const regex = new RegExp(`\\b${processStatusOption}\\b`); if ((searchParams.get('process_status') || '').match(regex)) { - processStatusSelectedArray.push({ label: processStatusOption }); + processStatusSelectedArray.push(processStatusOption); } - return { label: processStatusOption }; + return processStatusOption; } ); setProcessStatusSelection(processStatusSelectedArray); - setProcessStatusSelectionOptions(processStatusSelectionArray); + setProcessStatusAllOptions(processStatusAllOptionsArray); getProcessInstances(); } @@ -191,7 +190,7 @@ export default function ProcessInstanceList() { } }; - const handleFilter = (event: any) => { + const applyFilter = (event: any) => { event.preventDefault(); const { page, perPage } = getPageInfoFromSearchParams(searchParams); let queryParamString = `per_page=${perPage}&page=${page}`; @@ -226,16 +225,11 @@ export default function ProcessInstanceList() { queryParamString += `&end_till=${endTill}`; } if (processStatusSelection.length > 0) { - const processStatusSelectionString = processStatusSelection.map( - (pss: any) => { - return pss.label; - } - ); - queryParamString += `&process_status=${processStatusSelectionString}`; + queryParamString += `&process_status=${processStatusSelection}`; } - if (processModelSelection.length > 0) { - const currentProcessModel: any = processModelSelection[0]; - queryParamString += `&process_group_identifier=${currentProcessModel.process_group_id}&process_model_identifier=${currentProcessModel.id}`; + + if (processModelSelection) { + queryParamString += `&process_group_identifier=${processModelSelection.process_group_id}&process_model_identifier=${processModelSelection.id}`; } setErrorMessage(null); @@ -294,65 +288,6 @@ export default function ProcessInstanceList() { return queryParamString; }; - const processModelSearch = () => { - return ( - - - - Process Model:{' '} - - - - - ); - }; - - const processStatusSearch = () => { - // return ( - // - // - // - // Process Status:{' '} - // - // - // - // - // ); - return ( - { - return item.label || ''; - }} - selectionFeedback="top-after-reopen" - /> - ); - }; const shouldFilterProcessModel = (options: any) => { const processModel: ProcessModel = options.item; const { inputValue } = options; @@ -363,6 +298,54 @@ export default function ProcessInstanceList() { ); }; + const processModelSearch = () => { + return ( + + setProcessModelSelection(selection.selectedItem) + } + id="process-model-select" + items={processModelFilteredItems} + itemToString={(processModel: ProcessModel) => { + if (processModel) { + return `${processModel.process_group_id}/${ + processModel.id + } (${truncateString(processModel.display_name, 20)})`; + } + return null; + }} + shouldFilterItem={shouldFilterProcessModel} + placeholder="Choose a process model" + titleText="Process model" + selectedItem={processModelSelection} + /> + ); + }; + + const processStatusSearch = () => { + return ( + { + setProcessStatusSelection(selection.selectedItems); + }} + itemToString={(item: any) => { + return item || ''; + }} + selectionFeedback="top-after-reopen" + selectedItems={processStatusSelection} + /> + ); + }; + + const clearFilters = () => { + setProcessModelSelection(null); + setProcessStatusSelection([]); + }; + const filterOptions = () => { const { page, perPage } = getPageInfoFromSearchParams(searchParams); // return ( @@ -408,64 +391,25 @@ export default function ProcessInstanceList() { // // // ); - // return ( - // - // - // Hello1 - // - // - // Hello2 - // - // - // ); - // return ( - // - // - // - // Span 25% - // - // - // Span 25% - // - // - // Span 25% - // - // - // Span 25% - // - // - // - // ); return ( <> - - { - if (processModel) { - return `${processModel.process_group_id}/${ - processModel.id - } (${truncateString(processModel.display_name, 20)})`; - } - return null; - }} - shouldFilterItem={shouldFilterProcessModel} - placeholder="Process Model" - titleText="Process model" - /> - + {processModelSearch()} {processStatusSearch()} - - +