@datawheel/data-explorer 1.0.18 → 1.0.19

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 CHANGED
@@ -1194,6 +1194,7 @@ type TableView = {
1194
1194
  table: MRT_TableInstance<TData>;
1195
1195
  getColumn(id: string): AnyResultColumn | undefined;
1196
1196
  columns: AnyResultColumn[];
1197
+ setPagination: (pagination: MRT_PaginationState) => void;
1197
1198
  } & ViewProps;
1198
1199
  declare function TableView({ table, isError, isLoading, data, pagination, setPagination, result }: TableView): React.JSX.Element;
1199
1200
  declare namespace TableView {
package/dist/main.mjs CHANGED
@@ -1879,7 +1879,8 @@ function useUpdateUrl() {
1879
1879
  return useCallback(
1880
1880
  (query) => {
1881
1881
  const currPermalink = window.location.search.slice(1);
1882
- const nextPermalink = serializePermalink(query || queryItem);
1882
+ const q = query != null ? query : queryItem;
1883
+ const nextPermalink = serializePermalink(q);
1883
1884
  if (currPermalink !== nextPermalink) {
1884
1885
  navigate(`?${nextPermalink}`, { replace: true });
1885
1886
  }
@@ -2153,61 +2154,6 @@ function useAsync(initialState4) {
2153
2154
  };
2154
2155
  }
2155
2156
 
2156
- // src/components/Select.tsx
2157
- init_esm_shims();
2158
- var SelectObject = forwardRef(function(props, ref) {
2159
- var _a;
2160
- const {
2161
- getLabel,
2162
- getValue = identity,
2163
- items,
2164
- onItemSelect,
2165
- selectedItem,
2166
- selectProps = {}
2167
- } = props;
2168
- const [itemList, itemMap] = useMemo(() => {
2169
- const valueAccessor = accesorFactory(getValue);
2170
- const labelAccessor = getLabel ? accesorFactory(getLabel) : valueAccessor;
2171
- const list = items.map((item) => ({
2172
- label: labelAccessor(item),
2173
- value: valueAccessor(item),
2174
- item
2175
- }));
2176
- return [list, keyBy(list, (option) => option.value)];
2177
- }, [items, getLabel, getValue]);
2178
- const selected = useMemo(() => {
2179
- if (selectedItem == null) return null;
2180
- if (typeof selectedItem === "string") return selectedItem;
2181
- const valueAccessor = accesorFactory(getValue);
2182
- return valueAccessor(selectedItem);
2183
- }, [selectedItem, getValue]);
2184
- const itemSelectHandler = (value) => {
2185
- onItemSelect && onItemSelect(itemMap[value].item);
2186
- };
2187
- if (items.length === 0 || !selected) {
2188
- return null;
2189
- }
2190
- return /* @__PURE__ */ React13__default.createElement(
2191
- Select,
2192
- {
2193
- ref,
2194
- data: itemList,
2195
- disabled: props.loading || props.disabled,
2196
- hidden: props.hidden,
2197
- label: props.label,
2198
- onChange: itemSelectHandler,
2199
- onClick: inputFocusHandler,
2200
- onFocus: inputFocusHandler,
2201
- searchable: (_a = props.searchable) != null ? _a : props.items.length > 6,
2202
- value: selected,
2203
- ...selectProps
2204
- }
2205
- );
2206
- });
2207
- function inputFocusHandler(event) {
2208
- if (event.target instanceof HTMLInputElement) event.target.select();
2209
- }
2210
-
2211
2157
  // src/components/CubeSource.tsx
2212
2158
  init_esm_shims();
2213
2159
 
@@ -2420,6 +2366,61 @@ function CubeSource() {
2420
2366
 
2421
2367
  // src/components/LocaleSelector.tsx
2422
2368
  init_esm_shims();
2369
+
2370
+ // src/components/Select.tsx
2371
+ init_esm_shims();
2372
+ var SelectObject = forwardRef(function(props, ref) {
2373
+ var _a;
2374
+ const {
2375
+ getLabel,
2376
+ getValue = identity,
2377
+ items,
2378
+ onItemSelect,
2379
+ selectedItem,
2380
+ selectProps = {}
2381
+ } = props;
2382
+ const [itemList, itemMap] = useMemo(() => {
2383
+ const valueAccessor = accesorFactory(getValue);
2384
+ const labelAccessor = getLabel ? accesorFactory(getLabel) : valueAccessor;
2385
+ const list = items.map((item) => ({
2386
+ label: labelAccessor(item),
2387
+ value: valueAccessor(item),
2388
+ item
2389
+ }));
2390
+ return [list, keyBy(list, (option) => option.value)];
2391
+ }, [items, getLabel, getValue]);
2392
+ const selected = useMemo(() => {
2393
+ if (selectedItem == null) return null;
2394
+ if (typeof selectedItem === "string") return selectedItem;
2395
+ const valueAccessor = accesorFactory(getValue);
2396
+ return valueAccessor(selectedItem);
2397
+ }, [selectedItem, getValue]);
2398
+ const itemSelectHandler = (value) => {
2399
+ onItemSelect && onItemSelect(itemMap[value].item);
2400
+ };
2401
+ if (items.length === 0 || !selected) {
2402
+ return null;
2403
+ }
2404
+ return /* @__PURE__ */ React13__default.createElement(
2405
+ Select,
2406
+ {
2407
+ ref,
2408
+ data: itemList,
2409
+ disabled: props.loading || props.disabled,
2410
+ hidden: props.hidden,
2411
+ label: props.label,
2412
+ onChange: itemSelectHandler,
2413
+ onClick: inputFocusHandler,
2414
+ onFocus: inputFocusHandler,
2415
+ searchable: (_a = props.searchable) != null ? _a : props.items.length > 6,
2416
+ value: selected,
2417
+ ...selectProps
2418
+ }
2419
+ );
2420
+ });
2421
+ function inputFocusHandler(event) {
2422
+ if (event.target instanceof HTMLInputElement) event.target.select();
2423
+ }
2423
2424
  var localeSelectorStyle = (theme) => ({
2424
2425
  input: {
2425
2426
  border: "none",
@@ -2506,10 +2507,12 @@ var formatter = new Intl.NumberFormat("en-US", {
2506
2507
  });
2507
2508
  function TableFooter(props) {
2508
2509
  const { paginationConfig } = useSettings();
2509
- const { table, data = [], isLoading, pagination, setPagination, url } = props;
2510
+ const { table, data = [], isLoading, pagination, url } = props;
2510
2511
  const { translate: t } = useTranslation();
2511
2512
  const { copy, copied } = useClipboard({ timeout: 1e3 });
2512
2513
  const copyHandler = useCallback(() => copy(url), [url]);
2514
+ const updateURL = useUpdateUrl();
2515
+ const queryItem = useSelector(selectCurrentQueryItem);
2513
2516
  const totalRowCount = table.options.rowCount;
2514
2517
  const {
2515
2518
  pagination: { pageSize }
@@ -2525,22 +2528,19 @@ function TableFooter(props) {
2525
2528
  },
2526
2529
  [paginationConfig == null ? void 0 : paginationConfig.rowsLimits]
2527
2530
  );
2528
- const selectedItem = useMemo(
2529
- () => items.find((item) => Number(item.value) === pageSize),
2530
- [items, pageSize]
2531
- );
2532
2531
  const onItemSelect = useCallback(
2533
2532
  (item) => {
2534
2533
  const newPageSize = Number(item.value);
2535
- if (setPagination) {
2536
- setPagination({
2537
- ...pagination,
2538
- pageSize: newPageSize,
2539
- pageIndex: 0
2540
- });
2541
- }
2534
+ updateURL({
2535
+ ...queryItem,
2536
+ params: {
2537
+ ...queryItem.params,
2538
+ pagiOffset: 0,
2539
+ pagiLimit: newPageSize
2540
+ }
2541
+ });
2542
2542
  },
2543
- [pagination, setPagination]
2543
+ [pagination]
2544
2544
  );
2545
2545
  return /* @__PURE__ */ React13__default.createElement(Box, { w: "100%", sx: { flex: "0 0 70px" } }, /* @__PURE__ */ React13__default.createElement(
2546
2546
  Flex,
@@ -2553,13 +2553,14 @@ function TableFooter(props) {
2553
2553
  },
2554
2554
  /* @__PURE__ */ React13__default.createElement(CubeSource, null),
2555
2555
  !isLoading && /* @__PURE__ */ React13__default.createElement(Group, { position: "right", spacing: "sm" }, /* @__PURE__ */ React13__default.createElement(LocaleSelector, null), /* @__PURE__ */ React13__default.createElement(Box, { maw: "7rem", miw: "fit" }, /* @__PURE__ */ React13__default.createElement(
2556
- SelectObject,
2556
+ Select,
2557
2557
  {
2558
- getValue: (item) => item.value,
2559
- getLabel: (item) => item.label,
2560
- items,
2561
- selectedItem,
2562
- onItemSelect
2558
+ data: items,
2559
+ defaultValue: String(queryItem.params.pagiLimit),
2560
+ onChange: (value) => {
2561
+ const item = items.find((i) => i.value === value);
2562
+ if (item) onItemSelect(item);
2563
+ }
2563
2564
  }
2564
2565
  )), totalRowCount && /* @__PURE__ */ React13__default.createElement(Text, { c: "dimmed" }, t("results.count_rows_plural", { n: formatter.format(totalRowCount) })), showPagination && /* @__PURE__ */ React13__default.createElement(MRT_TablePagination, { table }), /* @__PURE__ */ React13__default.createElement(ApiAndCsvButtons, { copied, copyHandler, url, data }))
2565
2566
  ));
@@ -3042,13 +3043,12 @@ function useTable({
3042
3043
  const { limit, offset } = useSelector$1(selectPaginationParams);
3043
3044
  const queryItem = useSelector$1(selectCurrentQueryItem);
3044
3045
  const updateURL = useUpdateUrl();
3045
- const [pagination, setPagination] = useState({
3046
+ const pagination = {
3046
3047
  pageIndex: Math.floor(offset / (limit || 1)),
3047
3048
  pageSize: limit
3048
- });
3049
+ };
3049
3050
  const handlePaginationChange = (updatedPagination) => {
3050
3051
  const paginationUpdated = updatedPagination(pagination);
3051
- setPagination(updatedPagination);
3052
3052
  actions2.updatePagination({
3053
3053
  limit: paginationUpdated.pageSize,
3054
3054
  offset: paginationUpdated.pageIndex * paginationUpdated.pageSize
@@ -3268,7 +3268,6 @@ function useTable({
3268
3268
  showRowsPerPage: false
3269
3269
  },
3270
3270
  paginationDisplayMode: "pages",
3271
- enableRowVirtualization: false,
3272
3271
  globalFilterFn: "contains",
3273
3272
  initialState: {
3274
3273
  density: "xs"
@@ -3354,8 +3353,7 @@ function useTable({
3354
3353
  isFetching,
3355
3354
  data: tableData,
3356
3355
  columns,
3357
- pagination,
3358
- setPagination: handlePaginationChange
3356
+ pagination
3359
3357
  };
3360
3358
  }
3361
3359
  function TableView({
@@ -3731,7 +3729,7 @@ function LevelItem({
3731
3729
  const actions2 = useActions();
3732
3730
  const cutItems = useSelector$1(selectCutItems);
3733
3731
  let drilldowns = useSelector$1(selectDrilldownMap);
3734
- const ditems = useSelector$1(selectDrilldownItems);
3732
+ useSelector$1(selectDrilldownItems);
3735
3733
  const { idFormatters } = useidFormatters();
3736
3734
  const label = useMemo(() => {
3737
3735
  const captions = [
@@ -3749,49 +3747,28 @@ function LevelItem({
3749
3747
  level: captions[2]
3750
3748
  });
3751
3749
  }, [locale, dimension, hierarchy, level, isSubMenu, t]);
3752
- const createCutHandler = useCallback((level2) => {
3753
- const cutItem = buildCut({ ...level2, members: [], active: false });
3754
- actions2.updateCut(cutItem);
3755
- }, []);
3756
- function createDrilldown(level2, cuts) {
3757
- const drilldown = buildDrilldown({ ...level2, key: level2.name, active: false });
3758
- actions2.updateDrilldown(drilldown);
3759
- const cut2 = cuts.find((cut3) => cut3.level === drilldown.level);
3760
- if (!cut2) {
3761
- createCutHandler(level2);
3762
- }
3763
- return drilldown;
3764
- }
3765
3750
  const currentDrilldown = drilldowns[level.name];
3766
3751
  const isOtherHierarchySelected = activeItems.some(
3767
3752
  (activeItem) => activeItem.dimension === dimension.name && activeItem.hierarchy !== hierarchy.name
3768
3753
  );
3769
- useLayoutEffect(() => {
3770
- if (!drilldowns[level.name] && !ditems.find((d) => d.level === level.name)) {
3771
- createDrilldown(level, cutItems);
3772
- }
3773
- }, [level, ditems]);
3774
3754
  const cut = cutItems.find((cut2) => {
3775
3755
  return cut2.level === (currentDrilldown == null ? void 0 : currentDrilldown.level);
3776
3756
  });
3777
- const updatecutHandler = React13__default.useCallback((item, members) => {
3757
+ const updatecutHandler = (item, members) => {
3778
3758
  actions2.updateCut({ ...item, members });
3779
- }, []);
3759
+ };
3760
+ console.log(isOtherHierarchySelected, "isOtherHierarchySelected");
3780
3761
  const checked = activeItems.map((i) => i.level).includes(level.name);
3781
3762
  const disableUncheck = activeItems.length === 1 && checked;
3782
3763
  const isDisabled = isOtherHierarchySelected && !checked;
3783
3764
  if (!currentDrilldown) return;
3784
3765
  const paddingLeft = `${5 * depth + 5}px`;
3785
- const properities = currentDrilldown.properties.length ? currentDrilldown.properties : null;
3766
+ const properties = currentDrilldown.properties.length ? currentDrilldown.properties : null;
3786
3767
  return currentDrilldown && /* @__PURE__ */ React13__default.createElement(React13__default.Fragment, null, /* @__PURE__ */ React13__default.createElement(Group, { className: "dex-level-control", mt: "sm", position: "apart", key: level.name, noWrap: true }, /* @__PURE__ */ React13__default.createElement(
3787
3768
  Checkbox,
3788
3769
  {
3789
3770
  sx: { cursor: "pointer", paddingLeft },
3790
3771
  onChange: () => {
3791
- if (cut) {
3792
- const active = checked ? false : !!cut.members.length;
3793
- actions2.updateCut({ ...cut, active });
3794
- }
3795
3772
  actions2.updateDrilldown({
3796
3773
  ...currentDrilldown,
3797
3774
  active: !currentDrilldown.active
@@ -3811,7 +3788,7 @@ function LevelItem({
3811
3788
  disabled: isDisabled
3812
3789
  },
3813
3790
  activeFilter ? /* @__PURE__ */ React13__default.createElement(IconFilterOff, null) : /* @__PURE__ */ React13__default.createElement(IconFilter, null)
3814
- ), properities && /* @__PURE__ */ React13__default.createElement(Tooltip, { label: t("params.add_metadata") }, /* @__PURE__ */ React13__default.createElement(ActionIcon, { onClick: () => setActiveProperties((value) => !value) }, /* @__PURE__ */ React13__default.createElement(IconAdjustments, null))), /* @__PURE__ */ React13__default.createElement(ThemeIcon, { size: "xs", color: "gray", variant: "light", bg: "transparent" }, /* @__PURE__ */ React13__default.createElement(StackSVG, null)))), activeFilter && /* @__PURE__ */ React13__default.createElement(Box, { pt: "md" }, /* @__PURE__ */ React13__default.createElement(
3791
+ ), properties && /* @__PURE__ */ React13__default.createElement(Tooltip, { label: t("params.add_metadata") }, /* @__PURE__ */ React13__default.createElement(ActionIcon, { onClick: () => setActiveProperties((value) => !value) }, /* @__PURE__ */ React13__default.createElement(IconAdjustments, null))), /* @__PURE__ */ React13__default.createElement(ThemeIcon, { size: "xs", color: "gray", variant: "light", bg: "transparent" }, /* @__PURE__ */ React13__default.createElement(StackSVG, null)))), activeFilter && /* @__PURE__ */ React13__default.createElement(Box, { pt: "md" }, /* @__PURE__ */ React13__default.createElement(
3815
3792
  MultiSelect,
3816
3793
  {
3817
3794
  sx: { flex: "1 1 100%" },
@@ -4272,8 +4249,13 @@ function QueryProvider({ children, defaultCube }) {
4272
4249
  const { tesseract } = useLogicLayer();
4273
4250
  const location2 = useLocation();
4274
4251
  const { updateCurrentQuery } = useActions();
4275
- const { paginationConfig, measuresActive, serverURL, defaultLocale } = useSettings();
4276
- const { data: schema, isLoading: schemaLoading, isError: schemaError } = useServerSchema();
4252
+ const { measuresActive, serverURL, defaultLocale } = useSettings();
4253
+ const {
4254
+ data: schema,
4255
+ isLoading: schemaLoading,
4256
+ isFetching: schemaFetching,
4257
+ isError: schemaError
4258
+ } = useServerSchema();
4277
4259
  const updateUrl = useUpdateUrl();
4278
4260
  const queryItem = useSelector$1(selectCurrentQueryItem);
4279
4261
  const prevLocaleRef = useRef();
@@ -4294,7 +4276,7 @@ function QueryProvider({ children, defaultCube }) {
4294
4276
  const searchParams = new URLSearchParams(location2.search);
4295
4277
  const cube = searchParams.get("cube");
4296
4278
  const cubeMap = (schema == null ? void 0 : schema.cubeMap) || void 0;
4297
- if (cube && cubeMap && serverURL && cubeMap[cube] && (schema == null ? void 0 : schema.online)) {
4279
+ if (cube && cubeMap && serverURL && cubeMap[cube] && (schema == null ? void 0 : schema.online) && !schemaFetching) {
4298
4280
  let newQuery = parsePermalink(cubeMap[cube], searchParams);
4299
4281
  newQuery = isValidQuery(newQuery == null ? void 0 : newQuery.params) ? newQuery : buildQuery({ params: { cube } });
4300
4282
  newQuery.params.locale = defaultLocale || newQuery.params.locale;
@@ -4321,7 +4303,8 @@ function QueryProvider({ children, defaultCube }) {
4321
4303
  key: lvl.name,
4322
4304
  dimension: dimensions[name4],
4323
4305
  hierarchy: hierarchies[name4],
4324
- level: name4
4306
+ level: name4,
4307
+ properties: lvl.properties.map((prop) => buildProperty({ level: lvl.name, name: prop.name }))
4325
4308
  });
4326
4309
  });
4327
4310
  if (newQuery) {
@@ -4329,7 +4312,7 @@ function QueryProvider({ children, defaultCube }) {
4329
4312
  (dd) => {
4330
4313
  const currentDrilldown = queryItem.params.drilldowns[dd.key];
4331
4314
  const localeChanged = prevLocaleRef.current !== (newQuery == null ? void 0 : newQuery.params.locale);
4332
- if (currentDrilldown && currentDrilldown.members && currentDrilldown.members.length > 0 && !localeChanged) {
4315
+ if (currentDrilldown && currentDrilldown.members && currentDrilldown.members.length > 0 && !localeChanged && cube === queryItem.params.cube) {
4333
4316
  return Promise.resolve({
4334
4317
  drilldown: currentDrilldown,
4335
4318
  cut: buildCut({ ...currentDrilldown, active: false })
@@ -4371,7 +4354,15 @@ function QueryProvider({ children, defaultCube }) {
4371
4354
  const cubeDefault = defaultCube && hasProperty(cubeMap, defaultCube) ? defaultCube : Object.keys(cubeMap)[0];
4372
4355
  setDefaultValues(cubeMap[cubeDefault]);
4373
4356
  }
4374
- }, [location2.search, runFetchMembers, schema, schemaLoading, serverURL, defaultLocale]);
4357
+ }, [
4358
+ location2.search,
4359
+ runFetchMembers,
4360
+ schema,
4361
+ schemaLoading,
4362
+ schemaFetching,
4363
+ serverURL,
4364
+ defaultLocale
4365
+ ]);
4375
4366
  const onChangeCube = (table, subtopic) => {
4376
4367
  const locale = defaultLocale || queryItem.params.locale;
4377
4368
  const cubeMap = (schema == null ? void 0 : schema.cubeMap) || {};
@@ -4416,18 +4407,16 @@ function QueryProvider({ children, defaultCube }) {
4416
4407
  });
4417
4408
  updateUrl(query);
4418
4409
  }
4419
- return /* @__PURE__ */ React13__default.createElement(
4420
- QueryContext.Provider,
4421
- {
4422
- value: {
4423
- onChangeCube,
4424
- schemaLoading,
4425
- membersLoading,
4426
- transintionLocaleLoading
4427
- }
4428
- },
4429
- children
4410
+ const contextValue = React13__default.useMemo(
4411
+ () => ({
4412
+ onChangeCube,
4413
+ schemaLoading,
4414
+ membersLoading,
4415
+ transintionLocaleLoading
4416
+ }),
4417
+ [onChangeCube, schemaLoading, membersLoading, transintionLocaleLoading]
4430
4418
  );
4419
+ return /* @__PURE__ */ React13__default.createElement(QueryContext.Provider, { value: contextValue }, children);
4431
4420
  }
4432
4421
  function useQueryItem() {
4433
4422
  const context = useContext(QueryContext);
@@ -4545,7 +4534,7 @@ function SuccessResult(props) {
4545
4534
  actions2.switchPanel(newTab);
4546
4535
  updateUrl({ ...queryItem, panel: newTab });
4547
4536
  };
4548
- const { table, isError, isLoading, data, columns, result, pagination, isFetching, setPagination } = useTable({
4537
+ const { table, isError, isLoading, data, columns, result, pagination, isFetching } = useTable({
4549
4538
  cube
4550
4539
  });
4551
4540
  if ((data == null ? void 0 : data.length) === 0 && !isLoading && !isError) {
@@ -4611,7 +4600,6 @@ function SuccessResult(props) {
4611
4600
  isLoading,
4612
4601
  columns,
4613
4602
  pagination,
4614
- setPagination,
4615
4603
  isFetching
4616
4604
  }
4617
4605
  ))))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datawheel/data-explorer",
3
- "version": "1.0.18",
3
+ "version": "1.0.19",
4
4
  "main": "./dist/main.mjs",
5
5
  "types": "./dist/main.d.mts",
6
6
  "files": [