88 | >
89 | );
90 | }
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Contributor Covenant Code of Conduct
2 |
3 | ## Our Pledge
4 |
5 | We as members, contributors, and leaders pledge to make participation in our
6 | community a harassment-free experience for everyone, regardless of age, body
7 | size, visible or invisible disability, ethnicity, sex characteristics, gender
8 | identity and expression, level of experience, education, socio-economic status,
9 | nationality, personal appearance, race, religion, or sexual identity
10 | and orientation.
11 |
12 | We pledge to act and interact in ways that contribute to an open, welcoming,
13 | diverse, inclusive, and healthy community.
14 |
15 | ## Our Standards
16 |
17 | Examples of behavior that contributes to a positive environment for our
18 | community include:
19 |
20 | * Demonstrating empathy and kindness toward other people
21 | * Being respectful of differing opinions, viewpoints, and experiences
22 | * Giving and gracefully accepting constructive feedback
23 | * Accepting responsibility and apologizing to those affected by our mistakes,
24 | and learning from the experience
25 | * Focusing on what is best not just for us as individuals, but for the
26 | overall community
27 |
28 | Examples of unacceptable behavior include:
29 |
30 | * The use of sexualized language or imagery, and sexual attention or
31 | advances of any kind
32 | * Trolling, insulting or derogatory comments, and personal or political attacks
33 | * Public or private harassment
34 | * Publishing others' private information, such as a physical or email
35 | address, without their explicit permission
36 | * Other conduct which could reasonably be considered inappropriate in a
37 | professional setting
38 |
39 | ## Enforcement Responsibilities
40 |
41 | Community leaders are responsible for clarifying and enforcing our standards of
42 | acceptable behavior and will take appropriate and fair corrective action in
43 | response to any behavior that they deem inappropriate, threatening, offensive,
44 | or harmful.
45 |
46 | Community leaders have the right and responsibility to remove, edit, or reject
47 | comments, commits, code, wiki edits, issues, and other contributions that are
48 | not aligned to this Code of Conduct, and will communicate reasons for moderation
49 | decisions when appropriate.
50 |
51 | ## Scope
52 |
53 | This Code of Conduct applies within all community spaces, and also applies when
54 | an individual is officially representing the community in public spaces.
55 | Examples of representing our community include using an official e-mail address,
56 | posting via an official social media account, or acting as an appointed
57 | representative at an online or offline event.
58 |
59 | ## Enforcement
60 |
61 | Instances of abusive, harassing, or otherwise unacceptable behavior may be
62 | reported to the community leaders responsible for enforcement at
63 | .
64 | All complaints will be reviewed and investigated promptly and fairly.
65 |
66 | All community leaders are obligated to respect the privacy and security of the
67 | reporter of any incident.
68 |
69 | ## Enforcement Guidelines
70 |
71 | Community leaders will follow these Community Impact Guidelines in determining
72 | the consequences for any action they deem in violation of this Code of Conduct:
73 |
74 | ### 1. Correction
75 |
76 | **Community Impact**: Use of inappropriate language or other behavior deemed
77 | unprofessional or unwelcome in the community.
78 |
79 | **Consequence**: A private, written warning from community leaders, providing
80 | clarity around the nature of the violation and an explanation of why the
81 | behavior was inappropriate. A public apology may be requested.
82 |
83 | ### 2. Warning
84 |
85 | **Community Impact**: A violation through a single incident or series
86 | of actions.
87 |
88 | **Consequence**: A warning with consequences for continued behavior. No
89 | interaction with the people involved, including unsolicited interaction with
90 | those enforcing the Code of Conduct, for a specified period of time. This
91 | includes avoiding interactions in community spaces as well as external channels
92 | like social media. Violating these terms may lead to a temporary or
93 | permanent ban.
94 |
95 | ### 3. Temporary Ban
96 |
97 | **Community Impact**: A serious violation of community standards, including
98 | sustained inappropriate behavior.
99 |
100 | **Consequence**: A temporary ban from any sort of interaction or public
101 | communication with the community for a specified period of time. No public or
102 | private interaction with the people involved, including unsolicited interaction
103 | with those enforcing the Code of Conduct, is allowed during this period.
104 | Violating these terms may lead to a permanent ban.
105 |
106 | ### 4. Permanent Ban
107 |
108 | **Community Impact**: Demonstrating a pattern of violation of community
109 | standards, including sustained inappropriate behavior, harassment of an
110 | individual, or aggression toward or disparagement of classes of individuals.
111 |
112 | **Consequence**: A permanent ban from any sort of public interaction within
113 | the community.
114 |
115 | ## Attribution
116 |
117 | This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118 | version 2.0, available at
119 | https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
120 |
121 | Community Impact Guidelines were inspired by [Mozilla's code of conduct
122 | enforcement ladder](https://github.com/mozilla/diversity).
123 |
124 | [homepage]: https://www.contributor-covenant.org
125 |
126 | For answers to common questions about this code of conduct, see the FAQ at
127 | https://www.contributor-covenant.org/faq. Translations are available at
128 | https://www.contributor-covenant.org/translations.
129 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Drag & Drop workflow builder
2 |
3 | 🌐 Website : [wbuilder](https://wbuilder.vercel.app/)
4 |
5 | ## 📑Project Description
6 |
7 | Create a Workflow Builder application where users can create, edit, and visualize different workflows. Each workflow consists of multiple steps (nodes) and the relationships (edges) between them. Users should be able to drag and drop different types of nodes (e.g., filter, find, reduce, map, array methods) onto a canvas, and then draw lines between them to represent the workflow.
8 |
9 | Task is to create a workflow building that performs dynamic operations on large amounts of data. You will have multiple CSVs in your local project. User can perform various operations on data to see final result on the CSV user has selected. This CSV might contain million records too.
10 |
11 | 
12 | 
13 | 
14 | 
15 |
16 |
17 |
18 | ## 👨🏻💻 Developer's Talk
19 | Developed by Debraj Karmakar
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 | >Just wrapped up Workflow Builder, a React& Redux advance project. A compact journey with big learnings. From UI design to workflow canvas state management, faced challenges that shaped my skills as a front-end dev.
30 |
31 |
32 |
33 | ## 🚀 Tech Stack
34 |
35 | - HTML5
36 | - CSS3
37 | - Vite
38 | - React
39 | - Typescript
40 | - React Flow
41 | - React Hooks
42 | - React Redux
43 | - React Router
44 | - Tailwind CSS
45 | - Redux Toolkit
46 | - Tabler Icons
47 | - React Resizable Panels
48 |
49 |
50 |
51 | ## 📁Folder Structure
52 | ```typescript
53 | ├───data
54 | ├───public
55 | ├───src
56 | │ ├───app
57 | │ ├───assets
58 | │ ├───components
59 | │ │ ├───BlockLibrary
60 | │ │ ├───Canvas
61 | │ │ │ └───customNodes
62 | │ │ ├───Header
63 | │ │ ├───Table
64 | │ │ └───WorkflowCard
65 | │ ├───constants
66 | │ ├───hooks
67 | │ ├───layout
68 | │ ├───routes
69 | │ ├───services
70 | │ ├───utils
71 | │ └───view
72 | │ ├───Home
73 | │ ├───NoMatchFound
74 | │ └───WorkflowBuilder
75 | └───template
76 | ```
77 |
78 |
79 | ## 🔐Key Features
80 |
81 | - [✔] The dashboard will display all the workflows user has created. Users can either create a new workflow or edit the existing one.
82 | - [✔] The user will be represented with a blank canvas.
83 | - [✔] In the left panel,
84 | - there will be options to choose CSV data to perform operations on. (These CSVs will reside in the local project folder).
85 | - These CSV data will be input of the next node.
86 | - there will be nodes which represents Array methods such as filter, map, find etc.
87 | - [✔] User will select any node and will drop in canvas and will take few required inputs such as,
88 | - in sort method, column name & order
89 | - in filter method,
90 | - column name,
91 | - condition (is equal, is not equal to, includes, does not include)
92 | - value (this will be dynamically shown based on condition type selection)
93 | - [✔] All these blocks connected via each other and output of this block passed to the next connected block and perform operation only on the previous node’s output data.
94 | - [✔] There is a ``Run`` button inside every block and upon clicking it, final output will be shown in table format in bottom panel (which is collapsible)
95 | - [✔] These data has option to “Export data” in json or in CSV format again.
96 | - [✔] There is a ``Save workflow`` button on header. By clicking it that workflow along with its unique name should be stored in web storage (localStorage)
97 | - [✔] The application should handle large data efficiently and demonstrate good performance.
98 |
99 |
100 |
101 | ## ✅Development Technology
102 |
103 | 1. [✅] The application is built using React and related technology stack (Redux, React-Router, etc).
104 | 2. [✅] The workflow builder uses [React Flow](https://reactflow.dev/) and provides a seamless user experience.
105 | 3. [✅] Components are well-structured and properly organized.
106 | 4. [✅] State management is handled efficiently using Redux and context API.
107 | 5. [✅] Use of Redux-toolkit for state management.
108 | 6. [✅] React hooks are used where necessary.
109 | 7. [✅] React best practices are followed.
110 | 8. [✅] Proper error handling is implemented.
111 | 9. [✅] Proper use of async operations and Promises.
112 | 10. [✅] The code is clean, well-structured, and follows a recognized style guide ``(Airbnb's style guide)``.
113 | 11. [✅] Code runs with eslint enabled.
114 | 12. [✅] Error messages is proper along with fallback UI where there are no data.
115 | 13. [✅] Runtime UI crashes are not allowed, even if it happens anyhow, It should have a fallback UI with a gradient background and error message texts upon it which should be clearly readable.
116 |
117 |
118 |
119 | ## 🏃🏻♂️ Run Locally
120 |
121 | Clone the project
122 | ```
123 | $git clone https://github.com/debrajhyper/workflow-builder.git
124 | ```
125 |
126 | Go to the project directory
127 | ```
128 | cd workflow-builder
129 | ```
130 |
131 | Install dependencies
132 | ```
133 | $npm install
134 | ```
135 |
136 | Start the dev server
137 | ```
138 | $npm run dev
139 | ```
140 |
141 |
142 |
--------------------------------------------------------------------------------
/src/assets/error.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/services/workflowSlice.ts:
--------------------------------------------------------------------------------
1 | import { createSelector, createSlice, PayloadAction } from "@reduxjs/toolkit";
2 | import { LOCAL_STORAGE_KEY, NO_PREVIEW, NODE_TYPE_FILE_UPLOAD, STORE_NAME } from "@Constants";
3 | import { RootState } from "./workflowStore";
4 | import { Connection, Edge, EdgeChange, Node, NodeRemoveChange } from "reactflow";
5 | import { WorkflowBuilderState, WorkflowType } from "types";
6 |
7 | const storedItems: string | null = localStorage.getItem(LOCAL_STORAGE_KEY);
8 | const parsedItems = storedItems ? JSON.parse(storedItems) : null;
9 | const localItems = parsedItems !== null ? parsedItems : [];
10 | const initialState: WorkflowBuilderState = {
11 | items: localItems || [],
12 | currentItem: null,
13 | };
14 |
15 | export const workflowBuilderSlice = createSlice({
16 | name: STORE_NAME,
17 | initialState,
18 | reducers: {
19 | setCurrentWorkflow: (state, action: PayloadAction) => {
20 | state.currentItem = action.payload;
21 | },
22 | resetCurrentWorkflow: (state) => {
23 | state.currentItem = initialState.currentItem;
24 | },
25 | createWorkflow: (state, action: PayloadAction) => {
26 | // state.currentItem = initialState.currentItem;
27 | const newWorkflow = { ...action.payload, id: state.items.length + 1 };
28 | state.items.push(newWorkflow);
29 | state.currentItem = newWorkflow;
30 | localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(state.items));
31 | },
32 | updateWorkflow: (state, action: PayloadAction<{ id: number; data: WorkflowType }>) => {
33 | // state.currentItem = initialState.currentItem;
34 | const { id, data } = action.payload;
35 | const index = state.items.findIndex((item) => item.id === id);
36 | state.items[index] = data;
37 | state.currentItem = data;
38 | localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(state.items));
39 | },
40 | addNewNode: (state, action: PayloadAction) => {
41 | state.currentItem?.nodes.push({
42 | ...action.payload,
43 | id: (state.currentItem?.nodes.length + 1).toString(),
44 | });
45 | },
46 | updateNodes: (state, action: PayloadAction) => {
47 | if (state.currentItem) {
48 | state.currentItem.nodes = action.payload;
49 | }
50 | },
51 | updateNodeData: (state, action: PayloadAction<{ id: string; data: unknown }>) => {
52 | const { id, data } = action.payload;
53 | if (state.currentItem) {
54 | const index = state.currentItem.nodes.findIndex(
55 | (node: { id: string; }) => node.id === id
56 | );
57 | state.currentItem.nodes[index].data = data;
58 |
59 | if (
60 | state.currentItem.nodes[index].type === NODE_TYPE_FILE_UPLOAD &&
61 | state.currentItem.edges.some((edge: { source: string; }) => edge.source === id)
62 | ) {
63 | const filteredEdges = state.currentItem.edges.filter(
64 | (edge: { source: string; }) => edge.source === id
65 | );
66 | filteredEdges.forEach((edge) => {
67 | if (state.currentItem) {
68 | const index = state.currentItem.nodes.findIndex(
69 | (node) => node.id === edge.target
70 | );
71 | state.currentItem.nodes[index].data = data;
72 | }
73 | });
74 | }
75 | }
76 | },
77 | updateEdges: (
78 | state,
79 | action: PayloadAction<{
80 | edges: Edge[];
81 | currentEdge: Connection | EdgeChange[];
82 | }>
83 | ) => {
84 | const { edges, currentEdge } = action.payload;
85 | if (state.currentItem) {
86 | if (currentEdge instanceof Array) {
87 | if (currentEdge[0].type === "remove") {
88 | const edgeIndex = state.currentItem.edges.findIndex(
89 | (edge) => edge.id === (currentEdge[0] as NodeRemoveChange).id
90 | );
91 | const foundEdge = state.currentItem.edges[edgeIndex];
92 | const targetNodeIndex = state.currentItem.nodes.findIndex(
93 | (node) => node.id === foundEdge.target
94 | );
95 | state.currentItem.nodes[targetNodeIndex].data = null;
96 | }
97 | } else {
98 | const sourceNodeIndex = state.currentItem.nodes.findIndex(
99 | (node) => node.id === currentEdge.source
100 | );
101 | const targetNodeIndex = state.currentItem.nodes.findIndex(
102 | (node) => node.id === currentEdge.target
103 | );
104 | if (
105 | state.currentItem.nodes[sourceNodeIndex].type === NODE_TYPE_FILE_UPLOAD
106 | ) {
107 | state.currentItem.nodes[targetNodeIndex].data =
108 | state.currentItem.nodes[sourceNodeIndex].data;
109 | } else {
110 | state.currentItem.nodes[targetNodeIndex].data = null;
111 | }
112 | }
113 | state.currentItem.edges = edges;
114 | }
115 | },
116 | setPreview: (state, action) => {
117 | if (state.currentItem) {
118 | state.currentItem.preview = action.payload;
119 | }
120 | },
121 | resetPreview: (state) => {
122 | if (state.currentItem) {
123 | state.currentItem.preview =
124 | initialState.currentItem?.preview || NO_PREVIEW;
125 | }
126 | },
127 | }
128 | });
129 |
130 | export const {
131 | createWorkflow,
132 | resetCurrentWorkflow,
133 | updateWorkflow,
134 | addNewNode,
135 | setPreview,
136 | resetPreview,
137 | setCurrentWorkflow,
138 | updateNodes,
139 | updateEdges,
140 | updateNodeData, } = workflowBuilderSlice.actions;
141 |
142 |
143 | export const getWorkflowByIdSelectors = (state: RootState, workflowId?: number) => {
144 | return (
145 | state.workFlowBuilder.items.find((item: { id: number | undefined; }) => item.id === workflowId) || null
146 | );
147 | };
148 |
149 | export const getWorkFlowDataSelector = (state: RootState) => {
150 | return state.workFlowBuilder;
151 | };
152 |
153 | export const getWorkflowListSelectors = createSelector(getWorkFlowDataSelector, ({ items }) => {
154 | return items.map((workflow: { id: number; name: string; }) => ({
155 | id: workflow.id,
156 | name: workflow.name,
157 | }));
158 | }
159 | );
160 |
161 | export const getPreviewSelectors = createSelector(
162 | getWorkFlowDataSelector,
163 | ({ currentItem }) => {
164 | return currentItem?.preview || NO_PREVIEW;
165 | }
166 | );
167 |
168 | export const getNodesSelectors = createSelector(
169 | getWorkFlowDataSelector,
170 | ({ currentItem }) => {
171 | return currentItem?.nodes || [];
172 | }
173 | );
174 |
175 | export const getEdgesSelectors = createSelector(
176 | getWorkFlowDataSelector,
177 | ({ currentItem }) => {
178 | return currentItem?.edges || [];
179 | }
180 | );
181 |
182 | export const getCurrentWorkflowSelectors = createSelector(
183 | getWorkFlowDataSelector,
184 | ({ currentItem }) => {
185 | return currentItem || null;
186 | }
187 | );
188 |
189 |
190 |
191 |
192 |
193 | export default workflowBuilderSlice.reducer;
--------------------------------------------------------------------------------