-
Notifications
You must be signed in to change notification settings - Fork 0
Fix Progress component #145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
clarasb
wants to merge
8
commits into
main
Choose a base branch
from
clarasb/xxx-fix_progress_spinner
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+697
−122
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0429139
Add demo pannel 10
clarasb 5b4321b
add `visible` property
clarasb 4224898
extend invokeCallback with pendingProcesses
clarasb 5a33592
add `visible` property to `LinearProgress` component
clarasb 13ca6d6
fix vega_test.py
clarasb 63204c5
move everything progress related into helpers/pendingProgress.ts
clarasb 63449c8
update CHANGES.md
clarasb 0bee733
update package-lock.json
clarasb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
143 changes: 143 additions & 0 deletions
143
chartlets.js/packages/lib/src/actions/helpers/invokeCallbacks.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| /* | ||
| * Copyright (c) 2019-2026 by Brockmann Consult Development team | ||
| * Permissions are hereby granted under the terms of the MIT License: | ||
| * https://opensource.org/licenses/MIT. | ||
| */ | ||
|
|
||
| import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; | ||
|
|
||
| import { store } from "@/store"; | ||
| import type { CallbackRequest, StateChangeRequest } from "@/types/model/callback"; | ||
| import type { ComponentState } from "@/types/state/component"; | ||
| import { invokeCallbacks } from "./invokeCallbacks"; | ||
|
|
||
| function createDeferred<T>() { | ||
| let resolve!: (value: T) => void; | ||
| const promise = new Promise<T>((resolvePromise) => { | ||
| resolve = resolvePromise; | ||
| }); | ||
| return { promise, resolve }; | ||
| } | ||
|
|
||
| function getProgressComponent() { | ||
| return (store.getState().contributionsRecord.panels[0].component! | ||
| .children![0] as ComponentState); | ||
| } | ||
|
|
||
| const callbackRequest: CallbackRequest = { | ||
| contribPoint: "panels", | ||
| contribIndex: 0, | ||
| callbackIndex: 0, | ||
| inputIndex: 0, | ||
| inputValues: [true], | ||
| }; | ||
|
|
||
| describe("invokeCallbacks", () => { | ||
| beforeEach(() => { | ||
| store.setState({ | ||
| configuration: {}, | ||
| extensions: [{ name: "ext", version: "0", contributes: ["panels"] }], | ||
| contributionsResult: {}, | ||
| contributionsRecord: { | ||
| panels: [ | ||
| { | ||
| name: "panel", | ||
| extension: "ext", | ||
| container: {}, | ||
| componentResult: { status: "ok" }, | ||
| component: { | ||
| type: "Box", | ||
| children: [ | ||
| { | ||
| type: "CircularProgress", | ||
| id: "progress", | ||
| visible: false, | ||
| }, | ||
| ], | ||
| }, | ||
| callbacks: [ | ||
| { | ||
| function: { name: "calculate", parameters: [], return: {} }, | ||
| inputs: [{ id: "run", property: "clicked" }], | ||
| outputs: [{ id: "progress", property: "visible" }], | ||
| }, | ||
| ], | ||
| initialState: {}, | ||
| }, | ||
| ], | ||
| }, | ||
| lastCallbackInputValues: {}, | ||
| }); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| vi.restoreAllMocks(); | ||
| }); | ||
|
|
||
| it("shows pending progress and applies callback results", async () => { | ||
| const deferred = createDeferred<Response>(); | ||
| globalThis.fetch = vi.fn().mockReturnValue(deferred.promise); | ||
|
|
||
| invokeCallbacks([callbackRequest]); | ||
|
|
||
| expect(getProgressComponent().visible).toBe(true); | ||
|
|
||
| deferred.resolve(createCallbackResponse([ | ||
| { | ||
| contribPoint: "panels", | ||
| contribIndex: 0, | ||
| stateChanges: [{ id: "progress", property: "visible", value: false }], | ||
| }, | ||
| ])); | ||
|
|
||
| await vi.waitFor(() => { | ||
| expect(getProgressComponent().visible).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| it("logs and releases pending progress when a callback fails", async () => { | ||
| const deferred = createDeferred<Response>(); | ||
| const consoleError = vi.spyOn(console, "error").mockImplementation(() => {}); | ||
| globalThis.fetch = vi.fn().mockReturnValue(deferred.promise); | ||
|
|
||
| invokeCallbacks([callbackRequest]); | ||
|
|
||
| expect(getProgressComponent().visible).toBe(true); | ||
|
|
||
| deferred.resolve({ | ||
| ok: true, | ||
| status: 200, | ||
| statusText: "ok", | ||
| json: vi.fn().mockResolvedValue({ message: "unexpected" }), | ||
| } as unknown as Response); | ||
|
|
||
| await vi.waitFor(() => { | ||
| expect(getProgressComponent().visible).toBe(false); | ||
| }); | ||
| expect(consoleError).toHaveBeenCalledOnce(); | ||
| }); | ||
|
|
||
| it("logs callback requests and results when logging is enabled", async () => { | ||
| const deferred = createDeferred<Response>(); | ||
| const consoleInfo = vi.spyOn(console, "info").mockImplementation(() => {}); | ||
| globalThis.fetch = vi.fn().mockReturnValue(deferred.promise); | ||
| store.setState({ configuration: { logging: { enabled: true } } }); | ||
|
|
||
| invokeCallbacks([callbackRequest]); | ||
|
|
||
| deferred.resolve(createCallbackResponse([])); | ||
|
|
||
| await vi.waitFor(() => { | ||
| expect(consoleInfo).toHaveBeenCalledTimes(2); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| function createCallbackResponse(result: StateChangeRequest[]) { | ||
| return { | ||
| ok: true, | ||
| status: 200, | ||
| statusText: "ok", | ||
| json: vi.fn().mockResolvedValue({ result }), | ||
| } as unknown as Response; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
161 changes: 161 additions & 0 deletions
161
chartlets.js/packages/lib/src/actions/helpers/pendingProgress.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,161 @@ | ||
| /* | ||
| * Copyright (c) 2019-2026 by Brockmann Consult Development team | ||
| * Permissions are hereby granted under the terms of the MIT License: | ||
| * https://opensource.org/licenses/MIT. | ||
| */ | ||
|
|
||
| import { beforeEach, describe, expect, it } from "vitest"; | ||
|
|
||
| import { store } from "@/store"; | ||
| import type { CallbackRequest } from "@/types/model/callback"; | ||
| import type { ComponentState } from "@/types/state/component"; | ||
| import { | ||
| getPendingProgressTargets, | ||
| releasePendingProgressTargets, | ||
| showPendingProgressTargets, | ||
| } from "./pendingProgress"; | ||
|
|
||
| const callbackRequest: CallbackRequest = { | ||
| contribPoint: "panels", | ||
| contribIndex: 0, | ||
| callbackIndex: 0, | ||
| inputIndex: 0, | ||
| inputValues: [true], | ||
| }; | ||
|
|
||
| function getProgressComponent() { | ||
| return (store.getState().contributionsRecord.panels[0].component! | ||
| .children![0] as ComponentState); | ||
| } | ||
|
|
||
| describe("pendingProgress", () => { | ||
| beforeEach(() => { | ||
| store.setState({ | ||
| configuration: {}, | ||
| extensions: [{ name: "ext", version: "0", contributes: ["panels"] }], | ||
| contributionsResult: {}, | ||
| contributionsRecord: { | ||
| panels: [ | ||
| { | ||
| name: "panel", | ||
| extension: "ext", | ||
| container: {}, | ||
| componentResult: { status: "ok" }, | ||
| component: { | ||
| type: "Box", | ||
| children: [ | ||
| { | ||
| type: "CircularProgress", | ||
| id: "progress", | ||
| visible: false, | ||
| }, | ||
| { | ||
| type: "Typography", | ||
| id: "text", | ||
| visible: false, | ||
| }, | ||
| ], | ||
| }, | ||
| callbacks: [ | ||
| { | ||
| function: { name: "calculate", parameters: [], return: {} }, | ||
| inputs: [{ id: "run", property: "clicked" }], | ||
| outputs: [{ id: "progress", property: "visible" }], | ||
| }, | ||
| { | ||
| function: { name: "duplicate", parameters: [], return: {} }, | ||
| inputs: [{ id: "run", property: "clicked" }], | ||
| outputs: [ | ||
| { id: "progress", property: "visible" }, | ||
| { id: "progress", property: "visible" }, | ||
| ], | ||
| }, | ||
| { | ||
| function: { name: "text", parameters: [], return: {} }, | ||
| inputs: [{ id: "run", property: "clicked" }], | ||
| outputs: [{ id: "text", property: "visible" }], | ||
| }, | ||
| { | ||
| function: { name: "value", parameters: [], return: {} }, | ||
| inputs: [{ id: "run", property: "clicked" }], | ||
| outputs: [{ id: "progress", property: "value" }], | ||
| }, | ||
| ], | ||
| initialState: {}, | ||
| }, | ||
| ], | ||
| }, | ||
| lastCallbackInputValues: {}, | ||
| }); | ||
| }); | ||
|
|
||
| it("finds progress components targeted by visible callback outputs", () => { | ||
| expect(getPendingProgressTargets([callbackRequest])).toEqual([ | ||
| { | ||
| contribPoint: "panels", | ||
| contribIndex: 0, | ||
| id: "progress", | ||
| output: { id: "progress", property: "visible" }, | ||
| }, | ||
| ]); | ||
| }); | ||
|
|
||
| it("deduplicates repeated progress outputs from the same callback", () => { | ||
| const targets = getPendingProgressTargets([ | ||
| { ...callbackRequest, callbackIndex: 1 }, | ||
| ]); | ||
|
|
||
| expect(targets).toHaveLength(1); | ||
| }); | ||
|
|
||
| it("ignores non-progress components and non-visible outputs", () => { | ||
| expect( | ||
| getPendingProgressTargets([{ ...callbackRequest, callbackIndex: 2 }]), | ||
| ).toEqual([]); | ||
| expect( | ||
| getPendingProgressTargets([{ ...callbackRequest, callbackIndex: 3 }]), | ||
| ).toEqual([]); | ||
| }); | ||
|
|
||
| it("ignores progress outputs when no component tree has been loaded", () => { | ||
| store.setState({ | ||
| contributionsRecord: { | ||
| panels: [ | ||
| { | ||
| ...store.getState().contributionsRecord.panels[0], | ||
| component: undefined, | ||
| }, | ||
| ], | ||
| }, | ||
| }); | ||
|
|
||
| expect(getPendingProgressTargets([callbackRequest])).toEqual([]); | ||
| }); | ||
|
|
||
| it("shows and hides progress when a callback fails", () => { | ||
| const targets = getPendingProgressTargets([callbackRequest]); | ||
|
|
||
| showPendingProgressTargets(targets); | ||
|
|
||
| expect(getProgressComponent().visible).toBe(true); | ||
|
|
||
| releasePendingProgressTargets(targets, false); | ||
|
|
||
| expect(getProgressComponent().visible).toBe(false); | ||
| }); | ||
|
|
||
| it("keeps progress visible until overlapping callbacks have completed", () => { | ||
| const targets = getPendingProgressTargets([callbackRequest]); | ||
|
|
||
| showPendingProgressTargets(targets); | ||
| showPendingProgressTargets(targets); | ||
|
|
||
| releasePendingProgressTargets(targets, true); | ||
|
|
||
| expect(getProgressComponent().visible).toBe(true); | ||
|
|
||
| releasePendingProgressTargets(targets, false); | ||
|
|
||
| expect(getProgressComponent().visible).toBe(false); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above.