From a8d76950d0333a64f3382f11ab8f06d53fc036b7 Mon Sep 17 00:00:00 2001 From: Kevin Nadro Date: Wed, 5 Feb 2025 12:34:08 -0600 Subject: [PATCH] fix: fixing react race condition on parsing numeric literals in command bar on open --- e2e/playwright/fixtures/cmdBarFixture.ts | 17 +++++++++++++++++ e2e/playwright/point-click.spec.ts | 4 +++- package.json | 2 +- src/components/CommandBar/CommandBarHeader.tsx | 2 ++ .../CommandBar/CommandBarKclInput.tsx | 1 + src/lib/useCalculateKclExpression.ts | 11 ++++++++++- 6 files changed, 34 insertions(+), 3 deletions(-) diff --git a/e2e/playwright/fixtures/cmdBarFixture.ts b/e2e/playwright/fixtures/cmdBarFixture.ts index 6c9f720d7..24c3967ff 100644 --- a/e2e/playwright/fixtures/cmdBarFixture.ts +++ b/e2e/playwright/fixtures/cmdBarFixture.ts @@ -121,6 +121,23 @@ export class CmdBarFixture { } } + // Added data-testid to the command bar buttons + // command-bar-continue are the buttons to go to the next step + // does not include the submit which is the final button press + // aka the right arrow button + continue = async () => { + const continueButton = this.page.getByTestId('command-bar-continue') + await continueButton.click() + } + + // Added data-testid to the commad bar buttons + // command-bar-submit is the button for the final step to submit + // the command bar flow aka the checkmark button. + submit = async () => { + const submitButton = this.page.getByTestId('command-bar-submit') + await submitButton.click() + } + openCmdBar = async (selectCmd?: 'promptToEdit') => { // TODO why does this button not work in electron tests? // await this.cmdBarOpenBtn.click() diff --git a/e2e/playwright/point-click.spec.ts b/e2e/playwright/point-click.spec.ts index f672527ba..62e735cb1 100644 --- a/e2e/playwright/point-click.spec.ts +++ b/e2e/playwright/point-click.spec.ts @@ -30,11 +30,13 @@ test('verify extruding circle works', async ({ localStorage.setItem('persistCode', file) }, file) await homePage.goToModelingScene() + await scene.waitForExecutionDone() const [clickCircle, moveToCircle] = scene.makeMouseHelpers(582, 217) await test.step('because there is sweepable geometry, verify extrude is enable when nothing is selected', async () => { - await scene.clickNoWhere() + // FIXME: Do not click, clicking removes the activeLines in future checks + // await scene.clickNoWhere() await expect(toolbar.extrudeButton).toBeEnabled() }) diff --git a/package.json b/package.json index 7efd37be4..28f287a19 100644 --- a/package.json +++ b/package.json @@ -119,7 +119,7 @@ "test:playwright:electron:local": "yarn tronb:package:dev && NODE_ENV=development playwright test --config=playwright.electron.config.ts --grep-invert='@snapshot'", "test:playwright:electron:windows:local": "yarn tronb:package:dev && set NODE_ENV='development' && playwright test --config=playwright.electron.config.ts --grep-invert=\"@skipWin|@snapshot\"", "test:playwright:electron:macos:local": "yarn tronb:package:dev && NODE_ENV=development playwright test --config=playwright.electron.config.ts --grep-invert='@skipMacos|@snapshot'", - "test:playwright:electron:ubuntu:local": "yarn tronb:package:dev && NODE_ENV=development playwright test --config=playwright.electron.config.ts --grep-invert='@skipLinux|@snapshot'", + "test:playwright:electron:ubuntu:local": "yarn tronb:vite:dev && NODE_ENV=development playwright test --config=playwright.electron.config.ts --grep-invert='@skipLinux|@snapshot'", "test:unit:local": "yarn simpleserver:bg && yarn test:unit; kill-port 3000", "test:unit:kcl-samples:local": "yarn simpleserver:bg && yarn test:unit:kcl-samples; kill-port 3000" }, diff --git a/src/components/CommandBar/CommandBarHeader.tsx b/src/components/CommandBar/CommandBarHeader.tsx index a55a95a5c..6dd932823 100644 --- a/src/components/CommandBar/CommandBarHeader.tsx +++ b/src/components/CommandBar/CommandBarHeader.tsx @@ -195,6 +195,7 @@ function ReviewingButton() { type="submit" form="review-form" className="w-fit !p-0 rounded-sm hover:shadow" + data-testid="command-bar-submit" iconStart={{ icon: 'checkmark', bgClassName: 'p-1 rounded-sm !bg-primary hover:brightness-110', @@ -213,6 +214,7 @@ function GatheringArgsButton() { type="submit" form="arg-form" className="w-fit !p-0 rounded-sm hover:shadow" + data-testid="command-bar-continue" iconStart={{ icon: 'arrowRight', bgClassName: 'p-1 rounded-sm !bg-primary hover:brightness-110', diff --git a/src/components/CommandBar/CommandBarKclInput.tsx b/src/components/CommandBar/CommandBarKclInput.tsx index 48c8f3c86..dcee3b663 100644 --- a/src/components/CommandBar/CommandBarKclInput.tsx +++ b/src/components/CommandBar/CommandBarKclInput.tsx @@ -97,6 +97,7 @@ function CommandBarKclInput({ value, initialVariableName, }) + const varMentionData: Completion[] = prevVariables.map((v) => ({ label: v.key, detail: String(roundOff(v.value as number)), diff --git a/src/lib/useCalculateKclExpression.ts b/src/lib/useCalculateKclExpression.ts index d758d7b09..3e46250f6 100644 --- a/src/lib/useCalculateKclExpression.ts +++ b/src/lib/useCalculateKclExpression.ts @@ -48,7 +48,16 @@ export function useCalculateKclExpression({ bodyPath: [], }) const [valueNode, setValueNode] = useState(null) - const [calcResult, setCalcResult] = useState('NAN') + // If we pass in numeric literals, we should instantly parse them, they have nothing to do with application memory + const _code_value = `const __result__ = ${value}` + const codeValueParseResult = parse(_code_value) + let isValueParsable = true + if (err(codeValueParseResult) || !resultIsOk(codeValueParseResult)) { + isValueParsable = false + } + const initialCalcResult: number | string = + isNaN(Number(value)) || !isValueParsable ? 'NAN' : value + const [calcResult, setCalcResult] = useState(initialCalcResult) const [newVariableName, setNewVariableName] = useState('') const [isNewVariableNameUnique, setIsNewVariableNameUnique] = useState(true)