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

feat: Introduce component ids #1849

Draft
wants to merge 34 commits into
base: main
Choose a base branch
from
Draft
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
1b9079d
refactor: Small clean up
bprusinowski Nov 12, 2024
b1febb9
fix: Typo
bprusinowski Nov 12, 2024
08a8190
feat: Include cube iri in dimension iri
bprusinowski Nov 12, 2024
d5ba3d5
fix: Condition
bprusinowski Nov 12, 2024
0a30809
refactor: Await migrations & remove immer
bprusinowski Nov 13, 2024
50b5412
refactor: Extract constants
bprusinowski Nov 13, 2024
bdb5d28
feat: Add a way to query version history of a cube
bprusinowski Nov 13, 2024
27076d4
refactor: Remove publishIri
bprusinowski Nov 13, 2024
797980a
fix: Loading of min-max values
bprusinowski Nov 13, 2024
31a3ca4
fix: Async migration
bprusinowski Nov 13, 2024
a2da49b
feat: Add getUnversionedCubeIri helpers
bprusinowski Nov 13, 2024
d3de7a5
fix: Correctly handle componentIris
bprusinowski Nov 13, 2024
8b418f1
feat: Add migration
bprusinowski Nov 13, 2024
3c2ccd1
chore: Use undefined properly
bprusinowski Nov 13, 2024
2563a2c
chore: Improve debugging
bprusinowski Nov 14, 2024
654fb60
refactor: Clean up
bprusinowski Nov 14, 2024
0dfb712
fix: Mock
bprusinowski Nov 14, 2024
58689d7
fix: Tests
bprusinowski Nov 14, 2024
11284bf
fix: Versioning of tables
bprusinowski Nov 14, 2024
4d7a8a1
chore: Update comment
bprusinowski Nov 14, 2024
ce3c931
refactor: Dimension iri -> id
bprusinowski Nov 14, 2024
f2359a7
refactor: Rename
bprusinowski Nov 14, 2024
7c55a27
refactor: Config iri -> id
bprusinowski Nov 14, 2024
9b5da07
fix: Down 4.0.0 chart config migration + don't migrate empty iris
bprusinowski Nov 15, 2024
3217e57
fix: Tests
bprusinowski Nov 15, 2024
f247d1e
fix: Do not migrate joinBy ids
bprusinowski Nov 15, 2024
a64dff9
fix: Migrate component ids in colorMapping for combo charts
bprusinowski Nov 15, 2024
1374cb8
fix: Continue if field is not an object
bprusinowski Nov 15, 2024
8bbe035
feat: Decrease probability of a wrong unversioned cube iri assignment
bprusinowski Nov 15, 2024
8f616d0
feat: Migrate dashboardFilters
bprusinowski Nov 15, 2024
6c641ce
fix: Correctly filter combo footnotes
bprusinowski Nov 15, 2024
bcf7644
fix: Correctly scope chart filters list
bprusinowski Nov 15, 2024
ea4bd9f
chore: yarn.lock
bprusinowski Nov 15, 2024
6993887
fix: Test
bprusinowski Nov 15, 2024
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
71 changes: 37 additions & 34 deletions app/browse/datatable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import {
TooltipProps,
} from "@mui/material";
import { ascending, descending } from "d3-array";
import { useMemo, useRef, useState } from "react";
import { useCallback, useMemo, useRef, useState } from "react";

import {
extractChartConfigComponentIris,
extractChartConfigComponentIds,
useQueryFilters,
} from "@/charts/shared/chart-helpers";
import { Loading } from "@/components/hint";
Expand Down Expand Up @@ -92,62 +92,64 @@ export const PreviewTable = ({
const valuesIndex = uniqueMapBy(sortBy.values, (d) => d.label);
const convert =
isNumericalMeasure(sortBy) || sortBy.isNumerical
? (value: string) => +value
: (value: string) => valuesIndex.get(value)?.position ?? value;
? (v: string) => +v
: (v: string) => valuesIndex.get(v)?.position ?? v;

return [...observations].sort((a, b) =>
compare(
convert(a[sortBy.iri] as string),
convert(b[sortBy.iri] as string)
)
compare(convert(a[sortBy.id] as string), convert(b[sortBy.id] as string))
);
}, [observations, sortBy, sortDirection]);

