@datawheel/data-explorer 1.4.0 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/main.d.mts +6 -0
- package/dist/main.mjs +20 -5
- package/package.json +1 -1
package/dist/main.d.mts
CHANGED
|
@@ -463,6 +463,7 @@ interface PropertyItem extends QueryParamsItem {
|
|
|
463
463
|
}
|
|
464
464
|
|
|
465
465
|
type Formatter = (value: number | null, locale?: string) => string;
|
|
466
|
+
type DrilldownFormatter = (value: string | null, locale?: string) => string;
|
|
466
467
|
interface PanelDescriptor {
|
|
467
468
|
key: string;
|
|
468
469
|
label: string;
|
|
@@ -1146,6 +1147,10 @@ declare function ExplorerComponent<Locale extends string>(props: {
|
|
|
1146
1147
|
* that are displayed next to the value.
|
|
1147
1148
|
* */
|
|
1148
1149
|
idFormatters?: Record<string, Formatter>;
|
|
1150
|
+
/**
|
|
1151
|
+
* Defines an index of formatter functions available for drilldowns.
|
|
1152
|
+
* */
|
|
1153
|
+
drilldownFormatters?: Record<string, DrilldownFormatter>;
|
|
1149
1154
|
/**
|
|
1150
1155
|
* Defines an alternative height for the component structure.
|
|
1151
1156
|
* @default "100vh"
|
|
@@ -1333,6 +1338,7 @@ interface SettingsContextProps {
|
|
|
1333
1338
|
defaultMembersFilter: "id" | "name" | "any";
|
|
1334
1339
|
formatters: Record<string, Formatter>;
|
|
1335
1340
|
idFormatters: Record<string, Formatter>;
|
|
1341
|
+
drilldownFormatters: Record<string, DrilldownFormatter>;
|
|
1336
1342
|
previewLimit: number;
|
|
1337
1343
|
panels: PanelDescriptor[];
|
|
1338
1344
|
paginationConfig: Pagination;
|
package/dist/main.mjs
CHANGED
|
@@ -600,6 +600,7 @@ function SettingsProvider(props) {
|
|
|
600
600
|
defaultMembersFilter: props.defaultMembersFilter || "id",
|
|
601
601
|
formatters: props.formatters || {},
|
|
602
602
|
idFormatters: props.idFormatters || {},
|
|
603
|
+
drilldownFormatters: props.drilldownFormatters || {},
|
|
603
604
|
panels: props.panels,
|
|
604
605
|
previewLimit: props.previewLimit || 50,
|
|
605
606
|
paginationConfig: (_a = props.pagination) != null ? _a : { rowsLimits: [100, 300, 500, 1e3], defaultLimit: 100 },
|
|
@@ -713,6 +714,10 @@ function useidFormatters() {
|
|
|
713
714
|
const { idFormatters } = useSettings();
|
|
714
715
|
return { idFormatters };
|
|
715
716
|
}
|
|
717
|
+
function useDrilldownFormatters() {
|
|
718
|
+
const { drilldownFormatters } = useSettings();
|
|
719
|
+
return { drilldownFormatters };
|
|
720
|
+
}
|
|
716
721
|
|
|
717
722
|
// src/utils/structs.ts
|
|
718
723
|
function buildQuery(props) {
|
|
@@ -3318,6 +3323,7 @@ function useTable({
|
|
|
3318
3323
|
const { translate: t } = useTranslation();
|
|
3319
3324
|
const { getFormat, getFormatter } = useFormatter();
|
|
3320
3325
|
const { idFormatters } = useidFormatters();
|
|
3326
|
+
const { drilldownFormatters } = useDrilldownFormatters();
|
|
3321
3327
|
const { sortKey, sortDir } = useSelector$1(selectSortingParams);
|
|
3322
3328
|
const theme = useMantineTheme();
|
|
3323
3329
|
const isSmallerThanMd = useMediaQuery(
|
|
@@ -3471,6 +3477,8 @@ function useTable({
|
|
|
3471
3477
|
const row = cell.row;
|
|
3472
3478
|
const cellId = row.original[`${cell.column.id} ID`];
|
|
3473
3479
|
const idFormatter = idFormatters[`${keyCol.localeLabel} ID`];
|
|
3480
|
+
const drilldownFormatter = drilldownFormatters[`${keyCol.localeLabel}`] || drilldownFormatters[`${entity.name}`];
|
|
3481
|
+
const formattedValue = drilldownFormatter ? drilldownFormatter(cellValue, locale) : cellValue;
|
|
3474
3482
|
return /* @__PURE__ */ React15__default.createElement(Flex, { justify: "space-between", sx: { width: "100%", maxWidth: 400 }, gap: "sm" }, /* @__PURE__ */ React15__default.createElement(
|
|
3475
3483
|
Text,
|
|
3476
3484
|
{
|
|
@@ -3481,7 +3489,7 @@ function useTable({
|
|
|
3481
3489
|
textOverflow: "ellipsis"
|
|
3482
3490
|
}
|
|
3483
3491
|
},
|
|
3484
|
-
|
|
3492
|
+
formattedValue
|
|
3485
3493
|
), /* @__PURE__ */ React15__default.createElement(Box, null, cellId && /* @__PURE__ */ React15__default.createElement(Text, { color: "dimmed" }, idFormatter ? idFormatter(cellId) : cellId)));
|
|
3486
3494
|
}
|
|
3487
3495
|
};
|
|
@@ -3782,12 +3790,13 @@ var MultiFilter = ({ header }) => {
|
|
|
3782
3790
|
const { translate: t } = useTranslation();
|
|
3783
3791
|
const cutItems = useSelector$1(selectCutItems);
|
|
3784
3792
|
const drilldownItems = useSelector$1(selectDrilldownItems);
|
|
3785
|
-
useSelector$1(selectLocale);
|
|
3786
|
-
header.column.id;
|
|
3793
|
+
const locale = useSelector$1(selectLocale);
|
|
3794
|
+
const label = header.column.id;
|
|
3787
3795
|
const localeLabel = header.column.columnDef.header;
|
|
3788
3796
|
const drilldown = drilldownItems.find((d) => d.level === header.column.id);
|
|
3789
3797
|
const actions2 = useActions();
|
|
3790
3798
|
const { idFormatters } = useidFormatters();
|
|
3799
|
+
const { drilldownFormatters } = useDrilldownFormatters();
|
|
3791
3800
|
const navigate = useNavigate();
|
|
3792
3801
|
const debouncedUpdateUrl = useMemo(
|
|
3793
3802
|
() => debounce((query2) => {
|
|
@@ -3831,11 +3840,13 @@ var MultiFilter = ({ header }) => {
|
|
|
3831
3840
|
value: cut.members || [],
|
|
3832
3841
|
data: drilldown.members.map((m) => {
|
|
3833
3842
|
const idFormatter = idFormatters[`${localeLabel} ID`];
|
|
3843
|
+
const drilldownFormatter = drilldownFormatters[`${localeLabel}`] || drilldownFormatters[`${label}`];
|
|
3834
3844
|
const formattedKey = idFormatter ? idFormatter(m.key) : m.key;
|
|
3835
3845
|
const key = formattedKey ? `(${formattedKey})` : formattedKey;
|
|
3846
|
+
const formattedCaption = drilldownFormatter ? drilldownFormatter(m.caption || m.key, locale.code) : m.caption;
|
|
3836
3847
|
return {
|
|
3837
3848
|
value: `${m.key}`,
|
|
3838
|
-
label:
|
|
3849
|
+
label: formattedCaption ? `${formattedCaption} ${key}` : `${key}`
|
|
3839
3850
|
};
|
|
3840
3851
|
}),
|
|
3841
3852
|
clearButtonProps: { "aria-label": "Clear selection" },
|
|
@@ -4008,6 +4019,7 @@ function LevelItem({
|
|
|
4008
4019
|
const drilldowns = useSelector$1(selectDrilldownMap);
|
|
4009
4020
|
useSelector$1(selectDrilldownItems);
|
|
4010
4021
|
const { idFormatters } = useidFormatters();
|
|
4022
|
+
const { drilldownFormatters } = useDrilldownFormatters();
|
|
4011
4023
|
const label = useMemo(() => {
|
|
4012
4024
|
const captions = [
|
|
4013
4025
|
getCaption(dimension, locale),
|
|
@@ -4116,11 +4128,13 @@ function LevelItem({
|
|
|
4116
4128
|
value: (cut == null ? void 0 : cut.members) || [],
|
|
4117
4129
|
data: currentDrilldown.members.map((m) => {
|
|
4118
4130
|
const idFormatter = idFormatters[`${label} ID`];
|
|
4131
|
+
const drilldownFormatter = drilldownFormatters[`${label}`];
|
|
4119
4132
|
const formattedKey = idFormatter ? idFormatter(m.key) : m.key;
|
|
4120
4133
|
const key = formattedKey ? `(${formattedKey})` : formattedKey;
|
|
4134
|
+
const formattedCaption = drilldownFormatter ? drilldownFormatter(m.caption || m.key, locale) : m.caption;
|
|
4121
4135
|
return {
|
|
4122
4136
|
value: `${m.key}`,
|
|
4123
|
-
label:
|
|
4137
|
+
label: formattedCaption ? `${formattedCaption} ${key}` : `${key}`
|
|
4124
4138
|
};
|
|
4125
4139
|
}),
|
|
4126
4140
|
clearable: true,
|
|
@@ -6624,6 +6638,7 @@ function ExplorerComponent(props) {
|
|
|
6624
6638
|
defaultMembersFilter: props.defaultMembersFilter,
|
|
6625
6639
|
formatters: props.formatters,
|
|
6626
6640
|
idFormatters: props.idFormatters,
|
|
6641
|
+
drilldownFormatters: props.drilldownFormatters,
|
|
6627
6642
|
withPermalink: props.withPermalink,
|
|
6628
6643
|
panels,
|
|
6629
6644
|
pagination,
|