-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Piotr Rudnicki
committed
Sep 10, 2024
1 parent
4fa77c2
commit c4694c8
Showing
8 changed files
with
219 additions
and
111 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
designer/client/src/components/toolbars/search/AdvancedSearchFilters.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import React from "react"; | ||
import { TextField, Button, Box, Typography } from "@mui/material"; | ||
|
||
const transformInput = (input: string, fieldName: string) => { | ||
return input === "" ? "" : `${fieldName}:(${input})`; | ||
}; | ||
|
||
function extractSimpleSearchQuery(text: string): string { | ||
const regex = /(\w+):\(([^)]*)\)/g; | ||
let match: RegExpExecArray | null; | ||
let lastIndex = 0; | ||
|
||
while ((match = regex.exec(text)) !== null) { | ||
lastIndex = regex.lastIndex; | ||
} | ||
|
||
const rest = text.slice(lastIndex).trim(); | ||
|
||
return rest; | ||
} | ||
|
||
export function AdvancedSearchFilters({ | ||
filter, | ||
setFilter, | ||
setCollapsedHandler, | ||
}: { | ||
filter: string; | ||
setFilter: React.Dispatch<React.SetStateAction<string>>; | ||
setCollapsedHandler: React.Dispatch<React.SetStateAction<boolean>>; | ||
}) { | ||
const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => { | ||
event.preventDefault(); | ||
|
||
const formData = new FormData(event.currentTarget); | ||
|
||
const transformedInputs = Array.from(formData.entries()) | ||
.map(([fieldName, fieldValue]) => { | ||
const input = (fieldValue as string) || ""; | ||
return transformInput(input, fieldName); | ||
}) | ||
.filter((input) => input !== ""); | ||
|
||
const finalText = transformedInputs.join(" ").trim() + " " + extractSimpleSearchQuery(filter); | ||
|
||
setFilter(finalText); | ||
}; | ||
|
||
const handleCancel = () => { | ||
setCollapsedHandler(false); | ||
}; | ||
|
||
return ( | ||
<Box | ||
component="form" | ||
onSubmit={handleSubmit} | ||
sx={{ | ||
display: "flex", | ||
flexDirection: "column", | ||
maxWidth: "300px", | ||
justifyContent: "center", | ||
alignItems: "center", | ||
}} | ||
> | ||
<Typography fontWeight="bold" sx={{ m: 1 }}> | ||
Advanced Search | ||
</Typography> | ||
<TextField sx={{ m: 1 }} size="small" label="id" name="id" /> | ||
<TextField size="small" sx={{ m: 1 }} label="paramValue" name="paramValue" /> | ||
<TextField size="small" sx={{ m: 1 }} label="paramName" name="paramName" /> | ||
<TextField size="small" sx={{ m: 1 }} label="outputValue" name="outputValue" /> | ||
<TextField size="small" sx={{ m: 1 }} label="description" name="description" /> | ||
<TextField size="small" sx={{ m: 1 }} label="type" name="type" /> | ||
<TextField size="small" sx={{ m: 1 }} label="edgeExpression" name="edgeExpression" /> | ||
<Box sx={{ display: "flex", flexDirection: "row", justifyContent: "space-between", width: "85%", mt: 1, mb: 1 }}> | ||
<Button sx={{ width: "45%" }} size="small" variant="outlined" onClick={handleCancel}> | ||
Cancel | ||
</Button> | ||
<Button variant="contained" size="small" sx={{ width: "45%" }} type="submit"> | ||
Submit | ||
</Button> | ||
</Box> | ||
</Box> | ||
); | ||
} |
15 changes: 13 additions & 2 deletions
15
designer/client/src/components/toolbars/search/SearchPanel.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.