From 2cacc08310194042e4c3e1b3b0819a7af6be9d71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20Flatval?= Date: Wed, 24 Jul 2024 11:20:59 +0200 Subject: [PATCH 1/2] fix(react-components): correctly differentiate between command types --- .../components/Architecture/CommandButton.tsx | 8 ------ .../Architecture/CommandButtons.tsx | 16 ++++++++--- .../components/Architecture/RevealButtons.tsx | 28 ++++++++++++------- 3 files changed, 30 insertions(+), 22 deletions(-) diff --git a/react-components/src/components/Architecture/CommandButton.tsx b/react-components/src/components/Architecture/CommandButton.tsx index 308332042ba..a7ef18a2551 100644 --- a/react-components/src/components/Architecture/CommandButton.tsx +++ b/react-components/src/components/Architecture/CommandButton.tsx @@ -10,14 +10,6 @@ import { type BaseCommand } from '../../architecture/base/commands/BaseCommand'; import { getButtonType, getDefaultCommand, getIcon, getTooltipPlacement } from './utilities'; import { LabelWithShortcut } from './LabelWithShortcut'; -export const createCommandButton = ( - commandConstructor: () => BaseCommand, - isHorizontal = false -): ReactElement => { - const command = useMemo(commandConstructor, []); - return ; -}; - export const CommandButton = ({ inputCommand, isHorizontal = false diff --git a/react-components/src/components/Architecture/CommandButtons.tsx b/react-components/src/components/Architecture/CommandButtons.tsx index abc2cc5f3bb..84e20378de7 100644 --- a/react-components/src/components/Architecture/CommandButtons.tsx +++ b/react-components/src/components/Architecture/CommandButtons.tsx @@ -2,20 +2,28 @@ * Copyright 2023 Cognite AS */ -import { type ReactElement } from 'react'; +import { useMemo, type ReactElement } from 'react'; import { Divider } from '@cognite/cogs.js'; import { type BaseCommand } from '../../architecture/base/commands/BaseCommand'; import { OptionButton } from './OptionButton'; import { BaseOptionCommand } from '../../architecture/base/commands/BaseOptionCommand'; import { CommandButton } from './CommandButton'; -export const CreateButton = (command: BaseCommand, isHorizontal = false): ReactElement => { +export function createButton(command: BaseCommand, isHorizontal = false): ReactElement { if (command instanceof BaseOptionCommand) { return ; } else { return ; } -}; +} + +export function createButtonFromCommandConstructor( + commandConstructor: () => BaseCommand, + isHorizontal = false +): ReactElement { + const command = useMemo(commandConstructor, []); + return createButton(command, isHorizontal); +} export const CommandButtons = ({ commands, @@ -57,5 +65,5 @@ function CommandButtonWrapper({ const direction = !isHorizontal ? 'horizontal' : 'vertical'; return ; } - return CreateButton(command, isHorizontal); + return createButton(command, isHorizontal); } diff --git a/react-components/src/components/Architecture/RevealButtons.tsx b/react-components/src/components/Architecture/RevealButtons.tsx index aaa08579235..431aa6fa1cb 100644 --- a/react-components/src/components/Architecture/RevealButtons.tsx +++ b/react-components/src/components/Architecture/RevealButtons.tsx @@ -11,30 +11,38 @@ import { SetAxisVisibleCommand } from '../../architecture/concrete/axis/SetAxisV import { ClipTool } from '../../architecture/concrete/clipping/ClipTool'; import { MeasurementTool } from '../../architecture/concrete/measurements/MeasurementTool'; import { KeyboardSpeedCommand } from '../../architecture/base/concreteCommands/KeyboardSpeedCommand'; -import { createCommandButton } from './CommandButton'; import { ObservationsTool } from '../../architecture/concrete/observations/ObservationsTool'; +import { createButtonFromCommandConstructor } from './CommandButtons'; export class RevealButtons { - static FitView = (): ReactElement => createCommandButton(() => new FitViewCommand()); + static FitView = (): ReactElement => + createButtonFromCommandConstructor(() => new FitViewCommand()); - static NavigationTool = (): ReactElement => createCommandButton(() => new NavigationTool()); + static NavigationTool = (): ReactElement => + createButtonFromCommandConstructor(() => new NavigationTool()); static SetAxisVisible = (): ReactElement => - createCommandButton(() => new SetAxisVisibleCommand()); + createButtonFromCommandConstructor(() => new SetAxisVisibleCommand()); - static Measurement = (): ReactElement => createCommandButton(() => new MeasurementTool()); + static Measurement = (): ReactElement => + createButtonFromCommandConstructor(() => new MeasurementTool()); - static Clip = (): ReactElement => createCommandButton(() => new ClipTool()); + static Clip = (): ReactElement => createButtonFromCommandConstructor(() => new ClipTool()); static SetFlexibleControlsTypeOrbit = (): ReactElement => - createCommandButton(() => new SetFlexibleControlsTypeCommand(FlexibleControlsType.Orbit)); + createButtonFromCommandConstructor( + () => new SetFlexibleControlsTypeCommand(FlexibleControlsType.Orbit) + ); static SetFlexibleControlsTypeFirstPerson = (): ReactElement => - createCommandButton(() => new SetFlexibleControlsTypeCommand(FlexibleControlsType.FirstPerson)); + createButtonFromCommandConstructor( + () => new SetFlexibleControlsTypeCommand(FlexibleControlsType.FirstPerson) + ); static Observations = (): ReactElement => { - return createCommandButton(() => new ObservationsTool()); + return createButtonFromCommandConstructor(() => new ObservationsTool()); }; - static KeyboardSpeed = (): ReactElement => createCommandButton(() => new KeyboardSpeedCommand()); + static KeyboardSpeed = (): ReactElement => + createButtonFromCommandConstructor(() => new KeyboardSpeedCommand()); } From aa9480a716eb7ad67e0184d4d3da49c48f92e065 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20Flatval?= Date: Wed, 24 Jul 2024 11:32:07 +0200 Subject: [PATCH 2/2] chore: bump react-components to 0.54.1 --- react-components/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/react-components/package.json b/react-components/package.json index 9e65777e086..861597f981a 100644 --- a/react-components/package.json +++ b/react-components/package.json @@ -1,6 +1,6 @@ { "name": "@cognite/reveal-react-components", - "version": "0.54.0", + "version": "0.54.1", "exports": { ".": { "import": "./dist/index.js",