Skip to content

Commit

Permalink
rename 'ElementsData' to 'BlockData'
Browse files Browse the repository at this point in the history
  • Loading branch information
39bytes committed Feb 26, 2024
1 parent a0fccb0 commit 9d06979
Show file tree
Hide file tree
Showing 19 changed files with 61 additions and 61 deletions.
4 changes: 2 additions & 2 deletions docs/src/components/nodes/types/nodeProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type CtrlData = Record<
: never
>;

export type ElementsData = {
export type BlockData = {
id: string;
label: string;
type: string;
Expand All @@ -68,4 +68,4 @@ export type TextData = {
text: string;
};

export type CustomNodeProps = NodeProps<ElementsData>;
export type CustomNodeProps = NodeProps<BlockData>;
4 changes: 2 additions & 2 deletions src/renderer/data/RECIPES.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ElementsData } from "@/renderer/types";
import { BlockData } from "@/renderer/types";
import { ReactFlowJsonObject } from "reactflow";
import { defaultApp } from "./apps";

export const NOISY_SINE =
defaultApp.rfInstance as ReactFlowJsonObject<ElementsData>;
defaultApp.rfInstance as ReactFlowJsonObject<BlockData>;

export const EMPTY_CANVAS = {
elements: [],
Expand Down
18 changes: 9 additions & 9 deletions src/renderer/hooks/useFlowChartGraph.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ElementsData } from "@/renderer/types";
import { BlockData } from "@/renderer/types";
import { useAtom } from "jotai";
import { atomWithImmer } from "jotai-immer";
import { useCallback, useMemo } from "react";
Expand All @@ -15,10 +15,10 @@ import useWithPermission from "./useWithPermission";

const project = resolveDefaultProjectReference();
const projectData = resolveProjectReference(project) || RECIPES.NOISY_SINE;
const initialNodes: Node<ElementsData>[] = projectData.nodes;
const initialNodes: Node<BlockData>[] = projectData.nodes;
const initialEdges: Edge[] = projectData.edges;

const nodesAtom = atomWithImmer<Node<ElementsData>[]>(initialNodes);
const nodesAtom = atomWithImmer<Node<BlockData>[]>(initialNodes);
export const textNodesAtom = atomWithImmer<Node<TextData>[]>([]);
const edgesAtom = atomWithImmer<Edge[]>(initialEdges);

Expand All @@ -30,8 +30,8 @@ export const useFlowChartGraph = () => {
const setNodes = withPermissionCheck(setNodesOriginal);
const setEdges = withPermissionCheck(setEdgesOriginal);
const { selectedNodes, unSelectedNodes } = useMemo(() => {
const selectedNodes: Node<ElementsData>[] = [];
const unSelectedNodes: Node<ElementsData>[] = [];
const selectedNodes: Node<BlockData>[] = [];
const unSelectedNodes: Node<BlockData>[] = [];
for (const n of nodes) {
if (n.selected) {
selectedNodes.push(n);
Expand All @@ -44,7 +44,7 @@ export const useFlowChartGraph = () => {
const nodesMetadata = useFullMetadata();

const loadFlowExportObject = useCallback(
(flow: ReactFlowJsonObject<ElementsData>, textNodes?: Node<TextData>[]) => {
(flow: ReactFlowJsonObject<BlockData>, textNodes?: Node<TextData>[]) => {
if (!flow) {
return false;
}
Expand Down Expand Up @@ -80,7 +80,7 @@ export const useFlowChartGraph = () => {

const updateCtrlInputDataForNode = (
nodeId: string,
inputData: ElementsData["ctrls"][string],
inputData: BlockData["ctrls"][string],
) => {
setNodesOriginal((element) => {
const node = element.find((e) => e.id === nodeId);
Expand All @@ -96,7 +96,7 @@ export const useFlowChartGraph = () => {

const updateInitCtrlInputDataForNode = (
nodeId: string,
inputData: ElementsData["ctrls"][string],
inputData: BlockData["ctrls"][string],
) => {
setNodesOriginal((element) => {
const node = element.find((e) => e.id === nodeId);
Expand Down Expand Up @@ -145,7 +145,7 @@ export const useFlowChartGraph = () => {
};

const handleNodeChanges = (
cb: (nodes: Node<ElementsData>[]) => Node<ElementsData>[],
cb: (nodes: Node<BlockData>[]) => Node<BlockData>[],
) => {
setNodesOriginal(cb);
};
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/hooks/useFlowChartState.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { ElementsData } from "@/renderer/types";
import { BlockData } from "@/renderer/types";
import { TextData } from "@/renderer/types/node";
import { atom } from "jotai";
import { atomWithImmer } from "jotai-immer";
import { ReactFlowJsonObject, Node } from "reactflow";

export type Project = {
name?: string;
rfInstance?: ReactFlowJsonObject<ElementsData>;
rfInstance?: ReactFlowJsonObject<BlockData>;
textNodes?: Node<TextData>[];
};

Expand Down
6 changes: 3 additions & 3 deletions src/renderer/lib/save.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Project } from "@/renderer/hooks/useFlowChartState";
import { ElementsData } from "@/renderer/types";
import { BlockData } from "@/renderer/types";
import { TextData } from "@/renderer/types/node";
import saveAs from "file-saver";
import { Node, Edge } from "reactflow";

export const makeAppFileContent = (
project: Project,
nodes: Node<ElementsData>[],
nodes: Node<BlockData>[],
edges: Edge[],
textNodes: Node<TextData>[],
) => {
Expand All @@ -24,7 +24,7 @@ export const makeAppFileContent = (

export const saveFileAs = async (
project: Project,
nodes: Node<ElementsData>[],
nodes: Node<BlockData>[],
edges: Edge[],
textNodes: Node<TextData>[],
): Promise<string | undefined> => {
Expand Down
10 changes: 5 additions & 5 deletions src/renderer/lib/sync.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ElementsData } from "@/renderer/types";
import { BlockData } from "@/renderer/types";
import { BlocksMetadataMap } from "@/renderer/types/blocks-metadata";
import { Leaf, RootNode, TreeNode } from "@/renderer/utils/ManifestLoader";
import { Edge, Node } from "reactflow";
Expand All @@ -8,18 +8,18 @@ import { isCompatibleType } from "@/renderer/utils/TypeCheck";
import _ from "lodash";

export function syncFlowchartWithManifest(
nodes: Node<ElementsData>[],
nodes: Node<BlockData>[],
edges: Edge[],
blockManifest: RootNode,
blockMetadata: BlocksMetadataMap,
): [Node<ElementsData>[], Edge[]] {
): [Node<BlockData>[], Edge[]] {
const blocks = flattenManifest(blockManifest);

const inEdges = _.groupBy(edges, (e: Edge) => e.target);
const newNodes: Node<ElementsData>[] = [];
const newNodes: Node<BlockData>[] = [];
const newEdges: Edge[] = [];

const validEdge = (e: Edge, inputs?: ElementsData["inputs"]) => {
const validEdge = (e: Edge, inputs?: BlockData["inputs"]) => {
const outBlock = blocks.get(blockFuncFromId(e.source));
if (!outBlock) {
// If there is an unknown block in the flow chart,
Expand Down
8 changes: 4 additions & 4 deletions src/renderer/routes/flow_chart/FlowChartTabView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ import {
useManifest,
useNodesMetadata,
} from "@/renderer/hooks/useManifest";
import { ElementsData } from "@/renderer/types";
import { BlockData } from "@/renderer/types";
import { createNodeId, createNodeLabel } from "@/renderer/utils/NodeUtils";
import useKeyboardShortcut from "@/renderer/hooks/useKeyboardShortcut";
import { filterMap } from "@/renderer/utils/ArrayUtils";
Expand Down Expand Up @@ -207,11 +207,11 @@ const FlowChartTab = () => {
const addTextNode = useAddTextNode();

const duplicateNode = useCallback(
(node: Node<ElementsData>) => {
(node: Node<BlockData>) => {
const funcName = node.data.func;
const id = createNodeId(funcName);

const newNode: Node<ElementsData> = {
const newNode: Node<BlockData> = {
...node,
id,
data: {
Expand Down Expand Up @@ -400,7 +400,7 @@ const FlowChartTab = () => {
const ref = useRef<HTMLDivElement | null>(null);

const onNodeContextMenu = useCallback(
(event, node: Node<ElementsData>) => {
(event, node: Node<BlockData>) => {
// Prevent native context menu from showing
event.preventDefault();

Expand Down
4 changes: 2 additions & 2 deletions src/renderer/routes/flow_chart/components/NodeContextMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Button } from "@/renderer/components/ui/button";
import { ElementsData } from "@/renderer/types";
import { BlockData } from "@/renderer/types";
import { Code, CopyPlus, Info, LucideIcon, Pencil, X } from "lucide-react";
import { useCallback } from "react";
import { useStore, Node, useReactFlow } from "reactflow";
Expand Down Expand Up @@ -51,7 +51,7 @@ type ContextMenuProps = {
bottom?: number;
fullPath: string;
onClick?: () => void;
duplicateNode: (node: Node<ElementsData>) => void;
duplicateNode: (node: Node<BlockData>) => void;
setNodeModalOpen: (open: boolean) => void;
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Node } from "reactflow";
import { ElementsData } from "@/renderer/types";
import { BlockData } from "@/renderer/types";
import { memo, useEffect, useState } from "react";
import Draggable from "react-draggable";
import { useFlowChartGraph } from "@/renderer/hooks/useFlowChartGraph";
Expand All @@ -13,8 +13,8 @@ import useWithPermission from "@/renderer/hooks/useWithPermission";
import { useFlowchartStore } from "@/renderer/stores/flowchart";

type NodeEditModalProps = {
node: Node<ElementsData>;
otherNodes: Node<ElementsData>[] | null;
node: Node<BlockData>;
otherNodes: Node<BlockData>[] | null;
setNodeModalOpen: (open: boolean) => void;
handleDelete: (nodeId: string, nodeLabel: string) => void;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ElementsData } from "@/renderer/types";
import { BlockData } from "@/renderer/types";
import { ParamValueType } from "@/renderer/routes/common/types/ParamValueType";
import { Input } from "@/renderer/components/ui/input";
import {
Expand All @@ -22,9 +22,9 @@ import { useFlowchartStore } from "@/renderer/stores/flowchart";

type ParamFieldProps = {
nodeId: string;
nodeCtrl: ElementsData["ctrls"][string];
nodeCtrl: BlockData["ctrls"][string];
type: ParamValueType;
updateFunc: (nodeId: string, data: ElementsData["ctrls"][string]) => void;
updateFunc: (nodeId: string, data: BlockData["ctrls"][string]) => void;
options?: string[];
nodeReferenceOptions?: {
label: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { ParamValueType } from "@/renderer/routes/common/types/ParamValueType";
import { ParamTooltip } from "@/renderer/components/common/ParamTooltip";
import { ElementsData } from "@/renderer/types/node";
import { BlockData } from "@/renderer/types/node";
import ParamField from "./ParamField";

type ParamListProps = {
nodeId: string;
ctrls: ElementsData["ctrls"];
updateFunc: (nodeId: string, data: ElementsData["ctrls"][string]) => void;
ctrls: BlockData["ctrls"];
updateFunc: (nodeId: string, data: BlockData["ctrls"][string]) => void;
nodeReferenceOptions?: {
label: string;
value: string;
Expand Down
8 changes: 4 additions & 4 deletions src/renderer/routes/flow_chart/hooks/useAddNewNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Leaf as NodeElement } from "@/renderer/utils/ManifestLoader";
import { Draft } from "immer";
import { useCallback } from "react";
import { Node } from "reactflow";
import { ElementsData } from "@/renderer/types";
import { BlockData } from "@/renderer/types";
import { sendEventToMix } from "@/renderer/services/MixpanelServices";
import { centerPositionAtom } from "@/renderer/hooks/useFlowChartState";
import { useAtomValue } from "jotai";
Expand All @@ -21,8 +21,8 @@ export type AddNewNode = (node: NodeElement) => void;
export const useAddNewNode = (
setNodes: (
update:
| Node<ElementsData>[]
| ((draft: Draft<Node<ElementsData>>[]) => void),
| Node<BlockData>[]
| ((draft: Draft<Node<BlockData>>[]) => void),
) => void,
getTakenNodeLabels: (func: string) => string[][],
nodesMetadataMap: BlocksMetadataMap | undefined | null,
Expand Down Expand Up @@ -64,7 +64,7 @@ export const useAddNewNode = (
const nodeCtrls = ctrlsFromParams(params, funcName, hardwareDevices);
const initCtrls = ctrlsFromParams(initParams, funcName);

const newNode: Node<ElementsData> = {
const newNode: Node<BlockData> = {
id: nodeId,
type: uiComponentId ?? type,
data: {
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/routes/flow_chart/views/BlockExpandMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NodeResult } from "@/renderer/routes/common/types/ResultsType";
// import { useFlowChartState } from "@/renderer/hooks/useFlowChartState";
import { Node } from "reactflow";
import { ElementsData } from "@/renderer/types";
import { BlockData } from "@/renderer/types";
import BlockModal from "./BlockModal";
import { useEffect, useState } from "react";
// import { useFlowChartTabState } from "../FlowChartTabState";
Expand All @@ -10,7 +10,7 @@ type BlockExpandMenuProps = {
modalIsOpen: boolean;
setModalOpen: (open: boolean) => void;
nodeResults: NodeResult[];
selectedNode: Node<ElementsData> | null;
selectedNode: Node<BlockData> | null;
pythonString: string;
blockFilePath: string;
blockFullPath: string;
Expand Down
6 changes: 3 additions & 3 deletions src/renderer/routes/flow_chart/views/BlockModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
DialogTitle,
} from "@/renderer/components/ui/dialog";
import { NodeResult } from "@/renderer/routes/common/types/ResultsType";
import { ElementsData } from "@/renderer/types/node";
import { BlockData } from "@/renderer/types/node";
import { ScrollArea, ScrollBar } from "@/renderer/components/ui/scroll-area";
import { useTheme } from "@/renderer/providers/themeProvider";
import { Button } from "@/renderer/components/ui/button";
Expand Down Expand Up @@ -53,7 +53,7 @@ export type BlockModalProps = {
pythonString: string;
blockFilePath: string;
blockFullPath: string;
selectedNode: Node<ElementsData>;
selectedNode: Node<BlockData>;
};

const BlockModal = ({
Expand Down Expand Up @@ -179,7 +179,7 @@ const BlockModal = ({

type NodeModalDataVizProps = {
nd: NodeResult;
selectedNode: Node<ElementsData>;
selectedNode: Node<BlockData>;
theme: "light" | "dark";
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useFlowChartGraph } from "@/renderer/hooks/useFlowChartGraph";
import { Node, Edge } from "reactflow";
import { ElementsData } from "@/renderer/types";
import { BlockData } from "@/renderer/types";
import { Ban, Play } from "lucide-react";
import { Button } from "@/renderer/components/ui/button";
import { projectAtom } from "@/renderer/hooks/useFlowChartState";
Expand Down Expand Up @@ -42,7 +42,7 @@ const FlowControlButtons = () => {
alert("There is no running job on server.");
}
};
const onRun = async (nodes: Node<ElementsData>[], edges: Edge[]) => {
const onRun = async (nodes: Node<BlockData>[], edges: Edge[]) => {
if (project.rfInstance && nodes.length > 0) {
if (_.some(nodes, (n) => n.data.invalid)) {
toast.error(
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/routes/flow_chart/views/ControlBar/WatchBtn.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useState } from "react";
import { Node, Edge } from "reactflow";
import { ElementsData } from "@/renderer/types";
import { BlockData } from "@/renderer/types";
import { useFlowChartGraph } from "@/renderer/hooks/useFlowChartGraph";
import { Label } from "@/renderer/components/ui/label";
import { Switch } from "@/renderer/components/ui/switch";
Expand All @@ -14,7 +14,7 @@ import { toast } from "sonner";
import { useFlowchartStore } from "@/renderer/stores/flowchart";

interface WatchBtnProps {
playFC: (nodes: Node<ElementsData>[], edges: Edge[]) => void;
playFC: (nodes: Node<BlockData>[], edges: Edge[]) => void;
cancelFC: () => void;
}

Expand Down
6 changes: 3 additions & 3 deletions src/renderer/services/FlowChartServices.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Setting } from "../hooks/useSettings";
import { ReactFlowJsonObject } from "reactflow";
import { ElementsData } from "@/renderer/types";
import { BlockData } from "@/renderer/types";
import { Result } from "src/types/result";
import { captain } from "@/renderer/lib/ky";
import { HTTPError } from "ky";
Expand Down Expand Up @@ -39,7 +39,7 @@ export function saveAndRunFlowChartInServer({
jobId,
settings,
}: {
rfInstance?: ReactFlowJsonObject<ElementsData>;
rfInstance?: ReactFlowJsonObject<BlockData>;
jobId: string;
settings: Setting[];
}) {
Expand All @@ -62,7 +62,7 @@ export function saveAndRunFlowChartInServer({
}

export function cancelFlowChartRun(
rfInstance: ReactFlowJsonObject<ElementsData>,
rfInstance: ReactFlowJsonObject<BlockData>,
jobId: string,
) {
if (rfInstance) {
Expand Down
Loading

0 comments on commit 9d06979

Please sign in to comment.