Skip to content

Commit 684cbde

Browse files
committed
feat: Initialize editing of saved dashboard in layouting step
1 parent 32c4962 commit 684cbde

4 files changed

Lines changed: 14 additions & 9 deletions

File tree

app/config-types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1260,8 +1260,10 @@ export type ConfiguratorStateConfiguringChart = t.TypeOf<
12601260
typeof ConfiguratorStateConfiguringChart
12611261
>;
12621262

1263+
export const CONFIGURATOR_STATE_LAYOUTING = "LAYOUTING";
1264+
12631265
const ConfiguratorStateLayouting = t.intersection([
1264-
t.type({ state: t.literal("LAYOUTING") }),
1266+
t.type({ state: t.literal(CONFIGURATOR_STATE_LAYOUTING) }),
12651267
Config,
12661268
]);
12671269
export type ConfiguratorStateLayouting = t.TypeOf<

app/configurator/configurator-state/context.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { PUBLISHED_STATE } from "@prisma/client";
22
import { NextRouter, useRouter } from "next/router";
3-
import { createContext, Dispatch, useContext, useEffect, useMemo } from "react";
3+
import { Dispatch, createContext, useContext, useEffect, useMemo } from "react";
44
import { useClient } from "urql";
55
import { useImmerReducer } from "use-immer";
66

@@ -271,7 +271,8 @@ export const ConfiguratorStateProviderInternal = (
271271
} else if (query.edit && typeof query.edit === "string") {
272272
newChartState = await initChartStateFromChartEdit(
273273
client,
274-
query.edit
274+
query.edit,
275+
typeof query.state === "string" ? query.state : undefined
275276
);
276277
} else if (query.cube && typeof query.cube === "string") {
277278
newChartState = await initChartStateFromCube(

app/configurator/configurator-state/init.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,18 +159,19 @@ export const initChartStateFromChartCopy = async (
159159

160160
export const initChartStateFromChartEdit = async (
161161
client: Client,
162-
fromChartId: string
162+
fromChartId: string,
163+
state?: string
163164
): Promise<ConfiguratorStateConfiguringChart | undefined> => {
164165
const config = await fetchChartConfig(fromChartId);
165166

166167
if (config?.data) {
167-
const state = migrateConfiguratorState({
168+
const configState = migrateConfiguratorState({
168169
...config.data,
169-
state: "CONFIGURING_CHART",
170+
state: state ?? "CONFIGURING_CHART",
170171
}) as ConfiguratorStateConfiguringChart;
171-
return await upgradeConfiguratorState(state, {
172+
return await upgradeConfiguratorState(configState, {
172173
client,
173-
dataSource: state.dataSource,
174+
dataSource: configState.dataSource,
174175
});
175176
}
176177
};

app/login/components/profile-tables.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { MenuActionProps } from "@/components/menu-action-item";
2424
import { RenameDialog } from "@/components/rename-dialog";
2525
import { RowActions } from "@/components/row-actions";
2626
import useDisclosure from "@/components/use-disclosure";
27+
import { CONFIGURATOR_STATE_LAYOUTING } from "@/config-types";
2728
import { ParsedConfig } from "@/db/config";
2829
import { sourceToLabel } from "@/domain/datasource";
2930
import { truthy } from "@/domain/types";
@@ -213,7 +214,7 @@ const ProfileVisualizationsRow = (props: ProfileVisualizationsRowProps) => {
213214
},
214215
{
215216
type: "link",
216-
href: `/${locale}/create/new?edit=${config.key}`,
217+
href: `/${locale}/create/new?edit=${config.key}${config.data.chartConfigs.length > 1 ? `&state=${CONFIGURATOR_STATE_LAYOUTING}` : ""}`,
217218
label: t({ id: "login.chart.edit", message: "Edit" }),
218219
iconName: "edit",
219220
priority:

0 commit comments

Comments
 (0)