Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow edition of published charts #1208

Merged
merged 7 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
56 changes: 51 additions & 5 deletions app/components/chart-selection-tabs.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Trans } from "@lingui/macro";
import { Box, Button, Popover, Tab, Tabs, Theme } from "@mui/material";
import { Trans, t } from "@lingui/macro";
import { Box, Button, Popover, Tab, Tabs, Theme, Tooltip } from "@mui/material";
import { makeStyles } from "@mui/styles";
import { useSession } from "next-auth/react";
import { useRouter } from "next/router";
import React from "react";
import { DragDropContext, Draggable, Droppable } from "react-beautiful-dnd";

Expand All @@ -23,7 +25,9 @@ import {
} from "@/graphql/query-hooks";
import { Icon, IconName } from "@/icons";
import { useLocale } from "@/src";
import { fetchChartConfig } from "@/utils/chart-config/api";
import { createChartId } from "@/utils/create-chart-id";
import { getRouterChartId } from "@/utils/router/helpers";
import useEvent from "@/utils/use-event";

type TabsState = {
Expand Down Expand Up @@ -277,16 +281,58 @@ const PublishChartButton = () => {
}
});

return (
const [editingPublishedChart, setEditingPublishedChart] =
React.useState(false);
const [loaded, setLoaded] = React.useState(false);
const { asPath } = useRouter();
const session = useSession();
const chartId = getRouterChartId(asPath);

React.useEffect(() => {
const run = async () => {
if (session.data?.user && chartId) {
const config = await fetchChartConfig(chartId);

if (config?.user_id === session.data.user.id) {
setEditingPublishedChart(true);
}
}

if (session.status !== "loading") {
setLoaded(true);
}
};

run();
}, [chartId, session]);

bprusinowski marked this conversation as resolved.
Show resolved Hide resolved
return loaded ? (
<Button
color="primary"
variant="contained"
onClick={metadata && components ? goNext : undefined}
sx={{ minWidth: "fit-content" }}
>
<Trans id="button.publish">Publish this visualization</Trans>
{editingPublishedChart ? (
<Box sx={{ display: "flex", alignItems: "center", gap: 2 }}>
<Tooltip
title={t({
id: "button.update.warning",
message:
"Keep in mind that updating this visualization will affect all the places where it might be already embedded!",
})}
>
<div>
<Icon name="hintWarning" />
</div>
</Tooltip>
<Trans id="button.update">Update this visualization</Trans>
</Box>
) : (
<Trans id="button.publish">Publish this visualization</Trans>
)}
</Button>
);
) : null;
};

type TabsInnerProps = {
Expand Down
3 changes: 2 additions & 1 deletion app/configurator/configurator-state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ import {
migrateConfiguratorState,
} from "@/utils/chart-config/versioning";
import { createChartId } from "@/utils/create-chart-id";
import { getRouterChartId } from "@/utils/router/helpers";
import { unreachableError } from "@/utils/unreachable";

export type ConfiguratorStateAction =
Expand Down Expand Up @@ -1527,7 +1528,7 @@ const ConfiguratorStateProviderInternal = ({
(async () => {
try {
let dbConfig: ParsedConfig | undefined;
const key = asPath.split("?")[0].split("/").pop();
const key = getRouterChartId(asPath);

if (key && user) {
const config = await fetchChartConfig(key);
Expand Down
8 changes: 8 additions & 0 deletions app/locales/de/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ msgstr "Diese Visualisierung veröffentlichen"
msgid "button.share"
msgstr "Teilen"

#: app/components/chart-selection-tabs.tsx
msgid "button.update"
msgstr "Diese Visualisierung aktualisieren"

#: app/components/chart-selection-tabs.tsx
msgid "button.update.warning"
msgstr "Denken Sie daran, dass sich die Aktualisierung dieser Visualisierung auf alle Stellen auswirkt, an denen sie bereits eingebettet ist!"

#: app/configurator/components/field-i18n.ts
msgid "chart.map.layers.area"
msgstr "Flächen"
Expand Down
8 changes: 8 additions & 0 deletions app/locales/en/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ msgstr "Publish this visualization"
msgid "button.share"
msgstr "Share"

#: app/components/chart-selection-tabs.tsx
msgid "button.update"
msgstr "Update this visualization"

#: app/components/chart-selection-tabs.tsx
msgid "button.update.warning"
msgstr "Keep in mind that updating this visualization will affect all the places where it might be already embedded!"

#: app/configurator/components/field-i18n.ts
msgid "chart.map.layers.area"
msgstr "Areas"
Expand Down
8 changes: 8 additions & 0 deletions app/locales/fr/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ msgstr "Publier cette visualisation"
msgid "button.share"
msgstr "Partager"

#: app/components/chart-selection-tabs.tsx
msgid "button.update"
msgstr "Actualiser cette visualisation"

#: app/components/chart-selection-tabs.tsx
msgid "button.update.warning"
msgstr "Gardez à l'esprit que la mise à jour de cette visualisation affectera tous les endroits où elle est déjà intégrée !"

#: app/configurator/components/field-i18n.ts
msgid "chart.map.layers.area"
msgstr "Zones"
Expand Down
8 changes: 8 additions & 0 deletions app/locales/it/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ msgstr "Pubblica questa visualizzazione"
msgid "button.share"
msgstr "Condividi"

#: app/components/chart-selection-tabs.tsx
msgid "button.update"
msgstr "Aggiornare questa visualizzazione"

#: app/components/chart-selection-tabs.tsx
msgid "button.update.warning"
msgstr "Tenete presente che l'aggiornamento di questa visualizzazione avrà effetto su tutti i luoghi in cui potrebbe essere già incorporata!"

#: app/configurator/components/field-i18n.ts
msgid "chart.map.layers.area"
msgstr "Aree"
Expand Down
4 changes: 4 additions & 0 deletions app/utils/router/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ export const setURLParam = (param: string, value: string) => {
newUrl
);
};

export const getRouterChartId = (asPath: string) => {
return asPath.split("?")[0].split("/").pop();
};
Loading