From 6fc1cbebd2138c6483dbee8503fb6a2cfef1b359 Mon Sep 17 00:00:00 2001 From: Bartosz Prusinowski Date: Fri, 7 Jun 2024 15:20:00 +0200 Subject: [PATCH] refactor: Use npx knip to clean up unused things --- app/browser/dataset-browse.tsx | 6 +- app/browser/select-dataset-step.tsx | 2 +- app/charts/area/chart-area.tsx | 2 +- app/charts/column/chart-column.tsx | 2 +- app/charts/combo/chart-combo-line-column.tsx | 2 +- app/charts/combo/chart-combo-line-dual.tsx | 50 ++++--- app/charts/combo/chart-combo-line-single.tsx | 2 +- app/charts/index.ts | 14 +- app/charts/line/chart-lines.tsx | 2 +- app/charts/map/chart-map.tsx | 2 +- app/charts/map/get-base-layer-style.ts | 2 +- app/charts/map/helpers.ts | 2 +- app/charts/map/style-helpers.ts | 4 +- app/charts/pie/chart-pie.tsx | 2 +- app/charts/scatterplot/chart-scatterplot.tsx | 2 +- app/charts/shared/abbreviations.ts | 55 -------- app/charts/shared/brush/index.tsx | 6 +- app/charts/shared/chart-data-filters.tsx | 4 +- app/charts/shared/chart-helpers.tsx | 13 +- app/charts/shared/chart-loading-state.tsx | 2 +- app/charts/shared/interaction/hover-dot.tsx | 47 ------- app/charts/shared/interaction/tooltip-box.tsx | 12 +- app/charts/shared/observation-labels.ts | 31 ----- app/charts/shared/ticks.tsx | 2 +- app/charts/table/cell-mobile.tsx | 89 +------------ app/charts/table/example-props.ts | 53 -------- app/components/chart-panel-layout-tall.tsx | 4 +- app/components/chart-preview.tsx | 8 +- app/components/chart-selection-tabs.tsx | 4 +- .../copy-to-clipboard-text-input.tsx | 4 +- app/components/data-download.tsx | 8 +- app/components/debug-panel/index.tsx | 2 +- app/components/header.tsx | 2 +- app/components/menu-action-item.tsx | 2 +- app/components/publish-actions.tsx | 4 +- app/components/react-grid.tsx | 2 +- app/config-types.ts | 51 +------ .../components/add-dataset-dialog.tsx | 4 +- .../components/add-new-dataset-panel.tsx | 2 +- app/configurator/components/breadcrumbs.tsx | 45 ------- .../components/chart-controls/control-tab.tsx | 4 +- app/configurator/components/ui-helpers.ts | 2 +- .../components/use-hierarchy-parents.tsx | 29 +--- .../configurator-state/context.tsx | 4 +- app/configurator/configurator-state/index.tsx | 4 +- app/configurator/configurator-state/mocks.ts | 51 ------- .../configurator-state/reducer.tsx | 2 +- .../interactive-filters-config-state.tsx | 120 +---------------- .../interactive-filters-configurator.tsx | 6 - app/domain/data.ts | 8 +- app/domain/datasource/localStorage.ts | 2 +- app/domain/user-configs.ts | 4 +- app/flags/flag.tsx | 6 +- app/flags/ls-adapter.ts | 4 +- app/formatters.ts | 14 +- app/gql-flamegraph/devtool.tsx | 2 +- app/graphql/hooks.ts | 2 +- app/icons/index.tsx | 28 +--- app/palettes.ts | 49 ------- app/rdf/cube-filters.ts | 75 ----------- app/rdf/parse.ts | 124 +----------------- app/rdf/queries.ts | 73 +---------- app/rdf/query-latest-cube-iri.ts | 2 +- app/rdf/query-search-score-utils.ts | 5 - app/rdf/tree-utils.ts | 16 --- app/stores/data-source.ts | 2 +- app/stores/interactive-filters.tsx | 2 +- app/utils/cached-with-ttl.ts | 27 ---- app/utils/flashes.tsx | 2 +- app/utils/is-attr-equal.tsx | 16 --- app/utils/use-change.tsx | 11 -- 71 files changed, 119 insertions(+), 1129 deletions(-) delete mode 100644 app/charts/shared/interaction/hover-dot.tsx delete mode 100644 app/charts/table/example-props.ts delete mode 100644 app/configurator/components/breadcrumbs.tsx delete mode 100644 app/rdf/cube-filters.ts delete mode 100644 app/utils/cached-with-ttl.ts delete mode 100644 app/utils/is-attr-equal.tsx delete mode 100644 app/utils/use-change.tsx diff --git a/app/browser/dataset-browse.tsx b/app/browser/dataset-browse.tsx index 0252cce0c..f8dedcb5f 100644 --- a/app/browser/dataset-browse.tsx +++ b/app/browser/dataset-browse.tsx @@ -515,7 +515,7 @@ const NavItem = ({ ); }; -export const Subthemes = ({ +const Subthemes = ({ subthemes, filters, counts, @@ -556,7 +556,7 @@ type NavSectionTitleTheme = { borderColor: string; }; -export const NavSectionTitle = ({ +const NavSectionTitle = ({ children, theme, ...flexProps @@ -990,7 +990,7 @@ const useResultStyles = makeStyles((theme: Theme) => ({ }, })); -export const DateFormat = ({ date }: { date: string }) => { +const DateFormat = ({ date }: { date: string }) => { const formatter = useFormatDate(); const formatted = useMemo(() => { return formatter(date); diff --git a/app/browser/select-dataset-step.tsx b/app/browser/select-dataset-step.tsx index 13009b42f..164b5ad97 100644 --- a/app/browser/select-dataset-step.tsx +++ b/app/browser/select-dataset-step.tsx @@ -130,7 +130,7 @@ const useStyles = makeStyles< }, })); -export const formatBackLink = ( +const formatBackLink = ( query: Router["query"] ): React.ComponentProps["href"] => { const backParameters = softJSONParse(query.previous as string); diff --git a/app/charts/area/chart-area.tsx b/app/charts/area/chart-area.tsx index b94b45b22..ddd2b7891 100644 --- a/app/charts/area/chart-area.tsx +++ b/app/charts/area/chart-area.tsx @@ -25,7 +25,7 @@ export const ChartAreasVisualization = ( return ; }; -export const ChartAreas = memo((props: ChartProps) => { +const ChartAreas = memo((props: ChartProps) => { const { chartConfig } = props; const { fields, interactiveFiltersConfig } = chartConfig; diff --git a/app/charts/column/chart-column.tsx b/app/charts/column/chart-column.tsx index 0cd5134e2..fb32da3d6 100644 --- a/app/charts/column/chart-column.tsx +++ b/app/charts/column/chart-column.tsx @@ -36,7 +36,7 @@ export const ChartColumnsVisualization = ( return ; }; -export const ChartColumns = memo((props: ChartProps) => { +const ChartColumns = memo((props: ChartProps) => { const { chartConfig, dimensions } = props; const { fields, interactiveFiltersConfig } = chartConfig; const filters = useChartConfigFilters(chartConfig); diff --git a/app/charts/combo/chart-combo-line-column.tsx b/app/charts/combo/chart-combo-line-column.tsx index 05ad97306..388f237f8 100644 --- a/app/charts/combo/chart-combo-line-column.tsx +++ b/app/charts/combo/chart-combo-line-column.tsx @@ -22,7 +22,7 @@ export const ChartComboLineColumnVisualization = ( return ; }; -export const ChartComboLineColumn = memo( +const ChartComboLineColumn = memo( (props: ChartProps) => { const { chartConfig } = props; const { interactiveFiltersConfig } = chartConfig; diff --git a/app/charts/combo/chart-combo-line-dual.tsx b/app/charts/combo/chart-combo-line-dual.tsx index d11ff3fa0..469f46c95 100644 --- a/app/charts/combo/chart-combo-line-dual.tsx +++ b/app/charts/combo/chart-combo-line-dual.tsx @@ -22,30 +22,28 @@ export const ChartComboLineDualVisualization = ( return ; }; -export const ChartComboLineDual = memo( - (props: ChartProps) => { - const { chartConfig } = props; - const { interactiveFiltersConfig } = chartConfig; - const { sharedFilters } = useDashboardInteractiveFilters(); +const ChartComboLineDual = memo((props: ChartProps) => { + const { chartConfig } = props; + const { interactiveFiltersConfig } = chartConfig; + const { sharedFilters } = useDashboardInteractiveFilters(); - return ( - - - - - - - - - {shouldShowBrush(interactiveFiltersConfig, sharedFilters) && ( - - )} - - - - - - - ); - } -); + return ( + + + + + + + + + {shouldShowBrush(interactiveFiltersConfig, sharedFilters) && ( + + )} + + + + + + + ); +}); diff --git a/app/charts/combo/chart-combo-line-single.tsx b/app/charts/combo/chart-combo-line-single.tsx index 600e76d92..0eea201d6 100644 --- a/app/charts/combo/chart-combo-line-single.tsx +++ b/app/charts/combo/chart-combo-line-single.tsx @@ -27,7 +27,7 @@ export const ChartComboLineSingleVisualization = ( return ; }; -export const ChartComboLineSingle = memo( +const ChartComboLineSingle = memo( (props: ChartProps) => { const { chartConfig, measures } = props; const { interactiveFiltersConfig } = chartConfig; diff --git a/app/charts/index.ts b/app/charts/index.ts index 68b01ba43..487a0ed7b 100644 --- a/app/charts/index.ts +++ b/app/charts/index.ts @@ -89,7 +89,7 @@ import { createChartId } from "@/utils/create-chart-id"; import { isMultiHierarchyNode } from "@/utils/hierarchy"; import { unreachableError } from "@/utils/unreachable"; -export const chartTypes: ChartType[] = [ +const chartTypes: ChartType[] = [ "column", "line", "area", @@ -112,7 +112,7 @@ export const regularChartTypes: RegularChartType[] = [ "map", ]; -export const comboDifferentUnitChartTypes: ComboChartType[] = [ +const comboDifferentUnitChartTypes: ComboChartType[] = [ "comboLineDual", "comboLineColumn", ]; @@ -125,11 +125,7 @@ export const comboChartTypes: ComboChartType[] = [ ]; type ChartOrder = { [k in ChartType]: number }; -export function getChartTypeOrder({ - cubeCount, -}: { - cubeCount: number; -}): ChartOrder { +function getChartTypeOrder({ cubeCount }: { cubeCount: number }): ChartOrder { const multiCubeBoost = cubeCount > 1 ? -100 : 0; return { column: 0, @@ -284,7 +280,7 @@ export const initializeMapLayerField = ({ } }; -export const getInitialAreaLayer = ({ +const getInitialAreaLayer = ({ component, measure, }: { @@ -307,7 +303,7 @@ export const getInitialAreaLayer = ({ }; }; -export const getInitialSymbolLayer = ({ +const getInitialSymbolLayer = ({ component, measure, }: { diff --git a/app/charts/line/chart-lines.tsx b/app/charts/line/chart-lines.tsx index 70afff372..e1a5eaadd 100644 --- a/app/charts/line/chart-lines.tsx +++ b/app/charts/line/chart-lines.tsx @@ -27,7 +27,7 @@ export const ChartLinesVisualization = ( return ; }; -export const ChartLines = memo((props: ChartProps) => { +const ChartLines = memo((props: ChartProps) => { const { chartConfig } = props; const { fields, interactiveFiltersConfig } = chartConfig; const { sharedFilters } = useDashboardInteractiveFilters(); diff --git a/app/charts/map/chart-map.tsx b/app/charts/map/chart-map.tsx index ef71fc16d..e560c1571 100644 --- a/app/charts/map/chart-map.tsx +++ b/app/charts/map/chart-map.tsx @@ -128,7 +128,7 @@ export type ChartMapProps = ChartProps & { coordinates: GeoCoordinates | undefined; }; -export const ChartMap = memo((props: ChartMapProps) => { +const ChartMap = memo((props: ChartMapProps) => { const { chartConfig, dimensions, observations } = props; const { fields } = chartConfig; const filters = useChartConfigFilters(chartConfig); diff --git a/app/charts/map/get-base-layer-style.ts b/app/charts/map/get-base-layer-style.ts index 4763f2754..e8d30993e 100644 --- a/app/charts/map/get-base-layer-style.ts +++ b/app/charts/map/get-base-layer-style.ts @@ -16,7 +16,7 @@ const tokens = { const greyStyle = replaceStyleTokens(greyStyleBase as MapboxStyle, tokens); -export const emptyStyle = { +const emptyStyle = { version: 8, name: "Empty", metadata: { diff --git a/app/charts/map/helpers.ts b/app/charts/map/helpers.ts index 24b155188..34e5038eb 100644 --- a/app/charts/map/helpers.ts +++ b/app/charts/map/helpers.ts @@ -44,7 +44,7 @@ export const BASE_VIEW_STATE: MinMaxZoomViewState = { * @param chartDimensions Chart's dimensions needed to correctly initialize view state * in locked mode. */ -export const getViewStateFromBounds = ({ +const getViewStateFromBounds = ({ width, height, bbox, diff --git a/app/charts/map/style-helpers.ts b/app/charts/map/style-helpers.ts index 0dcf52f32..082c8bf6c 100644 --- a/app/charts/map/style-helpers.ts +++ b/app/charts/map/style-helpers.ts @@ -5,7 +5,7 @@ type AnyLayer = MapboxStyle["layers"][number]; // @TODO Find a way to make those guards generic type HasUrl = T extends { url?: string | undefined } ? T : never; -export function hasUrl(obj: AnySourceData): obj is HasUrl { +function hasUrl(obj: AnySourceData): obj is HasUrl { return Object.prototype.hasOwnProperty.call(obj, "url"); } @@ -14,7 +14,7 @@ export function hasLayout(obj: AnyLayer): obj is HasLayout { return Object.prototype.hasOwnProperty.call(obj, "layout"); } -export const replaceStringTokens = ( +const replaceStringTokens = ( s: string | undefined, tokens: Record ) => { diff --git a/app/charts/pie/chart-pie.tsx b/app/charts/pie/chart-pie.tsx index 86173c773..a5139abd3 100644 --- a/app/charts/pie/chart-pie.tsx +++ b/app/charts/pie/chart-pie.tsx @@ -20,7 +20,7 @@ export const ChartPieVisualization = (props: VisualizationProps) => { return ; }; -export const ChartPie = memo((props: ChartProps) => { +const ChartPie = memo((props: ChartProps) => { const { chartConfig, observations, dimensions } = props; const { fields, interactiveFiltersConfig } = chartConfig; const somePositive = observations.some( diff --git a/app/charts/scatterplot/chart-scatterplot.tsx b/app/charts/scatterplot/chart-scatterplot.tsx index 5882d3b7c..d5d8df850 100644 --- a/app/charts/scatterplot/chart-scatterplot.tsx +++ b/app/charts/scatterplot/chart-scatterplot.tsx @@ -30,7 +30,7 @@ export const ChartScatterplotVisualization = ( return ; }; -export const ChartScatterplot = memo((props: ChartProps) => { +const ChartScatterplot = memo((props: ChartProps) => { const { chartConfig, dimensions } = props; const { fields, interactiveFiltersConfig } = chartConfig; const filters = useChartConfigFilters(chartConfig); diff --git a/app/charts/shared/abbreviations.ts b/app/charts/shared/abbreviations.ts index 0c3fc118b..6d72aebe4 100644 --- a/app/charts/shared/abbreviations.ts +++ b/app/charts/shared/abbreviations.ts @@ -2,61 +2,6 @@ import { useCallback, useMemo } from "react"; import { DimensionValue, Observation, ObservationValue } from "@/domain/data"; -export const getMaybeAbbreviations = ({ - useAbbreviations, - dimensionIri, - dimensionValues, -}: { - useAbbreviations: boolean | undefined; - dimensionIri: string | undefined; - dimensionValues: DimensionValue[] | undefined; -}) => { - const values = dimensionValues ?? []; - - const valueLookup = new Map, DimensionValue>(); - const labelLookup = new Map(); - - for (const d of values) { - valueLookup.set(d.value, d); - labelLookup.set(d.label, d); - } - - const abbreviationOrLabelLookup = new Map( - Array.from(labelLookup, ([k, v]) => [ - useAbbreviations ? v.alternateName ?? k : k, - v, - ]) - ); - - const getAbbreviationOrLabelByValue = (d: Observation) => { - if (!dimensionIri) { - return ""; - } - - const value = d[`${dimensionIri}/__iri__`] as string | undefined; - const label = d[dimensionIri] as string | undefined; - - if (value === undefined && label === undefined) { - return ""; - } - - const lookedUpObservation = - (value ? valueLookup.get(value) : null) ?? - (label ? labelLookup.get(label) : null); - - const lookedUpLabel = lookedUpObservation?.label ?? ""; - - return useAbbreviations - ? lookedUpObservation?.alternateName ?? lookedUpLabel - : lookedUpLabel; - }; - - return { - abbreviationOrLabelLookup, - getAbbreviationOrLabelByValue, - }; -}; - export const useMaybeAbbreviations = ({ useAbbreviations, dimensionIri, diff --git a/app/charts/shared/brush/index.tsx b/app/charts/shared/brush/index.tsx index de33b22a4..35ea36ebf 100644 --- a/app/charts/shared/brush/index.tsx +++ b/app/charts/shared/brush/index.tsx @@ -30,9 +30,9 @@ import { useTransitionStore } from "@/stores/transition"; import { getTextWidth } from "@/utils/get-text-width"; // Brush constants -export const HANDLE_HEIGHT = 14; -export const BRUSH_HEIGHT = 3; -export const HEIGHT = HANDLE_HEIGHT + BRUSH_HEIGHT; +const HANDLE_HEIGHT = 14; +const BRUSH_HEIGHT = 3; +const HEIGHT = HANDLE_HEIGHT + BRUSH_HEIGHT; export const shouldShowBrush = ( interactiveFiltersConfig: diff --git a/app/charts/shared/chart-data-filters.tsx b/app/charts/shared/chart-data-filters.tsx index d343cf184..c19736a25 100644 --- a/app/charts/shared/chart-data-filters.tsx +++ b/app/charts/shared/chart-data-filters.tsx @@ -371,9 +371,7 @@ export type DataFilterGenericDimensionProps = { disabled: boolean; }; -export const DataFilterGenericDimension = ( - props: DataFilterGenericDimensionProps -) => { +const DataFilterGenericDimension = (props: DataFilterGenericDimensionProps) => { const { dimension, value, onChange, options: propOptions, disabled } = props; const { label, isKeyDimension } = dimension; const noneLabel = t({ diff --git a/app/charts/shared/chart-helpers.tsx b/app/charts/shared/chart-helpers.tsx index b876ddca7..a8f7fa3e1 100644 --- a/app/charts/shared/chart-helpers.tsx +++ b/app/charts/shared/chart-helpers.tsx @@ -126,7 +126,7 @@ export const useQueryFilters = ({ type IFKey = keyof NonNullable; -export const getChartConfigFilterComponentIris = ({ cubes }: ChartConfig) => { +const getChartConfigFilterComponentIris = ({ cubes }: ChartConfig) => { return Object.keys(getChartConfigFilters(cubes)).filter( (d) => !isJoinById(d) ); @@ -291,7 +291,7 @@ export const useDimensionWithAbbreviations = ( }; }; -export const makeUseParsedVariable = +const makeUseParsedVariable = (parser: (d: ObservationValue) => T) => (key: string) => { return useCallback((d: Observation) => parser(d[key]), [key]); @@ -326,15 +326,6 @@ export const getSegment = (d: Observation): string => segmentKey ? `${d[segmentKey]}` : "segment"; -export const useSegment = ( - segmentKey: string | undefined -): ((d: Observation) => string) => { - return useCallback( - (d: Observation) => getSegment(segmentKey)(d), - [segmentKey] - ); -}; - // Stacking helpers. // Modified from d3 source code to treat 0s as positive values and stack them correctly // in area charts. diff --git a/app/charts/shared/chart-loading-state.tsx b/app/charts/shared/chart-loading-state.tsx index 94d70f329..c90a97383 100644 --- a/app/charts/shared/chart-loading-state.tsx +++ b/app/charts/shared/chart-loading-state.tsx @@ -3,7 +3,7 @@ import { useSyncExternalStore } from "use-sync-external-store/shim"; import { Observable } from "@/utils/observables"; -export class LoadingState extends Observable { +class LoadingState extends Observable { public loading: boolean = false; private map: Record = {}; diff --git a/app/charts/shared/interaction/hover-dot.tsx b/app/charts/shared/interaction/hover-dot.tsx deleted file mode 100644 index a72c26690..000000000 --- a/app/charts/shared/interaction/hover-dot.tsx +++ /dev/null @@ -1,47 +0,0 @@ -import { Box } from "@mui/material"; -import { makeStyles } from "@mui/styles"; - -import { LinesState } from "@/charts/line/lines-state"; -import { useChartState } from "@/charts/shared/chart-state"; -import { useInteraction } from "@/charts/shared/use-interaction"; -import { Observation } from "@/domain/data"; - -const useStyles = makeStyles(() => ({ - root: { - width: 8, - height: 8, - borderRadius: "50%", - position: "absolute", - transform: "translate3d(-50%, -50%, 0)", - pointerEvents: "none", - }, -})); - -export const HoverDot = () => { - const [state] = useInteraction(); - - const { visible, d } = state.interaction; - - return <>{visible && d && }; -}; - -const DotInner = ({ d }: { d: Observation }) => { - const { getAnnotationInfo, bounds } = useChartState() as LinesState; - - const { xAnchor, yAnchor, datum } = getAnnotationInfo(d); - const classes = useStyles(); - return ( - <> - {yAnchor && ( - - )} - - ); -}; diff --git a/app/charts/shared/interaction/tooltip-box.tsx b/app/charts/shared/interaction/tooltip-box.tsx index 3e968ca36..1edc06c82 100644 --- a/app/charts/shared/interaction/tooltip-box.tsx +++ b/app/charts/shared/interaction/tooltip-box.tsx @@ -11,8 +11,8 @@ import ReactDOM from "react-dom"; import { Margins } from "@/charts/shared/use-width"; -export const TRIANGLE_SIZE = 8; -export const TOOLTIP_OFFSET = 4; +const TRIANGLE_SIZE = 8; +const TOOLTIP_OFFSET = 4; export type Xplacement = "left" | "center" | "right"; export type Yplacement = "top" | "middle" | "bottom"; @@ -197,8 +197,8 @@ const mxYOffset = (yAnchor: number, p: TooltipPlacement) => p.y === "top" ? yAnchor - TRIANGLE_SIZE - TOOLTIP_OFFSET : p.y === "bottom" - ? yAnchor + TRIANGLE_SIZE + TOOLTIP_OFFSET - : yAnchor; + ? yAnchor + TRIANGLE_SIZE + TOOLTIP_OFFSET + : yAnchor; // tooltip translation const mkTranslation = (p: TooltipPlacement) => @@ -213,8 +213,8 @@ const mkXTranslation = (xP: Xplacement, yP: Yplacement): Xtranslation => { return xP === "left" ? `calc(-100% - ${TRIANGLE_SIZE + TOOLTIP_OFFSET}px)` : xP === "center" - ? "-50%" - : `${TRIANGLE_SIZE + TOOLTIP_OFFSET}px`; + ? "-50%" + : `${TRIANGLE_SIZE + TOOLTIP_OFFSET}px`; } }; const mkYTranslation = (yP: Yplacement): YTranslation => diff --git a/app/charts/shared/observation-labels.ts b/app/charts/shared/observation-labels.ts index 84be8e52d..d11d6bc75 100644 --- a/app/charts/shared/observation-labels.ts +++ b/app/charts/shared/observation-labels.ts @@ -2,37 +2,6 @@ import { useCallback, useMemo } from "react"; import { Observation } from "@/domain/data"; -export const getObservationLabels = ( - data: Observation[], - getLabel: (d: Observation) => string, - componentIri?: string -) => { - const getIri = (d: Observation) => { - const iri = d[`${componentIri}/__iri__`] as string | undefined; - return iri; - }; - - const lookup = new Map(); - data.forEach((d) => { - const iri = getIri(d); - const label = getLabel(d); - lookup.set(iri ?? label, label); - }); - - const getValue = (d: Observation) => { - return getIri(d) ?? getLabel(d); - }; - - const getLookupLabel = (d: string) => { - return lookup.get(d) ?? d; - }; - - return { - getValue, - getLabel: getLookupLabel, - }; -}; - /** Use this hook to be able to retrieve observation values and labels, * where the value is the iri if present, otherwise the label. * diff --git a/app/charts/shared/ticks.tsx b/app/charts/shared/ticks.tsx index 1f6a226db..d3fab9dc0 100644 --- a/app/charts/shared/ticks.tsx +++ b/app/charts/shared/ticks.tsx @@ -1,4 +1,4 @@ -export const TICK_MIN_HEIGHT = 50; +const TICK_MIN_HEIGHT = 50; export const getTickNumber = (height: number) => { return Math.min(height / TICK_MIN_HEIGHT, 4); diff --git a/app/charts/table/cell-mobile.tsx b/app/charts/table/cell-mobile.tsx index 75306a2d6..ddfb3d9d5 100644 --- a/app/charts/table/cell-mobile.tsx +++ b/app/charts/table/cell-mobile.tsx @@ -1,97 +1,14 @@ -import { Box, Theme, Typography } from "@mui/material"; -import { makeStyles } from "@mui/styles"; +import { Box } from "@mui/material"; import { hcl } from "d3-color"; -import { Cell, Row } from "react-table"; +import { Cell } from "react-table"; import { useChartState } from "@/charts/shared/chart-state"; import { getBarLeftOffset, getBarWidth } from "@/charts/table/cell-desktop"; -import { ColumnMeta, TableChartState } from "@/charts/table/table-state"; +import { ColumnMeta } from "@/charts/table/table-state"; import { Tag } from "@/charts/table/tag"; import Flex from "@/components/flex"; import { Observation } from "@/domain/data"; import { useFormatNumber } from "@/formatters"; -import { Icon } from "@/icons"; - -const useStyles = makeStyles((theme: Theme) => ({ - root: { - color: theme.palette.grey[800], - fontSize: "0.75rem", - width: "100%", - justifyContent: "space-between", - alignItems: "center", - margin: `0 ${theme.spacing(2)}`, - "&:first-of-type": { - paddingTop: 2, - }, - "&:last-of-type": { - borderBottom: "1px solid", - borderBottomColor: theme.palette.grey[400], - paddingBottom: theme.spacing(3), - }, - }, -})); - -export const RowMobile = ({ - row, - prepareRow, -}: { - row: Row; - prepareRow: (row: Row) => void; -}) => { - const { tableColumnsMeta } = useChartState() as TableChartState; - const classes = useStyles(); - prepareRow(row); - - const headingLevel = row.depth === 0 ? "h2" : row.depth === 1 ? "h3" : "p"; - return ( - - {row.subRows.length === 0 ? ( - row.cells.map((cell, i) => { - return ( - - - {cell.column.Header} - - - - - - ); - }) - ) : ( - // Group - - - - {`${row.groupByVal}`} - - - )} - - ); -}; export const DDContent = ({ cell, diff --git a/app/charts/table/example-props.ts b/app/charts/table/example-props.ts deleted file mode 100644 index 5955c2bad..000000000 --- a/app/charts/table/example-props.ts +++ /dev/null @@ -1,53 +0,0 @@ -export const ex1 = { - fields: { - settings: { - showSearch: true, - showAllRows: true, - }, - sorting: [ - { componentIri: "one", sortingOrder: "ascending" }, - { componentIri: "two", sortingOrder: "descending" }, - ], - columns: [ - { - componentIri: "one", - isGroup: true, - isHidden: false, - columnStyle: "text", // category, heatmap, bar - textStyle: "regular", // bold - textColor: "#333", // optional - columnColor: "#fff", // optional - }, - { - componentIri: "two", - columnStyle: "text", // category, heatmap, bar - textStyle: "regular", // bold - textColor: "#333", // optional - columnColor: "#fff", // optional - }, - { - componentIri: "three", - columnStyle: "heatmap", // category, heatmap, bar - textStyle: "regular", // bold - palette: "magma", // color ramp - }, - { - componentIri: "four", - columnStyle: "bar", // category, heatmap, bar - textStyle: "regular", // bold - barColorPositive: "red", // color value - barColorNegative: "blue", // color value - barColorBackground: "#999", // optional? - barShowBackground: true, // optional? - }, - { - componentIri: "five", - columnStyle: "category", // category, heatmap, bar - textStyle: "regular", // bold - palette: "red", // categorical palette - colorMapping: {}, // see other charts :) - }, - ], - }, - filters: {}, -}; diff --git a/app/components/chart-panel-layout-tall.tsx b/app/components/chart-panel-layout-tall.tsx index bb885a9ab..d20dea7fe 100644 --- a/app/components/chart-panel-layout-tall.tsx +++ b/app/components/chart-panel-layout-tall.tsx @@ -27,9 +27,7 @@ type ChartPanelLayoutTallRowProps = { row: ChartPanelLayoutTallRow; }; -export const ChartPanelLayoutTallRow = ( - props: ChartPanelLayoutTallRowProps -) => { +const ChartPanelLayoutTallRow = (props: ChartPanelLayoutTallRowProps) => { const { row } = props; const theme = useTheme(); const isMobile = useMediaQuery(theme.breakpoints.down("md")); diff --git a/app/components/chart-preview.tsx b/app/components/chart-preview.tsx index 00466a79c..6f3a66a09 100644 --- a/app/components/chart-preview.tsx +++ b/app/components/chart-preview.tsx @@ -6,13 +6,13 @@ import { useDraggable, useDroppable, } from "@dnd-kit/core"; -import { t, Trans } from "@lingui/macro"; +import { Trans, t } from "@lingui/macro"; import { Box, IconButton, useEventCallback } from "@mui/material"; import { makeStyles } from "@mui/styles"; import Head from "next/head"; import React, { - forwardRef, ReactNode, + forwardRef, useCallback, useMemo, useState, @@ -46,10 +46,10 @@ import { BANNER_MARGIN_TOP } from "@/components/presence"; import { ChartConfig, DataSource, + Layout, getChartConfig, hasChartConfigs, isConfiguring, - Layout, useConfiguratorState, } from "@/configurator"; import { Description, Title } from "@/configurator/components/annotators"; @@ -441,7 +441,7 @@ type ChartPreviewInnerProps = ChartPreviewProps & { children?: React.ReactNode; }; -export const ChartPreviewInner = (props: ChartPreviewInnerProps) => { +const ChartPreviewInner = (props: ChartPreviewInnerProps) => { const { dataSource, chartKey, actionElementSlot } = props; const [state, dispatch] = useConfiguratorState(); const configuring = isConfiguring(state); diff --git a/app/components/chart-selection-tabs.tsx b/app/components/chart-selection-tabs.tsx index 69c2d232c..256dd4299 100644 --- a/app/components/chart-selection-tabs.tsx +++ b/app/components/chart-selection-tabs.tsx @@ -77,7 +77,7 @@ const TabsStateContext = createContext< [TabsState, React.Dispatch] | undefined >(undefined); -export const useTabsState = () => { +const useTabsState = () => { const ctx = useContext(TabsStateContext); if (ctx === undefined) { @@ -414,7 +414,7 @@ const NextStepButton = (props: React.PropsWithChildren<{}>) => { ); }; -export const LayoutChartButton = () => { +const LayoutChartButton = () => { return ( Proceed to layout options diff --git a/app/components/copy-to-clipboard-text-input.tsx b/app/components/copy-to-clipboard-text-input.tsx index 9598bb9f9..b856163d8 100644 --- a/app/components/copy-to-clipboard-text-input.tsx +++ b/app/components/copy-to-clipboard-text-input.tsx @@ -44,7 +44,7 @@ const useActionTooltipStyles = makeStyles((theme: Theme) => ({ }, })); -export const useCopyToClipboardTextInputStyles = makeStyles((theme: Theme) => ({ +const useCopyToClipboardTextInputStyles = makeStyles((theme: Theme) => ({ input: { color: theme.palette.grey[700], padding: `${theme.spacing(0)} ${theme.spacing(2)}`, @@ -94,7 +94,7 @@ export const useCopyToClipboardTextInputStyles = makeStyles((theme: Theme) => ({ }, })); -export const ActionTooltip = ({ children }: { children: ReactNode }) => { +const ActionTooltip = ({ children }: { children: ReactNode }) => { const classes = useActionTooltipStyles(); return
{children}
; }; diff --git a/app/components/data-download.tsx b/app/components/data-download.tsx index 20e5805bc..72b7f4f30 100644 --- a/app/components/data-download.tsx +++ b/app/components/data-download.tsx @@ -62,7 +62,7 @@ const DataDownloadStateContext = createContext< [DataDownloadState, Dispatch] | undefined >(undefined); -export const useDataDownloadState = () => { +const useDataDownloadState = () => { const ctx = useContext(DataDownloadStateContext); if (ctx === undefined) { @@ -74,11 +74,7 @@ export const useDataDownloadState = () => { return ctx; }; -export const DataDownloadStateProvider = ({ - children, -}: { - children: ReactNode; -}) => { +const DataDownloadStateProvider = ({ children }: { children: ReactNode }) => { const [state, dispatch] = useState({ isDownloading: false, }); diff --git a/app/components/debug-panel/index.tsx b/app/components/debug-panel/index.tsx index f278ed692..cc5b11041 100644 --- a/app/components/debug-panel/index.tsx +++ b/app/components/debug-panel/index.tsx @@ -8,7 +8,7 @@ import { DebugPanelProps } from "./DebugPanel"; const LazyDebugPanel = dynamic(() => import("./DebugPanel"), { ssr: false }); -export const shouldShowDebugPanel = () => { +const shouldShowDebugPanel = () => { return flag("debug") ?? process.env.NODE_ENV === "development"; }; diff --git a/app/components/header.tsx b/app/components/header.tsx index af2d9c297..7abbf2807 100644 --- a/app/components/header.tsx +++ b/app/components/header.tsx @@ -21,7 +21,7 @@ const useHeaderBorderStyles = makeStyles((theme: Theme) => ({ }, })); -export const HeaderBorder = () => { +const HeaderBorder = () => { const classes = useHeaderBorderStyles(); return ; }; diff --git a/app/components/menu-action-item.tsx b/app/components/menu-action-item.tsx index d0db8a451..481655a32 100644 --- a/app/components/menu-action-item.tsx +++ b/app/components/menu-action-item.tsx @@ -5,7 +5,7 @@ import ConfirmationDialog from "@/components/confirmation-dialog"; import useDisclosure from "@/components/use-disclosure"; import { Icon, IconName } from "@/icons"; -export const StyledMenuItem = styled(MenuItem)(({ theme, color }) => ({ +const StyledMenuItem = styled(MenuItem)(({ theme, color }) => ({ display: "flex", alignItems: "center", gap: theme.spacing(2), diff --git a/app/components/publish-actions.tsx b/app/components/publish-actions.tsx index c471627d8..3dc07f9a6 100644 --- a/app/components/publish-actions.tsx +++ b/app/components/publish-actions.tsx @@ -63,7 +63,7 @@ const TriggeredPopover = (props: TriggeredPopoverProps) => { ); }; -export const Embed = ({ configKey, locale }: PublishActionProps) => { +const Embed = ({ configKey, locale }: PublishActionProps) => { const [embedIframeUrl, setEmbedIframeUrl] = useState(""); const [embedAEMUrl, setEmbedAEMUrl] = useState(""); const [embedOptions, setEmbedOptions] = useEmbedOptions(); @@ -220,7 +220,7 @@ export const Embed = ({ configKey, locale }: PublishActionProps) => { ); }; -export const Share = ({ configKey, locale }: PublishActionProps) => { +const Share = ({ configKey, locale }: PublishActionProps) => { const [shareUrl, setShareUrl] = useState(""); const i18n = useI18n(); diff --git a/app/components/react-grid.tsx b/app/components/react-grid.tsx index f910b5932..0fd33015a 100644 --- a/app/components/react-grid.tsx +++ b/app/components/react-grid.tsx @@ -30,7 +30,7 @@ const INITIAL_H = 7; export const MIN_H = 5; /** In grid unit */ -export const MAX_W = 4; +const MAX_W = 4; export const COLS = { lg: 4, md: 2, sm: 1, xs: 1, xxs: 1 }; const ROW_HEIGHT = 100; diff --git a/app/config-types.ts b/app/config-types.ts index 75cbf0905..601549598 100644 --- a/app/config-types.ts +++ b/app/config-types.ts @@ -18,26 +18,12 @@ const DimensionType = t.union([ t.literal("StandardErrorDimension"), ]); export type DimensionType = t.TypeOf; -export const dimensionTypes: DimensionType[] = [ - "NominalDimension", - "OrdinalDimension", - "TemporalDimension", - "TemporalEntityDimension", - "TemporalOrdinalDimension", - "GeoCoordinatesDimension", - "GeoShapesDimension", - "StandardErrorDimension", -]; const MeasureType = t.union([ t.literal("NumericalMeasure"), t.literal("OrdinalMeasure"), ]); export type MeasureType = t.TypeOf; -export const measureTypes: MeasureType[] = [ - "NumericalMeasure", - "OrdinalMeasure", -]; const ComponentType = t.union([DimensionType, MeasureType]); export type ComponentType = t.TypeOf; @@ -80,7 +66,7 @@ const FilterValueSingle = t.intersection([ ]); export type FilterValueSingle = t.TypeOf; -export const isFilterValueSingle = ( +const isFilterValueSingle = ( filterValue: FilterValue ): filterValue is FilterValueSingle => { return filterValue.type === "single"; @@ -778,20 +764,6 @@ export type ChartType = ChartConfig["chartType"]; export type RegularChartType = RegularChartConfig["chartType"]; export type ComboChartType = ComboChartConfig["chartType"]; -export const isRegularChartConfig = ( - chartConfig: ChartConfig -): chartConfig is RegularChartConfig => { - return ( - isAreaConfig(chartConfig) || - isColumnConfig(chartConfig) || - isLineConfig(chartConfig) || - isMapConfig(chartConfig) || - isPieConfig(chartConfig) || - isScatterPlotConfig(chartConfig) || - isTableConfig(chartConfig) - ); -}; - export const isComboChartConfig = ( chartConfig: ChartConfig ): chartConfig is ComboChartConfig => { @@ -914,19 +886,6 @@ export const isColorFieldInConfig = ( return isMapConfig(chartConfig); }; -export const isSegmentColorMappingInConfig = ( - chartConfig: ChartConfig -): chartConfig is - | AreaConfig - | ColumnConfig - | LineConfig - | PieConfig - | ScatterPlotConfig => { - return ["area", "column", "line", "pie", "scatterplot"].includes( - chartConfig.chartType - ); -}; - // Chart Config Adjusters export type FieldAdjuster< NewChartConfigType extends ChartConfig, @@ -1223,14 +1182,6 @@ const Config = t.intersection([ export type Config = t.TypeOf; -export const isValidConfig = (config: unknown): config is Config => { - return Config.is(config); -}; - -export const decodeConfig = (config: unknown) => { - return Config.decode(config); -}; - const ConfiguratorStateInitial = t.type({ state: t.literal("INITIAL"), version: t.string, diff --git a/app/configurator/components/add-dataset-dialog.tsx b/app/configurator/components/add-dataset-dialog.tsx index 22def940f..2f83fd598 100644 --- a/app/configurator/components/add-dataset-dialog.tsx +++ b/app/configurator/components/add-dataset-dialog.tsx @@ -192,7 +192,7 @@ const useCautionAlert = () => { }; }; -export const CautionAlert = ({ +const CautionAlert = ({ onConfirm, ...props }: { onConfirm: () => void } & AlertProps) => { @@ -297,7 +297,7 @@ export type JoinBy = ReturnType; const columnId = (col: { iri: string; cubeIri: string }) => `${col.cubeIri}/${col.iri}`; -export const PreviewDataTable = ({ +const PreviewDataTable = ({ existingCubes, otherCube, dataSource, diff --git a/app/configurator/components/add-new-dataset-panel.tsx b/app/configurator/components/add-new-dataset-panel.tsx index 7bfdedbf9..5bb5922cc 100644 --- a/app/configurator/components/add-new-dataset-panel.tsx +++ b/app/configurator/components/add-new-dataset-panel.tsx @@ -35,7 +35,7 @@ export const useSearchDatasetPanelStore = createStore<{ /** * Inits a new chart state based on a new dataset and adds it to the configurator state */ -export const useAddChartConfigBasedOnNewDataset = () => { +const useAddChartConfigBasedOnNewDataset = () => { const [, dispatch] = useConfiguratorState(); const locale = useLocale(); const client = useClient(); diff --git a/app/configurator/components/breadcrumbs.tsx b/app/configurator/components/breadcrumbs.tsx deleted file mode 100644 index bface17ae..000000000 --- a/app/configurator/components/breadcrumbs.tsx +++ /dev/null @@ -1,45 +0,0 @@ -// @ts-nocheck - -import { Box, BoxProps } from "@mui/material"; -import React from "react"; - -const Breadcrumbs = ({ - breadcrumbs, - Breadcrumb, - onClickBreadcrumb, - ...boxProps -}: { - breadcrumbs: any; - Breadcrumb: React.ElementType<{ breadcrumb: any; onClick: () => void }>; - onClickBreadcrumb?: (i: number) => void; -} & BoxProps) => { - return ( - - {breadcrumbs - ? breadcrumbs.map((b: any, i: number) => { - const handleBreadcrumbClick = () => { - if (onClickBreadcrumb) { - onClickBreadcrumb(i); - } - }; - return ( - <> - - {i < breadcrumbs.length - 1 ? ( - - {">"} - - ) : null} - - ); - }) - : null} - - ); -}; - -export default Breadcrumbs; diff --git a/app/configurator/components/chart-controls/control-tab.tsx b/app/configurator/components/chart-controls/control-tab.tsx index 0c383b798..4abae68cb 100644 --- a/app/configurator/components/chart-controls/control-tab.tsx +++ b/app/configurator/components/chart-controls/control-tab.tsx @@ -317,7 +317,7 @@ const useStyles = makeStyles((theme: Theme) => ({ })); // Generic component -export const ControlTabButton = ({ +const ControlTabButton = ({ disabled, checked, value, @@ -348,7 +348,7 @@ export const ControlTabButton = ({ ); }; -export const ControlTabButtonInner = ({ +const ControlTabButtonInner = ({ iconName, upperLabel, mainLabel, diff --git a/app/configurator/components/ui-helpers.ts b/app/configurator/components/ui-helpers.ts index 1eb85e4c2..7e9414caf 100644 --- a/app/configurator/components/ui-helpers.ts +++ b/app/configurator/components/ui-helpers.ts @@ -246,7 +246,7 @@ export const getIconName = (name: string): IconName => { } }; -export const randomComparator = () => (Math.random() > 0.5 ? 1 : -1); +const randomComparator = () => (Math.random() > 0.5 ? 1 : -1); export const mapValueIrisToColor = ({ palette, diff --git a/app/configurator/components/use-hierarchy-parents.tsx b/app/configurator/components/use-hierarchy-parents.tsx index 0e313c5a8..3d1ca7193 100644 --- a/app/configurator/components/use-hierarchy-parents.tsx +++ b/app/configurator/components/use-hierarchy-parents.tsx @@ -1,12 +1,11 @@ import { groups } from "d3-array"; -import { useMemo } from "react"; -import { Dimension, HierarchyValue } from "@/domain/data"; +import { HierarchyValue } from "@/domain/data"; import { bfs } from "@/utils/bfs"; export type HierarchyParents = [ HierarchyValue[], - { node: HierarchyValue; parents: HierarchyValue[] }[] + { node: HierarchyValue; parents: HierarchyValue[] }[], ][]; export const groupByParents = (hierarchy: HierarchyValue[]) => { @@ -19,28 +18,6 @@ export const groupByParents = (hierarchy: HierarchyValue[]) => { return groups(allHierarchyValues, (v) => v.parents); }; -const useHierarchyParents = ({ - dimension, -}: { - dimension: Dimension; -}): HierarchyParents | undefined => { - return useMemo(() => { - if (!dimension.hierarchy) { - return; - } - - const values = dimension.values; - const valueSet = new Set(values.map((v) => v.value)); - const valueGroups = groupByParents(dimension.hierarchy); - - return valueGroups - .map(([parents, nodes]) => { - return [parents, nodes.filter((n) => valueSet.has(n.node.value))]; - }) - .filter((x) => x[1].length > 0) as HierarchyParents; - }, [dimension]); -}; - /** * Can be used for debugging, pass a hierarchy, and copy the output * to graphviz. @@ -64,5 +41,3 @@ export const hierarchyToGraphviz = (hierarchy: HierarchyValue[]) => { } `; }; - -export default useHierarchyParents; diff --git a/app/configurator/configurator-state/context.tsx b/app/configurator/configurator-state/context.tsx index caed0023c..da1cebcca 100644 --- a/app/configurator/configurator-state/context.tsx +++ b/app/configurator/configurator-state/context.tsx @@ -31,7 +31,7 @@ import { import { createChartId } from "@/utils/create-chart-id"; import { getRouterChartId } from "@/utils/router/helpers"; -export const ConfiguratorStateContext = createContext< +const ConfiguratorStateContext = createContext< [ConfiguratorState, Dispatch] | undefined >(undefined); @@ -235,7 +235,7 @@ const allSequential = async ( return res; }; -export const ConfiguratorStateProviderInternal = ( +const ConfiguratorStateProviderInternal = ( props: ConfiguratorStateProviderProps ) => { const { diff --git a/app/configurator/configurator-state/index.tsx b/app/configurator/configurator-state/index.tsx index 2e5713be0..79bba1441 100644 --- a/app/configurator/configurator-state/index.tsx +++ b/app/configurator/configurator-state/index.tsx @@ -69,9 +69,7 @@ export const getPreviousState = ( }; // FIXME: should by handled better, as color is a subfield and not actual field. // Side effects in ui encodings? -export const getNonGenericFieldValues = ( - chartConfig: ChartConfig -): string[] => { +const getNonGenericFieldValues = (chartConfig: ChartConfig): string[] => { const iris: string[] = []; if (isColorFieldInConfig(chartConfig)) { diff --git a/app/configurator/configurator-state/mocks.ts b/app/configurator/configurator-state/mocks.ts index 96f75fa2f..4f7c44536 100644 --- a/app/configurator/configurator-state/mocks.ts +++ b/app/configurator/configurator-state/mocks.ts @@ -11,57 +11,6 @@ import { CONFIGURATOR_STATE_VERSION, } from "@/utils/chart-config/versioning"; -export const chartConfigMock = { - columnCovid19: { - version: "1.2.1", - chartType: "column", - filters: { - "https://environment.ld.admin.ch/foen/COVID19VaccPersons_v2/georegion": { - type: "single", - value: "https://ld.admin.ch/canton/1", - }, - "https://environment.ld.admin.ch/foen/COVID19VaccPersons_v2/type": { - type: "single", - value: - "https://environment.ld.admin.ch/foen/COVID19VaccPersons_v2/type/COVID19AtLeastOneDosePersons", - }, - }, - interactiveFiltersConfig: { - legend: { - active: false, - componentIri: "", - }, - timeRange: { - active: false, - componentIri: "", - presets: { - type: "range", - from: "", - to: "", - }, - }, - dataFilters: { - active: false, - componentIris: [], - }, - }, - fields: { - x: { - componentIri: - "https://environment.ld.admin.ch/foen/COVID19VaccPersons_v2/date", - sorting: { - sortingType: "byDimensionLabel", - sortingOrder: "asc", - }, - }, - y: { - componentIri: - "https://environment.ld.admin.ch/foen/COVID19VaccPersons_v2/entries", - }, - }, - }, -}; - export const configStateMock = { map: { state: "CONFIGURING_CHART", diff --git a/app/configurator/configurator-state/reducer.tsx b/app/configurator/configurator-state/reducer.tsx index 24f3331ce..8032aa6dd 100644 --- a/app/configurator/configurator-state/reducer.tsx +++ b/app/configurator/configurator-state/reducer.tsx @@ -556,7 +556,7 @@ export const setRangeFilter = ( }; } }; -export const reducer_: Reducer = ( +const reducer_: Reducer = ( draft, action ) => { diff --git a/app/configurator/interactive-filters/interactive-filters-config-state.tsx b/app/configurator/interactive-filters/interactive-filters-config-state.tsx index 65e5e708f..dc57d1a0f 100644 --- a/app/configurator/interactive-filters/interactive-filters-config-state.tsx +++ b/app/configurator/interactive-filters/interactive-filters-config-state.tsx @@ -1,13 +1,12 @@ import produce from "immer"; import get from "lodash/get"; -import { ChangeEvent, useCallback } from "react"; +import { ChangeEvent } from "react"; import { getChartConfig, InteractiveFiltersConfig } from "@/config-types"; import { isConfiguring, useConfiguratorState, } from "@/configurator/configurator-state"; -import { Dimension } from "@/domain/data"; import useEvent from "@/utils/use-event"; export const useInteractiveFiltersToggle = (target: "legend") => { @@ -42,123 +41,6 @@ export const useInteractiveFiltersToggle = (target: "legend") => { }; }; -export const useInteractiveTimeRangeFiltersToggle = ({ - timeExtent, -}: { - timeExtent: [string, string]; -}) => { - const [state, dispatch] = useConfiguratorState(isConfiguring); - const chartConfig = getChartConfig(state); - - const onChange = useCallback<(e: ChangeEvent) => void>( - (e) => { - const active = e.currentTarget.checked; - - if (timeExtent) { - if (chartConfig.interactiveFiltersConfig?.timeRange) { - const { from, to } = - chartConfig.interactiveFiltersConfig.timeRange.presets; - chartConfig.interactiveFiltersConfig.timeRange.active = active; - - // set min and max date as default presets for time brush - if (active && !from && !to) { - chartConfig.interactiveFiltersConfig.timeRange.presets.from = - timeExtent[0]; - chartConfig.interactiveFiltersConfig.timeRange.presets.to = - timeExtent[1]; - } - } - - dispatch({ - type: "INTERACTIVE_FILTER_CHANGED", - value: chartConfig.interactiveFiltersConfig, - }); - } - }, - [chartConfig, timeExtent, dispatch] - ); - - const stateValue = get( - chartConfig, - `interactiveFiltersConfig.timeRange.active` - ); - const checked = stateValue ? stateValue : false; - - return { - name: "timeRange", - checked, - onChange, - }; -}; - -export const updateInteractiveTimeRangeFilter = produce( - ( - config: InteractiveFiltersConfig, - { timeExtent: [from, to] }: { timeExtent: [string, string] } - ): InteractiveFiltersConfig => { - if (!config?.timeRange) { - return config; - } - - config.timeRange.presets.from = from; - config.timeRange.presets.to = to; - - return config; - } -); - -/** - * Toggles all data filters - */ -export const useInteractiveDataFiltersToggle = ({ - dimensions, -}: { - dimensions: Dimension[]; -}) => { - const [state, dispatch] = useConfiguratorState(isConfiguring); - const chartConfig = getChartConfig(state); - - const onChange = useCallback<(e: ChangeEvent) => void>( - (e) => { - const active = e.currentTarget.checked; - - const newConfig = produce( - chartConfig.interactiveFiltersConfig, - (draft) => { - if (draft?.dataFilters) { - draft.dataFilters.active = active; - - // Default: toggle dimensions if none is selected, but they are set to true - if (active && draft.dataFilters.componentIris.length === 0) { - draft.dataFilters.componentIris = dimensions.map((d) => d.iri); - } - } - - return draft; - } - ); - - dispatch({ - type: "INTERACTIVE_FILTER_CHANGED", - value: newConfig, - }); - }, - [chartConfig, dimensions, dispatch] - ); - - const stateValue = get( - state, - "chartConfig.interactiveFiltersConfig.dataFilters.active" - ); - const checked = stateValue ? stateValue : false; - - return { - name: "dataFilters", - checked, - onChange, - }; -}; - /** * Toggles a single data filter */ diff --git a/app/configurator/interactive-filters/interactive-filters-configurator.tsx b/app/configurator/interactive-filters/interactive-filters-configurator.tsx index 03790dc7d..2003ba3dd 100644 --- a/app/configurator/interactive-filters/interactive-filters-configurator.tsx +++ b/app/configurator/interactive-filters/interactive-filters-configurator.tsx @@ -21,12 +21,6 @@ import { useLocale } from "@/locales/use-locale"; export type InteractiveFilterType = "legend" | "timeRange" | "dataFilters"; -export const isInteractiveFilterType = ( - field: string | undefined -): field is InteractiveFilterType => { - return ["legend", "timeRange", "dataFilters"].includes(field ?? ""); -}; - export const InteractiveFiltersConfigurator = ({ state, }: { diff --git a/app/domain/data.ts b/app/domain/data.ts index d10dc4750..c230b1260 100644 --- a/app/domain/data.ts +++ b/app/domain/data.ts @@ -418,7 +418,7 @@ export type SearchCube = { }; const xmlSchema = "http://www.w3.org/2001/XMLSchema#"; -export const parseRDFLiteral = (value: Literal): T => { +const parseRDFLiteral = (value: Literal): T => { const v = value.value; const dt = value.datatype.value.replace(xmlSchema, ""); switch (dt) { @@ -507,7 +507,7 @@ export const isOrdinalMeasure = ( return dimension?.__typename === "OrdinalMeasure"; }; -export const isCategoricalDimension = ( +const isCategoricalDimension = ( d: Component ): d is NominalDimension | OrdinalDimension | TemporalOrdinalDimension => { return ( @@ -536,7 +536,7 @@ export const getDimensionsByDimensionType = ({ dimensionTypes.includes(component.__typename) ); -export const isNominalDimension = ( +const isNominalDimension = ( dimension?: Component | null ): dimension is NominalDimension => { return dimension?.__typename === "NominalDimension"; @@ -598,7 +598,7 @@ export const isTemporalDimensionWithTimeUnit = ( return !!dimension && "timeUnit" in dimension; }; -export const isStandardErrorResolvedDimension = (dim: ResolvedDimension) => { +const isStandardErrorResolvedDimension = (dim: ResolvedDimension) => { return dim.data?.related.some((x) => x.type === "StandardError"); }; diff --git a/app/domain/datasource/localStorage.ts b/app/domain/datasource/localStorage.ts index f21a6e9aa..8df81780f 100644 --- a/app/domain/datasource/localStorage.ts +++ b/app/domain/datasource/localStorage.ts @@ -2,7 +2,7 @@ import { DataSource } from "@/config-types"; import { parseDataSource, stringifyDataSource } from "."; -export const retrieveStringifiedDataSourceFromLocalStorage = () => { +const retrieveStringifiedDataSourceFromLocalStorage = () => { return localStorage.getItem("dataSource"); }; diff --git a/app/domain/user-configs.ts b/app/domain/user-configs.ts index af08434d5..859b37515 100644 --- a/app/domain/user-configs.ts +++ b/app/domain/user-configs.ts @@ -2,10 +2,10 @@ import { useCallback } from "react"; import { ParsedConfig } from "@/db/config"; import { fetchChartConfig, fetchChartConfigs } from "@/utils/chart-config/api"; -import { useFetchData, UseFetchDataOptions } from "@/utils/use-fetch-data"; +import { UseFetchDataOptions, useFetchData } from "@/utils/use-fetch-data"; export const userConfigsKey = ["userConfigs"]; -export const userConfigKey = (t: string) => ["userConfigs", t]; +const userConfigKey = (t: string) => ["userConfigs", t]; export const useUserConfigs = (options?: UseFetchDataOptions) => useFetchData(userConfigsKey, fetchChartConfigs, options); diff --git a/app/flags/flag.tsx b/app/flags/flag.tsx index a96835b0b..9f5356f7b 100644 --- a/app/flags/flag.tsx +++ b/app/flags/flag.tsx @@ -23,12 +23,12 @@ const flag = function flag(...args: [FlagName] | [FlagName, FlagValue]) { }; /** List all flags from the store */ -export const listFlags = () => { +const listFlags = () => { return store.keys().sort(); }; /** Resets all the flags */ -export const resetFlags = () => { +const resetFlags = () => { listFlags().forEach((name) => store.remove(name as FlagName)); }; @@ -39,7 +39,7 @@ export const resetFlags = () => { * * @param {Record} flagsToEnable */ -export const enable = (flagsToEnable: FlagName[]) => { +const enable = (flagsToEnable: FlagName[]) => { const flagNameToValue = Object.entries(flagsToEnable); if (!flagNameToValue) { diff --git a/app/flags/ls-adapter.ts b/app/flags/ls-adapter.ts index a5938270f..25a087c28 100644 --- a/app/flags/ls-adapter.ts +++ b/app/flags/ls-adapter.ts @@ -1,10 +1,10 @@ import { FlagName, FlagValue } from "./types"; -export const prefix = "flag__"; +const prefix = "flag__"; type FlagNameOrString = FlagName | (string & {}); -export const getKey = (name: FlagNameOrString) => prefix + name; +const getKey = (name: FlagNameOrString) => prefix + name; const listFlagLocalStorage = () => { return Object.keys(localStorage) diff --git a/app/formatters.ts b/app/formatters.ts index e94c9207f..215e58062 100644 --- a/app/formatters.ts +++ b/app/formatters.ts @@ -79,9 +79,8 @@ export const getFormattersForLocale = memoize((locale) => { }; }); -export const useLocalFormatters = () => { +const useLocalFormatters = () => { const locale = useLocale(); - return getFormattersForLocale(locale); }; @@ -140,7 +139,7 @@ const decimalFormatter = (dim: NumericalMeasure, formatNumber: Formatter) => { }; }; -export const getDimensionFormatters = ({ +const getDimensionFormatters = ({ components, formatNumber, formatDateAuto, @@ -306,7 +305,7 @@ export const useTimeFormatUnit = () => { return formatter; }; -export const getFormatNumber = (props?: { decimals: number | "auto" }) => { +const getFormatNumber = (props?: { decimals: number | "auto" }) => { const { decimals = 2 } = props ?? {}; const { format } = getD3FormatLocale(); // Only valid for up to 6 decimals! @@ -378,13 +377,6 @@ export const useFormatShortDateAuto = () => { return formatter; }; -export const formatError = ( - error: [number, number], - formatNumber: (n: number) => string -) => { - return `[${formatNumber(error[0])}, ${formatNumber(error[1])}]`; -}; - export const formatNumberWithUnit = ( nb: number | null, formatter: (n: number) => string, diff --git a/app/gql-flamegraph/devtool.tsx b/app/gql-flamegraph/devtool.tsx index 4c281da88..e11f6a3b3 100644 --- a/app/gql-flamegraph/devtool.tsx +++ b/app/gql-flamegraph/devtool.tsx @@ -466,7 +466,7 @@ function GqlDebug({ controller }: { controller: GraphqlOperationsController }) { * Used to communicate between urql and the flamegraph * component */ -export const urqlEE = mitt<{ +const urqlEE = mitt<{ "urql-received-operation": Operation; "urql-received-result": VisualizeOperationResult; }>(); diff --git a/app/graphql/hooks.ts b/app/graphql/hooks.ts index 01a69a42a..9eea03cc1 100644 --- a/app/graphql/hooks.ts +++ b/app/graphql/hooks.ts @@ -102,7 +102,7 @@ type DataCubesMetadataData = { dataCubesMetadata: DataCubeMetadata[]; }; -export const executeDataCubesMetadataQuery = async ( +const executeDataCubesMetadataQuery = async ( client: Client, variables: DataCubesMetadataOptions["variables"], /** Callback triggered when data fetching starts (cache miss). */ diff --git a/app/icons/index.tsx b/app/icons/index.tsx index 5eefb2d8d..1896f9f0d 100644 --- a/app/icons/index.tsx +++ b/app/icons/index.tsx @@ -1,6 +1,6 @@ import { ComponentProps } from "react"; -import { ChartType, ComponentType } from "@/config-types"; +import { ChartType } from "@/config-types"; import { IconName, Icons } from "@/icons/components"; export { Icons } from "./components"; @@ -62,29 +62,3 @@ export const getChartIcon = (chartType: ChartType): IconName => { return _exhaustiveCheck; } }; - -export const getDimensionIconName = ( - dimensionType: ComponentType -): IconName => { - switch (dimensionType) { - case "GeoCoordinatesDimension": - case "GeoShapesDimension": - return "geographical"; - case "NominalDimension": - return "chartPie"; - case "NumericalMeasure": - case "StandardErrorDimension": - return "numerical"; - case "OrdinalDimension": - case "TemporalOrdinalDimension": - return "sort"; - case "OrdinalMeasure": - return "sort"; - case "TemporalDimension": - case "TemporalEntityDimension": - return "pointInTime"; - default: - const _exhaustiveCheck: never = dimensionType; - return _exhaustiveCheck; - } -}; diff --git a/app/palettes.ts b/app/palettes.ts index 3ae07ce21..f8d151a76 100644 --- a/app/palettes.ts +++ b/app/palettes.ts @@ -13,20 +13,11 @@ import { interpolateRdYlGn, interpolateReds, schemeAccent, - schemeBlues, - schemeBrBG, schemeCategory10, schemeDark2, - schemeGreens, - schemeGreys, - schemeOranges, schemePaired, schemePastel1, schemePastel2, - schemePiYG, - schemePuOr, - schemePurples, - schemeReds, schemeSet1, schemeSet2, schemeSet3, @@ -119,40 +110,6 @@ export const categoricalPalettes: Array = [ export const DEFAULT_CATEGORICAL_PALETTE_NAME = categoricalPalettes[0].value; -export const getSingleHueSequentialPalette = ({ - nbClass = 5, - palette, -}: { - nbClass: number; - palette?: DivergingPaletteType | SequentialPaletteType; -}): ReadonlyArray => { - switch (palette) { - case "BrBG": - return schemeBrBG[nbClass]; - case "PRGn": - return schemePiYG[nbClass]; - case "PiYG": - return schemePiYG[nbClass]; - case "PuOr": - return schemePuOr[nbClass]; - case "blues": - return schemeBlues[nbClass]; - case "greens": - return schemeGreens[nbClass]; - case "greys": - return schemeGreys[nbClass]; - case "oranges": - return schemeOranges[nbClass]; - case "purples": - return schemePurples[nbClass]; - case "reds": - return schemeReds[nbClass]; - - default: - return schemeOranges[nbClass]; - } -}; - export type Palette = { label: string; value: T; @@ -231,9 +188,3 @@ export const sequentialPalettes = sequentialPaletteKeys.map((d) => ({ value: d, interpolator: getColorInterpolator(d), })) as Palette[]; - -export const sequentialSteppedPalettes = sequentialPaletteKeys.map((d) => ({ - label: d, - value: d, - colors: steppedPaletteSteps.map((s) => getColorInterpolator(d)(s)), -})) as SteppedPalette[]; diff --git a/app/rdf/cube-filters.ts b/app/rdf/cube-filters.ts deleted file mode 100644 index 943f4f4d7..000000000 --- a/app/rdf/cube-filters.ts +++ /dev/null @@ -1,75 +0,0 @@ -import rdf from "rdf-ext"; -import { NamedNode } from "rdf-js"; - -import { truthy } from "@/domain/types"; -import { - SearchCubeFilter, - SearchCubeFilterType, -} from "@/graphql/resolver-types"; -import { ExtendedCube } from "@/rdf/extended-cube"; -import * as ns from "@/rdf/namespace"; - -import isAttrEqual from "../utils/is-attr-equal"; - -const where = (predicate: NamedNode, object: NamedNode) => { - return ({ cube }: $FixMe) => [[cube, predicate, object]]; -}; - -const isVisualizeCubeFilter = where( - ns.schema.workExample, - rdf.namedNode("https://ld.admin.ch/application/visualize") -); - -export const makeInQueryFilter = ( - predicate: NamedNode, - filters: SearchCubeFilter[] -) => { - return filters.length > 0 - ? ExtendedCube.filter.in( - predicate, - filters.map((x) => rdf.namedNode(x.value)) - ) - : null; -}; - -export const makeCubeFilters = ({ - includeDrafts, - filters, -}: { - includeDrafts: boolean; - filters?: SearchCubeFilter[]; -}) => { - const themeQueryFilter = makeInQueryFilter( - ns.dcat.theme, - filters?.filter(isAttrEqual("type", SearchCubeFilterType.DataCubeTheme)) ?? - [] - ); - const orgQueryFilter = makeInQueryFilter( - ns.dcterms.creator, - filters?.filter( - isAttrEqual("type", SearchCubeFilterType.DataCubeOrganization) - ) ?? [] - ); - const aboutQueryFilter = makeInQueryFilter( - ns.schema.about, - filters?.filter(isAttrEqual("type", SearchCubeFilterType.DataCubeAbout)) ?? - [] - ); - - const res = [ - // Cubes that have a newer version published have a schema.org/expires property; Only show cubes that don't have it - ExtendedCube.filter.noExpires(), - isVisualizeCubeFilter, - includeDrafts - ? null - : ExtendedCube.filter.status([ - ns.adminVocabulary("CreativeWorkStatus/Published"), - ]), - themeQueryFilter, - orgQueryFilter, - aboutQueryFilter, - ].filter(truthy); - - - return res; -}; diff --git a/app/rdf/parse.ts b/app/rdf/parse.ts index 9536c6867..ea3dc0a74 100644 --- a/app/rdf/parse.ts +++ b/app/rdf/parse.ts @@ -1,21 +1,9 @@ -import { - CountableTimeInterval, - timeDay, - timeHour, - timeMinute, - timeMonth, - timeSecond, - timeWeek, - timeYear, -} from "d3-time"; -import { timeFormat, timeParse } from "d3-time-format"; import { CubeDimension } from "rdf-cube-view-query"; import { Term } from "rdf-js"; import { truthy } from "@/domain/types"; import { ScaleType, TimeUnit } from "@/graphql/query-hooks"; -import { DataCubePublicationStatus } from "@/graphql/resolver-types"; -import { ResolvedDataCube, ResolvedDimension } from "@/graphql/shared-types"; +import { ResolvedDimension } from "@/graphql/shared-types"; import { ExtendedCube } from "@/rdf/extended-cube"; import { timeFormats, timeUnitFormats, timeUnits } from "@/rdf/mappings"; import * as ns from "@/rdf/namespace"; @@ -33,60 +21,6 @@ export const parseVersionHistory = (cube: ExtendedCube) => { return cube.in(ns.schema.hasPart)?.value; }; -export const parseIri = (cube: ExtendedCube) => { - return cube.term?.value ?? "[NO IRI]"; -}; - -/** - * Parses a cube coming from rdf-cube-view-query into a simple javascript object - * - * @see https://github.com/zazuko/cube-creator/blob/master/apis/core/bootstrap/shapes/dataset.ts for current list of cube metadata - */ -export const parseCube = ({ - cube, - locale, -}: { - cube: ExtendedCube; - locale: string; -}): ResolvedDataCube => { - const outOpts = { language: getQueryLocales(locale) }; - const creatorIri = cube.out(ns.dcterms.creator).value; - return { - cube, - locale, - data: { - iri: parseIri(cube), - identifier: cube.out(ns.dcterms.identifier)?.value ?? "[NO IDENTIFIER]", - title: cube.out(ns.schema.name, outOpts)?.value ?? "[NO TITLE]", - description: cube.out(ns.schema.description, outOpts)?.value ?? "", - version: cube.out(ns.schema.version)?.value, - publicationStatus: isCubePublished(cube) - ? DataCubePublicationStatus.Published - : DataCubePublicationStatus.Draft, - datePublished: cube.out(ns.schema.datePublished)?.value, - dateModified: cube.out(ns.schema.dateModified)?.value, - themes: cube - .out(ns.dcat.theme) - ?.values.filter(truthy) - .map((t) => ({ iri: t })), - creator: creatorIri - ? { - iri: creatorIri, - } - : undefined, - versionHistory: parseVersionHistory(cube), - contactPoint: { - name: cube.out(ns.dcat.contactPoint)?.out(ns.vcard.fn)?.value, - email: cube.out(ns.dcat.contactPoint)?.out(ns.vcard.hasEmail)?.value, - }, - publisher: cube.out(ns.dcterms.publisher)?.value, - landingPage: cube.out(ns.dcat.landingPage)?.value, - expires: cube.out(ns.schema.expires)?.value, - workExamples: cube.out(ns.schema.workExample)?.values, - }, - }; -}; - export const getScaleType = ( scaleTypeTerm: Term | undefined ): ScaleType | undefined => { @@ -287,59 +221,3 @@ export const getIsNumerical = (dataTypeTerm: Term | undefined) => { false ); }; - -const timeIntervals = new Map([ - [ns.time.unitYear.value, timeYear], - [ns.time.unitMonth.value, timeMonth], - [ns.time.unitWeek.value, timeWeek], - [ns.time.unitDay.value, timeDay], - [ns.time.unitHour.value, timeHour], - [ns.time.unitMinute.value, timeMinute], - [ns.time.unitSecond.value, timeSecond], -]); - -const timeFormatters = new Map string>([ - [ns.xsd.gYear.value, timeFormat("%Y")], - [ns.xsd.date.value, timeFormat("%Y-%m-%d")], - [ns.xsd.dateTime.value, timeFormat("%Y-%m-%dT%H:%M:%S")], -]); - -const timeParsers = new Map Date | null>([ - [ns.xsd.gYear.value, timeParse("%Y")], - [ns.xsd.date.value, timeParse("%Y-%m-%d")], - [ns.xsd.dateTime.value, timeParse("%Y-%m-%dT%H:%M:%S")], -]); - -export const interpolateTimeValues = ({ - dataType, - timeUnit, - min, - max, -}: { - dataType: string; - timeUnit: string; - min: string; - max: string; -}) => { - const format = timeFormatters.get(dataType); - const parse = timeParsers.get(dataType); - - if (!format || !parse) { - console.warn(`No time parser/formatter found for dataType <${dataType}>`); - return []; - } - - const minDate = parse(min); - const maxDate = parse(max); - const interval = timeIntervals.get(timeUnit); - - if (!minDate || !maxDate || !interval) { - console.warn( - `Couldn't parse dates ${min} or ${max}, or no interval found for timeUnit <${timeUnit}>` - ); - - return []; - } - - return [...interval.range(minDate, maxDate), maxDate].map(format); -}; diff --git a/app/rdf/queries.ts b/app/rdf/queries.ts index cda7914e5..ab199d111 100644 --- a/app/rdf/queries.ts +++ b/app/rdf/queries.ts @@ -1,4 +1,4 @@ -import { ascending, descending, index } from "d3-array"; +import { ascending, index } from "d3-array"; import { Maybe } from "graphql-tools"; import keyBy from "lodash/keyBy"; import { CubeDimension, Filter, LookupSource, View } from "rdf-cube-view-query"; @@ -25,11 +25,7 @@ import { import { createSource, pragmas } from "@/rdf/create-source"; import { ExtendedCube } from "@/rdf/extended-cube"; import * as ns from "@/rdf/namespace"; -import { - isCubePublished, - parseCubeDimension, - parseRelatedDimensions, -} from "@/rdf/parse"; +import { parseCubeDimension, parseRelatedDimensions } from "@/rdf/parse"; import { loadDimensionValuesWithMetadata, loadMaxDimensionValue, @@ -45,67 +41,6 @@ const DIMENSION_VALUE_UNDEFINED = ns.cube.Undefined.value; const labelDimensionIri = (iri: string) => `${iri}/__label__`; const iriDimensionIri = (iri: string) => `${iri}/__iri__`; -export const getLatestCube = async ( - cube: ExtendedCube -): Promise => { - const source = cube.source; - const versionHistory = cube.in(ns.schema.hasPart)?.term; - const isPublished = isCubePublished(cube); - const version = cube.out(ns.schema.version); - const isExpired = cube.out(ns.schema.expires)?.value !== undefined; - - // If it's not expired, don't even try to look for newer versions - if (!isExpired) { - return cube; - } - - const filters = [ - // Only cubes from the same version history - ExtendedCube.filter.isPartOf(versionHistory), - // With a higher version number - ExtendedCube.filter.version.gt(version), - // If the original cube is published, only select cubes that are also published - ExtendedCube.filter.status( - isPublished - ? [ns.adminVocabulary("CreativeWorkStatus/Published")] - : [ - ns.adminVocabulary("CreativeWorkStatus/Draft"), - ns.adminVocabulary("CreativeWorkStatus/Published"), - ] - ), - ]; - - const rows = await source.client.query.select(source.cubesQuery({ filters })); - const newerCubes = await Promise.all( - rows.map(async (row) => { - const cube = new ExtendedCube({ - parent: source, - term: row.cube, - source, - }); - await cube.fetchCube(); - - return cube; - }) - ); - - if (newerCubes.length > 0) { - newerCubes.sort((a, b) => - descending( - +a.out(ns.schema.version)?.value!, - +b.out(ns.schema.version)?.value! - ) - ); - - // If there's a newer cube that's published, it's preferred over drafts - // (this only applies if the original cube was in draft status anyway) - return newerCubes.find((cube) => isCubePublished(cube)) ?? newerCubes[0]; - } - - // If there are no newer cubes, return the original one - return cube; -}; - const getDimensionUnits = (d: CubeDimension) => { // Keeping qudt:unit format for backwards compatibility. const t = d.out(ns.qudt.unit).term ?? d.out(ns.qudt.hasUnit).term; @@ -591,9 +526,7 @@ const unversionServerFilters = async ( // ); export const hasHierarchy = (dim: CubeDimension) => { - return ( - dim.out(ns.cubeMeta.inHierarchy).values.length > 0 - ); + return dim.out(ns.cubeMeta.inHierarchy).values.length > 0; }; const buildFilters = async ({ diff --git a/app/rdf/query-latest-cube-iri.ts b/app/rdf/query-latest-cube-iri.ts index d7a6eedc5..df10c6147 100644 --- a/app/rdf/query-latest-cube-iri.ts +++ b/app/rdf/query-latest-cube-iri.ts @@ -3,7 +3,7 @@ import ParsingClient from "sparql-http-client/ParsingClient"; /** Creates SPARQL query to fetch latest cube iri. * Works for both versioned and unversioned cubes. */ -export const getLatestCubeIriQuery = (cubeIri: string) => { +const getLatestCubeIriQuery = (cubeIri: string) => { return `PREFIX cube: PREFIX schema: diff --git a/app/rdf/query-search-score-utils.ts b/app/rdf/query-search-score-utils.ts index baf95f4b6..b1486cc4e 100644 --- a/app/rdf/query-search-score-utils.ts +++ b/app/rdf/query-search-score-utils.ts @@ -1,10 +1,5 @@ import { SearchCube } from "@/domain/data"; -export const parseFloatZeroed = (s: string) => { - const n = parseFloat(s); - return Number.isNaN(n) ? 0 : n; -}; - export const fields = { title: { weight: 5, diff --git a/app/rdf/tree-utils.ts b/app/rdf/tree-utils.ts index 2a5d0a6f6..41fb88dd9 100644 --- a/app/rdf/tree-utils.ts +++ b/app/rdf/tree-utils.ts @@ -52,8 +52,6 @@ export const pruneTree = ( return filterTreeHelper(tree, isUsed); }; -type Value = string; - /** Sorts the tree by default chain of sorters (position -> identifier -> label). */ export const sortHierarchy = (tree: HierarchyValue[]): HierarchyValue[] => { const sortedTree = orderBy( @@ -108,20 +106,6 @@ export const findInHierarchy = ( return res; }; -export const makeTreeFromValues = ( - values: Value[], - dimensionIri: string, - { depth = 0 } -) => { - return values.map((x) => ({ - value: x, - label: "", - dimensionIri, - depth, - children: [], - })); -}; - export const getOptionsFromTree = (tree: HierarchyValue[]) => { return sortBy( bfs(tree, (node, { parents }) => ({ diff --git a/app/stores/data-source.ts b/app/stores/data-source.ts index bf7f10074..76a0589ad 100644 --- a/app/stores/data-source.ts +++ b/app/stores/data-source.ts @@ -49,7 +49,7 @@ const saveToURL = (dataSource: DataSource) => { * URL (stored as label: Prod, Int, Test); if it's not here, tries with * localStorage (also stored as label), otherwise uses a default data source. */ -export const dataSourceStoreMiddleware = +const dataSourceStoreMiddleware = (config: StateCreator, router: SingletonRouter) => ( set: StoreApi["setState"], diff --git a/app/stores/interactive-filters.tsx b/app/stores/interactive-filters.tsx index cbfc8eb90..5e974ba61 100644 --- a/app/stores/interactive-filters.tsx +++ b/app/stores/interactive-filters.tsx @@ -161,7 +161,7 @@ const InteractiveFiltersContext = createContext< /** * Returns filters that are shared across multiple charts. */ -export const getPotentialSharedFilters = ( +const getPotentialSharedFilters = ( chartConfigs: ChartConfig[] ): PotentialSharedFilter[] => { const temporalDimensions = chartConfigs.flatMap((config) => { diff --git a/app/utils/cached-with-ttl.ts b/app/utils/cached-with-ttl.ts deleted file mode 100644 index 2664cb323..000000000 --- a/app/utils/cached-with-ttl.ts +++ /dev/null @@ -1,27 +0,0 @@ -const cachedWithTTL = any>( - fn: T, - keyer: (...args: Parameters) => string, - ttl: number -) => { - const cache = {} as Record }>; - return async function (...args: Parameters) { - const key = keyer(...args); - for (let k of Object.keys(cache)) { - // Delete old results - if (cache[k].date < Date.now() - ttl) { - delete cache[k]; - } - } - let res; - if (cache[key]) { - res = cache[key].result; - } else { - const cached = fn(...args); - cache[key] = { date: Date.now(), result: cached }; - res = cache[key].result; - } - return res; - }; -}; - -export default cachedWithTTL; diff --git a/app/utils/flashes.tsx b/app/utils/flashes.tsx index 1d5e6f2fa..2bdb585e3 100644 --- a/app/utils/flashes.tsx +++ b/app/utils/flashes.tsx @@ -6,7 +6,7 @@ import React, { useMemo, useState } from "react"; import { Icon } from "@/icons"; -export const flashes = { +const flashes = { CANNOT_FIND_CUBE: "CANNOT_FIND_CUBE", } as const; diff --git a/app/utils/is-attr-equal.tsx b/app/utils/is-attr-equal.tsx deleted file mode 100644 index 38cf7323b..000000000 --- a/app/utils/is-attr-equal.tsx +++ /dev/null @@ -1,16 +0,0 @@ -/** - * Creates a typeguard based on attribute equality - * - * @example - * const users = users.filter(isAttrEqual('role', 'Admin')) - */ -const isAttrEqual = ( - k: K, - v: V -): ((o: T) => o is Extract>) => { - return (o: T): o is Extract> => { - return o[k] === v; - }; -}; - -export default isAttrEqual; diff --git a/app/utils/use-change.tsx b/app/utils/use-change.tsx deleted file mode 100644 index 59a0f5146..000000000 --- a/app/utils/use-change.tsx +++ /dev/null @@ -1,11 +0,0 @@ -import { useRef } from "react"; - -const useChange = (val: $IntentionalAny, message: string) => { - const ref = useRef(); - if (val !== ref.current && ref.current !== undefined) { - console.log("change", val, message); - } - ref.current = val; -}; - -export default useChange;