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

chore: Use npx knip to clean up unused things #1578

Merged
merged 1 commit into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions app/browser/dataset-browse.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ const NavItem = ({
);
};

export const Subthemes = ({
const Subthemes = ({
subthemes,
filters,
counts,
Expand Down Expand Up @@ -556,7 +556,7 @@ type NavSectionTitleTheme = {
borderColor: string;
};

export const NavSectionTitle = ({
const NavSectionTitle = ({
children,
theme,
...flexProps
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion app/browser/select-dataset-step.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ const useStyles = makeStyles<
},
}));

export const formatBackLink = (
const formatBackLink = (
query: Router["query"]
): React.ComponentProps<typeof NextLink>["href"] => {
const backParameters = softJSONParse(query.previous as string);
Expand Down
2 changes: 1 addition & 1 deletion app/charts/area/chart-area.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const ChartAreasVisualization = (
return <ChartDataWrapper {...props} Component={ChartAreas} />;
};

export const ChartAreas = memo((props: ChartProps<AreaConfig>) => {
const ChartAreas = memo((props: ChartProps<AreaConfig>) => {
const { chartConfig } = props;
const { fields, interactiveFiltersConfig } = chartConfig;

Expand Down
2 changes: 1 addition & 1 deletion app/charts/column/chart-column.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const ChartColumnsVisualization = (
return <ChartDataWrapper {...props} Component={ChartColumns} />;
};

export const ChartColumns = memo((props: ChartProps<ColumnConfig>) => {
const ChartColumns = memo((props: ChartProps<ColumnConfig>) => {
const { chartConfig, dimensions } = props;
const { fields, interactiveFiltersConfig } = chartConfig;
const filters = useChartConfigFilters(chartConfig);
Expand Down
2 changes: 1 addition & 1 deletion app/charts/combo/chart-combo-line-column.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const ChartComboLineColumnVisualization = (
return <ChartDataWrapper {...props} Component={ChartComboLineColumn} />;
};

export const ChartComboLineColumn = memo(
const ChartComboLineColumn = memo(
(props: ChartProps<ComboLineColumnConfig>) => {
const { chartConfig } = props;
const { interactiveFiltersConfig } = chartConfig;
Expand Down
50 changes: 24 additions & 26 deletions app/charts/combo/chart-combo-line-dual.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,28 @@ export const ChartComboLineDualVisualization = (
return <ChartDataWrapper {...props} Component={ChartComboLineDual} />;
};

export const ChartComboLineDual = memo(
(props: ChartProps<ComboLineDualConfig>) => {
const { chartConfig } = props;
const { interactiveFiltersConfig } = chartConfig;
const { sharedFilters } = useDashboardInteractiveFilters();
const ChartComboLineDual = memo((props: ChartProps<ComboLineDualConfig>) => {
const { chartConfig } = props;
const { interactiveFiltersConfig } = chartConfig;
const { sharedFilters } = useDashboardInteractiveFilters();

return (
<ComboLineDualChart {...props}>
<ChartContainer type="comboLineDual">
<ChartSvg>
<AxisHeightLinearDual orientation="left" />
<AxisHeightLinearDual orientation="right" /> <AxisTime />
<AxisTimeDomain />
<ComboLineDual />
<InteractionHorizontal />
{shouldShowBrush(interactiveFiltersConfig, sharedFilters) && (
<BrushTime />
)}
</ChartSvg>
<HoverDotMultiple />
<Ruler />
<Tooltip type="multiple" />
</ChartContainer>
</ComboLineDualChart>
);
}
);
return (
<ComboLineDualChart {...props}>
<ChartContainer type="comboLineDual">
<ChartSvg>
<AxisHeightLinearDual orientation="left" />
<AxisHeightLinearDual orientation="right" /> <AxisTime />
<AxisTimeDomain />
<ComboLineDual />
<InteractionHorizontal />
{shouldShowBrush(interactiveFiltersConfig, sharedFilters) && (
<BrushTime />
)}
</ChartSvg>
<HoverDotMultiple />
<Ruler />
<Tooltip type="multiple" />
</ChartContainer>
</ComboLineDualChart>
);
});
2 changes: 1 addition & 1 deletion app/charts/combo/chart-combo-line-single.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const ChartComboLineSingleVisualization = (
return <ChartDataWrapper {...props} Component={ChartComboLineSingle} />;
};

export const ChartComboLineSingle = memo(
const ChartComboLineSingle = memo(
(props: ChartProps<ComboLineSingleConfig>) => {
const { chartConfig, measures } = props;
const { interactiveFiltersConfig } = chartConfig;
Expand Down
14 changes: 5 additions & 9 deletions app/charts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -112,7 +112,7 @@ export const regularChartTypes: RegularChartType[] = [
"map",
];

export const comboDifferentUnitChartTypes: ComboChartType[] = [
const comboDifferentUnitChartTypes: ComboChartType[] = [
"comboLineDual",
"comboLineColumn",
];
Expand All @@ -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,
Expand Down Expand Up @@ -284,7 +280,7 @@ export const initializeMapLayerField = ({
}
};

export const getInitialAreaLayer = ({
const getInitialAreaLayer = ({
component,
measure,
}: {
Expand All @@ -307,7 +303,7 @@ export const getInitialAreaLayer = ({
};
};

export const getInitialSymbolLayer = ({
const getInitialSymbolLayer = ({
component,
measure,
}: {
Expand Down
2 changes: 1 addition & 1 deletion app/charts/line/chart-lines.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const ChartLinesVisualization = (
return <ChartDataWrapper {...props} Component={ChartLines} />;
};

export const ChartLines = memo((props: ChartProps<LineConfig>) => {
const ChartLines = memo((props: ChartProps<LineConfig>) => {
const { chartConfig } = props;
const { fields, interactiveFiltersConfig } = chartConfig;
const { sharedFilters } = useDashboardInteractiveFilters();
Expand Down
2 changes: 1 addition & 1 deletion app/charts/map/chart-map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export type ChartMapProps = ChartProps<MapConfig> & {
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);
Expand Down
2 changes: 1 addition & 1 deletion app/charts/map/get-base-layer-style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const tokens = {

const greyStyle = replaceStyleTokens(greyStyleBase as MapboxStyle, tokens);

export const emptyStyle = {
const emptyStyle = {
version: 8,
name: "Empty",
metadata: {
Expand Down
2 changes: 1 addition & 1 deletion app/charts/map/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions app/charts/map/style-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ type AnyLayer = MapboxStyle["layers"][number];

// @TODO Find a way to make those guards generic
type HasUrl<T> = T extends { url?: string | undefined } ? T : never;
export function hasUrl(obj: AnySourceData): obj is HasUrl<AnySourceData> {
function hasUrl(obj: AnySourceData): obj is HasUrl<AnySourceData> {
return Object.prototype.hasOwnProperty.call(obj, "url");
}

Expand All @@ -14,7 +14,7 @@ export function hasLayout(obj: AnyLayer): obj is HasLayout<AnySourceData> {
return Object.prototype.hasOwnProperty.call(obj, "layout");
}

export const replaceStringTokens = (
const replaceStringTokens = (
s: string | undefined,
tokens: Record<string, string>
) => {
Expand Down
2 changes: 1 addition & 1 deletion app/charts/pie/chart-pie.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const ChartPieVisualization = (props: VisualizationProps<PieConfig>) => {
return <ChartDataWrapper {...props} Component={ChartPie} />;
};

export const ChartPie = memo((props: ChartProps<PieConfig>) => {
const ChartPie = memo((props: ChartProps<PieConfig>) => {
const { chartConfig, observations, dimensions } = props;
const { fields, interactiveFiltersConfig } = chartConfig;
const somePositive = observations.some(
Expand Down
2 changes: 1 addition & 1 deletion app/charts/scatterplot/chart-scatterplot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const ChartScatterplotVisualization = (
return <ChartDataWrapper {...props} Component={ChartScatterplot} />;
};

export const ChartScatterplot = memo((props: ChartProps<ScatterPlotConfig>) => {
const ChartScatterplot = memo((props: ChartProps<ScatterPlotConfig>) => {
const { chartConfig, dimensions } = props;
const { fields, interactiveFiltersConfig } = chartConfig;
const filters = useChartConfigFilters(chartConfig);
Expand Down
55 changes: 0 additions & 55 deletions app/charts/shared/abbreviations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<NonNullable<ObservationValue>, DimensionValue>();
const labelLookup = new Map<string, DimensionValue>();

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,
Expand Down
6 changes: 3 additions & 3 deletions app/charts/shared/brush/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 1 addition & 3 deletions app/charts/shared/chart-data-filters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
13 changes: 2 additions & 11 deletions app/charts/shared/chart-helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export const useQueryFilters = ({

type IFKey = keyof NonNullable<InteractiveFiltersConfig>;

export const getChartConfigFilterComponentIris = ({ cubes }: ChartConfig) => {
const getChartConfigFilterComponentIris = ({ cubes }: ChartConfig) => {
return Object.keys(getChartConfigFilters(cubes)).filter(
(d) => !isJoinById(d)
);
Expand Down Expand Up @@ -291,7 +291,7 @@ export const useDimensionWithAbbreviations = (
};
};

export const makeUseParsedVariable =
const makeUseParsedVariable =
<T extends unknown>(parser: (d: ObservationValue) => T) =>
(key: string) => {
return useCallback((d: Observation) => parser(d[key]), [key]);
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion app/charts/shared/chart-loading-state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, boolean> = {};

Expand Down
Loading
Loading