Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/agent-drift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ concurrency:

jobs:
agent-drift:
uses: BehindTheMusicTree/github-workflows/.github/workflows/agent-drift.yml@b6b1f3922b06554dceac5fec7e7e5746b9bf7373 # v6.9.0
uses: BehindTheMusicTree/github-workflows/.github/workflows/agent-drift.yml@02de9e46e8450bbe63cf348f8b6b3f6e5a82370b # v6.9.1
permissions:
contents: read
2 changes: 1 addition & 1 deletion .github/workflows/org-conformance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ concurrency:

jobs:
org-conformance:
uses: BehindTheMusicTree/github-workflows/.github/workflows/org-conformance.yml@b6b1f3922b06554dceac5fec7e7e5746b9bf7373 # v6.9.0
uses: BehindTheMusicTree/github-workflows/.github/workflows/org-conformance.yml@02de9e46e8450bbe63cf348f8b6b3f6e5a82370b # v6.9.1
permissions:
contents: read
2 changes: 1 addition & 1 deletion .github/workflows/pr-title.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ concurrency:

jobs:
pr-title:
uses: BehindTheMusicTree/github-workflows/.github/workflows/pr-title.yml@b6b1f3922b06554dceac5fec7e7e5746b9bf7373 # v6.9.0
uses: BehindTheMusicTree/github-workflows/.github/workflows/pr-title.yml@02de9e46e8450bbe63cf348f8b6b3f6e5a82370b # v6.9.1
6 changes: 3 additions & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
tag:
permissions:
contents: write
uses: BehindTheMusicTree/github-workflows/.github/workflows/release-tag.yml@b6b1f3922b06554dceac5fec7e7e5746b9bf7373 # v6.9.0
uses: BehindTheMusicTree/github-workflows/.github/workflows/release-tag.yml@02de9e46e8450bbe63cf348f8b6b3f6e5a82370b # v6.9.1
with:
app-id: ${{ vars.RELEASE_APP_ID }}
secrets:
Expand All @@ -49,7 +49,7 @@ jobs:
uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09
with:
repository: BehindTheMusicTree/github-workflows
ref: b6b1f3922b06554dceac5fec7e7e5746b9bf7373 # v6.9.0
ref: 02de9e46e8450bbe63cf348f8b6b3f6e5a82370b # v6.9.1
path: .release-foundation
persist-credentials: false

