@datawheel/data-explorer 1.1.15 → 1.1.16

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
@@ -1102,6 +1102,13 @@ declare function ExplorerComponent<Locale extends string>(props: {
1102
1102
  * @default "en"
1103
1103
  */
1104
1104
  defaultLocale?: Locale;
1105
+ /**
1106
+ * The locale to use for sorting cube items within the SelectCubes component.
1107
+ * This controls the sorting of subtopics and cube buttons.
1108
+ * If not set, the defaultLocale will be used.
1109
+ * @default undefined
1110
+ */
1111
+ sortLocale?: string;
1105
1112
  /**
1106
1113
  * Specifies which property should be used to filter elements in the member
1107
1114
  * selection control of the Cuts parameter area.
package/dist/main.mjs CHANGED
@@ -5468,14 +5468,20 @@ function SuccessResult(props) {
5468
5468
  );
5469
5469
  }
5470
5470
  function Results(props) {
5471
- const { graph, selectedItem, locale, getCube: getCube2, isSelected: isSelected2 } = props;
5471
+ const { graph, selectedItem, locale, sortLocale, getCube: getCube2, isSelected: isSelected2 } = props;
5472
5472
  const { classes } = useStyles4();
5473
5473
  const { setExpanded, setInput, map } = useSideBar();
5474
5474
  const { onChangeCube } = useQueryItem();
5475
5475
  const results = [...map].flatMap((entry) => {
5476
5476
  const [key, items] = entry;
5477
5477
  const [topic, subtopic] = key.split(" - ");
5478
- const topicResults = items.map((item) => {
5478
+ const topicResults = [...items].sort((a, b) => {
5479
+ const cubeA = getCube2(graph.items, a, subtopic, locale);
5480
+ const cubeB = getCube2(graph.items, b, subtopic, locale);
5481
+ const aSort = cubeA ? getAnnotation(cubeA, "table", sortLocale) || a : a;
5482
+ const bSort = cubeB ? getAnnotation(cubeB, "table", sortLocale) || b : b;
5483
+ return aSort.localeCompare(bSort, sortLocale, { sensitivity: "base" });
5484
+ }).map((item) => {
5479
5485
  const cube = getCube2(graph.items, item, subtopic, locale);
5480
5486
  if (!cube) return null;
5481
5487
  const table = getAnnotation(cube, "table", locale);
@@ -5539,7 +5545,7 @@ var useStyles4 = createStyles((t) => ({
5539
5545
  var loadingCubes = Array.from({ length: 10 }, (v, index) => ({
5540
5546
  id: `loading-cube-${index}`
5541
5547
  }));
5542
- function SelectCubes({ locale }) {
5548
+ function SelectCubes({ locale, sortLocale }) {
5543
5549
  const items = useCubeItems();
5544
5550
  const selectedItem = useSelectedItem();
5545
5551
  const { schemaLoading } = useQueryItem();
@@ -5549,11 +5555,27 @@ function SelectCubes({ locale }) {
5549
5555
  if (items.length === 1) {
5550
5556
  return null;
5551
5557
  }
5552
- return /* @__PURE__ */ React21__default.createElement(SelectCubeInternal, { items, selectedItem, locale });
5558
+ return /* @__PURE__ */ React21__default.createElement(
5559
+ SelectCubeInternal,
5560
+ {
5561
+ items,
5562
+ selectedItem,
5563
+ locale,
5564
+ sortLocale: sortLocale || locale
5565
+ }
5566
+ );
5553
5567
  }
5554
5568
  function SelectCubeInternal(props) {
5555
- const { items, selectedItem, locale } = props;
5556
- return /* @__PURE__ */ React21__default.createElement(Stack, { id: "dex-select-cube", spacing: "xs", w: "100%" }, /* @__PURE__ */ React21__default.createElement(CubeTree, { items, locale, selectedItem }));
5569
+ const { items, selectedItem, locale, sortLocale } = props;
5570
+ return /* @__PURE__ */ React21__default.createElement(Stack, { id: "dex-select-cube", spacing: "xs", w: "100%" }, /* @__PURE__ */ React21__default.createElement(
5571
+ CubeTree,
5572
+ {
5573
+ items,
5574
+ locale,
5575
+ selectedItem,
5576
+ sortLocale
5577
+ }
5578
+ ));
5557
5579
  }
5558
5580
  function AccordionControl(props) {
5559
5581
  return /* @__PURE__ */ React21__default.createElement(Box, { sx: { display: "flex", alignItems: "center" } }, /* @__PURE__ */ React21__default.createElement(Accordion.Control, { ...props }));
@@ -5571,19 +5593,22 @@ function getKeys2(items, k, locale, filter) {
5571
5593
  return Array.from(keys);
5572
5594
  }
5573
5595
  function isSelected(selectedItem, currentItem) {
5574
- if (selectedItem && currentItem) {
5596
+ if (selectedItem && currentItem && selectedItem.name && currentItem.name) {
5575
5597
  return selectedItem.name === currentItem.name;
5576
5598
  }
5599
+ return false;
5577
5600
  }
5578
5601
  function getCube(items, name4, subtopic, locale) {
5602
+ if (!Array.isArray(items)) return void 0;
5579
5603
  const cube = items.find(
5580
- (item) => item.name === name4 && getAnnotation(item, "subtopic", locale) === subtopic
5604
+ (item) => item && item.name === name4 && getAnnotation(item, "subtopic", locale) === subtopic
5581
5605
  );
5582
5606
  return cube;
5583
5607
  }
5584
5608
  function CubeTree({
5585
5609
  locale,
5586
- selectedItem
5610
+ selectedItem,
5611
+ sortLocale
5587
5612
  }) {
5588
5613
  const { map, input, graph } = useSideBar();
5589
5614
  const { translate: t } = useTranslation();
@@ -5591,6 +5616,10 @@ function CubeTree({
5591
5616
  () => getKeys2(graph.items, "topic", locale),
5592
5617
  [graph.items, locale]
5593
5618
  );
5619
+ const sortTopics = useMemo(
5620
+ () => getKeys2(graph.items, "topic", sortLocale),
5621
+ [graph.items, sortLocale]
5622
+ );
5594
5623
  if (input.length > 0 && map && !(map.size > 0)) {
5595
5624
  return /* @__PURE__ */ React21__default.createElement(Text, { ta: "center", fz: "xs", my: "sm", italic: true }, t("params.label_no_results"));
5596
5625
  }
@@ -5601,9 +5630,20 @@ function CubeTree({
5601
5630
  getCube,
5602
5631
  isSelected,
5603
5632
  graph,
5604
- locale
5633
+ locale,
5634
+ sortLocale
5605
5635
  }
5606
- ) : graph.items.length > 0 && /* @__PURE__ */ React21__default.createElement(RootAccordions, { items: topics, graph, selectedItem, locale });
5636
+ ) : graph.items.length > 0 && /* @__PURE__ */ React21__default.createElement(
5637
+ RootAccordions,
5638
+ {
5639
+ items: topics,
5640
+ sortItems: sortTopics,
5641
+ graph,
5642
+ selectedItem,
5643
+ locale,
5644
+ sortLocale
5645
+ }
5646
+ );
5607
5647
  }
5608
5648
  function useAccordionValue(key, locale) {
5609
5649
  const selectedItem = useSelectedItem();
@@ -5616,7 +5656,7 @@ function useAccordionValue(key, locale) {
5616
5656
  }, [key, selectedItem, locale]);
5617
5657
  return { value, setValue };
5618
5658
  }
5619
- function RootAccordions({ items, graph, locale, selectedItem }) {
5659
+ function RootAccordions({ items, sortItems, graph, locale, selectedItem, sortLocale }) {
5620
5660
  const { value, setValue } = useAccordionValue("topic", locale);
5621
5661
  return /* @__PURE__ */ React21__default.createElement(
5622
5662
  Accordion,
@@ -5649,14 +5689,19 @@ function RootAccordions({ items, graph, locale, selectedItem }) {
5649
5689
  })
5650
5690
  },
5651
5691
  items.sort((a, b) => graph.topicOrder[a] - graph.topicOrder[b]).map((item) => {
5692
+ const sortItem = sortItems.find(
5693
+ (topic) => graph.topicOrder[topic] === graph.topicOrder[item]
5694
+ ) || item;
5652
5695
  return /* @__PURE__ */ React21__default.createElement(Accordion.Item, { value: `topic-${item}`, key: `topic-${item}` }, /* @__PURE__ */ React21__default.createElement(AccordionControl, null, item), /* @__PURE__ */ React21__default.createElement(Accordion.Panel, null, /* @__PURE__ */ React21__default.createElement(
5653
5696
  SubtopicAccordion,
5654
5697
  {
5655
5698
  graph,
5656
5699
  parent: item,
5700
+ sortParent: sortItem,
5657
5701
  items: graph.adjList[item],
5658
5702
  key: item,
5659
5703
  locale,
5704
+ sortLocale,
5660
5705
  selectedItem
5661
5706
  }
5662
5707
  )));
@@ -5668,12 +5713,13 @@ function CubeButton({
5668
5713
  selectedItem,
5669
5714
  graph,
5670
5715
  locale,
5716
+ sortLocale,
5671
5717
  parent
5672
5718
  }) {
5673
5719
  const { onChangeCube, membersLoading, schemaLoading } = useQueryItem();
5674
5720
  const { classes } = useStyles4();
5675
5721
  const isSelectionInProgress = membersLoading || schemaLoading;
5676
- const table = graph.getName(item, locale);
5722
+ const table = graph.getName ? graph.getName(item, locale) : item;
5677
5723
  const subtopic = parent != null ? parent : "";
5678
5724
  const handleClick = () => {
5679
5725
  onChangeCube(item, subtopic);
@@ -5706,8 +5752,10 @@ function SubtopicAccordion({
5706
5752
  items,
5707
5753
  graph,
5708
5754
  parent,
5755
+ sortParent,
5709
5756
  selectedItem,
5710
- locale
5757
+ locale,
5758
+ sortLocale
5711
5759
  }) {
5712
5760
  const { value, setValue } = useAccordionValue("subtopic", locale);
5713
5761
  return /* @__PURE__ */ React21__default.createElement(
@@ -5736,8 +5784,42 @@ function SubtopicAccordion({
5736
5784
  }
5737
5785
  })
5738
5786
  },
5739
- [...items].sort((a, b) => a.localeCompare(b, locale, { sensitivity: "base" })).map((item, index) => {
5740
- const filtered = [...graph.adjList[item]].filter((value2) => value2 !== parent);
5787
+ [...items].sort((a, b) => {
5788
+ const aLabel = graph.items.find(
5789
+ (cube) => getAnnotation(cube, "topic", locale) === parent && getAnnotation(cube, "subtopic", locale) === a
5790
+ );
5791
+ const bLabel = graph.items.find(
5792
+ (cube) => getAnnotation(cube, "topic", locale) === parent && getAnnotation(cube, "subtopic", locale) === b
5793
+ );
5794
+ const aSort = aLabel ? getAnnotation(aLabel, "subtopic", sortLocale) || a : a;
5795
+ const bSort = bLabel ? getAnnotation(bLabel, "subtopic", sortLocale) || b : b;
5796
+ return aSort.localeCompare(bSort, sortLocale, { sensitivity: "base" });
5797
+ }).map((item, index) => {
5798
+ let sortSubtopic = item;
5799
+ if (sortParent && item) {
5800
+ const hasCubeInLocale = graph.items.some(
5801
+ (cube) => getAnnotation(cube, "topic", locale) === parent && getAnnotation(cube, "subtopic", locale) === item
5802
+ );
5803
+ if (hasCubeInLocale) {
5804
+ const matchingCube = graph.items.find(
5805
+ (cube) => getAnnotation(cube, "topic", sortLocale) === sortParent && getAnnotation(cube, "subtopic", locale) === item
5806
+ );
5807
+ if (matchingCube) {
5808
+ const annotatedSubtopic = getAnnotation(matchingCube, "subtopic", sortLocale);
5809
+ if (annotatedSubtopic) {
5810
+ sortSubtopic = annotatedSubtopic;
5811
+ }
5812
+ }
5813
+ }
5814
+ }
5815
+ const adjListItem = graph.adjList[sortSubtopic];
5816
+ const filtered = adjListItem ? [...adjListItem].filter((value2) => value2 !== parent).sort((a, b) => {
5817
+ const aLabel = graph.items.find((cube) => cube && cube.name === a);
5818
+ const bLabel = graph.items.find((cube) => cube && cube.name === b);
5819
+ const aSort = aLabel ? getAnnotation(aLabel, "table", sortLocale) || a : a;
5820
+ const bSort = bLabel ? getAnnotation(bLabel, "table", sortLocale) || b : b;
5821
+ return aSort.localeCompare(bSort, sortLocale, { sensitivity: "base" });
5822
+ }) : [];
5741
5823
  return /* @__PURE__ */ React21__default.createElement(Accordion.Item, { value: `subtopic-${item}`, key: `subtopic-${item}-${index}` }, /* @__PURE__ */ React21__default.createElement(AccordionControl, null, item), /* @__PURE__ */ React21__default.createElement(Accordion.Panel, null, filtered.map((table, index2) => /* @__PURE__ */ React21__default.createElement(
5742
5824
  CubeButton,
5743
5825
  {
@@ -5745,6 +5827,7 @@ function SubtopicAccordion({
5745
5827
  graph,
5746
5828
  item: table,
5747
5829
  locale,
5830
+ sortLocale,
5748
5831
  selectedItem,
5749
5832
  parent: item
5750
5833
  }
@@ -5788,7 +5871,7 @@ function ExplorerContent(props) {
5788
5871
  const SplashComponent = props.splash;
5789
5872
  return SplashComponent ? /* @__PURE__ */ React21__default.createElement(SplashComponent, { translation }) : /* @__PURE__ */ React21__default.createElement(Center, { h: "100%", sx: { flex: 1 } }, /* @__PURE__ */ React21__default.createElement(AnimatedCube, null));
5790
5873
  }, [props.splash, translation]);
5791
- return /* @__PURE__ */ React21__default.createElement("div", { className: classes.container }, /* @__PURE__ */ React21__default.createElement("div", { className: classes.root }, /* @__PURE__ */ React21__default.createElement(SideBarProvider, { locale: defaultLocale }, /* @__PURE__ */ React21__default.createElement(SideBar_default, null, /* @__PURE__ */ React21__default.createElement(SideBarItem, null, /* @__PURE__ */ React21__default.createElement(SelectCubes, { locale: defaultLocale }))), /* @__PURE__ */ React21__default.createElement(
5874
+ return /* @__PURE__ */ React21__default.createElement("div", { className: classes.container }, /* @__PURE__ */ React21__default.createElement("div", { className: classes.root }, /* @__PURE__ */ React21__default.createElement(SideBarProvider, { locale: defaultLocale }, /* @__PURE__ */ React21__default.createElement(SideBar_default, null, /* @__PURE__ */ React21__default.createElement(SideBarItem, null, /* @__PURE__ */ React21__default.createElement(SelectCubes, { locale: defaultLocale, sortLocale: props.sortLocale || defaultLocale }))), /* @__PURE__ */ React21__default.createElement(
5792
5875
  ExplorerResults,
5793
5876
  {
5794
5877
  className: classes.flexCol,
@@ -6761,6 +6844,7 @@ function ExplorerComponent(props) {
6761
6844
  var _a;
6762
6845
  const {
6763
6846
  defaultLocale = "en",
6847
+ sortLocale,
6764
6848
  defaultOpenParams = "measures",
6765
6849
  height = "100vh",
6766
6850
  withinMantineProvider = true,
@@ -6823,7 +6907,8 @@ function ExplorerComponent(props) {
6823
6907
  serverConfig: props.serverConfig,
6824
6908
  serverURL: props.serverURL,
6825
6909
  splash: props.splash,
6826
- withMultiQuery
6910
+ withMultiQuery,
6911
+ sortLocale
6827
6912
  }
6828
6913
  ))))
6829
6914
  ));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datawheel/data-explorer",
3
- "version": "1.1.15",
3
+ "version": "1.1.16",
4
4
  "main": "./dist/main.mjs",
5
5
  "types": "./dist/main.d.mts",
6
6
  "files": [