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

[KED-2328] Add code panel #346

Merged
merged 42 commits into from
Feb 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
8d25877
[KED-2328] Add highlight.js
bru5 Dec 15, 2020
2569ac5
[KED-2328] Add MetaDataCode and MetaCodeToggle components
bru5 Dec 15, 2020
2533dee
[KED-2328] Add code panel features to MetaData panel behind new flag
bru5 Dec 15, 2020
c5856e9
[KED-2328] Improve copy button on metadata panel
bru5 Dec 15, 2020
531b54f
[KED-2328] Default to not expanded when values change on MetaDataList
bru5 Dec 16, 2020
07d64a3
[KED-2328] Adaptive chart sizing to fit space
bru5 Dec 17, 2020
d2e834b
[KED-2328] Adaptive chart sizing to fit space
bru5 Dec 18, 2020
1393089
[KED-2328] Add yaml language to code panel
bru5 Jan 4, 2021
883c2d6
Merge branch 'main' into feature/code-panel
bru5 Jan 4, 2021
2ccfaf4
[KED-2328] Improve responsive approach
bru5 Jan 7, 2021
735d800
Merge branch 'main' into feature/code-panel
bru5 Jan 8, 2021
e7ca799
[KED-2212] Update tests for code panel
bru5 Jan 8, 2021
5276b0d
[KED-2212] Update dependency highlight.js
bru5 Jan 8, 2021
d7e0c13
Merge branch 'main' into feature/code-panel
bru5 Jan 11, 2021
ddbd5db
[KED-2212] Avoid sidebar tooltip z-index issue
bru5 Jan 12, 2021
7f52bae
[KED-2212] Add shadow when sidebars overlap
bru5 Jan 12, 2021
27a8968
[KED-2212] Fix variable error on sidebar
bru5 Jan 14, 2021
e55a624
[KED-2212] Add padding to code block on code panel
bru5 Jan 14, 2021
abea22f
[KED-2212] Use screenReaderOnly mixin on code toggle
bru5 Jan 14, 2021
aa62253
[KED-2212] Add focus state to code toggle
bru5 Jan 14, 2021
742ab16
[KED-2212] Improve source order on metadata panel header
bru5 Jan 14, 2021
0936b64
[KED-2212] Change code highlighting to useMemo
bru5 Jan 14, 2021
15a93b8
[KED-2212] Use existing variable on code panel text
bru5 Jan 14, 2021
1de2faa
[KED-2212] Use em on code panel font size
bru5 Jan 14, 2021
83de37c
[KED-2212] Use % on code panel toggle transform
bru5 Jan 14, 2021
8e71211
[KED-2212] Simplify metadata code font selector
bru5 Jan 14, 2021
5e08f6d
Merge branch 'main' into feature/code-panel
bru5 Jan 14, 2021
687af58
[KED-2212] Remove additional metadata panel shadow
bru5 Jan 14, 2021
73e98bd
[KED-2328] Refactor getChartSize
bru5 Jan 14, 2021
976b705
[KED-2328] Add tests for MetaCodeToggle
bru5 Jan 14, 2021
0608a05
Protect against unrecognised language errors
richardwestenra Jan 18, 2021
27a31a3
Merge branch 'main' into feature/code-panel
bru5 Feb 10, 2021
b512030
[KED-2328] Update view behaviour for code panel
bru5 Feb 10, 2021
7c420a0
[KED-2328] Add tests for extents in flowchart
bru5 Feb 10, 2021
866fc14
[KED-2328] Improve code panel toggle focus style
bru5 Feb 10, 2021
3661158
[KED-2328] Use earlier test for getSidebarWidth
bru5 Feb 10, 2021
e6d4225
[KED-2421] Reformat all JavaScript in /src with Prettier
bru5 Feb 11, 2021
b500796
Merge main into feature/code-panel
bru5 Feb 11, 2021
7ab4ec1
[KED-2328] Refactor code panel positioning
bru5 Feb 12, 2021
9857e3a
[KED-2328] Fix code toggle contrast
bru5 Feb 15, 2021
f4908c3
Combine CSS rulesets
richardwestenra Feb 15, 2021
d30ca83
Format SCSS with stylelint
richardwestenra Feb 15, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"dagre": "git+https://github.com/richardwestenra/dagre.git#manual-ranking",
"deepmerge": "^4.2.2",
"fetch-mock": "^9.11.0",
"highlight.js": "^10.5.0",
"kiwi.js": "^1.1.2",
"konami-code": "^0.2.1",
"react-custom-scrollbars": "^4.2.1",
Expand Down
13 changes: 13 additions & 0 deletions src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,16 @@ export function changeFlag(name, value) {
value,
};
}

export const TOGGLE_CODE = 'TOGGLE_CODE';

/**
* Toggle code panel
* @param {string} visible Visibility status
*/
export function toggleCode(visible) {
return {
type: TOGGLE_CODE,
visible,
};
}
71 changes: 69 additions & 2 deletions src/components/flowchart/flowchart.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,39 @@ import React from 'react';
import $ from 'cheerio';
import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import FlowChart, { mapStateToProps, mapDispatchToProps } from './index';
import FlowChart, {
mapStateToProps,
mapDispatchToProps,
chartSizeTestFallback,
} from './index';
import { mockState, setup } from '../../utils/state.mock';
import { getViewTransform, origin } from '../../utils/view';
import { getViewTransform, getViewExtents, origin } from '../../utils/view';

