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

UI configurator enhancements #829

Merged
merged 34 commits into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
b924e72
feat: Remove right panel and flatter style
ptbrowne Nov 7, 2022
116ee91
fix: Do not show user id in Login Menu
ptbrowne Nov 7, 2022
7d854fb
feat: Move annotator config to configuring step
ptbrowne Nov 8, 2022
92cd06f
refactor: Extract TitleAndDescription
ptbrowne Nov 8, 2022
9f9dd11
feat: Show interactive filters in the left panel
ptbrowne Nov 8, 2022
ea84a81
feat: Add collapse to ControlSection
ptbrowne Nov 8, 2022
8e978c3
feat: Add warn icon when no title or description
ptbrowne Nov 8, 2022
4ec82a7
feat: Remove shadows according to new design
ptbrowne Nov 8, 2022
b210c11
refactor: Extract Title and Description options
ptbrowne Nov 8, 2022
96976af
fix: Control sections show their border top, to have a separation wit…
ptbrowne Nov 8, 2022
c72abb1
feat: Clicking on title & description brings title/description
ptbrowne Nov 8, 2022
1228afc
feat: Improve gutterBottom for section titles and rename collapse pro…
ptbrowne Nov 8, 2022
06cfd04
fix: Can change description/title in configuring step
ptbrowne Nov 8, 2022
bb84b2f
fix: Ability to click on page while configurator drawer is opened
ptbrowne Nov 8, 2022
a97319c
fix: Styling for drawer
ptbrowne Nov 8, 2022
2a2fd6e
feat: Add correct gutterBottom + collapse to table chart configurator
ptbrowne Nov 8, 2022
9ac95f5
feat: Use control section skeleton for interactive filters
ptbrowne Nov 8, 2022
a8bc8d8
feat: Use correct icon for chart annotator
ptbrowne Nov 8, 2022
8791afa
feat: Use translated string for Back to preview and Checkout to publi…
ptbrowne Nov 8, 2022
1413cf0
feat: Remove unused stepper
ptbrowne Nov 8, 2022
65968b0
feat: Add chevron right to publish chart
ptbrowne Nov 8, 2022
2788e66
feat: Remove describing chart step
ptbrowne Nov 8, 2022
ea34643
feat: Publish button send STEP_NEXT
ptbrowne Nov 8, 2022
97af247
fix: Keep a singleton Prisma across hot reloads
ptbrowne Nov 8, 2022
174a618
feat: Update messages
ptbrowne Nov 8, 2022
916dcb7
feat: Put login links below language menu
ptbrowne Nov 8, 2022
038ef2b
refactor: Remove unused
ptbrowne Nov 8, 2022
3143284
feat: Add right icon to field controls
ptbrowne Nov 8, 2022
b0fef1a
feat: Add warning on annotator fields
ptbrowne Nov 8, 2022
0962364
refactor: Remove unused EmptyRightPanel
ptbrowne Nov 8, 2022
71f5271
test: Use new data-testid for panel-drawer
ptbrowne Nov 8, 2022
82d3f9e
fix: Handle case where meta.title.<lang> is not defined
ptbrowne Nov 8, 2022
caf2822
fix: Remove unused
ptbrowne Nov 8, 2022
9892c3e
test: Close drawer before trying to change chart type
ptbrowne Nov 8, 2022
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
11 changes: 3 additions & 8 deletions app/components/chart-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import Flex from "@/components/flex";
import {
ChartType,
ConfiguratorStateConfiguringChart,
ConfiguratorStateDescribingChart,
ConfiguratorStatePublishing,
} from "@/configurator";
import { useConfiguratorState } from "@/src";
Expand All @@ -18,9 +17,7 @@ type ChartPanelProps = { children: ReactNode } & BoxProps;
export const ChartPanelConfigurator = (props: ChartPanelProps) => {
// This type of chart panel can only appear for below steps.
const [state] = useConfiguratorState() as unknown as [
| ConfiguratorStateConfiguringChart
| ConfiguratorStateDescribingChart
| ConfiguratorStatePublishing
ConfiguratorStateConfiguringChart | ConfiguratorStatePublishing
];

return (
Expand Down Expand Up @@ -53,12 +50,10 @@ const useChartPanelInnerStyles = makeStyles<Theme, { showTabs: boolean }>(
root: {
flexDirection: "column",
backgroundColor: theme.palette.grey[100],
boxShadow: theme.shadows[6],
borderRadius: 12,
borderTopLeftRadius: ({ showTabs }) => (showTabs ? 0 : 12),
border: "1px solid",
borderColor: theme.palette.divider,
// TODO: Handle properly when chart composition is implemented (enable when
// ChartSelectionTabs becomes scrollable)
borderTopRightRadius: 12,
overflow: "hidden",
width: "auto",
},
Expand Down
41 changes: 35 additions & 6 deletions app/components/chart-preview.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Trans } from "@lingui/macro";
import { Box, Typography } from "@mui/material";
import { Box, Theme, Typography } from "@mui/material";
import { makeStyles } from "@mui/styles";
import Head from "next/head";
import * as React from "react";

Expand Down Expand Up @@ -39,16 +40,33 @@ export const ChartPreview = ({
);
};

const useStyles = makeStyles<Theme>({
title: {
marginBottom: 2,
cursor: "pointer",
"&:hover": {
textDecoration: "underline",
},
},
description: {
marginBottom: 2,
cursor: "pointer",
"&:hover": {
textDecoration: "underline",
},
},
});

export const ChartPreviewInner = ({
dataSetIri,
dataSource,
}: {
dataSetIri: string;
dataSource: DataSource;
}) => {
const [state] = useConfiguratorState();
const [state, dispatch] = useConfiguratorState();
const locale = useLocale();

const classes = useStyles();
const [{ data: metaData }] = useDataCubeMetadataQuery({
variables: {
iri: dataSetIri,
Expand Down Expand Up @@ -91,16 +109,21 @@ export const ChartPreviewInner = ({
</Box>
)}
{(state.state === "CONFIGURING_CHART" ||
state.state === "DESCRIBING_CHART" ||
state.state === "PUBLISHING") && (
<>
<>
<Typography
variant="h2"
sx={{
mb: 2,
color: state.meta.title[locale] === "" ? "grey.500" : "text",
}}
className={classes.title}
onClick={() =>
dispatch({
type: "ACTIVE_FIELD_CHANGED",
value: "title",
})
}
>
{state.meta.title[locale] === "" ? (
<Trans id="annotation.add.title">[ Title ]</Trans>
Expand All @@ -118,11 +141,17 @@ export const ChartPreviewInner = ({
</Head>
<Typography
variant="body1"
className={classes.description}
sx={{
mb: 2,
color:
state.meta.description[locale] === "" ? "grey.500" : "text",
}}
onClick={() =>
dispatch({
type: "ACTIVE_FIELD_CHANGED",
value: "description",
})
}
>
{state.meta.description[locale] === "" ? (
<Trans id="annotation.add.description">[ Description ]</Trans>
Expand Down
68 changes: 53 additions & 15 deletions app/components/chart-selection-tabs.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Box, Popover, Tab, Tabs, Theme } from "@mui/material";
import { Trans } from "@lingui/macro";
import { Box, Popover, Tab, Tabs, Theme, Button } from "@mui/material";
import { makeStyles } from "@mui/styles";
import React, {
createContext,
Expand All @@ -12,13 +13,14 @@ import React, {
import {
ChartType,
ConfiguratorStateConfiguringChart,
ConfiguratorStateDescribingChart,
ConfiguratorStatePublishing,
useConfiguratorState,
} from "@/configurator";
import { ChartTypeSelector } from "@/configurator/components/chart-type-selector";
import { getIconName } from "@/configurator/components/ui-helpers";
import { useDataCubeMetadataWithComponentValuesQuery } from "@/graphql/query-hooks";
import { Icon, IconName } from "@/icons";
import { useLocale } from "@/src";
import useEvent from "@/utils/use-event";

import Flex from "./flex";
Expand Down Expand Up @@ -95,9 +97,7 @@ const useStyles = makeStyles<Theme, { editable: boolean }>((theme) => ({

const TabsEditable = ({ chartType }: { chartType: ChartType }) => {
const [configuratorState] = useConfiguratorState() as unknown as [
| ConfiguratorStateConfiguringChart
| ConfiguratorStateDescribingChart
| ConfiguratorStatePublishing
ConfiguratorStateConfiguringChart | ConfiguratorStatePublishing
];
const [tabsState, setTabsState] = useTabsState();
const [popoverAnchorEl, setPopoverAnchorEl] = useState<HTMLElement | null>(
Expand Down Expand Up @@ -149,6 +149,41 @@ const TabsFixed = ({ chartType }: { chartType: ChartType }) => {
return <TabsInner chartType={chartType} editable={false} />;
};

const PublishChartButton = () => {
const [state, dispatch] = useConfiguratorState();
const { dataSet: dataSetIri } = state as
| ConfiguratorStatePublishing
| ConfiguratorStateConfiguringChart;
const locale = useLocale();
const [{ data }] = useDataCubeMetadataWithComponentValuesQuery({
variables: {
iri: dataSetIri ?? "",
sourceType: state.dataSource.type,
sourceUrl: state.dataSource.url,
locale,
},
pause: !dataSetIri,
});
const goNext = useEvent(() => {
if (data?.dataCubeByIri) {
dispatch({
type: "STEP_NEXT",
dataSetMetadata: data?.dataCubeByIri,
});
}
});

return (
<Button
color="primary"
variant="contained"
onClick={data ? goNext : undefined}
>
<Trans id="button.publish">Publish the chart</Trans>
</Button>
);
};

const TabsInner = ({
chartType,
editable,
Expand All @@ -159,16 +194,19 @@ const TabsInner = ({
onActionButtonClick?: (e: React.MouseEvent<HTMLElement>) => void;
}) => {
return (
<Tabs value={0}>
{/* TODO: Generate dynamically when chart composition is implemented */}
<Tab
sx={{ p: 0 }}
onClick={onActionButtonClick}
label={
<TabContent iconName={getIconName(chartType)} editable={editable} />
}
/>
</Tabs>
<Box display="flex" sx={{ width: "100%", alignItems: "flex-start" }}>
<Tabs value={0} sx={{ position: "relative", top: 1, flexGrow: 1 }}>
{/* TODO: Generate dynamically when chart composition is implemented */}
<Tab
sx={{ p: 0, background: "white" }}
onClick={onActionButtonClick}
label={
<TabContent iconName={getIconName(chartType)} editable={editable} />
}
/>
</Tabs>
<PublishChartButton />
</Box>
);
};

Expand Down
1 change: 0 additions & 1 deletion app/components/language-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ export const LanguageMenu = ({ contentId }: { contentId?: string }) => {
ml: [0, "auto"],
width: ["100%", "auto"],
backgroundColor: ["grey.300", "transparent"],
order: [1, 2],
justifyContent: "flex-end",
}}
>
Expand Down
1 change: 0 additions & 1 deletion app/components/login-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ function LoginMenu() {
<>
<Typography variant="body2">
Signed in as <Link href="/profile">{session.user?.name}</Link>{" "}
{session.user?.id}
{" - "}
</Typography>
<Button
Expand Down
78 changes: 46 additions & 32 deletions app/configurator/components/chart-annotations-selector.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { Box } from "@mui/material";
import { useEffect, useMemo, useRef } from "react";

import { ConfiguratorStateDescribingChart } from "@/configurator";
import {
ControlSection,
ControlSectionContent,
SectionTitle,
} from "@/configurator/components/chart-controls/section";
import { EmptyRightPanel } from "@/configurator/components/empty-right-panel";
import { MetaInputField } from "@/configurator/components/field";
import { getFieldLabel } from "@/configurator/components/field-i18n";
import { getIconName } from "@/configurator/components/ui-helpers";
Expand All @@ -16,19 +14,60 @@ import { InteractiveFilterType } from "@/configurator/interactive-filters/intera
import { locales } from "@/locales/locales";
import { useLocale } from "@/locales/use-locale";

export const ChartAnnotationsSelector = ({
import { ConfiguratorStateConfiguringChart } from "../config-types";

const TitleAndDescriptionOptions = ({
state,
}: {
state: ConfiguratorStateDescribingChart;
state: ConfiguratorStateConfiguringChart;
}) => {
const { activeField, meta } = state;

const locale = useLocale();
// Reorder locales so the input field for
// the current locale is on top
const orderedLocales = [locale, ...locales.filter((l) => l !== locale)];

if (!activeField) {
return null;
}

return (
<ControlSection>
<SectionTitle iconName={getIconName(activeField)}>
{getFieldLabel(activeField)}
</SectionTitle>
<ControlSectionContent gap="none">
{orderedLocales.map((d) => (
<Box
key={`${d}-${activeField!}`}
sx={{ ":not(:first-of-type)": { mt: 2 } }}
>
<MetaInputField
metaKey={activeField}
locale={d}
label={getFieldLabel(d)}
value={meta[activeField === "title" ? "title" : "description"][d]}
/>
</Box>
))}
</ControlSectionContent>
</ControlSection>
);
};

export const ChartAnnotationsSelector = ({
state,
}: {
state: ConfiguratorStateConfiguringChart;
}) => {
const { activeField } = state;
const panelRef = useRef<HTMLDivElement>(null);
useEffect(() => {
if (panelRef && panelRef.current) {
panelRef.current.focus();
}
}, [activeField]);
const locale = useLocale();

const isInteractiveFilterField = useMemo(() => {
switch (activeField as InteractiveFilterType) {
Expand All @@ -43,10 +82,6 @@ export const ChartAnnotationsSelector = ({
}
}, [activeField]);

// Reorder locales so the input field for
// the current locale is on top
const orderedLocales = [locale, ...locales.filter((l) => l !== locale)];

if (activeField) {
return (
<Box
Expand All @@ -60,32 +95,11 @@ export const ChartAnnotationsSelector = ({
{isInteractiveFilterField ? (
<InteractiveFiltersOptions state={state} />
) : (
<ControlSection>
<SectionTitle iconName={getIconName(activeField)}>
{getFieldLabel(activeField)}
</SectionTitle>
<ControlSectionContent gap="none">
{orderedLocales.map((d) => (
<Box
key={`${d}-${activeField!}`}
sx={{ ":not(:first-of-type)": { mt: 2 } }}
>
<MetaInputField
metaKey={activeField}
locale={d}
label={getFieldLabel(d)}
value={
meta[activeField === "title" ? "title" : "description"][d]
}
/>
</Box>
))}
</ControlSectionContent>
</ControlSection>
<TitleAndDescriptionOptions state={state} />
)}
</Box>
);
} else {
return <EmptyRightPanel state={state} />;
return null;
}
};
Loading