Skip to content

Commit

Permalink
feat(frontend): add external filter
Browse files Browse the repository at this point in the history
  • Loading branch information
alice.juan committed Mar 27, 2024
1 parent f4add08 commit 6b1a5be
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 77 deletions.
28 changes: 21 additions & 7 deletions taxonomy-editor-frontend/src/pages/project/search/FiltersArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down Expand Up @@ -140,7 +144,17 @@ export const FiltersArea = ({
}
label="Root nodes"
/>
<ThreeOptionsSwitch filterValue={taxonomyScope} setFilterValue={setTaxonomyScope} options={{"in": {text:"IN", isNegated:true},"out":{text:"OUT",isNegated:false}}} setQ={setQ} keySearchTerm="external" setCurrentPage={setCurrentPage}/>
<ThreeOptionsSwitch
filterValue={taxonomyScope}
setFilterValue={setTaxonomyScope}
options={{
in: { text: "IN", isNegated: true },
out: { text: "OUT", isNegated: false },
}}
setQ={setQ}
keySearchTerm="external"
setCurrentPage={setCurrentPage}
/>
<MultipleSelectFilter
label="Translated into"
filterValue={chosenLanguagesCodes}
Expand Down
31 changes: 16 additions & 15 deletions taxonomy-editor-frontend/src/pages/project/search/SearchResults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,17 @@ import {
import { Dispatch, SetStateAction, useState } from "react";
import AddBoxIcon from "@mui/icons-material/AddBox";
import { useParams } from "react-router-dom";
import { NodeInfo } from "@/backend-types/types";

type AdvancedResearchResultsType = {
nodeIds: string[];
nodeInfos: NodeInfo[];
nodeCount: number | undefined;
currentPage: number;
setCurrentPage: Dispatch<SetStateAction<number>>;
};

export const AdvancedResearchResults = ({
nodeIds,
nodeInfos,
nodeCount = 0,
currentPage,
setCurrentPage,
Expand Down Expand Up @@ -68,26 +69,26 @@ export const AdvancedResearchResults = ({
<Table>
<TableHead>
<TableRow>
<Stack direction="row" alignItems="center">
<TableCell align="left">
<TableCell align="left">
<Stack direction="row" alignItems="center">
<Typography variant="h6">Nodes</Typography>
</TableCell>
<IconButton
sx={{ ml: 1, color: greyHexCode }}
onClick={() => {
setOpenNewNodeDialog(true);
}}
>
<AddBoxIcon />
</IconButton>
</Stack>
<IconButton
sx={{ ml: 1, color: greyHexCode }}
onClick={() => {
setOpenNewNodeDialog(true);
}}
>
<AddBoxIcon />
</IconButton>
</Stack>
</TableCell>
<TableCell align="left">
<Typography variant="h6">Action</Typography>
</TableCell>
</TableRow>
</TableHead>
<NodesTableBody
nodeIds={nodeIds ?? []}
nodeInfos={nodeInfos ?? []}
taxonomyName={taxonomyName ?? ""}
branchName={branchName ?? ""}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -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<SetStateAction<string>>,
options: {[key: string]: { text: string; isNegated: boolean}};
setQ: Dispatch<SetStateAction<string>>;
keySearchTerm: string;
setCurrentPage: Dispatch<SetStateAction<number>>;
}

export const ThreeOptionsSwitch = ({filterValue, setFilterValue, options, setQ, keySearchTerm, setCurrentPage}:ThreeOptionsSwitchType) => {
filterValue: string;
setFilterValue: Dispatch<SetStateAction<string>>;
options: { [key: string]: { text: string; isNegated: boolean } };
setQ: Dispatch<SetStateAction<string>>;
keySearchTerm: string;
setCurrentPage: Dispatch<SetStateAction<number>>;
};

const handleChange = (
event: React.MouseEvent<HTMLElement>,
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 (
<div style={{ display: 'flex', flexDirection: 'column' }}>
<Typography variant="subtitle1" gutterBottom sx={{mb:0, m:"8px", color:"#341100"}}>
Taxonomy
</Typography>
<ToggleButtonGroup
sx={toggleTheme}
value={filterValue}
exclusive
onChange={handleChange}
aria-label="Platform"
>
{Object.entries(options).map(([value,option]) => (
<ToggleButton key={value} value={value} sx={{height:"2em"}}>{option.text}</ToggleButton>
))}
</ToggleButtonGroup>
</div>
)
}
export const ThreeOptionsSwitch = ({
filterValue,
setFilterValue,
options,
setQ,
keySearchTerm,
setCurrentPage,
}: ThreeOptionsSwitchType) => {
const handleChange = (
event: React.MouseEvent<HTMLElement>,
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 (
<div style={{ display: "flex", flexDirection: "column" }}>
<Typography
variant="subtitle1"
gutterBottom
sx={{ mb: 0, m: "8px", color: "#341100" }}
>
Taxonomy
</Typography>
<ToggleButtonGroup
sx={toggleTheme}
value={filterValue}
exclusive
onChange={handleChange}
aria-label="Platform"
>
{Object.entries(options).map(([value, option]) => (
<ToggleButton key={value} value={value} sx={{ height: "2em" }}>
{option.text}
</ToggleButton>
))}
</ToggleButtonGroup>
</div>
);
};
7 changes: 6 additions & 1 deletion taxonomy-editor-frontend/src/pages/project/search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ export const AdvancedResearchForm = () => {
filters={entryNodeSearchResult?.filters ?? []}
/>
<AdvancedResearchResults
nodeIds={entryNodeSearchResult?.nodes.map((node) => node.id) ?? []}
nodeInfos={
entryNodeSearchResult?.nodes.map((node) => ({
id: node.id,
is_external: node.isExternal,
})) ?? []
}
nodeCount={entryNodeSearchResult?.nodeCount}
currentPage={currentPage}
setCurrentPage={setCurrentPage}
Expand Down

0 comments on commit 6b1a5be

Please sign in to comment.