From 6b1a5bea899b542872b4864169837175e0fa4bf5 Mon Sep 17 00:00:00 2001 From: "alice.juan" Date: Wed, 27 Mar 2024 08:55:27 +0100 Subject: [PATCH] feat(frontend): add external filter --- .../src/pages/project/search/FiltersArea.tsx | 28 +++- .../pages/project/search/SearchResults.tsx | 31 ++--- .../project/search/ThreeOptionsSwitch.tsx | 123 ++++++++++-------- .../src/pages/project/search/index.tsx | 7 +- 4 files changed, 112 insertions(+), 77 deletions(-) diff --git a/taxonomy-editor-frontend/src/pages/project/search/FiltersArea.tsx b/taxonomy-editor-frontend/src/pages/project/search/FiltersArea.tsx index 27199424..f4d5a01f 100644 --- a/taxonomy-editor-frontend/src/pages/project/search/FiltersArea.tsx +++ b/taxonomy-editor-frontend/src/pages/project/search/FiltersArea.tsx @@ -61,12 +61,16 @@ export const FiltersArea = ({ for (const filter of updatedFilters) { switch (filter.filterType) { case "is": - if (filter.filterValue === "root") { - filtersStates.isRootNodesChecked = true; - } else if (filter.filterValue === "external") { - filtersStates.taxonomyScopeMode = "out"; - } else if (filter.filterValue === "not:external") { - filtersStates.taxonomyScopeMode = "in"; + switch (filter.filterValue) { + case "root": + filtersStates.isRootNodesChecked = true; + break; + case "external": + filtersStates.taxonomyScopeMode = "out"; + break; + case "not:external": + filtersStates.taxonomyScopeMode = "in"; + break; } break; case "language": @@ -140,7 +144,17 @@ export const FiltersArea = ({ } label="Root nodes" /> - + >; }; export const AdvancedResearchResults = ({ - nodeIds, + nodeInfos, nodeCount = 0, currentPage, setCurrentPage, @@ -68,26 +69,26 @@ export const AdvancedResearchResults = ({ - - + + Nodes - - { - setOpenNewNodeDialog(true); - }} - > - - - + { + setOpenNewNodeDialog(true); + }} + > + + + + Action diff --git a/taxonomy-editor-frontend/src/pages/project/search/ThreeOptionsSwitch.tsx b/taxonomy-editor-frontend/src/pages/project/search/ThreeOptionsSwitch.tsx index 727b9965..454aac53 100644 --- a/taxonomy-editor-frontend/src/pages/project/search/ThreeOptionsSwitch.tsx +++ b/taxonomy-editor-frontend/src/pages/project/search/ThreeOptionsSwitch.tsx @@ -1,61 +1,76 @@ -import { ToggleButton, ToggleButtonGroup, Typography } from "@mui/material" +import { ToggleButton, ToggleButtonGroup, Typography } from "@mui/material"; import React, { Dispatch, SetStateAction } from "react"; - const toggleTheme = { - "& .MuiToggleButton-root": { +const toggleTheme = { + "& .MuiToggleButton-root": { + color: "#341100", + "&.Mui-selected": { color: "#341100", - "&.Mui-selected": { - color: "#341100", - }, - borderColor: "rgba(0, 0, 0, 0.23)", }, - }; + borderColor: "rgba(0, 0, 0, 0.23)", + }, +}; type ThreeOptionsSwitchType = { - filterValue: string, - setFilterValue: Dispatch>, - options: {[key: string]: { text: string; isNegated: boolean}}; - setQ: Dispatch>; - keySearchTerm: string; - setCurrentPage: Dispatch>; -} - -export const ThreeOptionsSwitch = ({filterValue, setFilterValue, options, setQ, keySearchTerm, setCurrentPage}:ThreeOptionsSwitchType) => { + filterValue: string; + setFilterValue: Dispatch>; + options: { [key: string]: { text: string; isNegated: boolean } }; + setQ: Dispatch>; + keySearchTerm: string; + setCurrentPage: Dispatch>; +}; - const handleChange = ( - event: React.MouseEvent, - newValue: string, - ) => { - setFilterValue(newValue); - setCurrentPage(1); - let newFilterExpression=""; - if (options[newValue].isNegated) { - newFilterExpression = ` is:not:${keySearchTerm}`; - } else { - newFilterExpression = ` is:${keySearchTerm}`; - } - setQ((prevQ) => { - prevQ = prevQ.replace(`is:not:${keySearchTerm}`,""); - prevQ = prevQ.replace(`is:${keySearchTerm}`,""); - return prevQ+newFilterExpression; - }); - }; - return ( -
- - Taxonomy - - - {Object.entries(options).map(([value,option]) => ( - {option.text} - ))} - -
- ) -} \ No newline at end of file +export const ThreeOptionsSwitch = ({ + filterValue, + setFilterValue, + options, + setQ, + keySearchTerm, + setCurrentPage, +}: ThreeOptionsSwitchType) => { + const handleChange = ( + event: React.MouseEvent, + newValue: string + ) => { + setFilterValue(newValue); + setCurrentPage(1); + let newFilterExpression = ""; + if (newValue) { + // one of the options is selected + if (options[newValue].isNegated) { + newFilterExpression = ` is:not:${keySearchTerm}`; + } else { + newFilterExpression = ` is:${keySearchTerm}`; + } + } + setQ((prevQ) => { + prevQ = prevQ.replace(`is:not:${keySearchTerm}`, ""); + prevQ = prevQ.replace(`is:${keySearchTerm}`, ""); + return prevQ + newFilterExpression; + }); + }; + return ( +
+ + Taxonomy + + + {Object.entries(options).map(([value, option]) => ( + + {option.text} + + ))} + +
+ ); +}; diff --git a/taxonomy-editor-frontend/src/pages/project/search/index.tsx b/taxonomy-editor-frontend/src/pages/project/search/index.tsx index a8912f3d..ba2c2dfd 100644 --- a/taxonomy-editor-frontend/src/pages/project/search/index.tsx +++ b/taxonomy-editor-frontend/src/pages/project/search/index.tsx @@ -62,7 +62,12 @@ export const AdvancedResearchForm = () => { filters={entryNodeSearchResult?.filters ?? []} /> node.id) ?? []} + nodeInfos={ + entryNodeSearchResult?.nodes.map((node) => ({ + id: node.id, + is_external: node.isExternal, + })) ?? [] + } nodeCount={entryNodeSearchResult?.nodeCount} currentPage={currentPage} setCurrentPage={setCurrentPage}