feat(curve): remove curve factory type

Signed-off-by: andrmaz <60042277+andrmaz@users.noreply.github.com>
This commit is contained in:
andrmaz
2022-10-09 23:56:17 +02:00
parent 46ee5188e9
commit 5b9b2e0e41
7 changed files with 16 additions and 29 deletions
+2 -5
View File
@@ -30,7 +30,7 @@ export const CatalogGraphPage: (props: {
mergeRelations?: boolean | undefined;
direction?: Direction | undefined;
showFilters?: boolean | undefined;
curve?: Curve | undefined;
curve?: 'curveStepBefore' | 'curveMonotoneX' | undefined;
}
| undefined;
}) => JSX.Element;
@@ -55,9 +55,6 @@ export const catalogGraphPlugin: BackstagePlugin<
// @public
export const catalogGraphRouteRef: RouteRef<undefined>;
// @public
export type Curve = 'curveStepBefore' | 'curveMonotoneX';
// @public
export enum Direction {
BOTTOM_TOP = 'BT',
@@ -123,7 +120,7 @@ export const EntityRelationsGraph: (props: {
renderLabel?:
| DependencyGraphTypes.RenderLabelFunction<EntityEdge>
| undefined;
curve?: Curve | undefined;
curve?: 'curveStepBefore' | 'curveMonotoneX' | undefined;
}) => JSX.Element;
// @public
@@ -35,7 +35,6 @@ import React, { MouseEvent, useCallback } from 'react';
import { useNavigate } from 'react-router';
import {
ALL_RELATION_PAIRS,
Curve,
Direction,
EntityNode,
EntityRelationsGraph,
@@ -112,7 +111,7 @@ export const CatalogGraphPage = (props: {
mergeRelations?: boolean;
direction?: Direction;
showFilters?: boolean;
curve?: Curve;
curve?: 'curveStepBefore' | 'curveMonotoneX';
};
}) => {
const { relationPairs = ALL_RELATION_PAIRS, initialState } = props;
@@ -16,8 +16,8 @@
import { Select } from '@backstage/core-components';
import { Box } from '@material-ui/core';
import React, { useCallback } from 'react';
import { Curve } from '../EntityRelationsGraph';
type Curve = 'curveStepBefore' | 'curveMonotoneX';
const CURVE_DISPLAY_NAMES: Record<Curve, string> = {
curveMonotoneX: 'Monotone X',
curveStepBefore: 'Step Before',
@@ -25,10 +25,10 @@ const CURVE_DISPLAY_NAMES: Record<Curve, string> = {
export type Props = {
value: Curve;
onChange: (value: Curve) => void;
onChange: (value: 'curveStepBefore' | 'curveMonotoneX') => void;
};
const curves: Curve[] = ['curveMonotoneX', 'curveStepBefore'];
const curves: Array<Curve> = ['curveMonotoneX', 'curveStepBefore'];
export const CurveFilter = ({ value, onChange }: Props) => {
const handleChange = useCallback(v => onChange(v as Curve), [onChange]);
@@ -29,7 +29,7 @@ import {
} from 'react';
import { useLocation } from 'react-router';
import usePrevious from 'react-use/lib/usePrevious';
import { Direction, Curve } from '../EntityRelationsGraph';
import { Direction } from '../EntityRelationsGraph';
export type CatalogGraphPageValue = {
rootEntityNames: CompoundEntityRef[];
@@ -46,8 +46,10 @@ export type CatalogGraphPageValue = {
setMergeRelations: Dispatch<React.SetStateAction<boolean>>;
direction: Direction;
setDirection: Dispatch<React.SetStateAction<Direction>>;
curve: Curve;
setCurve: Dispatch<React.SetStateAction<Curve>>;
curve: 'curveStepBefore' | 'curveMonotoneX';
setCurve: Dispatch<
React.SetStateAction<'curveStepBefore' | 'curveMonotoneX'>
>;
showFilters: boolean;
toggleShowFilters: DispatchWithoutAction;
};
@@ -64,7 +66,7 @@ export function useCatalogGraphPage({
mergeRelations?: boolean;
direction?: Direction;
showFilters?: boolean;
curve?: Curve;
curve?: 'curveStepBefore' | 'curveMonotoneX';
};
}): CatalogGraphPageValue {
const location = useLocation();
@@ -80,7 +82,7 @@ export function useCatalogGraphPage({
mergeRelations?: string[] | string;
direction?: string[] | Direction;
showFilters?: string[] | string;
curve?: string[] | Curve;
curve?: string[] | 'curveStepBefore' | 'curveMonotoneX';
},
[location.search],
);
@@ -126,7 +128,7 @@ export function useCatalogGraphPage({
? query.direction
: initialState?.direction ?? Direction.LEFT_RIGHT,
);
const [curve, setCurve] = useState<Curve>(() =>
const [curve, setCurve] = useState<'curveStepBefore' | 'curveMonotoneX'>(() =>
typeof query.curve === 'string'
? query.curve
: initialState?.curve ?? 'curveMonotoneX',
@@ -29,7 +29,7 @@ import React, { MouseEvent, useEffect, useMemo } from 'react';
import { CustomLabel } from './CustomLabel';
import { CustomNode } from './CustomNode';
import { ALL_RELATION_PAIRS, RelationPairs } from './relations';
import { Curve, Direction, EntityEdge, EntityNode } from './types';
import { Direction, EntityEdge, EntityNode } from './types';
import { useEntityRelationNodesAndEdges } from './useEntityRelationNodesAndEdges';
const useStyles = makeStyles(theme => ({
@@ -82,7 +82,7 @@ export const EntityRelationsGraph = (props: {
zoom?: 'enabled' | 'disabled' | 'enable-on-click';
renderNode?: DependencyGraphTypes.RenderNodeFunction<EntityNode>;
renderLabel?: DependencyGraphTypes.RenderLabelFunction<EntityEdge>;
curve?: Curve;
curve?: 'curveStepBefore' | 'curveMonotoneX';
}) => {
const {
rootEntityNames,
@@ -22,5 +22,4 @@ export type {
EntityEdge,
EntityNodeData,
EntityNode,
Curve,
} from './types';
@@ -108,13 +108,3 @@ export enum Direction {
*/
RIGHT_LEFT = 'RL',
}
/**
* Graph curve factory
*
* @public
*
* @see {@link @types/d3-shape/index.d.ts#curveMonotoneX}
* @see {@link @types/d3-shape/index.d.ts#curveStepBefore}
*/
export type Curve = 'curveStepBefore' | 'curveMonotoneX';