@civicactions/cmsds-open-data-components 4.0.19-alpha.3 → 4.0.19-alpha.5

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.js CHANGED
@@ -2,7 +2,7 @@ import "./main.css";
2
2
  import {jsx as $hgUW1$jsx, jsxs as $hgUW1$jsxs, Fragment as $hgUW1$Fragment} from "react/jsx-runtime";
3
3
  import {Accordion as $hgUW1$Accordion, AccordionItem as $hgUW1$AccordionItem, Button as $hgUW1$Button, CloseIconThin as $hgUW1$CloseIconThin, ArrowIcon as $hgUW1$ArrowIcon, Spinner as $hgUW1$Spinner, Alert as $hgUW1$Alert, Dialog as $hgUW1$Dialog, TextField as $hgUW1$TextField, Dropdown as $hgUW1$Dropdown, Pagination as $hgUW1$Pagination, Tooltip as $hgUW1$Tooltip, TooltipIcon as $hgUW1$TooltipIcon, Choice as $hgUW1$Choice, Table as $hgUW1$Table, TableHead as $hgUW1$TableHead, TableRow as $hgUW1$TableRow, TableCell as $hgUW1$TableCell, TableBody as $hgUW1$TableBody, Tabs as $hgUW1$Tabs, TabPanel as $hgUW1$TabPanel, ExternalLinkIcon as $hgUW1$ExternalLinkIcon, Badge as $hgUW1$Badge} from "@cmsgov/design-system";
4
4
  import $hgUW1$react, {createContext as $hgUW1$createContext, useState as $hgUW1$useState, useRef as $hgUW1$useRef, useEffect as $hgUW1$useEffect, useContext as $hgUW1$useContext, useMemo as $hgUW1$useMemo, useCallback as $hgUW1$useCallback} from "react";
5
- import {NavLink as $hgUW1$NavLink, Link as $hgUW1$Link, useNavigate as $hgUW1$useNavigate, useLocation as $hgUW1$useLocation, useSearchParams as $hgUW1$useSearchParams} from "react-router-dom";
5
+ import {NavLink as $hgUW1$NavLink, Link as $hgUW1$Link, useNavigate as $hgUW1$useNavigate, useSearchParams as $hgUW1$useSearchParams, useLocation as $hgUW1$useLocation} from "react-router-dom";
6
6
  import $hgUW1$qs from "qs";
7
7
  import $hgUW1$axios from "axios";
8
8
  import {useQuery as $hgUW1$useQuery, QueryClient as $hgUW1$QueryClient, QueryClientProvider as $hgUW1$QueryClientProvider} from "@tanstack/react-query";
@@ -1428,31 +1428,30 @@ async function $eff7d34c30f5a0fc$export$2d2256cb46e92ff7(rootUrl, options, ACA)
1428
1428
  const $e873081a6e8f024e$export$1040147c129fdde9 = (query)=>{
1429
1429
  return /^[a-zA-Z0-9 ]*$/.test(query.trim());
1430
1430
  };
