<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Anoop</title>
    <description>The latest articles on Forem by Anoop (@anoopw3bdev).</description>
    <link>https://forem.com/anoopw3bdev</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1393563%2F209ff112-3cd9-4a55-a0c9-a46d2bb29065.jpg</url>
      <title>Forem: Anoop</title>
      <link>https://forem.com/anoopw3bdev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/anoopw3bdev"/>
    <language>en</language>
    <item>
      <title>How to create a custom node in reactflow</title>
      <dc:creator>Anoop</dc:creator>
      <pubDate>Tue, 30 Apr 2024 09:49:18 +0000</pubDate>
      <link>https://forem.com/anoopw3bdev/how-to-create-a-custom-node-in-reactflow-1l13</link>
      <guid>https://forem.com/anoopw3bdev/how-to-create-a-custom-node-in-reactflow-1l13</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmew1k2frm5dpmb1tv4od.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmew1k2frm5dpmb1tv4od.png" alt="Custom node using reactflow"&gt;&lt;/a&gt;&lt;br&gt;
In this post I will walk you through how to create a custom node using reactflow.&lt;/p&gt;

&lt;p&gt;Few days back, I decided to build a flow builder using reactflow as part of a frontend coding challenge. It was my first time playing around with reactflow and I struggled a bit to create a custom node using the same. &lt;/p&gt;

&lt;p&gt;If you are trying to figure out how to create a custom node using reactflow, this post is for you.&lt;/p&gt;

&lt;p&gt;I am assuming you know how to setup a react project and to install reactflow. (feel free to refer &lt;a href="https://vitejs.dev/guide/" rel="noopener noreferrer"&gt;this&lt;/a&gt; page to understand how to create a new react project using vite).&lt;/p&gt;

&lt;p&gt;Follow the below steps to create a custom node&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a new component, lets give it a name CustomNode&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

import { Handle, Position } from "reactflow";
import { BiMessageRoundedDetail } from "react-icons/bi";
import { BiLogoWhatsapp } from "react-icons/bi";
import "../assets/styles/CustomNode.css";

