From b0fef1a14ea850e478bf9723d603c7353be994cd Mon Sep 17 00:00:00 2001 From: Patrick Browne Date: Tue, 8 Nov 2022 14:02:15 +0100 Subject: [PATCH] feat: Add warning on annotator fields --- .../components/chart-annotator.tsx | 28 +++++++---- .../components/chart-controls/control-tab.tsx | 48 +++++++++++++------ app/configurator/components/field.tsx | 34 ++++++++++--- .../table/table-chart-configurator.tsx | 4 +- app/locales/de/messages.po | 18 +++++-- app/locales/en/messages.po | 18 +++++-- app/locales/fr/messages.po | 20 +++++--- app/locales/it/messages.po | 18 +++++-- 8 files changed, 133 insertions(+), 55 deletions(-) diff --git a/app/configurator/components/chart-annotator.tsx b/app/configurator/components/chart-annotator.tsx index 97f0ffbfd..e41336785 100644 --- a/app/configurator/components/chart-annotator.tsx +++ b/app/configurator/components/chart-annotator.tsx @@ -11,20 +11,18 @@ import { AnnotatorTabField } from "@/configurator/components/field"; import { getFieldLabel } from "@/configurator/components/field-i18n"; import { InteractiveFiltersConfigurator } from "@/configurator/interactive-filters/interactive-filters-configurator"; import SvgIcExclamation from "@/icons/components/IcExclamation"; -import { useConfiguratorState } from "@/src"; +import { useConfiguratorState, useLocale } from "@/src"; import { ConfiguratorStateConfiguringChart } from "../config-types"; import { isConfiguring } from "../configurator-state"; const WarnTitleDescription = () => { const [state] = useConfiguratorState(isConfiguring); + const locale = useLocale(); const hasSomeTitleOrDescription = React.useMemo(() => { const { title, description } = state.meta; - return ( - Object.values(title).some((x) => x != "") || - Object.values(description).some((x) => x != "") - ); - }, [state.meta]); + return title[locale] !== "" && description[locale] !== ""; + }, [state.meta, locale]); return hasSomeTitleOrDescription ? null : ( { + emptyValueWarning={ + + Please add a title + + } + mainLabel={getFieldLabel("title")} + /> + emptyValueWarning={ + + Please add a description + + } + mainLabel={getFieldLabel("description")} + /> ); diff --git a/app/configurator/components/chart-controls/control-tab.tsx b/app/configurator/components/chart-controls/control-tab.tsx index ee303793b..09ec7557e 100644 --- a/app/configurator/components/chart-controls/control-tab.tsx +++ b/app/configurator/components/chart-controls/control-tab.tsx @@ -40,7 +40,7 @@ export const ControlTab = ({ void; + value: string; + icon: IconName; + mainLabel: ReactNode; + upperLabel?: ReactNode; + lowerLabel?: ReactNode; + rightIcon?: ReactNode; +} & FieldProps; + export const AnnotatorTab = ({ value, checked, onClick, icon, - label, + upperLabel, + mainLabel, + lowerLabel, rightIcon, -}: { - disabled?: boolean; - onClick: (x: string) => void; - value: string; - icon: IconName; - label: ReactNode; - rightIcon?: ReactNode; -} & FieldProps) => { +}: AnnotatorTabProps) => { return ( @@ -166,7 +174,7 @@ export const DraggableTab = ({ @@ -242,6 +250,7 @@ export const ControlTabButton = ({ export const ControlTabButtonInner = ({ iconName, upperLabel, + mainLabel, lowerLabel, checked, rightIcon, @@ -251,7 +260,8 @@ export const ControlTabButtonInner = ({ }: { iconName: IconName; upperLabel?: string | ReactNode; - lowerLabel: string | ReactNode; + mainLabel: string | ReactNode; + lowerLabel?: string | ReactNode; checked?: boolean; optional?: boolean; // On / Off indicator @@ -307,8 +317,16 @@ export const ControlTabButtonInner = ({ textAlign: "left", }} > - {lowerLabel} + {mainLabel} + {lowerLabel && ( + + {lowerLabel} + + )} {showIsActive && isActive === false ? ( diff --git a/app/configurator/components/field.tsx b/app/configurator/components/field.tsx index 5737e625c..38f067eb2 100644 --- a/app/configurator/components/field.tsx +++ b/app/configurator/components/field.tsx @@ -1,9 +1,15 @@ import { t } from "@lingui/macro"; -import { CircularProgress, Theme } from "@mui/material"; +import { CircularProgress, Theme, Typography } from "@mui/material"; import { makeStyles } from "@mui/styles"; import { extent, timeFormat, TimeLocaleObject, timeParse } from "d3"; import get from "lodash/get"; -import { ChangeEvent, ReactNode, useCallback, useMemo, useState } from "react"; +import React, { + ChangeEvent, + ReactNode, + useCallback, + useMemo, + useState, +} from "react"; import Flex from "@/components/flex"; import { @@ -19,6 +25,7 @@ import { import { ColorPickerMenu } from "@/configurator/components/chart-controls/color-picker"; import { AnnotatorTab, + AnnotatorTabProps, ControlTab, OnOffControlTab, } from "@/configurator/components/chart-controls/control-tab"; @@ -51,7 +58,6 @@ import { FIELD_VALUE_NONE } from "@/configurator/constants"; import { truthy } from "@/domain/types"; import { useTimeFormatLocale } from "@/formatters"; import { DimensionMetadataFragment, TimeUnit } from "@/graphql/query-hooks"; -import { IconName } from "@/icons"; import SvgIcEdit from "@/icons/components/IcEdit"; import { useLocale } from "@/locales/use-locale"; import { getPalette } from "@/palettes"; @@ -447,19 +453,33 @@ export const TimeInput = ({ export const AnnotatorTabField = ({ value, + emptyValueWarning, ...tabProps }: { value: string; - disabled?: boolean; - icon: IconName; - label: ReactNode; -}) => { + emptyValueWarning?: React.ReactNode; +} & Omit) => { const fieldProps = useActiveFieldField({ value, }); + + const [state] = useConfiguratorState(isConfiguring); + const locale = useLocale(); + const hasText = useMemo(() => { + const key = value as "title" | "description"; + return state.meta[key][locale] !== ""; + }, [state.meta, value, locale]); + return ( + {emptyValueWarning} + + ) + } value={`${fieldProps.value}`} checked={fieldProps.checked} onClick={fieldProps.onClick} diff --git a/app/configurator/table/table-chart-configurator.tsx b/app/configurator/table/table-chart-configurator.tsx index 6d369848a..804e6c49b 100644 --- a/app/configurator/table/table-chart-configurator.tsx +++ b/app/configurator/table/table-chart-configurator.tsx @@ -140,13 +140,13 @@ export const ChartConfiguratorTable = ({ key={"settings"} value={"table-settings"} icon="settings" - label={Settings} + mainLabel={Settings} /> Sorting} + mainLabel={Sorting} /> diff --git a/app/locales/de/messages.po b/app/locales/de/messages.po index 3614456b5..f6016ea59 100644 --- a/app/locales/de/messages.po +++ b/app/locales/de/messages.po @@ -187,6 +187,14 @@ msgstr "Normal" msgid "controls..interactiveFilters.time.defaultSettings" msgstr "Standardeinstellung" +#: app/configurator/components/chart-annotator.tsx:67 +msgid "controls.annotator.add-description-warning" +msgstr "Fügen Sie eine Beschreibung hinzu" + +#: app/configurator/components/chart-annotator.tsx:57 +msgid "controls.annotator.add-title-warning" +msgstr "Füge einen Titel hinzu" + #: app/configurator/components/field-i18n.ts:5 msgid "controls.axis.horizontal" msgstr "Horizontale Achse" @@ -232,7 +240,7 @@ msgstr "Tabelle" msgid "controls.color" msgstr "Farbe" -#: app/configurator/components/chart-controls/control-tab.tsx:45 +#: app/configurator/components/chart-controls/control-tab.tsx:47 msgid "controls.color.add" msgstr "Hinzufügen …" @@ -455,11 +463,11 @@ msgstr "" msgid "controls.none" msgstr "" -#: app/configurator/components/chart-controls/control-tab.tsx:312 +#: app/configurator/components/chart-controls/control-tab.tsx:338 msgid "controls.option.isActive" msgstr "Ein" -#: app/configurator/components/chart-controls/control-tab.tsx:308 +#: app/configurator/components/chart-controls/control-tab.tsx:334 msgid "controls.option.isNotActive" msgstr "Aus" @@ -495,7 +503,7 @@ msgstr "Spaltenstil" msgid "controls.section.data.filters" msgstr "Filter" -#: app/configurator/components/chart-annotator.tsx:52 +#: app/configurator/components/chart-annotator.tsx:50 msgid "controls.section.description" msgstr "Titel & Beschreibung" @@ -549,7 +557,7 @@ msgstr "Tabellensortierung" msgid "controls.section.tableoptions" msgstr "Tabellenoptionen" -#: app/configurator/components/chart-annotator.tsx:32 +#: app/configurator/components/chart-annotator.tsx:30 msgid "controls.section.title.warning" msgstr "Fügen Sie einen Titel oder eine Beschreibung hinzu" diff --git a/app/locales/en/messages.po b/app/locales/en/messages.po index 80d4ad8c0..a419e2113 100644 --- a/app/locales/en/messages.po +++ b/app/locales/en/messages.po @@ -207,6 +207,14 @@ msgstr "Regular" msgid "controls..interactiveFilters.time.defaultSettings" msgstr "Default Settings" +#: app/configurator/components/chart-annotator.tsx:67 +msgid "controls.annotator.add-description-warning" +msgstr "Please add a description" + +#: app/configurator/components/chart-annotator.tsx:57 +msgid "controls.annotator.add-title-warning" +msgstr "Please add a title" + #: app/configurator/components/field-i18n.ts:5 msgid "controls.axis.horizontal" msgstr "Horizontal Axis" @@ -252,7 +260,7 @@ msgstr "Table" msgid "controls.color" msgstr "Color" -#: app/configurator/components/chart-controls/control-tab.tsx:45 +#: app/configurator/components/chart-controls/control-tab.tsx:47 msgid "controls.color.add" msgstr "Add ..." @@ -475,11 +483,11 @@ msgstr "Back to preview" msgid "controls.none" msgstr "None" -#: app/configurator/components/chart-controls/control-tab.tsx:312 +#: app/configurator/components/chart-controls/control-tab.tsx:338 msgid "controls.option.isActive" msgstr "On" -#: app/configurator/components/chart-controls/control-tab.tsx:308 +#: app/configurator/components/chart-controls/control-tab.tsx:334 msgid "controls.option.isNotActive" msgstr "Off" @@ -511,7 +519,7 @@ msgstr "Column Style" msgid "controls.section.data.filters" msgstr "Filters" -#: app/configurator/components/chart-annotator.tsx:52 +#: app/configurator/components/chart-annotator.tsx:50 msgid "controls.section.description" msgstr "Title & Description" @@ -565,7 +573,7 @@ msgstr "Table Sorting" msgid "controls.section.tableoptions" msgstr "Table Options" -#: app/configurator/components/chart-annotator.tsx:32 +#: app/configurator/components/chart-annotator.tsx:30 msgid "controls.section.title.warning" msgstr "Please add a title or description." diff --git a/app/locales/fr/messages.po b/app/locales/fr/messages.po index 344ddfdc0..ff0d3de22 100644 --- a/app/locales/fr/messages.po +++ b/app/locales/fr/messages.po @@ -207,6 +207,14 @@ msgstr "Normal" msgid "controls..interactiveFilters.time.defaultSettings" msgstr "Paramètres d'origine" +#: app/configurator/components/chart-annotator.tsx:67 +msgid "controls.annotator.add-description-warning" +msgstr "Ajoutez une description au graphique" + +#: app/configurator/components/chart-annotator.tsx:57 +msgid "controls.annotator.add-title-warning" +msgstr "Ajoutez un titre au graphique" + #: app/configurator/components/field-i18n.ts:5 msgid "controls.axis.horizontal" msgstr "Axe horizontal" @@ -252,7 +260,7 @@ msgstr "Tableau" msgid "controls.color" msgstr "Couleur" -#: app/configurator/components/chart-controls/control-tab.tsx:45 +#: app/configurator/components/chart-controls/control-tab.tsx:47 msgid "controls.color.add" msgstr "Ajouter…" @@ -470,11 +478,11 @@ msgstr "Retour à l'aperçu" msgid "controls.none" msgstr "Aucun" -#: app/configurator/components/chart-controls/control-tab.tsx:312 +#: app/configurator/components/chart-controls/control-tab.tsx:338 msgid "controls.option.isActive" msgstr "Actif" -#: app/configurator/components/chart-controls/control-tab.tsx:308 +#: app/configurator/components/chart-controls/control-tab.tsx:334 msgid "controls.option.isNotActive" msgstr "Inactif" @@ -506,7 +514,7 @@ msgstr "Style de la colonne" msgid "controls.section.data.filters" msgstr "Filtres" -#: app/configurator/components/chart-annotator.tsx:52 +#: app/configurator/components/chart-annotator.tsx:50 msgid "controls.section.description" msgstr "Titre & description" @@ -560,9 +568,9 @@ msgstr "Tri du tableau" msgid "controls.section.tableoptions" msgstr "Options du tableau" -#: app/configurator/components/chart-annotator.tsx:32 +#: app/configurator/components/chart-annotator.tsx:30 msgid "controls.section.title.warning" -msgstr "Ajoutez un titre ou une description" +msgstr "Ajoutez un titre et une description" #: app/configurator/components/chart-configurator.tsx:537 #: app/configurator/components/chart-type-selector.tsx:131 diff --git a/app/locales/it/messages.po b/app/locales/it/messages.po index 7f7ecbd79..1e2f8152d 100644 --- a/app/locales/it/messages.po +++ b/app/locales/it/messages.po @@ -207,6 +207,14 @@ msgstr "Regular" msgid "controls..interactiveFilters.time.defaultSettings" msgstr "Impostazioni predefinite" +#: app/configurator/components/chart-annotator.tsx:67 +msgid "controls.annotator.add-description-warning" +msgstr "Aggiungi una descrizione" + +#: app/configurator/components/chart-annotator.tsx:57 +msgid "controls.annotator.add-title-warning" +msgstr "Aggiungi un titolo" + #: app/configurator/components/field-i18n.ts:5 msgid "controls.axis.horizontal" msgstr "Asse orizzontale" @@ -252,7 +260,7 @@ msgstr "Tabella" msgid "controls.color" msgstr "Colore" -#: app/configurator/components/chart-controls/control-tab.tsx:45 +#: app/configurator/components/chart-controls/control-tab.tsx:47 msgid "controls.color.add" msgstr "Aggiungi ..." @@ -475,11 +483,11 @@ msgstr "Torna all'anteprima" msgid "controls.none" msgstr "Nessuno" -#: app/configurator/components/chart-controls/control-tab.tsx:312 +#: app/configurator/components/chart-controls/control-tab.tsx:338 msgid "controls.option.isActive" msgstr "Attivo" -#: app/configurator/components/chart-controls/control-tab.tsx:308 +#: app/configurator/components/chart-controls/control-tab.tsx:334 msgid "controls.option.isNotActive" msgstr "Inattivo" @@ -511,7 +519,7 @@ msgstr "Stile della colonna" msgid "controls.section.data.filters" msgstr "Filtri" -#: app/configurator/components/chart-annotator.tsx:52 +#: app/configurator/components/chart-annotator.tsx:50 msgid "controls.section.description" msgstr "Titolo e descrizione" @@ -565,7 +573,7 @@ msgstr "Ordinamento della tabella" msgid "controls.section.tableoptions" msgstr "Opzioni della tabella" -#: app/configurator/components/chart-annotator.tsx:32 +#: app/configurator/components/chart-annotator.tsx:30 msgid "controls.section.title.warning" msgstr "Aggiungi un titolo o una descrizione"