Skip to content

Commit

Permalink
Reduce Code Editor Debounce Delay (#2819)
Browse files Browse the repository at this point in the history
* Reduce Editor debounce delay to make it send changes back to the server more quickly

* Update CL

* Add the delay in the hook

* Format
  • Loading branch information
elias-ba authored Jan 15, 2025
1 parent 4967c6b commit 593dfa7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ and this project adheres to

### Fixed

- Fixed Save and Run to always execute jobs with latest changes
[#2804](https://github.com/OpenFn/lightning/issues/2804)
- Fixed aggressive CSS rule in app.css that made it hard to style menu items
[#2807](https://github.com/OpenFn/lightning/pull/2807)
- `z-index` broken on unsaved dot on workflow edit page
Expand Down
29 changes: 22 additions & 7 deletions assets/js/common.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
// this has been added here because we still can't find a better place for it
// it's being used in both the hooks and the job editor
// @ts-nocheck
import pDebounce from 'p-debounce';

export const EDITOR_DEBOUNCE_MS = 300

const debouncedDispatchEvent = pDebounce(
(eventTarget, event) => {
eventTarget.dispatchEvent(event);
},
EDITOR_DEBOUNCE_MS
);

export function initiateSaveAndRun(buttonElement) {
if (buttonElement.getAttribute('type') == 'submit') {
if (buttonElement.getAttribute('type') === 'submit') {
const formId = buttonElement.getAttribute('form');
const form = document.getElementById(formId);
form.dispatchEvent(
new Event('submit', { bubbles: true, cancelable: true })
);

if (form) {
debouncedDispatchEvent(
form,
new Event('submit', { bubbles: true, cancelable: true })
);
}
} else {
buttonElement.dispatchEvent(
debouncedDispatchEvent(
buttonElement,
new Event('click', { bubbles: true, cancelable: true })
);
}
Expand Down
3 changes: 1 addition & 2 deletions assets/js/job-editor/mount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import pRetry from 'p-retry';
import pDebounce from 'p-debounce';
import { WorkflowStore } from '../workflow-editor/store';
import { Lightning } from '../workflow-diagram/types';
import { EDITOR_DEBOUNCE_MS } from '../common';

type JobEditorEntrypoint = PhoenixHook<
{
Expand Down Expand Up @@ -42,8 +43,6 @@ type AttributeMutationRecord = MutationRecord & {

let JobEditorComponent: typeof JobEditor | undefined;

const EDITOR_DEBOUNCE_MS = 300;

export default {
findWorkflowEditorStore() {
return pRetry(
Expand Down

0 comments on commit 593dfa7

Please sign in to comment.