export const CustomNode = ({ data }) =&amp;gt; {
  return (
    &amp;lt;div className="custom-node"&amp;gt;
      &amp;lt;Handle type="target" position={Position.Left} id="target" /&amp;gt;
      &amp;lt;div className="custom-node__header"&amp;gt;
        &amp;lt;div&amp;gt;
          &amp;lt;BiMessageRoundedDetail /&amp;gt;
          &amp;lt;div className="custom-node__title"&amp;gt;Send message&amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;
        &amp;lt;div className="custom-node__whatsapp-icon"&amp;gt;
          &amp;lt;BiLogoWhatsapp /&amp;gt;
        &amp;lt;/div&amp;gt;
      &amp;lt;/div&amp;gt;
      &amp;lt;div className="custom-node__text"&amp;gt;{data?.label}&amp;lt;/div&amp;gt;
      &amp;lt;Handle type="source" position={Position.Right} id="source" /&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Style the component according to your requirement. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Keep a constant variable nodeTypes and set the value as  follows &lt;code&gt;const nodeTypes = { textUpdater: CustomNode };&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;here, replace &lt;code&gt;textUpdater&lt;/code&gt; with the name of your choice.&lt;br&gt;
&lt;code&gt;CustomNode&lt;/code&gt; is the component we have created previously. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Pass the nodeTypes to &lt;code&gt;ReactFlow&lt;/code&gt; component along with the other values&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&amp;lt;ReactFlow
 nodes={nodes}
 edges={edges}
 onNodesChange={onNodesChange}
 onEdgesChange={onEdgesChange}
 onConnect={onConnect}
 onInit={setReactFlowInstance}
 onDrop={onDrop}
 onDragOver={onDragOver}
 onNodeClick={onNodeClick}
 nodeTypes={nodeTypes}
 fitView           
/&amp;gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;With this changes, you will be able to see your custom node in action..&lt;/p&gt;

&lt;p&gt;Feel free to comment or reach out to me if you face issues dealing with custom nodes or reactflow, I will be more than happy to help! Cheers.&lt;/p&gt;

</description>
      <category>reactflow</category>
      <category>react</category>
      <category>webdev</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Writing your first Github CI workflow</title>
      <dc:creator>Anoop</dc:creator>
      <pubDate>Mon, 08 Apr 2024 13:39:05 +0000</pubDate>
      <link>https://forem.com/anoopw3bdev/writing-your-first-github-ci-workflow-26i0</link>
      <guid>https://forem.com/anoopw3bdev/writing-your-first-github-ci-workflow-26i0</guid>
      <description>&lt;p&gt;In this post, I would like to share my experience in writing the very first CI workflow in github and what are the things to be noticed while creating one.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj8rywaqt08jjghp7gzdl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj8rywaqt08jjghp7gzdl.png" alt="CI workflow image" width="800" height="375"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Let's understand why CI workflows are important
&lt;/h2&gt;

&lt;p&gt;Let's say you are working on a new feature and creating a PR to the main branch once the development is completed. A manual code review process may be initiated by another team member or a lead developer, after the code review, the changes are merged into the main branch. Testing is performed manually by developers or a QA team. If issues are found during testing, developers have to go back to their code, make fixes, and repeat the process. This process is time consuming and a waste of resource. &lt;/p&gt;

&lt;p&gt;With a CI workflow, each time a developer pushes changes to their branch, a CI workflow is triggered automatically.&lt;br&gt;
The CI workflow includes steps to build the application, run automated tests, and perform other checks. If any tests fail or there are issues in the code, the CI system immediately notifies the developer. Developers can quickly identify and fix issues, reducing the time between introducing a problem and fixing it. Once all checks pass, the changes can be merged into the main branch confidently, knowing that they have been thoroughly tested.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Github actions?
&lt;/h2&gt;

&lt;p&gt;GitHub Actions is a powerful automation platform provided by GitHub that allows developers to build, test, and deploy their code directly from their GitHub repositories. It enables developers to create custom workflows, which are sequences of steps that execute tasks such as running tests, building Docker images, deploying applications, and more.&lt;/p&gt;

&lt;p&gt;With GitHub Actions, developers can define workflows using YAML syntax directly within their repositories, making it easy to automate various aspects of their development process. Workflows can be triggered in response to events such as pushes to the repository, pull requests, issue comments, or scheduled events.&lt;/p&gt;

&lt;h2&gt;
  
  
  Writing the first workflow
&lt;/h2&gt;

&lt;p&gt;I had the opportunity to work on a github issue in an &lt;a href="https://github.com/twentyhq/twenty/issues/4832"&gt;open source project&lt;/a&gt; to add a Github workflow that runs if some files where modified in the path &lt;code&gt;packages/twenty-website&lt;/code&gt; and checks that the website is still building.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpsfrk0wy9ldyifk743u7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpsfrk0wy9ldyifk743u7.png" alt="Workflow code" width="800" height="646"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Lets breakdown the changes and understand what does it mean&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Workflow Name and Triggers:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The workflow is named "CI Website".&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It's triggered by two events:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Pushes to the main branch.&lt;/li&gt;
&lt;li&gt;Pull requests that modify specific files.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The specified files are "package.json" and any file within the "packages/twenty-website/" directory. Which means whenever the package.json or any files in packages/twenty-website changes, the workflow will be run.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Concurrency:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This section manages workflow concurrency, ensuring that only one instance of the workflow runs for each combination of workflow and branch simultaneously.&lt;br&gt;
If a new instance is triggered while another is still running, the existing one will be canceled.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Jobs:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The workflow contains a single job named "website-build".&lt;br&gt;
This job runs on an Ubuntu latest virtual environment.&lt;br&gt;
Job Steps:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; Check out the Repository:&lt;br&gt;
It uses the actions/checkout@v4 action to fetch the repository's content into the runner environment.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; Setup Node.js Environment:&lt;br&gt;
Utilizes the actions/setup-node@v3 action to set up the Node.js environment.&lt;br&gt;
Specifies Node.js version 18 as the desired version.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Step 3:&lt;/strong&gt; Install Dependencies:&lt;br&gt;
Uses the "yarn" command to install dependencies required for the website project.&lt;br&gt;
Dependencies are typically defined in the "package.json" file.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Step 4:&lt;/strong&gt; Build Website:&lt;br&gt;
Executes the "yarn nx build twenty-website" command to build the website.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Summary&lt;/strong&gt;&lt;br&gt;
With these changes, whenever a new PR is created and it has some changes inside &lt;code&gt;package.json&lt;/code&gt; file or &lt;code&gt;packages/twenty-front&lt;/code&gt; the workflow will run, the developers can make sure that the website builds successfully.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/twentyhq/twenty/pull/4869/files"&gt;Checkout the actual PR here&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ci</category>
      <category>github</category>
      <category>cicd</category>
      <category>development</category>
    </item>
    <item>
      <title>Configuring/ fixing absolute path in a react, typescript and vite project.</title>
      <dc:creator>Anoop</dc:creator>
      <pubDate>Thu, 28 Mar 2024 19:57:58 +0000</pubDate>
      <link>https://forem.com/anoopw3bdev/configuring-fixing-absolute-path-in-a-react-typescript-and-vite-project-36lk</link>
      <guid>https://forem.com/anoopw3bdev/configuring-fixing-absolute-path-in-a-react-typescript-and-vite-project-36lk</guid>
      <description>&lt;p&gt;If you are someone trying to configure absolute import in a react, ts and vite project or facing issue with resolving absolute paths in same, this post is for you.&lt;/p&gt;

&lt;p&gt;Recently I tried to make my hands dirty by building something in react and decided to use typescript and vite in the project.&lt;/p&gt;

&lt;p&gt;I didn’t want to use the relative import (import Sidebar from “../components/Sidebar”;) as it leads to longer and less readable import paths as well as it will be difficult to manage when the project grows.&lt;/p&gt;

&lt;p&gt;So I decided to use the absolute import (import { Sidebar } from ‘@components/Sidebar’;)&lt;/p&gt;

&lt;p&gt;In order to configure absolute import in this project there are few things we have to add in tsconfig.json and vite.config.ts file.&lt;/p&gt;

&lt;p&gt;In the tsconfig.json file add the baseUrl and paths, example code is given below&lt;/p&gt;

&lt;p&gt;&lt;code&gt;{&lt;br&gt;
  "compilerOptions": {&lt;br&gt;
    ... &lt;br&gt;
    "baseUrl": "./src",&lt;br&gt;
    "paths": {&lt;br&gt;
      "@components/*": ["components/*"],&lt;br&gt;
      "@constants/*": ["constants/*"],&lt;br&gt;
      "@pages/*": ["pages/*"]&lt;br&gt;
    }&lt;br&gt;
  },&lt;br&gt;
  ...&lt;br&gt;
}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The above code tells typescript how to resolve import paths.&lt;/p&gt;

&lt;p&gt;But that is not enough, we have to tell vite on how to build import path. For this you can use this plugin &lt;a href="https://www.npmjs.com/package/vite-tsconfig-paths"&gt;https://www.npmjs.com/package/vite-tsconfig-paths&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;After installing vite-tsconfig-paths plugin, import tsconfigPaths from it and add it to the plugins array in vite.config.ts file as below&lt;/p&gt;

&lt;p&gt;`&lt;br&gt;
import { defineConfig } from 'vite';&lt;br&gt;
import react from '@vitejs/plugin-react';&lt;br&gt;
import tsconfigPaths from 'vite-tsconfig-paths';&lt;/p&gt;

&lt;p&gt;export default defineConfig({&lt;br&gt;
  plugins: [react(), tsconfigPaths()],&lt;br&gt;
});&lt;br&gt;
`&lt;/p&gt;

&lt;p&gt;With this configurations we will be able to setup absolute import in a react, ts and vite project.&lt;/p&gt;

</description>
      <category>react</category>
      <category>vite</category>
      <category>typescript</category>
    </item>
  </channel>
</rss>