const getNodeIDs = (state) => state.node.ids;
const getNodeName = (state) => state.node.name;
const getLayerIDs = (state) => state.layer.ids;

const chartWidth = chartSizeTestFallback.width;
const chartHeight = chartSizeTestFallback.height;

const mockChartSize = (
chartSize,
width = chartWidth,
height = chartHeight
) => ({
left: 0,
top: 0,
outerWidth: width,
outerHeight: height,
height,
width,
minWidthScale: 1,
sidebarWidth: 0,
metaSidebarWidth: 0,
codeSidebarWidth: 0,
...chartSize,
});

describe('FlowChart', () => {
it('renders without crashing', () => {
const svg = setup.mount(<FlowChart />).find('svg');
Expand Down Expand Up @@ -49,6 +74,46 @@ describe('FlowChart', () => {
expect(viewTransform.k).toBeGreaterThan(0);
});

it('applies expected view extents when all sidebars closed', () => {
const wrapper = setup.mount(
<FlowChart
chartSize={mockChartSize({
sidebarWidth: 0,
metaSidebarWidth: 0,
codeSidebarWidth: 0,
})}
/>
);

const instance = wrapper.find('FlowChart').instance();
const viewExtents = getViewExtents(instance.view);

expect(viewExtents).toEqual({
translate: { minX: -500, minY: -500, maxX: 1044, maxY: 1553 },
scale: { minK: 0.8, maxK: 2 },
});
});

it('applies expected view extents when all sidebars open', () => {
const wrapper = setup.mount(
<FlowChart
chartSize={mockChartSize({
sidebarWidth: 150,
metaSidebarWidth: 180,
codeSidebarWidth: 255,
})}
/>
);

const instance = wrapper.find('FlowChart').instance();
const viewExtents = getViewExtents(instance.view);

expect(viewExtents).toEqual({
translate: { minX: -650, minY: -500, maxX: 1479, maxY: 1553 },
scale: { minK: 0.8, maxK: 2 },
});
});

it('resizes the chart if the window resizes', () => {
const map = {};
window.addEventListener = jest.fn((event, cb) => {
Expand Down Expand Up @@ -185,6 +250,8 @@ describe('FlowChart', () => {
nodes: expect.any(Array),
visibleGraph: expect.any(Boolean),
visibleSidebar: expect.any(Boolean),
visibleCode: expect.any(Boolean),
visibleMetaSidebar: expect.any(Boolean),
};
expect(mapStateToProps(mockState.animals)).toEqual(expectedResult);
});
Expand Down
24 changes: 19 additions & 5 deletions src/components/flowchart/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { getNodeActive, getNodeSelected } from '../../selectors/nodes';
import { getChartSize, getChartZoom } from '../../selectors/layout';
import { getLayers } from '../../selectors/layers';
import { getCentralNode, getLinkedNodes } from '../../selectors/linked-nodes';
import { getVisibleMetaSidebar } from '../../selectors/metadata';
import { drawNodes, drawEdges, drawLayers, drawLayerNames } from './draw';
import {
viewing,
Expand Down Expand Up @@ -64,6 +65,7 @@ export class FlowChart extends Component {
onViewEnd: this.onViewChangeEnd,
});

this.updateViewExtents();
this.addGlobalEventListeners();
this.update();

Expand All @@ -89,7 +91,7 @@ export class FlowChart extends Component {
const { chartZoom } = this.props;
const changed = (...names) => this.changed(names, prevProps, this.props);

if (changed('visibleSidebar')) {
if (changed('visibleSidebar', 'visibleCode', 'visibleMetaSidebar')) {
this.updateChartSize();
}
richardwestenra marked this conversation as resolved.
Show resolved Hide resolved

Expand Down Expand Up @@ -273,19 +275,29 @@ export class FlowChart extends Component {
}

/**
* Updates view extents based on the current view transform
* Updates view extents based on the current view transform.
* Offsets the extents considering any open sidebars.
* Allows additional margin for user panning within limits.
* Zoom scale is limited to a practical range for usability.
* @param {?Object} transform Current transform override
*/
updateViewExtents(transform) {
const { k: scale } = transform || getViewTransform(this.view);
const { sidebarWidth, metaSidebarWidth } = this.props.chartSize;
const {
sidebarWidth = 0,
metaSidebarWidth = 0,
codeSidebarWidth = 0,
} = this.props.chartSize;
const { width = 0, height = 0 } = this.props.graphSize;

const leftSidebarOffset = sidebarWidth / scale;
const rightSidebarOffset = (metaSidebarWidth + codeSidebarWidth) / scale;
const margin = this.MARGIN;

setViewExtents(this.view, {
translate: {
minX: -sidebarWidth / scale - margin,
maxX: width + margin + metaSidebarWidth / scale,
minX: -leftSidebarOffset - margin,
maxX: width + margin + rightSidebarOffset,
minY: -margin,
maxY: height + margin,
},
Expand Down Expand Up @@ -538,6 +550,8 @@ export const mapStateToProps = (state, ownProps) => ({
nodeSelected: getNodeSelected(state),
visibleGraph: state.visible.graph,
visibleSidebar: state.visible.sidebar,
visibleCode: state.visible.code,
visibleMetaSidebar: getVisibleMetaSidebar(state),
...ownProps,
});

Expand Down
Loading