Skip to content

Commit

Permalink
refactor: node string param component
Browse files Browse the repository at this point in the history
  • Loading branch information
yamankatby committed Apr 28, 2023
1 parent 9f0960b commit 7b261b6
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 50 deletions.
11 changes: 8 additions & 3 deletions src/components/Workflow/HttpTriggerNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ import {
NodeName,
NodeParam,
NodeParams,
NodeStringParam,
NodeToolbar,
} from "@src/components/Workflow";
import { useCallback, useState } from "react";

export default function HttpTriggerNode() {
const [name, setName] = useState("HTTP Trigger");
const [method, setMethod] = useState("GET");
const [path, setPath] = useState("/");

const [collapsed, setCollapsed] = useState(false);

Expand All @@ -32,14 +35,16 @@ export default function HttpTriggerNode() {
</NodeToolbar>
<NodeParams open={!collapsed}>
<NodeParam
name="Method"
label="Method"
tooltip="The HTTP method to listen for"
htmlFor="method"
/>
<NodeParam
name="Path"
<NodeStringParam
label="Path"
tooltip="The path to listen for"
htmlFor="path"
value={path}
onChange={setPath}
/>
</NodeParams>
</Node>
Expand Down
41 changes: 0 additions & 41 deletions src/components/Workflow/NodeParam.tsx

This file was deleted.

38 changes: 38 additions & 0 deletions src/components/Workflow/NodeParam/NodeParam.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Stack, Tooltip, Typography } from "@mui/material";
import { FC, PropsWithChildren } from "react";

export interface NodeParamProps {
htmlFor?: string;

label: string;

tooltip?: string;
}

const NodeParam: FC<PropsWithChildren<NodeParamProps>> = ({
htmlFor,
label,
tooltip,
children,
}) => {
return (
<Stack direction="row">
<Tooltip title={tooltip}>
<Typography
component="label"
htmlFor={htmlFor}
variant="caption"
flex={1}
overflow="hidden"
textOverflow="ellipsis"
sx={{ whiteSpace: "nowrap" }}
>
{label}
</Typography>
</Tooltip>
{children}
</Stack>
);
};

export default NodeParam;
33 changes: 33 additions & 0 deletions src/components/Workflow/NodeParam/NodeStringParam.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Box } from "@mui/material";
import NodeParam, { NodeParamProps } from "./NodeParam";

export interface NodeStringParamProps extends NodeParamProps {
value: string;

onChange: (value: string) => void;
}

export default function NodeStringParam({
htmlFor,
value,
onChange,
...rest
}: NodeStringParamProps) {
return (
<NodeParam htmlFor={htmlFor} {...rest}>
<Box
component="input"
id={htmlFor}
type="text"
value={value}
onChange={(e) => onChange(e.target.value)}
height={24}
width={140}
border={0}
borderRadius={1}
bgcolor="background.default"
sx={(theme) => ({ outlineColor: theme.palette.primary.main })}
/>
</NodeParam>
);
}
4 changes: 2 additions & 2 deletions src/components/Workflow/OpenApiNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { map } from "lodash-es";
import { SVGProps, useMemo, useState } from "react";
import Node from "./Node";
import NodeName from "./NodeName";
import NodeParam from "./NodeParam";
import NodeParam from "./NodeParam/NodeParam";
import NodeToolbar from "./NodeToolbar";

export interface OpenApiNodeProps {
Expand Down Expand Up @@ -86,7 +86,7 @@ const Params = ({ meth, collapsed }: any) => {
<NodeParam
key={param.name}
htmlFor={`${meth.operationId}_${param.name}`}
name={param.name}
label={param.name}
tooltip={param.description}
/>
))}
Expand Down
4 changes: 2 additions & 2 deletions src/components/Workflow/ScriptNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { map } from "lodash-es";
import { FC, SVGProps, useCallback, useEffect, useState } from "react";
import Node from "./Node";
import NodeName from "./NodeName";
import NodeParam from "./NodeParam";
import NodeParam from "./NodeParam/NodeParam";
import NodeParams from "./NodeParams";
import NodeToolbar from "./NodeToolbar";

Expand Down Expand Up @@ -84,7 +84,7 @@ const ScriptNode: FC<IScriptNodeProps> = ({}) => {
<NodeParam
key={key}
htmlFor={key}
name={key}
label={key}
tooltip={(param as any).description as any}
/>
))}
Expand Down
13 changes: 11 additions & 2 deletions src/components/Workflow/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import HttpTriggerNode from "./HttpTriggerNode";
import Node from "./Node";
import NodeName from "./NodeName";
import NodeParam from "./NodeParam";
import NodeParam from "./NodeParam/NodeParam";
import NodeStringParam from "./NodeParam/NodeStringParam";
import NodeParams from "./NodeParams";
import NodeToolbar from "./NodeToolbar";

export { HttpTriggerNode, Node, NodeName, NodeParam, NodeParams, NodeToolbar };
export {
HttpTriggerNode,
Node,
NodeName,
NodeParam,
NodeStringParam,
NodeParams,
NodeToolbar,
};
7 changes: 7 additions & 0 deletions src/pages/Workflow/WorkflowPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,20 @@ import {
bindToggle,
usePopupState,
} from "material-ui-popup-state/hooks";
import { useState } from "react";

export default function WorkflowPage() {
const addTriggerPopupState = usePopupState({
variant: "popover",
popupId: "addTrigger",
});

const [trigger, setTrigger] = useState({
type: "http",
method: "get",
path: "/some",
});

return (
<Stack alignItems="center">
<Button startIcon={<PlusIcon />} {...bindToggle(addTriggerPopupState)}>
Expand Down

0 comments on commit 7b261b6

Please sign in to comment.