Skip to content

Commit

Permalink
autocomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotr Fałdrowicz authored and vder committed Dec 11, 2024
1 parent 3463881 commit 1e9f0a4
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Autocomplete, FormControl } from "@mui/material";
import { nodeInput } from "../graph/node-modal/NodeDetailsContent/NodeTableStyled";
import React from "react";

export const SearchLabeledAutocomplete = ({ children, name, values }) => {
return (
<FormControl sx={{ display: "flex", flexDirection: "column", m: 0, gap: 1, width: "100%" }}>
{children}
<Autocomplete
options={values}
className={nodeInput}
renderInput={(params) => (
<div ref={params.InputProps.ref}>
<input name={name} {...params.inputProps} placeholder="Type to search..." className={nodeInput} />
</div>
)}
/>
</FormControl>
);
};

SearchLabeledAutocomplete.displayName = "SearchLabeledAutocomplete";
13 changes: 4 additions & 9 deletions designer/client/src/components/sidePanels/SearchLabeledInput.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
import { forwardRef, PropsWithChildren } from "react";
import React, { PropsWithChildren } from "react";
import { FormControl } from "@mui/material";
import { nodeInput } from "../graph/node-modal/NodeDetailsContent/NodeTableStyled";
import React from "react";

export type SearchLabeledInputProps = PropsWithChildren<{
name: string;
}>;

export const SearchLabeledInput = forwardRef<HTMLInputElement, SearchLabeledInputProps>(({ children, ...props }, ref) => {
export const SearchLabeledInput = ({ children, ...props }) => {
return (
<FormControl sx={{ display: "flex", flexDirection: "column", m: 0, gap: 1, width: "100%" }}>
{children}
<input ref={ref} {...props} className={nodeInput} />
<input {...props} className={nodeInput} />
</FormControl>
);
});
};

SearchLabeledInput.displayName = "SearchLabeledInput";
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { Button, Box, Typography } from "@mui/material";
import { useTranslation } from "react-i18next";
import { SearchLabeledInput } from "../../sidePanels/SearchLabeledInput";
import { SearchLabel } from "../../sidePanels/SearchLabel";
import { resolveSearchQuery } from "./utils";
import { useNodeTypes, resolveSearchQuery } from "./utils";
import { SearchLabeledAutocomplete } from "../../sidePanels/SearchLabeledAutocomplete";

const transformInput = (input: string, fieldName: string) => {
return input === "" ? "" : `${fieldName}:(${input})`;
Expand Down Expand Up @@ -111,12 +112,12 @@ export function AdvancedSearchFilters({
<SearchLabeledInput name="paramValue">
<SearchLabel label={displayNames["paramValue"]} />
</SearchLabeledInput>
<SearchLabeledInput name="componentGroup">
<SearchLabeledAutocomplete name="componentGroup" values={useNodeTypes("componentGroup")}>
<SearchLabel label={displayNames["componentGroup"]} />
</SearchLabeledInput>
<SearchLabeledInput name="type">
</SearchLabeledAutocomplete>
<SearchLabeledAutocomplete name="type" values={useNodeTypes("type")}>
<SearchLabel label={displayNames["type"]} />
</SearchLabeledInput>
</SearchLabeledAutocomplete>
<SearchLabeledInput name="paramName">
<SearchLabel label={displayNames["paramName"]} />
</SearchLabeledInput>
Expand Down
19 changes: 16 additions & 3 deletions designer/client/src/components/toolbars/search/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Edge, NodeType } from "../../../types";
import { uniq } from "lodash";
import { isEqual, uniq } from "lodash";
import { useSelector } from "react-redux";
import { isEqual } from "lodash";
import { getScenario } from "../../../reducers/selectors/graph";
import NodeUtils from "../../graph/NodeUtils";
import { useMemo } from "react";
Expand Down Expand Up @@ -29,7 +28,7 @@ const fieldsSelectors: FilterSelector = [
},
{
name: "type",
selector: (node) => [node.nodeType, node.type, node.ref?.typ],
selector: (node) => [node.nodeType, node.ref?.typ, node.ref?.id],
},
{
name: "paramValue",
Expand Down Expand Up @@ -84,6 +83,20 @@ const findFieldsUsingSelectorWithName = (selectorName: string, filterValues: str
);
};

export function useNodeTypes(selectorName: string): string[] {
const { scenarioGraph } = useSelector(getScenario);
const allNodes = NodeUtils.nodesFromScenarioGraph(scenarioGraph);

return useMemo(() => {
const nodeSelector = fieldsSelectors.find((selector) => selector.name == selectorName)?.selector;
const partial = allNodes
.flatMap((node) => ensureArray(nodeSelector(node)).filter((item) => item !== undefined))
.map((selectorResult) => (typeof selectorResult === "string" ? selectorResult : selectorResult?.expression));

return uniq(partial);
}, [allNodes]);
}

export function useFilteredNodes(searchQuery: SearchQuery): {
groups: string[];
node: NodeType;
Expand Down

0 comments on commit 1e9f0a4

Please sign in to comment.