Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce onActionCallback prop in Kedro-Viz react component #2027

Merged
merged 10 commits into from
Aug 22, 2024

Conversation

jitu5
Copy link
Contributor

@jitu5 jitu5 commented Aug 6, 2024

Description

Resolves #2022

This PR addresses a requirement for users of Kedro-Viz as a React component in embedded mode. It allows displaying node metadata in a custom UI. Additionally, it supports the VSCode extension use case where clicking on a node passes the node data to the extension to open the relevant file.

<KedroViz 
  data={data} 
  options={...}
  onActionCallback={(action) => {
    console.log('Action: ', action);
  }}
/>

Below is the action format, which will be pass as argument to call back function

action = {
  type: <ACTION_NAME>,
  payload: <PAYLOAD_OF_ANY_TYPE>
}

Note: We can not put onNodeClickCallback under a options prop as onActionCallback is a callback function and options are Redux state, it should only contain plain JavaScript objects, arrays, and primitives.

Development notes

  • Callback is pass to store via configureStore in App.js
  • Callback call happens in createCallbackMiddleware
  • On TOGGLE_NODE_CLICKED action intercept in middleware, using clicked node id and state.graph.nodes entire node object is pass as an argument to callback.

QA notes

You can test new prop in src/components/container.js as is the entry point or top level component for a standalone use case.

import React from 'react';
import App from '../app';
import getPipelineData from '../../utils/data-source';
import './container.scss';

/**
 * Top-level component for the use-case where Kedro-Viz is run as a standalone
 * app rather than imported as a library/package into a larger application.
 */
const Container = () => (
  <>
    <App
      options={{
        display: {
          globalNavigation: false,
          metadataPanel: false,
          sidebar: false,
        },
        theme: 'dark',
      }}
      onActionCallback ={(action) => {
        console.log('Action: ', action);
      }}
      data={getPipelineData()}
    />
  </>
);

export default Container;

Checklist

  • Read the contributing guidelines
  • Opened this PR as a 'Draft Pull Request' if it is work-in-progress
  • Updated the documentation to reflect the code changes
  • Added new entries to the RELEASE.md file
  • Added tests to cover my changes

Signed-off-by: Jitendra Gundaniya <[email protected]>
@jitu5 jitu5 self-assigned this Aug 6, 2024
@jitu5 jitu5 added the Javascript Pull requests that update Javascript code label Aug 6, 2024
@jitu5 jitu5 marked this pull request as ready for review August 6, 2024 16:07
@jitu5 jitu5 requested a review from rashidakanchwala as a code owner August 6, 2024 16:07
Signed-off-by: Jitendra Gundaniya <[email protected]>
@jitu5 jitu5 requested a review from astrojuanlu as a code owner August 6, 2024 16:13
Signed-off-by: Jitendra Gundaniya <[email protected]>
Copy link
Contributor

@Huongg Huongg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey generally the PR is looking pretty good and simple, thank you @jitu5 . My first thought would be what happens if we introduce another callback? eg: for slicing, run command etc. Would it be better to have a group for all the callback? Let me know your thought

<KedroViz 
  data={data} 
  options={...}
  callbacks={
     onNodeClick={(node) => {
         console.log('Node clicked:', node);
      }} 
     onRunCommandClick={(runCommand) => ...}
  }
/>

src/store/middleware.js Show resolved Hide resolved
jitu5 added 2 commits August 16, 2024 14:55
Signed-off-by: Jitendra Gundaniya <[email protected]>
@jitu5 jitu5 changed the title Introduce onNodeClickCallback prop in Kedro-Viz react component Introduce onActionCallback prop in Kedro-Viz react component Aug 16, 2024
@jitu5
Copy link
Contributor Author

jitu5 commented Aug 16, 2024

hey generally the PR is looking pretty good and simple, thank you @jitu5 . My first thought would be what happens if we introduce another callback? eg: for slicing, run command etc. Would it be better to have a group for all the callback? Let me know your thought

<KedroViz 
  data={data} 
  options={...}
  callbacks={
     onNodeClick={(node) => {
         console.log('Node clicked:', node);
      }} 
     onRunCommandClick={(runCommand) => ...}
  }
/>

@Huongg I made changes to accept any event or action if we want to use a callback, as shown below.

<KedroViz 
  data={data} 
  options={...}
  onActionCallback={(action) => {
    console.log('Action: ', action);
  }}
/>

Below is the action format, which will be pass as argument to call back function

action = {
  type: <ACTION_NAME>,
  payload: <PAYLOAD_OF_ANY_TYPE>
}

Copy link
Contributor

@rashidakanchwala rashidakanchwala left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look's great!. thanks @jitu5

Copy link
Contributor

@Huongg Huongg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the update @jitu5 . looks good to me too

@jitu5 jitu5 merged commit d171b50 into main Aug 22, 2024
10 checks passed
@jitu5 jitu5 deleted the feature/callback-node-click branch August 22, 2024 10:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Javascript Pull requests that update Javascript code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Introduce a callback as prop to React component to track node click in flowchart
4 participants