@civicactions/cmsds-open-data-components 3.2.0-alpha.2 → 3.2.0

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
@@ -1,6 +1,6 @@
1
1
  import "./main.css";
2
2
  import {jsxs as $hgUW1$jsxs, jsx as $hgUW1$jsx, Fragment as $hgUW1$Fragment} from "react/jsx-runtime";
3
- import $hgUW1$react, {useState as $hgUW1$useState, useRef as $hgUW1$useRef, useEffect as $hgUW1$useEffect} from "react";
3
+ import $hgUW1$react, {useState as $hgUW1$useState, useRef as $hgUW1$useRef, useEffect as $hgUW1$useEffect, useMemo as $hgUW1$useMemo} from "react";
4
4
  import {Button as $hgUW1$Button, Accordion as $hgUW1$Accordion, AccordionItem as $hgUW1$AccordionItem, TextField as $hgUW1$TextField, Spinner as $hgUW1$Spinner, Dropdown as $hgUW1$Dropdown, Alert as $hgUW1$Alert, Pagination as $hgUW1$Pagination, Dialog as $hgUW1$Dialog, Choice as $hgUW1$Choice, Tabs as $hgUW1$Tabs, TabPanel as $hgUW1$TabPanel, Tooltip as $hgUW1$Tooltip, Badge as $hgUW1$Badge, Table as $hgUW1$Table, TableBody as $hgUW1$TableBody, TableRow as $hgUW1$TableRow, TableCell as $hgUW1$TableCell, TableHead as $hgUW1$TableHead, TooltipIcon as $hgUW1$TooltipIcon} from "@cmsgov/design-system";
5
5
  import $hgUW1$proptypes from "prop-types";
6
6
  import {NavLink as $hgUW1$NavLink, useLocation as $hgUW1$useLocation, useSearchParams as $hgUW1$useSearchParams, Link as $hgUW1$Link, useNavigate as $hgUW1$useNavigate} from "react-router-dom";