Expand Down Expand Up @@ -99,7 +99,7 @@ jobs:
needs: [tag, publish]
# Ordinary pushes skip publishing and still reconcile the release PR.
if: ${{ !cancelled() && needs.tag.result == 'success' && (needs.tag.outputs.tag == '' || needs.publish.result == 'success') }}
uses: BehindTheMusicTree/github-workflows/.github/workflows/release-please.yml@b6b1f3922b06554dceac5fec7e7e5746b9bf7373 # v6.9.0
uses: BehindTheMusicTree/github-workflows/.github/workflows/release-please.yml@02de9e46e8450bbe63cf348f8b6b3f6e5a82370b # v6.9.1
with:
app-id: ${{ vars.RELEASE_PR_APP_ID }}
auto-merge: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
needs: build
permissions:
contents: read
uses: BehindTheMusicTree/github-workflows/.github/workflows/coverage.yml@b6b1f3922b06554dceac5fec7e7e5746b9bf7373 # v6.9.0
uses: BehindTheMusicTree/github-workflows/.github/workflows/coverage.yml@02de9e46e8450bbe63cf348f8b6b3f6e5a82370b # v6.9.1
with:
# Floor shared by both packages; their vitest configs keep stricter per-package thresholds.
line: 85
Expand Down
4 changes: 2 additions & 2 deletions packages/app-kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"test": "vitest run --coverage"
},
"peerDependencies": {
"@behindthemusictree/grow-api": ">=0.1.0-next.13 <0.2.0",
"@behindthemusictree/grow-api": ">=0.1.0-next.17 <0.2.0",
"@tanstack/react-query": ">=5.0.0",
"next": ">=14.0.0",
"react": ">=18.0.0",
Expand All @@ -77,7 +77,7 @@
"zod": "^4.6.6"
},
"devDependencies": {
"@behindthemusictree/grow-api": "0.1.0-next.13",
"@behindthemusictree/grow-api": "0.1.0-next.17",
"@tanstack/react-query": "^5.72.2",
"@testing-library/jest-dom": "^7.0.0",
"@testing-library/react": "^16.3.2",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[
{
"itemId": "LOCAL:malay-world",
"wikidataId": "LOCAL:malay-world",
"uuid": "c9de6dc7-1e68-44ba-bc2c-fb3340f795c7",
"name": "music of the Malay world",
Expand All @@ -9,6 +10,7 @@
"viewsCount": 0
},
{
"itemId": "LOCAL:region-q100",
"wikidataId": "LOCAL:region-q100",
"uuid": "918f9b52-4d78-4232-81c3-637d4b490038",
"name": "music of Boston",
Expand All @@ -18,6 +20,7 @@
"viewsCount": 0
},
{
"itemId": "LOCAL:region-q10126",
"wikidataId": "LOCAL:region-q10126",
"uuid": "e386e7d0-5675-46c4-84fa-da7737695f44",
"name": "music of Serang",
Expand Down
86 changes: 86 additions & 0 deletions packages/app-kit/src/genre-tree/useRegionGenreLexicon.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { describe, it, expect, beforeEach, vi } from "vitest";
import { renderHook } from "@testing-library/react";

const { fetchMock, useQueryWithParseMock } = vi.hoisted(() => ({
fetchMock: vi.fn(),
useQueryWithParseMock: vi.fn(),
}));

vi.mock("../transport/useFetchWrapper", () => ({
useFetchWrapper: () => ({ fetch: fetchMock }),
}));

vi.mock("../transport/lib/use-query-with-parse", () => ({
useQueryWithParse: (options: unknown) => useQueryWithParseMock(options),
}));

import { useRegionGenreLexicon } from "./useRegionGenreLexicon";
import { zRegionMapGenresResponse } from "@behindthemusictree/grow-api";

const getBackendBaseUrl = () => "https://backend.example.com";

const entry = (itemId: string, wikidataId: string, uuid: string) => ({
itemId,
wikidataId,
uuid,
name: `Genre ${itemId}`,
treeName: "regional",
genrePlaylistUuid: null,
isUmbrella: false,
viewsCount: 3,
});

const localOverview = entry("LOCAL:region-q10690", "LOCAL:region-q10690", "3f0d7b1e-8a3c-4d57-9a53-2b7f4f9c0a11");
const qidGenre = entry("Q11399", "Q11399", "5b2e4c9a-1d3f-4e6a-8b7c-9d0e1f2a3b4c");

describe("useRegionGenreLexicon", () => {
beforeEach(() => {
vi.clearAllMocks();
useQueryWithParseMock.mockReturnValue({ data: undefined, isPending: true, isError: false });
});

it("parses the response keeping itemId for LOCAL graph IDs and QIDs", () => {
const parsed = zRegionMapGenresResponse.parse([localOverview, qidGenre]);

expect(parsed.map(({ itemId, uuid }) => ({ itemId, uuid }))).toEqual([
{ itemId: "LOCAL:region-q10690", uuid: localOverview.uuid },
{ itemId: "Q11399", uuid: qidGenre.uuid },
]);
});

it("stays disabled and not pending until enabled", () => {
const { result } = renderHook(() => useRegionGenreLexicon(getBackendBaseUrl, false));

expect(result.current).toEqual({ entries: [], isError: false, isPending: false });
expect(useQueryWithParseMock.mock.calls[0][0].enabled).toBe(false);
});

it("loads the lexicon once with an infinite cache, forwarding the abort signal", async () => {
const { result } = renderHook(() => useRegionGenreLexicon(getBackendBaseUrl, true));
const options = useQueryWithParseMock.mock.calls[0][0];
const signal = new AbortController().signal;

expect(result.current).toEqual({ entries: [], isError: false, isPending: true });
expect(options.queryKey).toEqual(["regionGenreLexicon"]);
expect(options.schema).toBe(zRegionMapGenresResponse);
expect(options.staleTime).toBe(Infinity);
await options.queryFn({ signal });
expect(fetchMock).toHaveBeenCalledWith("regions/map/genres/", true, false, { signal });
});

it("returns the parsed entries on success and flags an error on failure", () => {
useQueryWithParseMock.mockReturnValue({ data: [localOverview, qidGenre], isPending: false, isError: false });
expect(renderHook(() => useRegionGenreLexicon(getBackendBaseUrl, true)).result.current).toEqual({
entries: [localOverview, qidGenre],
isError: false,
isPending: false,
});

useQueryWithParseMock.mockReturnValue({ data: undefined, isPending: false, isError: true });
expect(renderHook(() => useRegionGenreLexicon(getBackendBaseUrl, true)).result.current).toEqual({
entries: [],
isError: true,
isPending: false,
});
});
});
13 changes: 11 additions & 2 deletions packages/app-kit/src/genre-tree/useRegionGenreLexicon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,17 @@ import type { RegionGenreLexiconEntry } from "./schemas/reference";

const EMPTY_ENTRIES: RegionGenreLexiconEntry[] = [];

/** Every genre the region map index references, loaded once on demand (`regions/map/genres/`). */
export function useRegionGenreLexicon(getBackendBaseUrl: () => string, enabled: boolean) {
/**
* Named so the declaration refers to the consumer's installed grow-api schema rather than inlining
* the entry fields of the grow-api this package was built against.
*/
export type RegionGenreLexicon = { entries: RegionGenreLexiconEntry[]; isError: boolean; isPending: boolean };

/**
* Every genre the region map index references, loaded once on demand (`regions/map/genres/`).
* Each entry's `itemId` is the index's item ID (a QID or a `LOCAL:` graph ID).
*/
export function useRegionGenreLexicon(getBackendBaseUrl: () => string, enabled: boolean): RegionGenreLexicon {
const { fetch } = useFetchWrapper(getBackendBaseUrl);
const { data, isError, isPending } = useQueryWithParse({
queryKey: genreSearchQueryKeys.regionLexicon(),
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading