From 85951cd67ef37cfcd5c400d5803d3f8d7799e40a Mon Sep 17 00:00:00 2001 From: guerler Date: Sat, 1 Jun 2024 09:54:35 +0300 Subject: [PATCH 1/5] Add pinia to manually mounted vue components --- client/src/utils/mountVueComponent.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/client/src/utils/mountVueComponent.js b/client/src/utils/mountVueComponent.js index 0e0ee949728d..2adedbba5d1f 100644 --- a/client/src/utils/mountVueComponent.js +++ b/client/src/utils/mountVueComponent.js @@ -4,8 +4,12 @@ import BootstrapVue from "bootstrap-vue"; import { iconPlugin, localizationPlugin, vueRxShortcutPlugin } from "components/plugins"; +import { createPinia, PiniaVuePlugin } from "pinia"; import Vue from "vue"; +// Load Pinia +Vue.use(PiniaVuePlugin); + // Bootstrap components Vue.use(BootstrapVue); @@ -18,15 +22,18 @@ Vue.use(vueRxShortcutPlugin); // font-awesome svg icon registration/loading Vue.use(iconPlugin); +// Create Pinia +const pinia = createPinia(); + export const mountVueComponent = (ComponentDefinition) => { const component = Vue.extend(ComponentDefinition); - return (propsData, el) => new component({ propsData, el }); + return (propsData, el) => new component({ propsData, el, pinia }); }; export const replaceChildrenWithComponent = (el, ComponentDefinition, propsData = {}) => { const container = document.createElement("div"); el.replaceChildren(container); const component = Vue.extend(ComponentDefinition); - const mountFn = (propsData, el) => new component({ propsData, el }); + const mountFn = (propsData, el) => new component({ propsData, el, pinia }); return mountFn(propsData, container); }; From b2076ee5f98aa86a194446ccf573042879bebc8a Mon Sep 17 00:00:00 2001 From: Nicola Soranzo Date: Sun, 2 Jun 2024 19:21:10 +0100 Subject: [PATCH 2/5] Move carbon data loading to ``GalaxyManagerApplication`` Fix the galaxy-config package wrongly depending on galaxy-app. Also move the carbon_emissions unit tests to the `app/` subdirectory. Refines @mvdbeek's proposed patch from https://github.com/galaxyproject/galaxy/pull/17159#issuecomment-1850276194 . Close https://github.com/galaxyproject/galaxy/pull/17159 . --- lib/galaxy/app.py | 5 +++++ lib/galaxy/config/__init__.py | 8 -------- lib/galaxy/managers/configuration.py | 4 ++-- lib/galaxy/structured_app.py | 2 ++ test/unit/{ => app}/carbon_emissions/__init__.py | 0 .../carbon_emissions/test_get_carbon_intensity_entry.py | 0 6 files changed, 9 insertions(+), 10 deletions(-) rename test/unit/{ => app}/carbon_emissions/__init__.py (100%) rename test/unit/{ => app}/carbon_emissions/test_get_carbon_intensity_entry.py (100%) diff --git a/lib/galaxy/app.py b/lib/galaxy/app.py index 1d65289f499a..0cd8c8eab102 100644 --- a/lib/galaxy/app.py +++ b/lib/galaxy/app.py @@ -28,6 +28,7 @@ jobs, tools, ) +from galaxy.carbon_emissions import get_carbon_intensity_entry from galaxy.celery.base_task import ( GalaxyTaskBeforeStart, GalaxyTaskBeforeStartUserRateLimitPostgres, @@ -556,6 +557,10 @@ def __init__(self, configure_logging=True, use_converters=True, use_display_appl self.application_stack = self._register_singleton(ApplicationStack, application_stack_instance(app=self)) if configure_logging: config.configure_logging(self.config, self.application_stack.facts) + # Carbon emissions configuration + carbon_intensity_entry = get_carbon_intensity_entry(self.config.geographical_server_location_code) + self.carbon_intensity = carbon_intensity_entry["carbon_intensity"] + self.geographical_server_location_name = carbon_intensity_entry["location_name"] # Initialize job metrics manager, needs to be in place before # config so per-destination modifications can be made. self.job_metrics = self._register_singleton( diff --git a/lib/galaxy/config/__init__.py b/lib/galaxy/config/__init__.py index e3da3e743e55..554018472dc9 100644 --- a/lib/galaxy/config/__init__.py +++ b/lib/galaxy/config/__init__.py @@ -34,7 +34,6 @@ import yaml -from galaxy.carbon_emissions import get_carbon_intensity_entry from galaxy.config.schema import AppSchema from galaxy.exceptions import ConfigurationError from galaxy.util import ( @@ -700,7 +699,6 @@ class GalaxyAppConfiguration(BaseAppConfiguration, CommonConfigurationMixin): allowed_origin_hostnames: List[str] builds_file_path: str - carbon_intensity: float container_resolvers_config_file: str database_connection: str drmaa_external_runjob_script: str @@ -708,7 +706,6 @@ class GalaxyAppConfiguration(BaseAppConfiguration, CommonConfigurationMixin): enable_tool_shed_check: bool galaxy_data_manager_data_path: str galaxy_infrastructure_url: str - geographical_server_location_name: str hours_between_check: int integrated_tool_panel_config: str involucro_path: str @@ -814,11 +811,6 @@ def _process_config(self, kwargs: Dict[str, Any]) -> None: else: self.version_extra = extra_info - # Carbon emissions configuration - carbon_intensity_entry = get_carbon_intensity_entry(kwargs.get("geographical_server_location_code", "")) - self.carbon_intensity = carbon_intensity_entry["carbon_intensity"] - self.geographical_server_location_name = carbon_intensity_entry["location_name"] - # Database related configuration self.check_migrate_databases = string_as_bool(kwargs.get("check_migrate_databases", True)) if not self.database_connection: # Provide default if not supplied by user diff --git a/lib/galaxy/managers/configuration.py b/lib/galaxy/managers/configuration.py index 14348c06742b..7a133b3f0fb2 100644 --- a/lib/galaxy/managers/configuration.py +++ b/lib/galaxy/managers/configuration.py @@ -183,8 +183,8 @@ def _config_is_truthy(item, key, **context): "interactivetools_enable": _use_config, "aws_estimate": _use_config, "carbon_emission_estimates": _defaults_to(True), - "carbon_intensity": _use_config, - "geographical_server_location_name": _use_config, + "carbon_intensity": lambda item, key, **context: self.app.carbon_intensity, + "geographical_server_location_name": lambda item, key, **context: self.app.geographical_server_location_name, "geographical_server_location_code": _use_config, "power_usage_effectiveness": _use_config, "message_box_content": _use_config, diff --git a/lib/galaxy/structured_app.py b/lib/galaxy/structured_app.py index ebab917098fc..7ab7bcba3977 100644 --- a/lib/galaxy/structured_app.py +++ b/lib/galaxy/structured_app.py @@ -101,8 +101,10 @@ class MinimalApp(BasicSharedApp): class MinimalManagerApp(MinimalApp): # Minimal App that is sufficient to run Celery tasks + carbon_intensity: float file_sources: ConfiguredFileSources genome_builds: GenomeBuilds + geographical_server_location_name: str dataset_collection_manager: "DatasetCollectionManager" tool_data_tables: "ToolDataTableManager" history_manager: "HistoryManager" diff --git a/test/unit/carbon_emissions/__init__.py b/test/unit/app/carbon_emissions/__init__.py similarity index 100% rename from test/unit/carbon_emissions/__init__.py rename to test/unit/app/carbon_emissions/__init__.py diff --git a/test/unit/carbon_emissions/test_get_carbon_intensity_entry.py b/test/unit/app/carbon_emissions/test_get_carbon_intensity_entry.py similarity index 100% rename from test/unit/carbon_emissions/test_get_carbon_intensity_entry.py rename to test/unit/app/carbon_emissions/test_get_carbon_intensity_entry.py From 1174bbe8f47aa238615a1366b3598f5cf2b89220 Mon Sep 17 00:00:00 2001 From: Nicola Soranzo Date: Sun, 2 Jun 2024 19:39:05 +0100 Subject: [PATCH 3/5] Fix packages' dependencies and MANIFEST.in files Also: - Add missing `graphene` and `graphql-core` dependencies to `pyproject.toml` (already installed as other dependencies' deps, but explicitly imported by ToolShed code). - Move `test_tool_validation.py` unit tests to the galaxy-tool-shed package. --- packages/test_driver/setup.cfg | 2 -- packages/tool_shed/MANIFEST.in | 1 + packages/tool_shed/setup.cfg | 25 +++++++++++++++++++ packages/web_apps/MANIFEST.in | 2 -- .../datatypes/display_applications/configs | 1 - packages/web_apps/setup.cfg | 2 -- pyproject.toml | 4 ++- .../test_tool_validation.py | 0 8 files changed, 29 insertions(+), 8 deletions(-) delete mode 120000 packages/web_apps/galaxy/datatypes/display_applications/configs rename test/unit/{webapps => tool_shed}/test_tool_validation.py (100%) diff --git a/packages/test_driver/setup.cfg b/packages/test_driver/setup.cfg index 6f4efce2cfab..5c3292823c1b 100644 --- a/packages/test_driver/setup.cfg +++ b/packages/test_driver/setup.cfg @@ -40,8 +40,6 @@ install_requires = galaxy-util galaxy-web-apps pytest - graphene-sqlalchemy==3.0.0rc1 # these are only needed by tool shed - which we've split out but the test driver loads - starlette-graphene3 packages = find: python_requires = >=3.8 diff --git a/packages/tool_shed/MANIFEST.in b/packages/tool_shed/MANIFEST.in index 12302eb8dff0..d9a9578d12ba 100644 --- a/packages/tool_shed/MANIFEST.in +++ b/packages/tool_shed/MANIFEST.in @@ -1 +1,2 @@ include *.rst *.txt LICENSE */py.typed +graft tool_shed/webapp/templates/ diff --git a/packages/tool_shed/setup.cfg b/packages/tool_shed/setup.cfg index 4e78a7c84c29..9ec024a7992c 100644 --- a/packages/tool_shed/setup.cfg +++ b/packages/tool_shed/setup.cfg @@ -32,8 +32,33 @@ version = 23.2.dev0 [options] include_package_data = True install_requires = + galaxy-app + galaxy-auth + galaxy-config + galaxy-data + galaxy-util + galaxy-web-framework galaxy-web-stack galaxy-web-apps + a2wsgi + alembic + fastapi>=0.101.0 + graphene + graphene-sqlalchemy>=3.0.0rc1 + graphql-core + Mako + MarkupSafe + mercurial + Paste + pydantic>=2,!=2.6.0,!=2.6.1 + Routes + SQLAlchemy>=2.0,<2.1 + starlette + starlette-context + starlette-graphene3 + typing-extensions + WebOb + Whoosh packages = find: python_requires = >=3.8 diff --git a/packages/web_apps/MANIFEST.in b/packages/web_apps/MANIFEST.in index fe784b101c20..9c04be40d0fd 100644 --- a/packages/web_apps/MANIFEST.in +++ b/packages/web_apps/MANIFEST.in @@ -7,5 +7,3 @@ prune galaxy/webapps/base/static/plugins/ exclude galaxy/webapps/base/static/style/base.css exclude galaxy/webapps/base/static/welcome.html graft galaxy/webapps/base/templates/ -include tool_shed/webapp/model/migrate/migrate.cfg -graft tool_shed/webapp/templates/ diff --git a/packages/web_apps/galaxy/datatypes/display_applications/configs b/packages/web_apps/galaxy/datatypes/display_applications/configs deleted file mode 120000 index bd4fe9cae4ab..000000000000 --- a/packages/web_apps/galaxy/datatypes/display_applications/configs +++ /dev/null @@ -1 +0,0 @@ -../../../../../lib/galaxy/datatypes/display_applications/configs \ No newline at end of file diff --git a/packages/web_apps/setup.cfg b/packages/web_apps/setup.cfg index 53ef00625581..02b2a8005312 100644 --- a/packages/web_apps/setup.cfg +++ b/packages/web_apps/setup.cfg @@ -49,7 +49,6 @@ install_requires = importlib-resources;python_version<'3.9' Mako MarkupSafe - mercurial Paste pydantic>=2,!=2.6.0,!=2.6.1 PyJWT @@ -67,7 +66,6 @@ install_requires = uvicorn uvloop WebOb - Whoosh packages = find: python_requires = >=3.8 diff --git a/pyproject.toml b/pyproject.toml index f927c91fc45c..2f7355735122 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -61,7 +61,9 @@ fastapi-slim = ">=0.111.0" fs = "*" future = ">=1.0.0" # Python 3.12 support galaxy_sequence_utils = "*" -graphene-sqlalchemy = "3.0.0rc1" # need a beta release to be compat. with starlette plugin +graphene = "*" +graphene-sqlalchemy = ">=3.0.0rc1" # need a beta release to be compat. with starlette plugin +graphql-core = "*" gravity = ">=1.0.4" gunicorn = "*" gxformat2 = "*" diff --git a/test/unit/webapps/test_tool_validation.py b/test/unit/tool_shed/test_tool_validation.py similarity index 100% rename from test/unit/webapps/test_tool_validation.py rename to test/unit/tool_shed/test_tool_validation.py From 80701f4fc125db4009c96175732a1ef573dd7525 Mon Sep 17 00:00:00 2001 From: Nicola Soranzo Date: Sun, 2 Jun 2024 19:56:07 +0100 Subject: [PATCH 4/5] Add ``pytest.ini`` files to all packages Previously, when running pytest from `packages/test.sh`, it was using our main `pytest.ini` as configfile, therefore setting the wrong rootdir and using `lib` as `pythonpath`. This was hiding various packaging issues fixed in the previous commits. --- packages/app/pytest.ini | 3 +-- packages/auth/pytest.ini | 1 + packages/config/pytest.ini | 1 + packages/data/pytest.ini | 1 + packages/files/pytest.ini | 1 + packages/job_execution/pytest.ini | 1 + packages/job_metrics/pytest.ini | 1 + packages/meta/pytest.ini | 1 + packages/navigation/pytest.ini | 1 + packages/objectstore/pytest.ini | 1 + packages/package-pytest.ini | 6 ++++++ packages/schema/pytest.ini | 1 + packages/selenium/pytest.ini | 1 + packages/test.sh | 5 +---- packages/test_api/pytest.ini | 1 + packages/test_base/pytest.ini | 1 + packages/test_driver/pytest.ini | 1 + packages/test_selenium/pytest.ini | 1 + packages/tool_shed/pytest.ini | 1 + packages/tool_util/pytest.ini | 1 + packages/tours/pytest.ini | 1 + packages/util/pytest.ini | 1 + packages/web_apps/pytest.ini | 1 + packages/web_framework/pytest.ini | 1 + packages/web_stack/pytest.ini | 1 + 25 files changed, 30 insertions(+), 6 deletions(-) mode change 100644 => 120000 packages/app/pytest.ini create mode 120000 packages/auth/pytest.ini create mode 120000 packages/config/pytest.ini create mode 120000 packages/data/pytest.ini create mode 120000 packages/files/pytest.ini create mode 120000 packages/job_execution/pytest.ini create mode 120000 packages/job_metrics/pytest.ini create mode 120000 packages/meta/pytest.ini create mode 120000 packages/navigation/pytest.ini create mode 120000 packages/objectstore/pytest.ini create mode 100644 packages/package-pytest.ini create mode 120000 packages/schema/pytest.ini create mode 120000 packages/selenium/pytest.ini create mode 120000 packages/test_api/pytest.ini create mode 120000 packages/test_base/pytest.ini create mode 120000 packages/test_driver/pytest.ini create mode 120000 packages/test_selenium/pytest.ini create mode 120000 packages/tool_shed/pytest.ini create mode 120000 packages/tool_util/pytest.ini create mode 120000 packages/tours/pytest.ini create mode 120000 packages/util/pytest.ini create mode 120000 packages/web_apps/pytest.ini create mode 120000 packages/web_framework/pytest.ini create mode 120000 packages/web_stack/pytest.ini diff --git a/packages/app/pytest.ini b/packages/app/pytest.ini deleted file mode 100644 index 6b5e4056f66f..000000000000 --- a/packages/app/pytest.ini +++ /dev/null @@ -1,2 +0,0 @@ -[pytest] -addopts = --ignore-glob 'galaxy/tools/bundled/*' diff --git a/packages/app/pytest.ini b/packages/app/pytest.ini new file mode 120000 index 000000000000..d1bd969dce80 --- /dev/null +++ b/packages/app/pytest.ini @@ -0,0 +1 @@ +../package-pytest.ini \ No newline at end of file diff --git a/packages/auth/pytest.ini b/packages/auth/pytest.ini new file mode 120000 index 000000000000..d1bd969dce80 --- /dev/null +++ b/packages/auth/pytest.ini @@ -0,0 +1 @@ +../package-pytest.ini \ No newline at end of file diff --git a/packages/config/pytest.ini b/packages/config/pytest.ini new file mode 120000 index 000000000000..d1bd969dce80 --- /dev/null +++ b/packages/config/pytest.ini @@ -0,0 +1 @@ +../package-pytest.ini \ No newline at end of file diff --git a/packages/data/pytest.ini b/packages/data/pytest.ini new file mode 120000 index 000000000000..d1bd969dce80 --- /dev/null +++ b/packages/data/pytest.ini @@ -0,0 +1 @@ +../package-pytest.ini \ No newline at end of file diff --git a/packages/files/pytest.ini b/packages/files/pytest.ini new file mode 120000 index 000000000000..d1bd969dce80 --- /dev/null +++ b/packages/files/pytest.ini @@ -0,0 +1 @@ +../package-pytest.ini \ No newline at end of file diff --git a/packages/job_execution/pytest.ini b/packages/job_execution/pytest.ini new file mode 120000 index 000000000000..d1bd969dce80 --- /dev/null +++ b/packages/job_execution/pytest.ini @@ -0,0 +1 @@ +../package-pytest.ini \ No newline at end of file diff --git a/packages/job_metrics/pytest.ini b/packages/job_metrics/pytest.ini new file mode 120000 index 000000000000..d1bd969dce80 --- /dev/null +++ b/packages/job_metrics/pytest.ini @@ -0,0 +1 @@ +../package-pytest.ini \ No newline at end of file diff --git a/packages/meta/pytest.ini b/packages/meta/pytest.ini new file mode 120000 index 000000000000..d1bd969dce80 --- /dev/null +++ b/packages/meta/pytest.ini @@ -0,0 +1 @@ +../package-pytest.ini \ No newline at end of file diff --git a/packages/navigation/pytest.ini b/packages/navigation/pytest.ini new file mode 120000 index 000000000000..d1bd969dce80 --- /dev/null +++ b/packages/navigation/pytest.ini @@ -0,0 +1 @@ +../package-pytest.ini \ No newline at end of file diff --git a/packages/objectstore/pytest.ini b/packages/objectstore/pytest.ini new file mode 120000 index 000000000000..d1bd969dce80 --- /dev/null +++ b/packages/objectstore/pytest.ini @@ -0,0 +1 @@ +../package-pytest.ini \ No newline at end of file diff --git a/packages/package-pytest.ini b/packages/package-pytest.ini new file mode 100644 index 000000000000..34f513224dcf --- /dev/null +++ b/packages/package-pytest.ini @@ -0,0 +1,6 @@ +[pytest] +# Prevent execution of alembic/env.py at test collection stage (alembic.context not set). +# Also ignore functional tests (galaxy_test/ and tool_shed/test/). +addopts = --doctest-modules --ignore=galaxy/model/migrations/alembic/ --ignore=galaxy/tools/bundled/ --ignore=galaxy_test/ --ignore=tool_shed/test/ --ignore=tool_shed/webapp/model/migrations/alembic/ --doctest-continue-on-failure --verbosity=1 +asyncio_mode = auto +log_level = DEBUG diff --git a/packages/schema/pytest.ini b/packages/schema/pytest.ini new file mode 120000 index 000000000000..d1bd969dce80 --- /dev/null +++ b/packages/schema/pytest.ini @@ -0,0 +1 @@ +../package-pytest.ini \ No newline at end of file diff --git a/packages/selenium/pytest.ini b/packages/selenium/pytest.ini new file mode 120000 index 000000000000..d1bd969dce80 --- /dev/null +++ b/packages/selenium/pytest.ini @@ -0,0 +1 @@ +../package-pytest.ini \ No newline at end of file diff --git a/packages/test.sh b/packages/test.sh index be98e038285e..d2ed377c352b 100755 --- a/packages/test.sh +++ b/packages/test.sh @@ -63,11 +63,8 @@ while read -r package_dir || [ -n "$package_dir" ]; do # https://stackoverflow. else marker_args=() fi - # Prevent execution of alembic/env.py at test collection stage (alembic.context not set) - # Also ignore functional tests (galaxy_test/ and tool_shed/test/). - unit_extra=(--doctest-modules --ignore=galaxy/model/migrations/alembic/ --ignore=galaxy_test/ --ignore=tool_shed/test/ --ignore=tool_shed/webapp/model/migrations/alembic/ "${marker_args[@]}") # Ignore exit code 5 (no tests ran) - pytest "${unit_extra[@]}" . || test $? -eq 5 + pytest "${marker_args[@]}" . || test $? -eq 5 if [ $FOR_PULSAR -eq 0 ]; then make mypy fi diff --git a/packages/test_api/pytest.ini b/packages/test_api/pytest.ini new file mode 120000 index 000000000000..d1bd969dce80 --- /dev/null +++ b/packages/test_api/pytest.ini @@ -0,0 +1 @@ +../package-pytest.ini \ No newline at end of file diff --git a/packages/test_base/pytest.ini b/packages/test_base/pytest.ini new file mode 120000 index 000000000000..d1bd969dce80 --- /dev/null +++ b/packages/test_base/pytest.ini @@ -0,0 +1 @@ +../package-pytest.ini \ No newline at end of file diff --git a/packages/test_driver/pytest.ini b/packages/test_driver/pytest.ini new file mode 120000 index 000000000000..d1bd969dce80 --- /dev/null +++ b/packages/test_driver/pytest.ini @@ -0,0 +1 @@ +../package-pytest.ini \ No newline at end of file diff --git a/packages/test_selenium/pytest.ini b/packages/test_selenium/pytest.ini new file mode 120000 index 000000000000..d1bd969dce80 --- /dev/null +++ b/packages/test_selenium/pytest.ini @@ -0,0 +1 @@ +../package-pytest.ini \ No newline at end of file diff --git a/packages/tool_shed/pytest.ini b/packages/tool_shed/pytest.ini new file mode 120000 index 000000000000..d1bd969dce80 --- /dev/null +++ b/packages/tool_shed/pytest.ini @@ -0,0 +1 @@ +../package-pytest.ini \ No newline at end of file diff --git a/packages/tool_util/pytest.ini b/packages/tool_util/pytest.ini new file mode 120000 index 000000000000..d1bd969dce80 --- /dev/null +++ b/packages/tool_util/pytest.ini @@ -0,0 +1 @@ +../package-pytest.ini \ No newline at end of file diff --git a/packages/tours/pytest.ini b/packages/tours/pytest.ini new file mode 120000 index 000000000000..d1bd969dce80 --- /dev/null +++ b/packages/tours/pytest.ini @@ -0,0 +1 @@ +../package-pytest.ini \ No newline at end of file diff --git a/packages/util/pytest.ini b/packages/util/pytest.ini new file mode 120000 index 000000000000..d1bd969dce80 --- /dev/null +++ b/packages/util/pytest.ini @@ -0,0 +1 @@ +../package-pytest.ini \ No newline at end of file diff --git a/packages/web_apps/pytest.ini b/packages/web_apps/pytest.ini new file mode 120000 index 000000000000..d1bd969dce80 --- /dev/null +++ b/packages/web_apps/pytest.ini @@ -0,0 +1 @@ +../package-pytest.ini \ No newline at end of file diff --git a/packages/web_framework/pytest.ini b/packages/web_framework/pytest.ini new file mode 120000 index 000000000000..d1bd969dce80 --- /dev/null +++ b/packages/web_framework/pytest.ini @@ -0,0 +1 @@ +../package-pytest.ini \ No newline at end of file diff --git a/packages/web_stack/pytest.ini b/packages/web_stack/pytest.ini new file mode 120000 index 000000000000..d1bd969dce80 --- /dev/null +++ b/packages/web_stack/pytest.ini @@ -0,0 +1 @@ +../package-pytest.ini \ No newline at end of file From 51ae8d721522e608039edbd872433456e369c498 Mon Sep 17 00:00:00 2001 From: Laila Los <44241786+ElectronicBlueberry@users.noreply.github.com> Date: Mon, 3 Jun 2024 11:07:07 +0200 Subject: [PATCH 5/5] keep lazy label updated actions queued longer --- .../Workflow/Editor/Actions/stepActions.ts | 56 +++++++++++++------ client/src/stores/undoRedoStore/index.ts | 2 +- 2 files changed, 40 insertions(+), 18 deletions(-) diff --git a/client/src/components/Workflow/Editor/Actions/stepActions.ts b/client/src/components/Workflow/Editor/Actions/stepActions.ts index 16c8903498f4..d8035b0ea171 100644 --- a/client/src/components/Workflow/Editor/Actions/stepActions.ts +++ b/client/src/components/Workflow/Editor/Actions/stepActions.ts @@ -423,26 +423,38 @@ export function useStepActions( } } + interface ChangeValueOrCreateActionOptions { + step: Step; + key: K; + value: Step[K]; + name?: string; + actionConstructor?: () => LazyMutateStepAction; + keepActionAlive?: boolean; + timeout?: number; + } + /** * Mutates a queued lazy action, if a matching one exists, * otherwise creates a new lazy action ans queues it. */ function changeValueOrCreateAction( - step: Step, - key: K, - value: Step[K], - name?: string, - actionConstructor?: () => LazyMutateStepAction + options: ChangeValueOrCreateActionOptions ): InstanceType> { + const { step, key, value, name, keepActionAlive, timeout } = options; const actionForKey = actionForIdAndKey(step.id, key); if (actionForKey) { actionForKey.changeValue(value); + if (keepActionAlive) { + undoRedoStore.setLazyActionTimeout(timeout); + } + return actionForKey; } else { - actionConstructor = - actionConstructor ?? (() => new LazyMutateStepAction(stepStore, step.id, key, step[key], value)); + const actionConstructor = + options.actionConstructor ?? + (() => new LazyMutateStepAction(stepStore, step.id, key, step[key], value)); const action = actionConstructor(); @@ -450,7 +462,7 @@ export function useStepActions( action.name = name; } - undoRedoStore.applyLazyAction(action); + undoRedoStore.applyLazyAction(action, timeout); action.onUndoRedo = () => { stateStore.activeNodeId = step.id; @@ -462,11 +474,11 @@ export function useStepActions( } function setPosition(step: Step, position: NonNullable) { - changeValueOrCreateAction(step, "position", position, "change step position"); + changeValueOrCreateAction({ step, key: "position", value: position, name: "change step position" }); } function setAnnotation(step: Step, annotation: Step["annotation"]) { - changeValueOrCreateAction(step, "annotation", annotation, "modify step annotation"); + changeValueOrCreateAction({ step, key: "annotation", value: annotation, name: "modify step annotation" }); } function setOutputLabel( @@ -478,18 +490,28 @@ export function useStepActions( const actionConstructor = () => new LazySetOutputLabelAction(stepStore, stateStore, step.id, fromLabel, toLabel, workflowOutputs); - changeValueOrCreateAction( + changeValueOrCreateAction({ step, - "workflow_outputs", - workflowOutputs, - "modify step output label", - actionConstructor - ); + key: "workflow_outputs", + value: workflowOutputs, + name: "modify step output label", + actionConstructor, + keepActionAlive: true, + timeout: 2000, + }); } function setLabel(step: Step, label: Step["label"]) { const actionConstructor = () => new LazySetLabelAction(stepStore, stateStore, step.id, step.label, label); - changeValueOrCreateAction(step, "label", label, "modify step label", actionConstructor); + changeValueOrCreateAction({ + step, + key: "label", + value: label, + name: "modify step label", + actionConstructor, + keepActionAlive: true, + timeout: 2000, + }); } const { refresh } = useRefreshFromStore(); diff --git a/client/src/stores/undoRedoStore/index.ts b/client/src/stores/undoRedoStore/index.ts index 86d798abf349..aee67a9e04b3 100644 --- a/client/src/stores/undoRedoStore/index.ts +++ b/client/src/stores/undoRedoStore/index.ts @@ -108,7 +108,7 @@ export const useUndoRedoStore = defineScopedStore("undoRedoStore", () => { } } - function setLazyActionTimeout(timeout: number) { + function setLazyActionTimeout(timeout = 1000) { clearTimeout(lazyActionTimeout); lazyActionTimeout = setTimeout(() => flushLazyAction(), timeout); }