-
Notifications
You must be signed in to change notification settings - Fork 1
feat(workspace): lead the chart with tonight's first action #1115
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
seonghobae
wants to merge
7
commits into
develop
Choose a base branch
from
feat/workspace-chart-first-action
base: develop
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.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b159392
feat(workspace): lead the chart with tonight's first action
seonghobae 42d07ab
test(workspace): keep chart export full-band after role selection
seonghobae df8ceff
test(workspace): keep chart helper full-band
seonghobae c7652ec
fix(workspace): keep chart action full-band
seonghobae 9a52462
docs(chart): state optional first action
seonghobae 13b0f51
docs(chart): clarify missing first action
seonghobae 223d53f
docs(chart): record export privacy contract
seonghobae 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
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
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
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
60 changes: 60 additions & 0 deletions
60
apps/desktop/src/features/workspace/Workspace.chartExport.test.tsx
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,60 @@ | ||
| import { fireEvent, render, screen } from "@testing-library/react"; | ||
| import { createDemoRehearsalSong } from "@bandscope/shared-types"; | ||
| import { afterEach, describe, expect, it, vi } from "vitest"; | ||
| import { Workspace } from "./Workspace"; | ||
|
|
||
| const originalLanguage = navigator.language; | ||
| const originalCreateObjectUrl = URL.createObjectURL; | ||
| const originalRevokeObjectUrl = URL.revokeObjectURL; | ||
|
|
||
| function setNavigatorLanguage(language: string) { | ||
| Object.defineProperty(navigator, "language", { | ||
| configurable: true, | ||
| value: language | ||
| }); | ||
| } | ||
|
|
||
| describe("Workspace chart export contract", () => { | ||
| afterEach(() => { | ||
| setNavigatorLanguage(originalLanguage); | ||
| vi.restoreAllMocks(); | ||
| Object.defineProperty(URL, "createObjectURL", { | ||
| configurable: true, | ||
| value: originalCreateObjectUrl | ||
| }); | ||
| Object.defineProperty(URL, "revokeObjectURL", { | ||
| configurable: true, | ||
| value: originalRevokeObjectUrl | ||
| }); | ||
| }); | ||
|
|
||
| it("keeps the full-band chart lead stable when the UI role changes", async () => { | ||
| setNavigatorLanguage("en-US"); | ||
| const song = createDemoRehearsalSong(); | ||
| const createObjectUrl = vi.fn(() => "blob:full-band-chart"); | ||
| vi.spyOn(HTMLAnchorElement.prototype, "click").mockImplementation(() => undefined); | ||
| Object.defineProperty(URL, "createObjectURL", { | ||
| configurable: true, | ||
| value: createObjectUrl | ||
| }); | ||
| Object.defineProperty(URL, "revokeObjectURL", { | ||
| configurable: true, | ||
| value: vi.fn() | ||
| }); | ||
|
|
||
| render(<Workspace song={song} />); | ||
| fireEvent.click(screen.getByRole("tab", { name: "Lead Vocal" })); | ||
| fireEvent.click(screen.getByRole("button", { name: "Download tonight's first-action chart" })); | ||
|
|
||
| const blob = createObjectUrl.mock.calls[0]?.[0] as Blob; | ||
| const payload = JSON.parse(await blob.text()) as { | ||
| firstAction?: { role?: string }; | ||
| sections?: Array<{ roles?: Array<{ name?: string }> }>; | ||
| }; | ||
|
|
||
| expect(payload.firstAction?.role).toBe("Bass Guitar"); | ||
| expect(payload.sections?.[0]?.roles?.map((role) => role.name)).toEqual( | ||
| expect.arrayContaining(["Bass Guitar", "Lead Vocal"]) | ||
| ); | ||
| }); | ||
| }); |
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
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
69 changes: 69 additions & 0 deletions
69
apps/desktop/src/features/workspace/firstChartAction.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,69 @@ | ||
| import { createDemoRehearsalSong, type RehearsalSong } from "@bandscope/shared-types"; | ||
| import { describe, expect, it } from "vitest"; | ||
| import { createTranslator } from "../../i18n"; | ||
| import { firstChartAction } from "./firstChartAction"; | ||
|
|
||
| describe("firstChartAction", () => { | ||
| const t = createTranslator("en"); | ||
|
|
||
| it("leads with the first clashing span and the instrument-check next action", () => { | ||
| expect(firstChartAction(createDemoRehearsalSong(), null, t)).toEqual({ | ||
| section: "verse", | ||
| role: "Bass Guitar", | ||
| lowestNote: "C#2", | ||
| highestNote: "E3", | ||
| next: "Bass Guitar sits C#2–E3 in verse. Hear that clash on your instrument before the verse." | ||
| }); | ||
| }); | ||
|
|
||
| it("keeps the full-band lead when a UI role is selected", () => { | ||
| const action = firstChartAction(createDemoRehearsalSong(), "lead-vocal", t); | ||
|
|
||
| expect(action?.role).toBe("Bass Guitar"); | ||
| expect(action?.lowestNote).toBe("C#2"); | ||
| expect(action?.highestNote).toBe("E3"); | ||
| expect(action?.next).toBe( | ||
| "Bass Guitar sits C#2–E3 in verse. Hear that clash on your instrument before the verse." | ||
| ); | ||
| }); | ||
|
|
||
| it("uses the check copy when the first span has no clash", () => { | ||
| const song = createDemoRehearsalSong(); | ||
| song.sections[0]!.roles = song.sections[0]!.roles.map((role) => ({ | ||
| ...role, | ||
| overlapWarnings: [] | ||
| })); | ||
|
|
||
| expect(firstChartAction(song, null, t)?.next).toBe( | ||
| "Bass Guitar sits C#2–E3 in verse. Check that span on your instrument before the verse." | ||
| ); | ||
| }); | ||
|
|
||
| it("returns null when no named span exists", () => { | ||
| const song = createDemoRehearsalSong(); | ||
| song.sections[0]!.roles = song.sections[0]!.roles.map((role) => ({ | ||
| ...role, | ||
| range: { lowestNote: "", highestNote: "none" }, | ||
| overlapWarnings: [] | ||
| })); | ||
|
|
||
| expect(firstChartAction(song, null, t)).toBeNull(); | ||
| }); | ||
|
|
||
| it("fails closed on malformed runtime collections", () => { | ||
| expect(firstChartAction(null as unknown as RehearsalSong, null, t)).toBeNull(); | ||
| }); | ||
|
|
||
| it("keeps formula-shaped role names literal so JSON encoding can neutralize them later", () => { | ||
| const song = createDemoRehearsalSong(); | ||
| song.sections[0]!.roles[0] = { | ||
| ...song.sections[0]!.roles[0]!, | ||
| name: "=HYPERLINK(\"http://evil\")" | ||
| }; | ||
|
|
||
| expect(firstChartAction(song, "bass-guitar", t)).toMatchObject({ | ||
| role: "=HYPERLINK(\"http://evil\")", | ||
| next: "=HYPERLINK(\"http://evil\") sits C#2–E3 in verse. Hear that clash on your instrument before the verse." | ||
| }); | ||
| }); | ||
| }); |
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,43 @@ | ||
| import type { RehearsalSong } from "@bandscope/shared-types"; | ||
| import type { TranslationKey } from "../../i18n"; | ||
| import type { ChartFirstAction } from "../../lib/export"; | ||
| import { fillRangeCopy, firstRangeSqueeze } from "./firstRangeSqueeze"; | ||
|
|
||
| /** Documented. */ | ||
| type Translator = (key: TranslationKey) => string; | ||
|
|
||
| /** | ||
| * Build tonight's first-action lead for the full-band rehearsal chart JSON. | ||
| * | ||
| * Uses the same playable-span authority as the ready map. Values stay | ||
| * literal so JSON encoding, not this helper, is the serialization boundary. | ||
| * Malformed songs and unnamed spans fail closed instead of inventing a lead. | ||
| */ | ||
| export function firstChartAction( | ||
| song: RehearsalSong, | ||
| activeRole: string | null, | ||
| t: Translator | ||
| ): ChartFirstAction | null { | ||
| // The chart body always contains the full band, so a transient UI role filter must not alter its lead. | ||
| void activeRole; | ||
| const squeeze = firstRangeSqueeze(song, null); | ||
| if (!squeeze) { | ||
| return null; | ||
| } | ||
|
|
||
| return { | ||
| section: squeeze.sectionLabel, | ||
| role: squeeze.roleName, | ||
| lowestNote: squeeze.lowestNote, | ||
| highestNote: squeeze.highestNote, | ||
| next: fillRangeCopy( | ||
| t(squeeze.overlapWarning ? "workspaceFirstRangeClash" : "workspaceFirstRangeCheck"), | ||
| { | ||
| roleName: squeeze.roleName, | ||
| lowestNote: squeeze.lowestNote, | ||
| highestNote: squeeze.highestNote, | ||
| sectionLabel: squeeze.sectionLabel | ||
| } | ||
| ) | ||
| }; | ||
| } |
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
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.
Uh oh!
There was an error while loading. Please reload this page.