Skip to content

Commit

Permalink
refactor: Use option object for useHierarchyParents
Browse files Browse the repository at this point in the history
  • Loading branch information
ptbrowne committed Nov 11, 2022
1 parent 2bff7a7 commit 8b69780
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
10 changes: 5 additions & 5 deletions app/charts/shared/chart-data-filters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,13 @@ const DataFilter = ({
},
});

const { data: hierarchyParents } = useHierarchyParents(
dataSetIri,
const { data: hierarchyParents } = useHierarchyParents({
datasetIri: dataSetIri,
dataSource,
data?.dataCubeByIri?.dimensionByIri!,
dimension: data?.dataCubeByIri?.dimensionByIri!,
locale,
!data?.dataCubeByIri?.dimensionByIri
);
pause: !data?.dataCubeByIri?.dimensionByIri,
});

const optionGroups = React.useMemo(() => {
return makeOptionGroups(hierarchyParents);
Expand Down
10 changes: 5 additions & 5 deletions app/configurator/components/chart-configurator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ const DataFilterSelectGeneric = ({
const locale = useLocale();
const [pause, setPause] = useState(true);
const { data: hierarchyParents, fetching: fetchingHierarchy } =
useHierarchyParents(
state.dataSet,
state.dataSource,
useHierarchyParents({
datasetIri: state.dataSet,
dataSource: state.dataSource,
dimension,
locale,
pause
);
pause,
});

const optionGroups = useMemo(() => {
return makeOptionGroups(hierarchyParents);
Expand Down
22 changes: 14 additions & 8 deletions app/configurator/components/use-hierarchy-parents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,25 @@ export const groupByParents = (hierarchy: DimensionHierarchyQueryHierarchy) => {
return groups(allHierarchyValues, (v) => v.parents);
};

const useHierarchyParents = (
dataSet: string,
dataSource: DataSource,
dimension: DataCubeMetadata["dimensions"][number],
locale: string,
pause?: boolean
): {
const useHierarchyParents = ({
datasetIri,
dataSource,
dimension,
locale,
pause,
}: {
datasetIri: string;
dataSource: DataSource;
dimension: DataCubeMetadata["dimensions"][number];
locale: string;
pause?: boolean;
}): {
fetching: boolean;
data: HierarchyParents | undefined;
} => {
const [hierarchyResp] = useDimensionHierarchyQuery({
variables: {
cubeIri: dataSet,
cubeIri: datasetIri,
dimensionIri: dimension?.iri,
sourceType: dataSource.type,
sourceUrl: dataSource.url,
Expand Down

0 comments on commit 8b69780

Please sign in to comment.