1431
+ const $e873081a6e8f024e$var$sortOptions = [
1432
+ {
1433
+ label: 'Newest',
1434
+ value: 'newest'
1435
+ },
1436
+ {
1437
+ label: 'Oldest',
1438
+ value: 'oldest'
1439
+ },
1440
+ {
1441
+ label: 'Title A-Z',
1442
+ value: 'titleAZ'
1443
+ },
1444
+ {
1445
+ label: 'Title Z-A',
1446
+ value: 'titleZA'
1447
+ }
1448
+ ];
1431
1449
  const $e873081a6e8f024e$var$DatasetSearch = (props)=>{
1432
1450
  const { rootUrl: rootUrl, enableSort: enableSort = true, enablePagination: enablePagination = true, defaultPageSize: defaultPageSize = 10, defaultSort: defaultSort = {
1433
1451
  defaultSort: 'modified',
1434
1452
  defaultOrder: 'desc'
1435
1453
  }, pageTitle: pageTitle = 'Dataset Explorer', categoriesTitle: categoriesTitle = 'Categories', filterTitle: filterTitle = 'Tags', showLargeFileWarning: showLargeFileWarning = false, largeFileThemes: largeFileThemes, introText: introText = '', showDownloadIcon: showDownloadIcon = false, altMobileSearchButton: altMobileSearchButton, dataDictionaryLinks: dataDictionaryLinks = false, showDateDetails: showDateDetails = false, showTopics: showTopics = false, topicSlugFunction: topicSlugFunction, children: children } = props;
1436
1454
  const { ACA: ACA } = (0, $hgUW1$useContext)((0, $844981eac9b63865$export$eccc29c8d0ff408));
1437
- const sortOptions = [
1438
- {
1439
- label: 'Newest',
1440
- value: 'newest'
1441
- },
1442
- {
1443
- label: 'Oldest',
1444
- value: 'oldest'
1445
- },
1446
- {
1447
- label: 'Title A-Z',
1448
- value: 'titleAZ'
1449
- },
1450
- {
1451
- label: 'Title Z-A',
1452
- value: 'titleZA'
1453
- }
1454
- ];
1455
- const location = (0, $hgUW1$useLocation)();
1456
1455
  const [searchParams, setSearchParams] = (0, $hgUW1$useSearchParams)();
1457
1456
  // Derive all search state from URL params
1458
1457
  const selectedFacets = (0, $hgUW1$useMemo)(()=>({
@@ -1533,7 +1532,7 @@ const $e873081a6e8f024e$var$DatasetSearch = (props)=>{
1533
1532
  setSearchParams({});
1534
1533
  }
1535
1534
  const pageSize = defaultPageSize;
1536
- let params = {
1535
+ const params = {
1537
1536
  fulltext: fulltext ? fulltext : undefined,
1538
1537
  ...selectedFacets,
1539
1538
  sort: sort ? sort : undefined,
@@ -1541,7 +1540,7 @@ const $e873081a6e8f024e$var$DatasetSearch = (props)=>{
1541
1540
  page: page !== 1 ? page : undefined,
1542
1541
  ['page-size']: pageSize !== 10 ? pageSize : undefined
1543
1542
  };
1544
- const { data: data, isPending: isPending, error: error } = (0, $hgUW1$useQuery)({
1543
+ const { data: data, isPending: isPending } = (0, $hgUW1$useQuery)({
1545
1544
  queryKey: [
1546
1545
  "datasets",
1547
1546
  params
@@ -1554,7 +1553,7 @@ const $e873081a6e8f024e$var$DatasetSearch = (props)=>{
1554
1553
  }
1555
1554
  });
1556
1555
  const totalItems = data?.data?.total ? Number(data.data.total) : 0;
1557
- const facets = data && data.data.facets ? (0, $eff7d34c30f5a0fc$export$959638e8dca60ce6)(data ? data.data.facets : []) : {
1556
+ const facets = data && data.data.facets ? (0, $eff7d34c30f5a0fc$export$959638e8dca60ce6)(data.data.facets) : {
1558
1557
  theme: null,
1559
1558
  keyword: null
1560
1559
  };
@@ -1572,7 +1571,7 @@ const $e873081a6e8f024e$var$DatasetSearch = (props)=>{
1572
1571
  pageSize,
1573
1572
  page
1574
1573
  ]);
1575
- const noResults = totalItems <= 0 && !isPending;
1574
+ const noResults = totalItems <= 0 && !isPending && data?.data?.results !== undefined;
1576
1575
  const announcementText = (0, $hgUW1$useMemo)(()=>{
1577
1576
  if (noResults) return 'No results found.';
1578
1577
  if (!isPending && (!data || !data.data.results)) return 'Could not connect to the API.';
@@ -1632,6 +1631,12 @@ const $e873081a6e8f024e$var$DatasetSearch = (props)=>{
1632
1631
  page: null
1633
1632
  }));
1634
1633
  } else setInvalidSearch(true);
1634
+ } else {
1635
+ setInvalidSearch(false);
1636
+ setSearchParams(buildNextParams({
1637
+ fulltext: null,
1638
+ page: null
1639
+ }));
1635
1640
  }
1636
1641
  },
1637
1642
  className: "dkan-dataset-search ds-l-form-row ds-u-padding-bottom--4 ds-u-border-bottom--1",
@@ -1719,7 +1724,7 @@ const $e873081a6e8f024e$var$DatasetSearch = (props)=>{
1719
1724
  enableSort && /*#__PURE__*/ (0, $hgUW1$jsx)("div", {
1720
1725
  className: "ds-l-col--12 ds-l-sm-col--6 ds-l-md-col--4 ds-u-sm-padding-right--0",
1721
1726
  children: /*#__PURE__*/ (0, $hgUW1$jsx)((0, $hgUW1$Dropdown), {
1722
- options: sortOptions,
1727
+ options: $e873081a6e8f024e$var$sortOptions,
1723
1728
  value: sortDisplay,
1724
1729
  label: "Sort",
1725
1730
  labelClassName: "ds-u-margin-top--0",
@@ -1738,46 +1743,42 @@ const $e873081a6e8f024e$var$DatasetSearch = (props)=>{
1738
1743
  role: "region",
1739
1744
  heading: "No results found."
1740
1745
  }),
1741
- data && data.data.results ? Object.keys(data.data.results).map((key)=>{
1742
- return data.data.results[key];
1743
- }).map((item)=>{
1744
- function getDownloadUrl(item) {
1745
- let distribution_array = item.distribution ? item.distribution : [];
1746
- return distribution_array.length ? item.distribution[0].downloadURL : null;
1747
- }
1748
- let showLargeFile = false;
1749
- if (largeFileThemes && item.theme) largeFileThemes.forEach((theme)=>{
1750
- if (item.theme.includes(theme)) showLargeFile = true;
1751
- });
1752
- let dateDetailProps = {};
1753
- if (showDateDetails) dateDetailProps = {
1746
+ data && data.data.results ? Object.values(data.data.results).map((item)=>{
1747
+ const downloadUrl = (()=>{
1748
+ const distribution_array = item.distribution ?? [];
1749
+ return distribution_array.length ? distribution_array[0].downloadURL : null;
1750
+ })();
1751
+ const showLargeFile = largeFileThemes && item.theme ? largeFileThemes.some((theme)=>item.theme.includes(theme)) : false;
1752
+ const dateDetailProps = showDateDetails ? {
1754
1753
  showDateDetails: showDateDetails,
1755
1754
  released: item.released,
1756
1755
  refresh: item.nextUpdateDate
1757
- };
1758
- let topicProps = {};
1759
- if (showTopics) {
1760
- let topicSlugs = {};
1756
+ } : {};
1757
+ const topicProps = (()=>{
1758
+ if (!showTopics) return {};
1759
+ const topicSlugs = {};
1761
1760
  if (item.theme && Array.isArray(item.theme)) item.theme.forEach((topic)=>{
1762
- if (topic) topicSlugs[topic] = topicSlugFunction ? topicSlugFunction(topic) : topic.split(' ').join('-').toLowerCase();
1761
+ if (topic) {
1762
+ const slug = topicSlugFunction ? topicSlugFunction(topic) : topic.split(' ').join('-').toLowerCase();
1763
+ if (slug) topicSlugs[topic] = slug;
1764
+ }
1763
1765
  });
1764
- topicProps = {
1766
+ return {
1765
1767
  showTopics: showTopics,
1766
1768
  theme: item.theme,
1767
1769
  topicSlugs: topicSlugs
1768
1770
  };
1769
- }
1771
+ })();
1770
1772
  return /*#__PURE__*/ (0, $hgUW1$jsx)((0, $52c6454cae137465$export$2e2bcd8739ae039), {
1771
- location: location,
1772
1773
  title: item.title,
1773
1774
  modified: item.modified,
1774
1775
  description: item.description,
1775
1776
  identifier: item.identifier,
1776
- downloadUrl: showDownloadIcon ? getDownloadUrl(item) : null,
1777
+ downloadUrl: showDownloadIcon ? downloadUrl : null,
1777
1778
  largeFile: showLargeFile,
1778
1779
  paginationEnabled: enablePagination,
1779
1780
  dataDictionaryLinks: dataDictionaryLinks,
1780
- distribution: "%Ref:distribution" in item ? item["%Ref:distribution"][0] : {},
1781
+ distribution: "%Ref:distribution" in item && item["%Ref:distribution"] ? item["%Ref:distribution"][0] : {},
1781
1782
  ...dateDetailProps,
1782
1783
  ...topicProps
1783
1784
  }, item.identifier);
@@ -1788,7 +1789,7 @@ const $e873081a6e8f024e$var$DatasetSearch = (props)=>{
1788
1789
  })
1789
1790
  ]
1790
1791
  }),
1791
- enablePagination && data && data.data.total && data.data.total != 0 && /*#__PURE__*/ (0, $hgUW1$jsx)((0, $hgUW1$Pagination), {
1792
+ enablePagination && data && data.data.total && Number(data.data.total) !== 0 && /*#__PURE__*/ (0, $hgUW1$jsx)((0, $hgUW1$Pagination), {
1792
1793
  currentPage: Number(page),
1793
1794
  totalPages: Math.ceil(Number(data.data.total) / pageSize),
1794
1795
  onPageChange: (evt, page)=>{
@@ -3732,10 +3733,11 @@ const $6f4318b1e14124e5$var$FilterDataset = ()=>{
3732
3733
  const { distribution: distribution, resource: resource, customColumns: customColumns = [], enableEmptyFilters: enableEmptyFilters } = (0, $hgUW1$useContext)((0, $43a30d745a7bbc86$export$2e2bcd8739ae039));
3733
3734
  const { setPage: setPage } = (0, $hgUW1$useContext)((0, $ee0d4d4f34048447$export$f814ea079e65d8fe));
3734
3735
  if (!resource) return null;
3735
- const customColumnHeaders = (0, $7264a673914aa746$export$8049e8f40a9bdfb8)(customColumns, resource.columns, resource.schema[distribution.identifier]);
3736
3736
  const id = distribution.identifier;
3737
- const columns = customColumnHeaders ? customColumnHeaders : (0, $a35cf16d1488f54e$export$1147582dfae658c6)(resource.columns, resource.schema[id]);
3738
3737
  const { conditions: conditions, schema: schema, setConditions: setConditions, setOffset: setOffset } = resource;
3738
+ if (!schema[id]?.fields) return null;
3739
+ const customColumnHeaders = (0, $7264a673914aa746$export$8049e8f40a9bdfb8)(customColumns, resource.columns, resource.schema[distribution.identifier]);
3740
+ const columns = customColumnHeaders ? customColumnHeaders : (0, $a35cf16d1488f54e$export$1147582dfae658c6)(resource.columns, resource.schema[id]);
3739
3741
  const fields = Object.keys(schema[id].fields);
3740
3742
  const [queryConditions, setQueryConditions] = (0, $hgUW1$useState)([]);
3741
3743
  const [titleConditions, setTitleConditions] = (0, $hgUW1$useState)([]);