Skip to content

Commit

Permalink
Merge pull request #1209 from visualize-admin/fix/homepage-charts-dat…
Browse files Browse the repository at this point in the history
…a-source

fix: Use data source defined in configurator state
  • Loading branch information
bprusinowski authored Oct 11, 2023
2 parents ecb7add + 32bfc56 commit f4547b4
Showing 1 changed file with 18 additions and 36 deletions.
54 changes: 18 additions & 36 deletions app/configurator/configurator-state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,7 @@ import setWith from "lodash/setWith";
import sortBy from "lodash/sortBy";
import unset from "lodash/unset";
import { useRouter } from "next/router";
import {
Dispatch,
ReactNode,
createContext,
useContext,
useEffect,
useMemo,
} from "react";
import { Dispatch, createContext, useContext, useEffect, useMemo } from "react";
import { Client, useClient } from "urql";
import { Reducer, useImmerReducer } from "use-immer";

Expand Down Expand Up @@ -1421,21 +1414,18 @@ export const initChartStateFromLocalStorage = async (
}
};

const ConfiguratorStateProviderInternal = ({
chartId,
children,
initialState = INITIAL_STATE,
allowDefaultRedirect = true,
}: {
key: string;
chartId: string;
children?: ReactNode;
initialState?: ConfiguratorState;
allowDefaultRedirect?: boolean;
}) => {
const ConfiguratorStateProviderInternal = (
props: ConfiguratorStateProviderProps
) => {
const {
chartId,
initialState,
allowDefaultRedirect = true,
children,
} = props;
const { dataSource } = useDataSourceStore();
const initialStateWithDataSource = useMemo(() => {
return { ...initialState, dataSource };
return initialState ? initialState : { ...INITIAL_STATE, dataSource };
}, [initialState, dataSource]);
const locale = useLocale();
const stateAndDispatch = useImmerReducer(reducer, initialStateWithDataSource);
Expand Down Expand Up @@ -1489,13 +1479,6 @@ const ConfiguratorStateProviderInternal = ({
client,
]);

useEffect(() => {
dispatch({
type: "DATASOURCE_CHANGED",
value: dataSource,
});
}, [dispatch, dataSource]);

useEffect(() => {
try {
switch (state.state) {
Expand Down Expand Up @@ -1621,17 +1604,16 @@ const ConfiguratorStateProviderInternal = ({
);
};

export const ConfiguratorStateProvider = ({
chartId,
children,
initialState,
allowDefaultRedirect,
}: {
type ConfiguratorStateProviderProps = React.PropsWithChildren<{
chartId: string;
children?: ReactNode;
initialState?: ConfiguratorState;
allowDefaultRedirect?: boolean;
}) => {
}>;

export const ConfiguratorStateProvider = (
props: ConfiguratorStateProviderProps
) => {
const { chartId, initialState, allowDefaultRedirect, children } = props;
// Ensure that the state is reset by using the `chartId` as `key`
return (
<ConfiguratorStateProviderInternal
Expand Down

1 comment on commit f4547b4

@vercel
Copy link

@vercel vercel bot commented on f4547b4 Oct 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

visualization-tool – ./

visualization-tool-alpha.vercel.app
visualization-tool-git-main-ixt1.vercel.app
visualization-tool-ixt1.vercel.app

Please sign in to comment.