From f832265fae99e7d332d7798d9b2bdfcbe2889ae0 Mon Sep 17 00:00:00 2001 From: Bartosz Prusinowski Date: Tue, 23 Aug 2022 11:19:25 +0200 Subject: [PATCH] refactor: useStyles instead of sx --- .../table/table-chart-sorting-options.tsx | 182 ++++++++++-------- 1 file changed, 97 insertions(+), 85 deletions(-) diff --git a/app/configurator/table/table-chart-sorting-options.tsx b/app/configurator/table/table-chart-sorting-options.tsx index bdbda0df89..8c2a5f3ff5 100644 --- a/app/configurator/table/table-chart-sorting-options.tsx +++ b/app/configurator/table/table-chart-sorting-options.tsx @@ -1,6 +1,13 @@ import { t, Trans } from "@lingui/macro"; -import { Box, Button, SelectChangeEvent, Typography } from "@mui/material"; -import React, { useCallback } from "react"; +import { + Box, + Button, + SelectChangeEvent, + Theme, + Typography, +} from "@mui/material"; +import { makeStyles } from "@mui/styles"; +import React, { ChangeEvent, useCallback } from "react"; import { DragDropContext, Draggable, @@ -36,19 +43,58 @@ import { DataCubeMetadata } from "@/graphql/types"; import { Icon } from "@/icons"; import useEvent from "@/lib/use-event"; +const useStyles = makeStyles((theme) => ({ + sortingItemContainer: { + backgroundColor: theme.palette.grey[100], + paddingTop: theme.spacing(4), + paddingBottom: theme.spacing(4), + paddingLeft: theme.spacing(4), + paddingRight: `calc(${theme.spacing(6)} + ${theme.spacing(2)})`, + + borderTopColor: theme.palette.grey[500], + borderTopStyle: "solid", + borderTopWidth: 1, + }, + selectWrapper: { + color: theme.palette.grey[800], + lineHeight: "1rem", + textAlign: "left", + marginBottom: theme.spacing(4), + }, + metaOptionsContainer: { + marginBottom: -theme.spacing(1), + width: "100%", + alignItems: "flex-start", + }, + removeButton: { + padding: 0, + cursor: "pointer", + marginLeft: "auto", + minWidth: 0, + minHeight: 0, + }, + iconWrapper: { + // @ts-ignore + color: theme.palette.secondary.disabled, + "&:hover": { + color: theme.palette.secondary.main, + }, + }, +})); + const TableSortingOptionItem = ({ componentIri, - componentType, index, + chartConfig, sortingOrder, metaData, - chartConfig, }: { metaData: DataCubeMetadata; index: number; chartConfig: TableConfig; } & TableSortingOption) => { const [, dispatch] = useConfiguratorState(); + const classes = useStyles(); const component = metaData.dimensions.find(({ iri }) => iri === componentIri) ?? metaData.measures.find(({ iri }) => iri === componentIri); @@ -66,94 +112,60 @@ const TableSortingOptionItem = ({ }); const onChangeSortingOrder = useEvent((e: ChangeEvent) => { - dispatch({ - type: "CHART_CONFIG_REPLACED", - value: { - chartConfig: changeSortingOptionOrder(chartConfig, { - index, + dispatch({ + type: "CHART_CONFIG_REPLACED", + value: { + chartConfig: changeSortingOptionOrder(chartConfig, { + index, sortingOrder: e.currentTarget.value as "asc" | "desc", - }), - dataSetMetadata: metaData, - }, - }); + }), + dataSetMetadata: metaData, + }, + }); }); const sortingType = component?.__typename === "Measure" ? "byMeasure" : "byDimensionLabel"; return component ? ( - - - + + + + + + + - - + + + Remove sorting dimension + + + + + ) : null; }; @@ -351,7 +363,7 @@ export const TableSortingOptions = ({ return ( - + Table Sorting