const tooltipContainerRef = useRef(null);
const tooltipContainerRef = useRef<HTMLDivElement>(null);
const tooltipProps = useMemo(() => {
return {
PopperProps: {
// Tooltip contained inside the table so as not to overflow when table is scrolled
container: tooltipContainerRef.current,
},
};
}, []);

// Tooltip contained inside the table so as not to overflow when table is scrolled
const tooltipProps = useMemo(
() => ({ PopperProps: { container: tooltipContainerRef.current } }),
[]
const handleSort = useCallback(
(header: Component) => {
if (sortBy?.id === header.id) {
setSortDirection(sortDirection === "asc" ? "desc" : "asc");
} else {
setSortBy(header);
setSortDirection("asc");
}
},
[sortBy, sortDirection]
);

return (
<div ref={tooltipContainerRef}>
<Table>
<caption style={{ display: "none" }}>{title}</caption>
<TableHead sx={{ position: "sticky", top: 0, background: "white" }}>
<TableHead
sx={{ position: "sticky", top: 0, background: "background.paper" }}
>
<TableRow sx={{ borderBottom: "none" }}>
{headers.map((header) => {
return (
<TableCell
key={header.iri}
key={header.id}
component="th"
role="columnheader"
onClick={() => {
if (sortBy?.iri === header.iri) {
setSortDirection(
sortDirection === "asc" ? "desc" : "asc"
);
} else {
setSortBy(header);
setSortDirection("asc");
}
}}
onClick={() => handleSort(header)}
sx={{
textAlign: isNumericalMeasure(header) ? "right" : "left",
borderBottom: "none",
whiteSpace: "nowrap",
}}
>
<TableSortLabel
active={sortBy === undefined || sortBy.iri === header.iri}
direction={sortBy === undefined ? "desc" : sortDirection}
active={!sortBy || sortBy.id === header.id}
direction={!sortBy ? "desc" : sortDirection}
IconComponent={SvgIcChevronDown}
sx={{
"&:hover > svg": {
...(sortBy === undefined
? { transform: "translateY(-15%)" }
: {}),
...(!sortBy ? { transform: "translateY(-15%)" } : {}),
},
}}
>
Expand All @@ -168,18 +170,19 @@ export const PreviewTable = ({
return (
<TableRow key={i}>
{headers.map((header) => {
const formatter = formatters[header.iri];
const format = formatters[header.id];

return (
<TableCell
key={header.iri}
key={header.id}
component="td"
sx={{
textAlign: isNumericalMeasure(header)
? "right"
: "left",
}}
>
{formatter(obs[header.iri])}
{format(obs[header.id])}
</TableCell>
);
})}
Expand Down Expand Up @@ -242,7 +245,7 @@ export const DataSetTable = ({
sx?: SxProps<Theme>;
}) => {
const locale = useLocale();
const componentIris = extractChartConfigComponentIris({ chartConfig });
const componentIris = extractChartConfigComponentIds({ chartConfig });
const commonQueryVariables = {
sourceType: dataSource.type,
sourceUrl: dataSource.url,
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 @@ -340,7 +340,7 @@ const SelectDatasetStepContent = ({
>
<Trans id="browse.datasets.description">
Explore datasets provided by the LINDAS Linked Data
Service by either filtering by categories or organisations
Service by either filtering by categories or organizations
or search directly for specific keywords. Click on a
dataset to see more detailed information and start
creating your own visualizations.
Expand Down
12 changes: 6 additions & 6 deletions app/charts/area/areas-state-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,24 @@ export type AreasStateVariables = BaseVariables &
export const useAreasStateVariables = (
props: ChartProps<AreaConfig>
): AreasStateVariables => {
const { chartConfig, observations, dimensionsByIri, measuresByIri } = props;
const { chartConfig, observations, dimensionsById, measuresById } = props;
const { fields } = chartConfig;
const { x, y, segment } = fields;

const baseVariables = useBaseVariables(chartConfig);
const temporalXVariables = useTemporalXVariables(x, {
dimensionsByIri,
dimensionsById,
});
const numericalYVariables = useNumericalYVariables("area", y, {
measuresByIri,
measuresById,
});
const segmentVariables = useSegmentVariables(segment, {
dimensionsByIri,
dimensionsById,
observations,
});
const interactiveFiltersVariables = useInteractiveFiltersVariables(
chartConfig.interactiveFiltersConfig,
{ dimensionsByIri }
{ dimensionsById }
);

const { getX } = temporalXVariables;
Expand Down Expand Up @@ -92,7 +92,7 @@ export const useAreasStateData = (
}, [sortData, plottableData]);
const data = useChartData(sortedPlottableData, {
chartConfig,
timeRangeDimensionIri: xDimension.iri,
timeRangeDimensionId: xDimension.id,
getXAsDate: getX,
getSegmentAbbreviationOrLabel,
getTimeRangeDate,
Expand Down
16 changes: 8 additions & 8 deletions app/charts/area/areas-state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const useAreasState = (
getSegmentAbbreviationOrLabel,
getSegmentLabel,
} = variables;
const getIdentityY = useGetIdentityY(yMeasure.iri);
const getIdentityY = useGetIdentityY(yMeasure.id);
const {
chartData,
scalesData,
Expand Down Expand Up @@ -121,9 +121,9 @@ const useAreasState = (
const segmentSortingType = segmentSorting?.sortingType;
const segmentSortingOrder = segmentSorting?.sortingOrder;

const segmentFilter = segmentDimension?.iri
const segmentFilter = segmentDimension?.id
? chartConfig.cubes.find((d) => d.iri === segmentDimension.cubeIri)
?.filters[segmentDimension.iri]
?.filters[segmentDimension.id]
: undefined;

const sumsBySegment = useMemo(() => {
Expand Down Expand Up @@ -170,7 +170,7 @@ const useAreasState = (
fields.segment?.useAbbreviations,
]);

const xKey = fields.x.componentIri;
const xKey = fields.x.componentId;
const sumsByX = useMemo(() => {
return Object.fromEntries(
rollup(
Expand All @@ -186,7 +186,7 @@ const useAreasState = (
if (normalize) {
return group(
normalizeData(chartData, {
yKey: yMeasure.iri,
yKey: yMeasure.id,
getY,
getTotalGroupValue: (d) => {
return sumsByX[getXAsString(d)];
Expand All @@ -197,7 +197,7 @@ const useAreasState = (
}

return group(chartData, getXAsString);
}, [chartData, getXAsString, sumsByX, getY, yMeasure.iri, normalize]);
}, [chartData, getXAsString, sumsByX, getY, yMeasure.id, normalize]);

const chartWideData = useMemo(() => {
return getWideData({
Expand Down Expand Up @@ -366,7 +366,7 @@ const useAreasState = (
});
const yValueFormatter = getStackedTooltipValueFormatter({
normalize,
yMeasureIri: yMeasure.iri,
yMeasureId: yMeasure.id,
yMeasureUnit: yMeasure.unit,
formatters,
formatNumber,
Expand Down Expand Up @@ -415,7 +415,7 @@ const useAreasState = (
timeFormatUnit,
xDimension.timeUnit,
xScale,
yMeasure.iri,
yMeasure.id,
yMeasure.unit,
normalize,
getIdentityY,
Expand Down
2 changes: 1 addition & 1 deletion app/charts/chart-config-ui-options.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe("defaultSegmentOnChange", () => {
expect(Object.keys(chartConfig.fields)).toEqual(["segment"]);
expect(chartConfig.fields.segment).toEqual(
expect.objectContaining({
componentIri: "iri",
componentId: "iri",
palette: DEFAULT_CATEGORICAL_PALETTE_NAME,
})
);
Expand Down
Loading
Loading