Skip to content

Commit

Permalink
Introduce behaviour prop object with reFocus prop (#2161)
Browse files Browse the repository at this point in the history
* Introduce modeOptions prop object with reFocus prop

Signed-off-by: Jitendra Gundaniya <[email protected]>

* test fix

Signed-off-by: Jitendra Gundaniya <[email protected]>

* Release note added

Signed-off-by: Jitendra Gundaniya <[email protected]>

* Documentation

Signed-off-by: Jitendra Gundaniya <[email protected]>

* Code review change

Signed-off-by: Jitendra Gundaniya <[email protected]>

* Prop renamed to behaviour from modeOptions

Signed-off-by: Jitendra Gundaniya <[email protected]>

* Revert container changes

Signed-off-by: Jitendra Gundaniya <[email protected]>

---------

Signed-off-by: Jitendra Gundaniya <[email protected]>
  • Loading branch information
jitu5 authored Nov 4, 2024
1 parent c7cdab9 commit 4ec409e
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 11 deletions.
6 changes: 6 additions & 0 deletions README.npm.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ The example below demonstrates how to configure your kedro-viz using different `
tag: {
enabled: {companies: true}
},
behaviour: {
reFocus: true,
},
theme: "dark"
}}
/>
Expand All @@ -161,6 +164,9 @@ The example below demonstrates how to configure your kedro-viz using different `
| `sidebar` | boolean | true | Show/Hide Sidebar and action toolbar |
| `zoomToolbar` | boolean | true | Show/Hide zoom-in, zoom-out and zoom reset buttons together |
| options.expandAllPipelines | boolean | false | Expand/Collapse Modular pipelines on first load |
| options.behaviour | | | |
| `reFocus` | boolean | true | In the flowchart, enable or disable the node re-focus behavior when clicking on nodes.
| options.nodeType | `{disabled: {parameters: boolean,task: boolean,data: boolean}}` | `{disabled: {parameters: true,task: false,data: false}}` | Configuration for node type options |
| options.tag | `{enabled: {<tagName>: boolean}}` | - | Configuration for tag options |
| options.theme | string | dark | select `Kedro-Viz` theme : dark/light |
Expand Down
1 change: 1 addition & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Please follow the established format:
## Major features and improvements

- Update Kedro-Viz telemetry for opt-out model (#2022)
- Introduce `behaviour` prop object with `reFocus` prop (#2161)

## Bug fixes and other changes

Expand Down
6 changes: 6 additions & 0 deletions src/components/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ App.propTypes = {
tag: PropTypes.shape({
enabled: PropTypes.objectOf(PropTypes.bool),
}),
/**
* Whether to re-focus the graph when a node is clicked
*/
behaviour: PropTypes.shape({
reFocus: PropTypes.bool,
}),
/**
* Override the default enabled/disabled node types
*/
Expand Down
29 changes: 18 additions & 11 deletions src/components/flowchart/flowchart.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,22 +220,28 @@ export class FlowChart extends Component {

if (changed('edges', 'nodes', 'layers', 'chartSize', 'clickedNode')) {
// Don't zoom out when the metadata or code panels are opened or closed
if (prevProps.visibleMetaSidebar !== this.props.visibleMetaSidebar) {
const metaSidebarViewChanged =
prevProps.visibleMetaSidebar !== this.props.visibleMetaSidebar;

const codeViewChangedWithoutMetaSidebar =
prevProps.visibleCode !== this.props.visibleCode &&
!this.props.visibleMetaSidebar;

// Don't zoom out when the clicked node changes and the nodeReFocus is disabled
const clickedNodeChangedWithoutReFocus =
prevProps.clickedNode !== this.props.clickedNode &&
!this.props.nodeReFocus;

if (
metaSidebarViewChanged ||
codeViewChangedWithoutMetaSidebar ||
clickedNodeChangedWithoutReFocus
) {
drawNodes.call(this, changed);
drawEdges.call(this, changed);

return;
}

if (prevProps.visibleCode !== this.props.visibleCode) {
if (!this.props.visibleMetaSidebar) {
drawNodes.call(this, changed);
drawEdges.call(this, changed);

return;
}
}

this.resetView(preventZoom);
} else {
this.onChartZoomChanged(chartZoom);
Expand Down Expand Up @@ -1000,6 +1006,7 @@ export const mapStateToProps = (state, ownProps) => ({
slicedPipeline: getSlicedPipeline(state),
isSlicingPipelineApplied: state.slice.apply,
visibleSlicing: state.visible.slicing,
nodeReFocus: state.behaviour.reFocus,
runCommand: getRunCommand(state),
...ownProps,
});
Expand Down
1 change: 1 addition & 0 deletions src/components/flowchart/flowchart.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,7 @@ describe('FlowChart', () => {
runCommand: expect.any(Object),
modularPipelineIds: expect.any(Object),
visibleSlicing: expect.any(Boolean),
nodeReFocus: expect.any(Boolean),
};
expect(mapStateToProps(mockState.spaceflights)).toEqual(expectedResult);
});
Expand Down
1 change: 1 addition & 0 deletions src/reducers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ const combinedReducer = combineReducers({
// These props don't have any actions associated with them
display: createReducer(null),
dataSource: createReducer(null),
behaviour: createReducer({}),
edge: createReducer({}),
// These props have very simple non-nested actions
chartSize: createReducer({}, UPDATE_CHART_SIZE, 'chartSize'),
Expand Down
3 changes: 3 additions & 0 deletions src/store/initial-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ export const createInitialState = () => ({
zoomToolbar: true,
metadataPanel: true,
},
behaviour: {
reFocus: true,
},
zoom: {},
runsMetadata: {},
});
Expand Down

0 comments on commit 4ec409e

Please sign in to comment.