From 92431298b2c2d7fe45ece3f2e6a8cf9a3725a8c9 Mon Sep 17 00:00:00 2001 From: David Lechner Date: Wed, 10 Aug 2022 12:47:18 -0500 Subject: [PATCH] toolbar/RunButton: enable only when active file Before multi-file support, it was not possible to have no open file. So we need to change the state logic to only enable the button when there is an active file rather than when the editor "is ready". Fixes: https://github.com/pybricks/support/issues/691 --- CHANGELOG.md | 5 +++++ src/toolbar/buttons/run/RunButton.test.tsx | 4 ++-- src/toolbar/buttons/run/RunButton.tsx | 4 ++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f31e6178..3574d5f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ ## [Unreleased] +### Fixed +- Fixed run button enabled when no file open ([support#691]). + +[support#691]: https://github.com/pybricks/support/issues/691 + ## [2.0.0-beta.5] - 2022-07-28 ### Fixed diff --git a/src/toolbar/buttons/run/RunButton.test.tsx b/src/toolbar/buttons/run/RunButton.test.tsx index 9359fb44..653ed1a7 100644 --- a/src/toolbar/buttons/run/RunButton.test.tsx +++ b/src/toolbar/buttons/run/RunButton.test.tsx @@ -3,7 +3,7 @@ import { cleanup } from '@testing-library/react'; import React from 'react'; -import { testRender } from '../../../../test'; +import { testRender, uuid } from '../../../../test'; import { downloadAndRun } from '../../../hub/actions'; import { HubRuntimeState } from '../../../hub/reducers'; import RunButton from './RunButton'; @@ -14,7 +14,7 @@ afterEach(() => { it('should dispatch action when clicked', async () => { const [user, button, dispatch] = testRender(, { - editor: { isReady: true }, + editor: { activeFileUuid: uuid(0) }, hub: { runtime: HubRuntimeState.Idle }, }); diff --git a/src/toolbar/buttons/run/RunButton.tsx b/src/toolbar/buttons/run/RunButton.tsx index 4eb265cd..35cee8dd 100644 --- a/src/toolbar/buttons/run/RunButton.tsx +++ b/src/toolbar/buttons/run/RunButton.tsx @@ -16,7 +16,7 @@ const RunButton: React.VoidFunctionComponent = ({ id }) => { const downloadProgress = useSelector((s) => s.hub.downloadProgress); const mpyAbiVersion = useSelector((s) => s.hub.mpyAbiVersion); const runtime = useSelector((s) => s.hub.runtime); - const isEditorReady = useSelector((s) => s.editor.isReady); + const activeFile = useSelector((s) => s.editor.activeFileUuid); const keyboardShortcut = 'F5'; const i18n = useI18n(); @@ -35,7 +35,7 @@ const RunButton: React.VoidFunctionComponent = ({ id }) => { : i18n.translate('tooltip.action', { key: keyboardShortcut }) } icon={icon} - enabled={isEditorReady && runtime === HubRuntimeState.Idle} + enabled={activeFile !== null && runtime === HubRuntimeState.Idle} showProgress={runtime === HubRuntimeState.Loading} progress={downloadProgress === null ? undefined : downloadProgress} onAction={() => dispatch(downloadAndRun(mpyAbiVersion))}