@datawheel/data-explorer 1.1.8 → 1.1.10

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.
Files changed (2) hide show
  1. package/dist/main.mjs +43 -1
  2. package/package.json +1 -1
package/dist/main.mjs CHANGED
@@ -1848,16 +1848,58 @@ var useDimensionItems = () => {
1848
1848
  (a, b) => getOrderValue(a.item) - getOrderValue(b.item) || b.count - a.count || a.alpha.localeCompare(b.alpha)
1849
1849
  ).map((i) => i.item);
1850
1850
  };
1851
+ function getISO3Drilldowns({ cube, search }) {
1852
+ const ISO_3_CODE = "ISO 3";
1853
+ if (!cube) return false;
1854
+ function getList(search2, key, separator) {
1855
+ return search2.getAll(key).join(separator).split(separator).filter((token) => token);
1856
+ }
1857
+ const dimensions = {};
1858
+ const hierarchies = {};
1859
+ const levels = Object.fromEntries(
1860
+ cube.dimensions.flatMap(
1861
+ (dim) => dim.hierarchies.flatMap(
1862
+ (hie) => hie.levels.map((lvl) => {
1863
+ dimensions[lvl.name] = dim.name;
1864
+ hierarchies[lvl.name] = hie.name;
1865
+ return [lvl.name, lvl];
1866
+ })
1867
+ )
1868
+ )
1869
+ );
1870
+ const properties = [ISO_3_CODE];
1871
+ const drilldowns = getList(search, "drilldowns", ",").map((name4) => {
1872
+ const lvl = levels[name4];
1873
+ return buildDrilldown({
1874
+ active: true,
1875
+ key: lvl.name,
1876
+ dimension: dimensions[name4],
1877
+ hierarchy: hierarchies[name4],
1878
+ level: name4,
1879
+ properties: filterMap(
1880
+ lvl.properties,
1881
+ (prop) => properties.includes(prop.name) ? buildProperty({ name: prop.name, level: name4, active: true }) : null
1882
+ )
1883
+ });
1884
+ });
1885
+ return keyBy(drilldowns, "key");
1886
+ }
1851
1887
  function useDownloadQuery() {
1852
1888
  const { tesseract } = useLogicLayer();
1853
1889
  const { params } = useSelector(selectCurrentQueryItem);
1890
+ const { data: schema } = useServerSchema();
1854
1891
  return useMutation({
1855
1892
  mutationFn: async ({ format: format2 }) => {
1856
1893
  if (!isValidQuery(params)) {
1857
1894
  throw new Error("The current query is not valid.");
1858
1895
  }
1859
1896
  const queryParams = { ...params, pagiLimit: 0, pagiOffset: 0 };
1860
- const request = queryParamsToRequest(queryParams);
1897
+ const drilldowns = getISO3Drilldowns({
1898
+ cube: schema == null ? void 0 : schema.cubeMap[params.cube],
1899
+ search: new URLSearchParams(location.search)
1900
+ });
1901
+ const paramsUpdated = drilldowns ? { ...queryParams, drilldowns } : queryParams;
1902
+ const request = queryParamsToRequest(paramsUpdated);
1861
1903
  const response = await tesseract.fetchData({
1862
1904
  request,
1863
1905
  format: format2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datawheel/data-explorer",
3
- "version": "1.1.8",
3
+ "version": "1.1.10",
4
4
  "main": "./dist/main.mjs",
5
5
  "types": "./dist/main.d.mts",
6
6
  "files": [