Skip to content

Commit

Permalink
fix: handle Tokyo sample data as Tokyo prefecture data (#358)
Browse files Browse the repository at this point in the history
  • Loading branch information
keiya01 authored Nov 19, 2024
1 parent 7b1328e commit aeec6b2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
1 change: 1 addition & 0 deletions extension/src/shared/constants/dataset.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const TOKYO_SAMPLE_DATA_CITY_CODE = "13999";
1 change: 1 addition & 0 deletions extension/src/shared/constants/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from "./localStorage";
export * from "./colorMaps";
export * from "./dataset";
24 changes: 22 additions & 2 deletions extension/src/shared/graphql/hooks/catalog/area.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useMemo } from "react";

import { TOKYO_SAMPLE_DATA_CITY_CODE } from "../../../constants";
import { AREAS, AREA_DATASETS } from "../../base/catalog/queries/area";
import { AreasInput, DatasetsInput } from "../../types/catalog";

Expand All @@ -10,12 +11,26 @@ type Options = {
};

export const useAreas = (input?: AreasInput, options?: Options) => {
return useQuery(AREAS, {
const data = useQuery(AREAS, {
variables: {
input: input ?? {},
},
skip: options?.skip,
});
const next = useMemo(
() => ({
...data,
data: data.data
? {
...data.data,
areas: data.data.areas.filter(a => a.code !== TOKYO_SAMPLE_DATA_CITY_CODE),
}
: undefined,
}),
[data],
);

return next;
};

export const useAreaDatasets = (code: string, input?: DatasetsInput, options?: Options) => {
Expand All @@ -28,7 +43,12 @@ export const useAreaDatasets = (code: string, input?: DatasetsInput, options?: O
});

const nextDatasets = useMemo(
() => data?.area?.datasets.slice().sort((a, b) => a.type.order - b.type.order),
() =>
data?.area?.datasets
.map(d =>
d.cityCode === TOKYO_SAMPLE_DATA_CITY_CODE ? { ...d, cityCode: null, city: null } : d,
)
.sort((a, b) => a.type.order - b.type.order),
[data],
);

Expand Down

0 comments on commit aeec6b2

Please sign in to comment.