@@ -12,7 +12,7 @@ import {useQuery as $hgUW1$useQuery, QueryClient as $hgUW1$QueryClient, QueryCli
12
12
  import {useMediaQuery as $hgUW1$useMediaQuery} from "react-responsive";
13
13
  import $hgUW1$dompurify from "dompurify";
14
14
  import $hgUW1$lodashtruncate from "lodash.truncate";
15
- import {createColumnHelper as $hgUW1$createColumnHelper, useReactTable as $hgUW1$useReactTable, getCoreRowModel as $hgUW1$getCoreRowModel, getSortedRowModel as $hgUW1$getSortedRowModel, flexRender as $hgUW1$flexRender, getPaginationRowModel as $hgUW1$getPaginationRowModel} from "@tanstack/react-table";
15
+ import {createColumnHelper as $hgUW1$createColumnHelper, useReactTable as $hgUW1$useReactTable, getCoreRowModel as $hgUW1$getCoreRowModel, getSortedRowModel as $hgUW1$getSortedRowModel, flexRender as $hgUW1$flexRender, getFilteredRowModel as $hgUW1$getFilteredRowModel, getPaginationRowModel as $hgUW1$getPaginationRowModel} from "@tanstack/react-table";
16
16
  import $hgUW1$reactdatepicker from "react-datepicker";
17
17
  import "react-datepicker/dist/react-datepicker.css";
18
18
  import {usePopper as $hgUW1$usePopper} from "react-popper";
@@ -1632,6 +1632,7 @@ const $64a351d3fd8413c3$var$HeaderResizeElement = ({ table: table, header: heade
1632
1632
  style: {
1633
1633
  maxWidth: header.getSize() - 16
1634
1634
  },
1635
+ title: header.column.columnDef.header,
1635
1636
  children: header.isPlaceholder ? null : (0, $hgUW1$flexRender)(header.column.columnDef.header, header.getContext())
1636
1637
  }),
1637
1638
  sortElement && /*#__PURE__*/ (0, $hgUW1$jsx)("button", {
@@ -2324,7 +2325,7 @@ const $6369abf590ca298f$var$QueryRow = ({ id: id, condition: condition, index: i
2324
2325
  /*#__PURE__*/ (0, $hgUW1$jsx)((0, $hgUW1$Button), {
2325
2326
  variation: "ghost",
2326
2327
  size: "small",
2327
- className: "ds-u-margin-top--3 ds-u-padding-right--0",
2328
+ className: "ds-u-margin-top--6 ds-u-padding-right--0",
2328
2329
  "aria-label": "Delete filter",
2329
2330
  onClick: ()=>remove(index),
2330
2331
  children: /*#__PURE__*/ (0, $hgUW1$jsx)("span", {
@@ -2339,6 +2340,26 @@ const $6369abf590ca298f$var$QueryRow = ({ id: id, condition: condition, index: i
2339
2340
  var $6369abf590ca298f$export$2e2bcd8739ae039 = $6369abf590ca298f$var$QueryRow;
2340
2341
 
2341
2342
 
2343
+
2344
+
2345
+
2346
+
2347
+ const $2eec38d4d0dbf714$var$ClearFiltersButton = ({ disabled: disabled = false, clearFiltersFn: clearFiltersFn })=>{
2348
+ const small = (0, $hgUW1$useMediaQuery)({
2349
+ minWidth: 0,
2350
+ maxWidth: 544
2351
+ });
2352
+ return /*#__PURE__*/ (0, $hgUW1$jsx)((0, $hgUW1$Button), {
2353
+ disabled: disabled,
2354
+ className: "ds-u-float--right ds-l-md-col--6 ds-l-col--5",
2355
+ variation: small ? "ghost" : undefined,
2356
+ onClick: ()=>clearFiltersFn(),
2357
+ children: small ? "Clear all" : "Clear all filters"
2358
+ });
2359
+ };
2360
+ var $2eec38d4d0dbf714$export$2e2bcd8739ae039 = $2eec38d4d0dbf714$var$ClearFiltersButton;
2361
+
2362
+
2342
2363
  function $ee4ad47aa483e5b5$var$updateQueryForDatastore(condition) {
2343
2364
  let cond = condition;
2344
2365
  delete cond.key;
@@ -2494,16 +2515,13 @@ const $ee4ad47aa483e5b5$var$QueryBuilder = (props)=>{
2494
2515
  variation: "solid",
2495
2516
  children: "Apply filters"
2496
2517
  }),
2497
- /*#__PURE__*/ (0, $hgUW1$jsx)((0, $hgUW1$Button), {
2518
+ /*#__PURE__*/ (0, $hgUW1$jsx)((0, $2eec38d4d0dbf714$export$2e2bcd8739ae039), {
2498
2519
  disabled: queryConditions.length === 0,
2499
- className: "ds-u-float--right ds-l-md-col--6 ds-l-col--5",
2500
- variation: small ? "ghost" : undefined,
2501
- onClick: ()=>{
2520
+ clearFiltersFn: ()=>{
2502
2521
  setQueryConditions([]);
2503
2522
  setTitleConditions([]);
2504
2523
  setConditionsCleared(true);
2505
- },
2506
- children: small ? "Clear all" : "Clear all filters"
2524
+ }
2507
2525
  })
2508
2526
  ]
2509
2527
  })
@@ -2792,7 +2810,7 @@ const $7357cc0f79f9c514$var$Resource = ({ distributions: distributions, resource
2792
2810
  order: sm ? "1" : "0",
2793
2811
  width: sm ? "100%" : "auto"
2794
2812
  },
2795
- "aria-label": "Download " + title + " " + fileFormat,
2813
+ "aria-label": `Download ${dist.data.title || title} ${fileFormat}`,
2796
2814
  className: "ds-c-button",
2797
2815
  children: [
2798
2816
  /*#__PURE__*/ (0, $hgUW1$jsx)("i", {
@@ -2958,25 +2976,99 @@ var $cf6eaefd6b928de3$export$2e2bcd8739ae039 = $cf6eaefd6b928de3$var$DatasetAPI;
2958
2976
 
2959
2977
 
2960
2978
 
2961
- const $6765a74df807d015$var$DataDictionaryTable = ({ tableColumns: tableColumns, tableData: tableData, count: count, pageSize: pageSize })=>{
2962
- const [pagination, setPagination] = (0, $hgUW1$useState)({
2963
- pageIndex: 1,
2964
- pageSize: pageSize
2965
- });
2979
+
2980
+ const $6765a74df807d015$var$DataDictionaryTable = ({ tableColumns: tableColumns, tableData: tableData, pageSize: pageSize, columnFilters: columnFilters })=>{
2981
+ const [sorting, setSorting] = (0, $hgUW1$useState)([]);
2966
2982
  const [ariaLiveFeedback, setAriaLiveFeedback] = (0, $hgUW1$useState)("");
2983
+ const mobile = (0, $hgUW1$useMediaQuery)({
2984
+ minWidth: 0,
2985
+ maxWidth: 544
2986
+ });
2987
+ const sortElement = (isSorted)=>{
2988
+ if (isSorted === "asc") return "dc-c-sort--asc";
2989
+ if (isSorted === "desc") return "dc-c-sort--desc";
2990
+ return "dc-c-sort--default";
2991
+ };
2967
2992
  const table = (0, $hgUW1$useReactTable)({
2968
2993
  data: tableData,
2969
2994
  columns: tableColumns,
2970
2995
  columnResizeMode: "onChange",
2971
2996
  getCoreRowModel: (0, $hgUW1$getCoreRowModel)(),
2997
+ getFilteredRowModel: (0, $hgUW1$getFilteredRowModel)(),
2972
2998
  getPaginationRowModel: (0, $hgUW1$getPaginationRowModel)(),
2973
- onPaginationChange: setPagination,
2999
+ getSortedRowModel: (0, $hgUW1$getSortedRowModel)(),
3000
+ onSortingChange: setSorting,
2974
3001
  state: {
2975
- pagination: pagination
3002
+ sorting: sorting,
3003
+ columnFilters: columnFilters
2976
3004
  }
2977
3005
  });
3006
+ const sortOptions = [
3007
+ {
3008
+ value: "default",
3009
+ label: "No Sort"
3010
+ },
3011
+ {
3012
+ value: "titleasc",
3013
+ label: "Title A-Z"
3014
+ },
3015
+ {
3016
+ value: "titledesc",
3017
+ label: "Title Z-A"
3018
+ },
3019
+ {
3020
+ value: "typeasc",
3021
+ label: "Type A-Z"
3022
+ },
3023
+ {
3024
+ value: "typedesc",
3025
+ label: "Type Z-A"
3026
+ }
3027
+ ];
3028
+ const sortStatesLookup = {
3029
+ default: [],
3030
+ titleasc: [
3031
+ {
3032
+ id: "titleResizable",
3033
+ desc: false
3034
+ }
3035
+ ],
3036
+ titledesc: [
3037
+ {
3038
+ id: "titleResizable",
3039
+ desc: true
3040
+ }
3041
+ ],
3042
+ typeasc: [
3043
+ {
3044
+ id: "type",
3045
+ desc: false
3046
+ }
3047
+ ],
3048
+ typedesc: [
3049
+ {
3050
+ id: "type",
3051
+ desc: true
3052
+ }
3053
+ ]
3054
+ };
2978
3055
  return /*#__PURE__*/ (0, $hgUW1$jsxs)("div", {
2979
3056
  children: [
3057
+ mobile && /*#__PURE__*/ (0, $hgUW1$jsx)("div", {
3058
+ className: "ds-u-margin-bottom--3 ds-l-col--12 ds-l-sm-col--6",
3059
+ children: /*#__PURE__*/ (0, $hgUW1$jsx)((0, $hgUW1$Dropdown), {
3060
+ labelClassName: "ds-u-margin-top--1 ds-u-sm-margin-top--0",
3061
+ options: sortOptions,
3062
+ label: "Sort",
3063
+ value: Object.keys(sortStatesLookup).find((key)=>{
3064
+ return JSON.stringify(sortStatesLookup[key]) == JSON.stringify(sorting);
3065
+ }),
3066
+ name: "dc-data-dictionary-type",
3067
+ onChange: (e)=>{
3068
+ setSorting(sortStatesLookup[e.target.value]);
3069
+ }
3070
+ })
3071
+ }),
2980
3072
  /*#__PURE__*/ (0, $hgUW1$jsxs)("div", {
2981
3073
  className: "dc-c-datadictionary-table",
2982
3074
  children: [
@@ -2985,6 +3077,7 @@ const $6765a74df807d015$var$DataDictionaryTable = ({ tableColumns: tableColumns,
2985
3077
  style: {
2986
3078
  width: "100%"
2987
3079
  },
3080
+ stackable: true,
2988
3081
  children: [
2989
3082
  /*#__PURE__*/ (0, $hgUW1$jsx)((0, $hgUW1$TableHead), {
2990
3083
  className: "dc-thead--truncated dc-thead--resizeable",
@@ -2993,11 +3086,20 @@ const $6765a74df807d015$var$DataDictionaryTable = ({ tableColumns: tableColumns,
2993
3086
  return header.id === "titleResizable" ? /*#__PURE__*/ (0, $hgUW1$jsx)((0, $64a351d3fd8413c3$export$2e2bcd8739ae039), {
2994
3087
  table: table,
2995
3088
  header: header,
2996
- setAriaLiveFeedback: setAriaLiveFeedback
2997
- }, header.id + "_resize") : /*#__PURE__*/ (0, $hgUW1$jsx)((0, $hgUW1$TableCell), {
3089
+ setAriaLiveFeedback: setAriaLiveFeedback,
3090
+ sortElement: sortElement
3091
+ }, header.id + "_resize") : /*#__PURE__*/ (0, $hgUW1$jsxs)((0, $hgUW1$TableCell), {
2998
3092
  key: header.id,
2999
- className: "ds-u-border-y--2 ds-u-border--dark ds-u-border-x--0",
3000
- children: (0, $hgUW1$flexRender)(header.column.columnDef.header, header.getContext())
3093
+ className: `ds-u-border-y--2 ds-u-border--dark ds-u-border-x--0`,
3094
+ id: "dataDictionary_" + header.id,
3095
+ children: [
3096
+ (0, $hgUW1$flexRender)(header.column.columnDef.header, header.getContext()),
3097
+ header.id === "type" && /*#__PURE__*/ (0, $hgUW1$jsx)("button", {
3098
+ onClick: header.column.getToggleSortingHandler(),
3099
+ className: header.column.getCanSort() ? `cursor-pointer select-none ds-u-focus-visible ${sortElement(header.column.getIsSorted())}` : "",
3100
+ "aria-label": `${header.column.columnDef.header} sort order`
3101
+ })
3102
+ ]
3001
3103
  });
3002
3104
  })
3003
3105
  }, "header" + headerGroup.id))
@@ -3009,9 +3111,12 @@ const $6765a74df807d015$var$DataDictionaryTable = ({ tableColumns: tableColumns,
3009
3111
  return /*#__PURE__*/ (0, $hgUW1$jsx)((0, $hgUW1$TableCell), {
3010
3112
  key: cell.id,
3011
3113
  style: {
3012
- maxWidth: cell.column.getSize()
3114
+ maxWidth: mobile ? "100%" : cell.column.getSize(),
3115
+ whiteSpace: cell.column.id === "description" ? "pre-wrap" : "normal"
3013
3116
  },
3014
3117
  className: `${cell.column.id === "titleResizable" ? "ds-u-word-break" : ""}`,
3118
+ headers: "dataDictionary_" + cell.column.id,
3119
+ stackedTitle: cell.column.id === "titleResizable" ? "Title" : cell.column.columnDef.header,
3015
3120
  children: (0, $hgUW1$flexRender)(cell.column.columnDef.cell, cell.getContext())
3016
3121
  });
3017
3122
  })
@@ -3028,15 +3133,12 @@ const $6765a74df807d015$var$DataDictionaryTable = ({ tableColumns: tableColumns,
3028
3133
  })
3029
3134
  ]
3030
3135
  }),
3031
- count > pageSize ? /*#__PURE__*/ (0, $hgUW1$jsx)((0, $hgUW1$Pagination), {
3032
- totalPages: Math.ceil(count / pagination.pageSize),
3033
- currentPage: pagination.pageIndex + 1,
3136
+ table.getRowCount() > pageSize ? /*#__PURE__*/ (0, $hgUW1$jsx)((0, $hgUW1$Pagination), {
3137
+ totalPages: table.getPageCount(),
3138
+ currentPage: table.getState().pagination.pageIndex + 1,
3034
3139
  onPageChange: (evt, page)=>{
3035
3140
  evt.preventDefault();
3036
- setPagination({
3037
- pageIndex: page - 1,
3038
- pageSize: pageSize
3039
- });
3141
+ table.setPageIndex(page - 1);
3040
3142
  },
3041
3143
  renderHref: (page)=>{
3042
3144
  return "";
@@ -3067,7 +3169,6 @@ const $a24829b27758fe6c$var$SitewideDataDictionaryTable = ({ datasetDictionary:
3067
3169
  return /*#__PURE__*/ (0, $hgUW1$jsx)((0, $6765a74df807d015$export$2e2bcd8739ae039), {
3068
3170
  tableColumns: tableColumns,
3069
3171
  tableData: datasetDictionary,
3070
- count: datasetDictionary.length,
3071
3172
  pageSize: pageSize
3072
3173
  });
3073
3174
  };
@@ -3080,7 +3181,23 @@ var $a24829b27758fe6c$export$2e2bcd8739ae039 = $a24829b27758fe6c$var$SitewideDat
3080
3181
 
3081
3182
 
3082
3183
 
3184
+
3083
3185
  const $a6e312940f7003ef$var$DatasetDictionaryTable = ({ datasetDictionary: datasetDictionary, pageSize: pageSize })=>{
3186
+ const [titleFilter, setTitleFilter] = (0, $hgUW1$useState)("");
3187
+ const [typeFilter, setTypeFilter] = (0, $hgUW1$useState)("all");
3188
+ const columnFilters = (0, $hgUW1$useMemo)(()=>[
3189
+ {
3190
+ id: "titleResizable",
3191
+ value: titleFilter
3192
+ },
3193
+ {
3194
+ id: "type",
3195
+ value: typeFilter === "all" ? "" : typeFilter
3196
+ }
3197
+ ], [
3198
+ titleFilter,
3199
+ typeFilter
3200
+ ]);
3084
3201
  const tableData = datasetDictionary.map((item)=>{
3085
3202
  return {
3086
3203
  titleResizable: item.title,
@@ -3096,7 +3213,7 @@ const $a6e312940f7003ef$var$DatasetDictionaryTable = ({ datasetDictionary: datas
3096
3213
  children: [
3097
3214
  "Title",
3098
3215
  /*#__PURE__*/ (0, $hgUW1$jsx)((0, $hgUW1$Tooltip), {
3099
- title: "Title represents the column headers of the data file (e.g., Change_Type)",
3216
+ title: "Title represents the column headers of the data file",
3100
3217
  // @ts-ignore
3101
3218
  style: {
3102
3219
  border: "none",
@@ -3119,11 +3236,95 @@ const $a6e312940f7003ef$var$DatasetDictionaryTable = ({ datasetDictionary: datas
3119
3236
  enableResizing: false
3120
3237
  })
3121
3238
  ];
3122
- return /*#__PURE__*/ (0, $hgUW1$jsx)((0, $6765a74df807d015$export$2e2bcd8739ae039), {
3123
- tableColumns: tableColumns,
3124
- tableData: tableData,
3125
- count: datasetDictionary.length,
3126
- pageSize: pageSize
3239
+ const typeOptions = [
3240
+ {
3241
+ value: "all",
3242
+ label: "All Types"
3243
+ },
3244
+ {
3245
+ value: "string",
3246
+ label: "String"
3247
+ },
3248
+ {
3249
+ value: "date",
3250
+ label: "Date"
3251
+ },
3252
+ {
3253
+ value: "datetime",
3254
+ label: "Datetime"
3255
+ },
3256
+ {
3257
+ value: "year",
3258
+ label: "Year"
3259
+ },
3260
+ {
3261
+ value: "integer",
3262
+ label: "Integer"
3263
+ },
3264
+ {
3265
+ value: "number",
3266
+ label: "Number"
3267
+ },
3268
+ {
3269
+ value: "boolean",
3270
+ label: "Boolean"
3271
+ }
3272
+ ];
3273
+ return /*#__PURE__*/ (0, $hgUW1$jsxs)((0, $hgUW1$Fragment), {
3274
+ children: [
3275
+ /*#__PURE__*/ (0, $hgUW1$jsx)("div", {
3276
+ className: "dc-query-builder ds-u-margin-bottom--3",
3277
+ children: /*#__PURE__*/ (0, $hgUW1$jsx)("div", {
3278
+ className: "ds-c-accordion ds-c-accordion--bordered",
3279
+ children: /*#__PURE__*/ (0, $hgUW1$jsx)((0, $hgUW1$AccordionItem), {
3280
+ heading: "Data Dictionary Filters",
3281
+ defaultOpen: true,
3282
+ children: /*#__PURE__*/ (0, $hgUW1$jsxs)("div", {
3283
+ className: "ds-u-display--flex ds-u-flex-wrap--wrap",
3284
+ children: [
3285
+ /*#__PURE__*/ (0, $hgUW1$jsx)((0, $hgUW1$TextField), {
3286
+ className: "ds-l-col--12 ds-l-sm-col--6",
3287
+ labelClassName: "ds-u-margin-top--1 ds-u-sm-margin-top--0",
3288
+ label: "Title",
3289
+ value: titleFilter,
3290
+ name: "dc-data-dictionary-title",
3291
+ onChange: (e)=>setTitleFilter(e.target.value)
3292
+ }),
3293
+ /*#__PURE__*/ (0, $hgUW1$jsx)("div", {
3294
+ className: "ds-l-col--12 ds-l-sm-col--6",
3295
+ children: /*#__PURE__*/ (0, $hgUW1$jsx)((0, $hgUW1$Dropdown), {
3296
+ labelClassName: "ds-u-margin-top--1 ds-u-sm-margin-top--0",
3297
+ options: typeOptions,
3298
+ label: "Type",
3299
+ value: typeFilter,
3300
+ name: "dc-data-dictionary-type",
3301
+ onChange: (e)=>setTypeFilter(e.target.value)
3302
+ })
3303
+ }),
3304
+ /*#__PURE__*/ (0, $hgUW1$jsx)("div", {
3305
+ className: "ds-u-float--right ds-u-padding-y--2 ds-l-col--12 ds-u-display--flex ds-u-flex-wrap--wrap ds-u-justify-content--end",
3306
+ children: /*#__PURE__*/ (0, $hgUW1$jsx)("div", {
3307
+ className: "ds-u-display--flex ds-u-justify-content--end ds-l-col--12 ds-l-md-col--6 ds-u-padding-x--0",
3308
+ children: /*#__PURE__*/ (0, $hgUW1$jsx)((0, $2eec38d4d0dbf714$export$2e2bcd8739ae039), {
3309
+ clearFiltersFn: ()=>{
3310
+ setTitleFilter("");
3311
+ setTypeFilter("all");
3312
+ }
3313
+ })
3314
+ })
3315
+ })
3316
+ ]
3317
+ })
3318
+ })
3319
+ })
3320
+ }),
3321
+ /*#__PURE__*/ (0, $hgUW1$jsx)((0, $6765a74df807d015$export$2e2bcd8739ae039), {
3322
+ tableColumns: tableColumns,
3323
+ tableData: tableData,
3324
+ pageSize: pageSize,
3325
+ columnFilters: columnFilters
3326
+ })
3327
+ ]
3127
3328
  });
3128
3329
  };
3129
3330
  var $a6e312940f7003ef$export$2e2bcd8739ae039 = $a6e312940f7003ef$var$DatasetDictionaryTable;
@@ -5349,8 +5550,6 @@ function $3b6ca952e79f0695$var$updateQueryForDatastore(condition) {
5349
5550
  const $3b6ca952e79f0695$var$QueryBuilder = ({ resource: resource, id: id, includeSearchParams: includeSearchParams, customColumns: customColumns })=>{
5350
5551
  const { conditions: conditions, schema: schema, setConditions: setConditions } = resource;
5351
5552
  const fields = Object.keys(schema[id].fields);
5352
- const hasConditions = conditions.length > 0;
5353
- const [queryCount, setQueryCount] = (0, $hgUW1$useState)(0);
5354
5553
  const [queryConditions, setQueryConditions] = (0, $hgUW1$useState)([]);
5355
5554
  const [titleConditions, setTitleConditions] = (0, $hgUW1$useState)([]); // Add use effect to load conditions on first load if needed
5356
5555
  const [conditionsChanged, setConditionsChanged] = (0, $hgUW1$useState)(false);