Skip to content

Commit

Permalink
Add ptp diff (#1496)
Browse files Browse the repository at this point in the history
* implement version diff for ptp and synce

* handle null value in version select

* refactor used type in redux reducers
  • Loading branch information
MarcoMruz authored Mar 8, 2024
1 parent 8ebc39f commit 569ff39
Show file tree
Hide file tree
Showing 12 changed files with 501 additions and 54 deletions.
42 changes: 34 additions & 8 deletions packages/frinx-device-topology/src/__generated__/graphql.ts

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

Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import { chakra } from '@chakra-ui/react';
import React, { PointerEvent, VoidFunctionComponent } from 'react';
import { PtpGraphNodeWithDiff } from '../../helpers/topology-helpers';
import { GraphPtpNodeInterface, PositionsWithGroupsMap } from '../../pages/topology/graph.helpers';
import { TopologyMode } from '../../state.actions';
import { GraphEdge, PtpGraphNode } from '../../__generated__/graphql';
import { GraphEdge } from '../../__generated__/graphql';
import NodeIconImage from './node-icon-image';
import { getDeviceNodeTransformProperties, getNodeInterfaceGroups } from './node-icon.helpers';
import { getDeviceNodeTransformProperties, getNodeBackgroundColor, getNodeInterfaceGroups } from './node-icon.helpers';
import NodeInterface from './node-interface';

type Props = {
isPtpDiffSynceShown: boolean;
ptpDiffSynceIds: string[];
positions: PositionsWithGroupsMap<GraphPtpNodeInterface>;
isFocused: boolean;
isSelected: boolean;
isSelectedForGmPath: boolean;
isGmPath: boolean;
node: PtpGraphNode;
node: PtpGraphNodeWithDiff;
topologyMode: TopologyMode;
selectedEdge: GraphEdge | null;
onPointerDown: (event: PointerEvent<SVGRectElement>) => void;
Expand All @@ -31,6 +33,7 @@ const PtpNodeIcon: VoidFunctionComponent<Props> = ({
isPtpDiffSynceShown,
ptpDiffSynceIds,
isFocused,
isSelected,
isSelectedForGmPath,
isGmPath,
node,
Expand All @@ -44,7 +47,10 @@ const PtpNodeIcon: VoidFunctionComponent<Props> = ({
const interfaceGroups = getNodeInterfaceGroups(node.name, positions.interfaceGroups);
const { circleDiameter, sizeTransform } = getDeviceNodeTransformProperties('MEDIUM');

const ptpDiffSynceNodeColor = isPtpDiffSynceShown && ptpDiffSynceIds?.includes(node.nodeId) ? 'red.200' : 'gray.400';
const ptpNodeBackgroundColor =
isPtpDiffSynceShown && ptpDiffSynceIds?.includes(node.nodeId)
? 'red.200'
: getNodeBackgroundColor({ isSelected, change: node.change });

return (
<G
Expand All @@ -65,9 +71,9 @@ const PtpNodeIcon: VoidFunctionComponent<Props> = ({
<G>
<Circle
r={`${circleDiameter / 2}px`}
fill={ptpDiffSynceNodeColor}
fill={ptpNodeBackgroundColor}
strokeWidth={1}
stroke={ptpDiffSynceNodeColor}
stroke={ptpNodeBackgroundColor}
/>
</G>
<Text
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
import { chakra } from '@chakra-ui/react';
import React, { PointerEvent, VoidFunctionComponent } from 'react';
import { SynceGraphNodeWithDiff } from '../../helpers/topology-helpers';
import { GraphSynceNodeInterface, PositionsWithGroupsMap } from '../../pages/topology/graph.helpers';
import { TopologyMode } from '../../state.actions';
import { GraphEdge, SynceGraphNode } from '../../__generated__/graphql';
import { GraphEdge } from '../../__generated__/graphql';
import NodeIconImage from './node-icon-image';
import { getDeviceNodeTransformProperties, getNodeInterfaceGroups } from './node-icon.helpers';
import { getDeviceNodeTransformProperties, getNodeInterfaceGroups, getNodeBackgroundColor } from './node-icon.helpers';
import NodeInterface from './node-interface';

type Props = {
positions: PositionsWithGroupsMap<GraphSynceNodeInterface>;
isFocused: boolean;
isSelectedForGmPath: boolean;
isGmPath: boolean;
node: SynceGraphNode;
node: SynceGraphNodeWithDiff;
topologyMode: TopologyMode;
onPointerDown: (event: PointerEvent<SVGRectElement>) => void;
onPointerMove: (event: PointerEvent<SVGRectElement>) => void;
onPointerUp: (event: PointerEvent<SVGRectElement>) => void;
selectedEdge: GraphEdge | null;
isSelected: boolean;
};

const G = chakra('g');
Expand All @@ -35,6 +37,7 @@ const SynceNodeIcon: VoidFunctionComponent<Props> = ({
onPointerMove,
onPointerUp,
selectedEdge,
isSelected,
}) => {
const { x, y } = positions.nodes[node.name];
const interfaceGroups = getNodeInterfaceGroups(node.name, positions.interfaceGroups);
Expand All @@ -57,7 +60,18 @@ const SynceNodeIcon: VoidFunctionComponent<Props> = ({
transition="all .2s ease-in-out"
/>
<G>
<Circle r={`${circleDiameter / 2}px`} fill="gray.400" strokeWidth={1} stroke="gray.400" />
<Circle
r={`${circleDiameter / 2}px`}
fill={getNodeBackgroundColor({
isSelected,
change: node.change,
})}
strokeWidth={1}
stroke={getNodeBackgroundColor({
isSelected,
change: node.change,
})}
/>
</G>
<Text
height={`${circleDiameter / 2}px`}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { format } from 'date-fns';
import React, { ChangeEvent, VoidFunctionComponent } from 'react';
import { gql, useQuery } from 'urql';
import { getLocalDateFromUTC } from '@frinx/shared';
import { setSelectedVersion } from '../../state.actions';
import { setSelectedVersion, setSynceDiffVisibility } from '../../state.actions';
import { useStateContext } from '../../state.provider';
import { VersionsQuery, VersionsQueryVariables } from '../../__generated__/graphql';

Expand All @@ -26,6 +26,7 @@ const VersionSelect: VoidFunctionComponent = () => {
const handleSelectVersionChange = (event: ChangeEvent<HTMLSelectElement>) => {
const { value } = event.currentTarget;
dispatch(setSelectedVersion(value === 'none' ? null : value));
dispatch(setSynceDiffVisibility(false));
};

if (isFetchingVersions) {
Expand All @@ -37,7 +38,7 @@ const VersionSelect: VoidFunctionComponent = () => {
return (
<>
<FormLabel marginBottom={4}>Compare current topology with:</FormLabel>
<Select value={selectedVersion || undefined} onChange={handleSelectVersionChange} background="white">
<Select value={selectedVersion ?? 'none'} onChange={handleSelectVersionChange} background="white">
<option value="none">None</option>
{versions.map((v) => (
<option key={`version-${v}`} value={v}>
Expand Down
Loading

0 comments on commit 569ff39

Please sign in to comment.