@civicactions/cmsds-open-data-components 3.1.10-alpha.1 → 3.1.10-alpha.3

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, AddIcon as $hgUW1$AddIcon, RemoveIcon as $hgUW1$RemoveIcon, 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";
@@ -1307,9 +1307,11 @@ var $b4aa9c66f2e86959$export$2e2bcd8739ae039 = $b4aa9c66f2e86959$var$useMetastor
1307
1307
  const $1d3d480a9cfaabe0$var$useDatastore = (resourceId, rootAPIUrl, options, additionalParams = {})=>{
1308
1308
  const keys = options.keys ? options.keys : true;
1309
1309
  const { prepareColumns: prepareColumns } = options;
1310
+ const [values, setValues] = (0, $hgUW1$useState)([]);
1310
1311
  const [id, setResource] = (0, $hgUW1$useState)(resourceId);
1311
1312
  const [rootUrl, setRootUrl] = (0, $hgUW1$useState)(rootAPIUrl);
1312
1313
  const [limit, setLimit] = (0, $hgUW1$useState)(options.limit ? options.limit : 20);
1314
+ const [count, setCount] = (0, $hgUW1$useState)(null);
1313
1315
  const [columns, setColumns] = (0, $hgUW1$useState)([]);
1314
1316
  const [offset, setOffset] = (0, $hgUW1$useState)(options.offset ? options.offset : 0);
1315
1317
  const [conditions, setConditions] = (0, $hgUW1$useState)(options.conditions ? options.conditions : undefined);
@@ -1347,6 +1349,7 @@ const $1d3d480a9cfaabe0$var$useDatastore = (resourceId, rootAPIUrl, options, add
1347
1349
  (0, $hgUW1$useEffect)(()=>{
1348
1350
  if (data) {
1349
1351
  const propertyKeys = data.schema && data.schema[id] && data.schema[id].fields ? Object.keys(data.schema[id].fields) : [];
1352
+ setValues(data.results), setCount(data.count);
1350
1353
  if (propertyKeys.length) setColumns(prepareColumns ? prepareColumns(propertyKeys) : propertyKeys);
1351
1354
  if (data.schema) setSchema(data.schema);
1352
1355
  }
@@ -1355,8 +1358,8 @@ const $1d3d480a9cfaabe0$var$useDatastore = (resourceId, rootAPIUrl, options, add
1355
1358
  ]);
1356
1359
  return {
1357
1360
  loading: enabled ? isPending : false,
1358
- values: data ? data.results : undefined,
1359
- count: data ? data.count : null,
1361
+ values: values,
1362
+ count: count,
1360
1363
  columns: columns,
1361
1364
  limit: limit,
1362
1365
  offset: offset,
@@ -2345,6 +2348,26 @@ const $6369abf590ca298f$var$QueryRow = ({ id: id, condition: condition, index: i
2345
2348
  var $6369abf590ca298f$export$2e2bcd8739ae039 = $6369abf590ca298f$var$QueryRow;
2346
2349
 
2347
2350
 
2351
+
2352
+
2353
+
2354
+
2355
+ const $2eec38d4d0dbf714$var$ClearFiltersButton = ({ disabled: disabled = false, clearFiltersFn: clearFiltersFn })=>{
2356
+ const small = (0, $hgUW1$useMediaQuery)({
2357
+ minWidth: 0,
2358
+ maxWidth: 544
2359
+ });
2360
+ return /*#__PURE__*/ (0, $hgUW1$jsx)((0, $hgUW1$Button), {
2361
+ disabled: disabled,
2362
+ className: "ds-u-float--right ds-l-md-col--6 ds-l-col--5",
2363
+ variation: small ? "ghost" : undefined,
2364
+ onClick: ()=>clearFiltersFn(),
2365
+ children: small ? "Clear all" : "Clear all filters"
2366
+ });
2367
+ };
2368
+ var $2eec38d4d0dbf714$export$2e2bcd8739ae039 = $2eec38d4d0dbf714$var$ClearFiltersButton;
2369
+
2370
+
2348
2371
  function $ee4ad47aa483e5b5$var$updateQueryForDatastore(condition) {
2349
2372
  let cond = condition;
2350
2373
  delete cond.key;
@@ -2500,16 +2523,13 @@ const $ee4ad47aa483e5b5$var$QueryBuilder = (props)=>{
2500
2523
  variation: "solid",
2501
2524
  children: "Apply filters"
2502
2525
  }),
2503
- /*#__PURE__*/ (0, $hgUW1$jsx)((0, $hgUW1$Button), {
2526
+ /*#__PURE__*/ (0, $hgUW1$jsx)((0, $2eec38d4d0dbf714$export$2e2bcd8739ae039), {
2504
2527
  disabled: queryConditions.length === 0,
2505
- className: "ds-u-float--right ds-l-md-col--6 ds-l-col--5",
2506
- variation: small ? "ghost" : undefined,
2507
- onClick: ()=>{
2528
+ clearFiltersFn: ()=>{
2508
2529
  setQueryConditions([]);
2509
2530
  setTitleConditions([]);
2510
2531
  setConditionsCleared(true);
2511
- },
2512
- children: small ? "Clear all" : "Clear all filters"
2532
+ }
2513
2533
  })
2514
2534
  ]
2515
2535
  })
@@ -2964,21 +2984,31 @@ var $cf6eaefd6b928de3$export$2e2bcd8739ae039 = $cf6eaefd6b928de3$var$DatasetAPI;
2964
2984
 
2965
2985
 
2966
2986
 
2967
- const $6765a74df807d015$var$DataDictionaryTable = ({ tableColumns: tableColumns, tableData: tableData, count: count, pageSize: pageSize })=>{
2968
- const [pagination, setPagination] = (0, $hgUW1$useState)({
2969
- pageIndex: 1,
2970
- pageSize: pageSize
2971
- });
2987
+
2988
+ const $6765a74df807d015$var$DataDictionaryTable = ({ tableColumns: tableColumns, tableData: tableData, pageSize: pageSize, columnFilters: columnFilters })=>{
2989
+ const [sorting, setSorting] = (0, $hgUW1$useState)([]);
2972
2990
  const [ariaLiveFeedback, setAriaLiveFeedback] = (0, $hgUW1$useState)("");
2991
+ const mobile = (0, $hgUW1$useMediaQuery)({
2992
+ minWidth: 0,
2993
+ maxWidth: 544
2994
+ });
2995
+ const sortElement = (isSorted)=>{
2996
+ if (isSorted === "asc") return "dc-c-sort--asc";
2997
+ if (isSorted === "desc") return "dc-c-sort--desc";
2998
+ return "dc-c-sort--default";
2999
+ };
2973
3000
  const table = (0, $hgUW1$useReactTable)({
2974
3001
  data: tableData,
2975
3002
  columns: tableColumns,
2976
3003
  columnResizeMode: "onChange",
2977
3004
  getCoreRowModel: (0, $hgUW1$getCoreRowModel)(),
3005
+ getFilteredRowModel: (0, $hgUW1$getFilteredRowModel)(),
2978
3006
  getPaginationRowModel: (0, $hgUW1$getPaginationRowModel)(),
2979
- onPaginationChange: setPagination,
3007
+ getSortedRowModel: (0, $hgUW1$getSortedRowModel)(),
3008
+ onSortingChange: setSorting,
2980
3009
  state: {
2981
- pagination: pagination
3010
+ sorting: sorting,
3011
+ columnFilters: columnFilters
2982
3012
  }
2983
3013
  });
2984
3014
  return /*#__PURE__*/ (0, $hgUW1$jsxs)("div", {
@@ -2991,6 +3021,7 @@ const $6765a74df807d015$var$DataDictionaryTable = ({ tableColumns: tableColumns,
2991
3021
  style: {
2992
3022
  width: "100%"
2993
3023
  },
3024
+ stackable: true,
2994
3025
  children: [
2995
3026
  /*#__PURE__*/ (0, $hgUW1$jsx)((0, $hgUW1$TableHead), {
2996
3027
  className: "dc-thead--truncated dc-thead--resizeable",
@@ -2999,11 +3030,20 @@ const $6765a74df807d015$var$DataDictionaryTable = ({ tableColumns: tableColumns,
2999
3030
  return header.id === "titleResizable" ? /*#__PURE__*/ (0, $hgUW1$jsx)((0, $64a351d3fd8413c3$export$2e2bcd8739ae039), {
3000
3031
  table: table,
3001
3032
  header: header,
3002
- setAriaLiveFeedback: setAriaLiveFeedback
3003
- }, header.id + "_resize") : /*#__PURE__*/ (0, $hgUW1$jsx)((0, $hgUW1$TableCell), {
3033
+ setAriaLiveFeedback: setAriaLiveFeedback,
3034
+ sortElement: sortElement
3035
+ }, header.id + "_resize") : /*#__PURE__*/ (0, $hgUW1$jsxs)((0, $hgUW1$TableCell), {
3004
3036
  key: header.id,
3005
- className: "ds-u-border-y--2 ds-u-border--dark ds-u-border-x--0",
3006
- children: (0, $hgUW1$flexRender)(header.column.columnDef.header, header.getContext())
3037
+ className: `ds-u-border-y--2 ds-u-border--dark ds-u-border-x--0`,
3038
+ id: "dataDictionary_" + header.id,
3039
+ children: [
3040
+ (0, $hgUW1$flexRender)(header.column.columnDef.header, header.getContext()),
3041
+ header.id === "type" && /*#__PURE__*/ (0, $hgUW1$jsx)("button", {
3042
+ onClick: header.column.getToggleSortingHandler(),
3043
+ className: header.column.getCanSort() ? `cursor-pointer select-none ds-u-focus-visible ${sortElement(header.column.getIsSorted())}` : "",
3044
+ "aria-label": `${header.column.columnDef.header} sort order`
3045
+ })
3046
+ ]
3007
3047
  });
3008
3048
  })
3009
3049
  }, "header" + headerGroup.id))
@@ -3015,9 +3055,12 @@ const $6765a74df807d015$var$DataDictionaryTable = ({ tableColumns: tableColumns,
3015
3055
  return /*#__PURE__*/ (0, $hgUW1$jsx)((0, $hgUW1$TableCell), {
3016
3056
  key: cell.id,
3017
3057
  style: {
3018
- maxWidth: cell.column.getSize()
3058
+ maxWidth: mobile ? "100%" : cell.column.getSize(),
3059
+ whiteSpace: cell.column.id === "description" ? "pre-wrap" : "normal"
3019
3060
  },
3020
3061
  className: `${cell.column.id === "titleResizable" ? "ds-u-word-break" : ""}`,
3062
+ headers: "dataDictionary_" + cell.column.id,
3063
+ stackedTitle: cell.column.id === "titleResizable" ? "Title" : cell.column.columnDef.header,
3021
3064
  children: (0, $hgUW1$flexRender)(cell.column.columnDef.cell, cell.getContext())
3022
3065
  });
3023
3066
  })
@@ -3034,15 +3077,12 @@ const $6765a74df807d015$var$DataDictionaryTable = ({ tableColumns: tableColumns,
3034
3077
  })
3035
3078
  ]
3036
3079
  }),
3037
- count > pageSize ? /*#__PURE__*/ (0, $hgUW1$jsx)((0, $hgUW1$Pagination), {
3038
- totalPages: Math.ceil(count / pagination.pageSize),
3039
- currentPage: pagination.pageIndex + 1,
3080
+ table.getRowCount() > pageSize ? /*#__PURE__*/ (0, $hgUW1$jsx)((0, $hgUW1$Pagination), {
3081
+ totalPages: table.getPageCount(),
3082
+ currentPage: table.getState().pagination.pageIndex + 1,
3040
3083
  onPageChange: (evt, page)=>{
3041
3084
  evt.preventDefault();
3042
- setPagination({
3043
- pageIndex: page - 1,
3044
- pageSize: pageSize
3045
- });
3085
+ table.setPageIndex(page - 1);
3046
3086
  },
3047
3087
  renderHref: (page)=>{
3048
3088
  return "";
@@ -3073,7 +3113,6 @@ const $a24829b27758fe6c$var$SitewideDataDictionaryTable = ({ datasetDictionary:
3073
3113
  return /*#__PURE__*/ (0, $hgUW1$jsx)((0, $6765a74df807d015$export$2e2bcd8739ae039), {
3074
3114
  tableColumns: tableColumns,
3075
3115
  tableData: datasetDictionary,
3076
- count: datasetDictionary.length,
3077
3116
  pageSize: pageSize
3078
3117
  });
3079
3118
  };
@@ -3086,7 +3125,23 @@ var $a24829b27758fe6c$export$2e2bcd8739ae039 = $a24829b27758fe6c$var$SitewideDat
3086
3125
 
3087
3126
 
3088
3127
 
3128
+
3089
3129
  const $a6e312940f7003ef$var$DatasetDictionaryTable = ({ datasetDictionary: datasetDictionary, pageSize: pageSize })=>{
3130
+ const [titleFilter, setTitleFilter] = (0, $hgUW1$useState)("");
3131
+ const [typeFilter, setTypeFilter] = (0, $hgUW1$useState)("all");
3132
+ const columnFilters = (0, $hgUW1$useMemo)(()=>[
3133
+ {
3134
+ id: "titleResizable",
3135
+ value: titleFilter
3136
+ },
3137
+ {
3138
+ id: "type",
3139
+ value: typeFilter === "all" ? "" : typeFilter
3140
+ }
3141
+ ], [
3142
+ titleFilter,
3143
+ typeFilter
3144
+ ]);
3090
3145
  const tableData = datasetDictionary.map((item)=>{
3091
3146
  return {
3092
3147
  titleResizable: item.title,
@@ -3102,7 +3157,7 @@ const $a6e312940f7003ef$var$DatasetDictionaryTable = ({ datasetDictionary: datas
3102
3157
  children: [
3103
3158
  "Title",
3104
3159
  /*#__PURE__*/ (0, $hgUW1$jsx)((0, $hgUW1$Tooltip), {
3105
- title: "Title represents the column headers of the data file (e.g., Change_Type)",
3160
+ title: "Title represents the column headers of the data file",
3106
3161
  // @ts-ignore
3107
3162
  style: {
3108
3163
  border: "none",
@@ -3125,11 +3180,93 @@ const $a6e312940f7003ef$var$DatasetDictionaryTable = ({ datasetDictionary: datas
3125
3180
  enableResizing: false
3126
3181
  })
3127
3182
  ];
3128
- return /*#__PURE__*/ (0, $hgUW1$jsx)((0, $6765a74df807d015$export$2e2bcd8739ae039), {
3129
- tableColumns: tableColumns,
3130
- tableData: tableData,
3131
- count: datasetDictionary.length,
3132
- pageSize: pageSize
3183
+ const typeOptions = [
3184
+ {
3185
+ value: "all",
3186
+ label: "All Types"
3187
+ },
3188
+ {
3189
+ value: "string",
3190
+ label: "String"
3191
+ },
3192
+ {
3193
+ value: "date",
3194
+ label: "Date"
3195
+ },
3196
+ {
3197
+ value: "datetime",
3198
+ label: "Datetime"
3199
+ },
3200
+ {
3201
+ value: "year",
3202
+ label: "Year"
3203
+ },
3204
+ {
3205
+ value: "integer",
3206
+ label: "Integer"
3207
+ },
3208
+ {
3209
+ value: "number",
3210
+ label: "Number"
3211
+ },
3212
+ {
3213
+ value: "boolean",
3214
+ label: "Boolean"
3215
+ }
3216
+ ];
3217
+ return /*#__PURE__*/ (0, $hgUW1$jsxs)((0, $hgUW1$Fragment), {
3218
+ children: [
3219
+ /*#__PURE__*/ (0, $hgUW1$jsx)("div", {
3220
+ className: "dc-query-builder ds-u-margin-bottom--3",
3221
+ children: /*#__PURE__*/ (0, $hgUW1$jsx)("div", {
3222
+ className: "ds-c-accordion ds-c-accordion--bordered",
3223
+ children: /*#__PURE__*/ (0, $hgUW1$jsx)((0, $hgUW1$AccordionItem), {
3224
+ heading: "Data Dictionary Filters",
3225
+ defaultOpen: true,
3226
+ children: /*#__PURE__*/ (0, $hgUW1$jsxs)("div", {
3227
+ className: "ds-u-display--flex ds-u-flex-wrap--wrap",
3228
+ children: [
3229
+ /*#__PURE__*/ (0, $hgUW1$jsx)((0, $hgUW1$TextField), {
3230
+ className: "ds-l-col--12 ds-l-sm-col--6",
3231
+ labelClassName: "ds-u-margin-top--1 ds-u-sm-margin-top--0",
3232
+ label: "Title",
3233
+ value: titleFilter,
3234
+ name: "dc-data-dictionary-title",
3235
+ onChange: (e)=>setTitleFilter(e.target.value)
3236
+ }),
3237
+ /*#__PURE__*/ (0, $hgUW1$jsx)((0, $hgUW1$Dropdown), {
3238
+ className: "ds-l-col--12 ds-l-sm-col--6",
3239
+ labelClassName: "ds-u-margin-top--1 ds-u-sm-margin-top--0",
3240
+ options: typeOptions,
3241
+ label: "Type",
3242
+ value: typeFilter,
3243
+ name: "dc-data-dictionary-type",
3244
+ onChange: (e)=>setTypeFilter(e.target.value)
3245
+ }),
3246
+ /*#__PURE__*/ (0, $hgUW1$jsx)("div", {
3247
+ 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",
3248
+ children: /*#__PURE__*/ (0, $hgUW1$jsx)("div", {
3249
+ className: "ds-u-display--flex ds-u-justify-content--end ds-l-col--12 ds-l-md-col--6 ds-u-padding-x--0",
3250
+ children: /*#__PURE__*/ (0, $hgUW1$jsx)((0, $2eec38d4d0dbf714$export$2e2bcd8739ae039), {
3251
+ clearFiltersFn: ()=>{
3252
+ setTitleFilter("");
3253
+ setTypeFilter("all");
3254
+ }
3255
+ })
3256
+ })
3257
+ })
3258
+ ]
3259
+ })
3260
+ })
3261
+ })
3262
+ }),
3263
+ /*#__PURE__*/ (0, $hgUW1$jsx)((0, $6765a74df807d015$export$2e2bcd8739ae039), {
3264
+ tableColumns: tableColumns,
3265
+ tableData: tableData,
3266
+ pageSize: pageSize,
3267
+ columnFilters: columnFilters
3268
+ })
3269
+ ]
3133
3270
  });
3134
3271
  };
3135
3272
  var $a6e312940f7003ef$export$2e2bcd8739ae039 = $a6e312940f7003ef$var$DatasetDictionaryTable;
@@ -5398,8 +5535,6 @@ function $3b6ca952e79f0695$var$updateQueryForDatastore(condition) {
5398
5535
  const $3b6ca952e79f0695$var$QueryBuilder = ({ resource: resource, id: id, includeSearchParams: includeSearchParams, customColumns: customColumns })=>{
5399
5536
  const { conditions: conditions, schema: schema, setConditions: setConditions } = resource;
5400
5537
  const fields = Object.keys(schema[id].fields);
5401
- const hasConditions = conditions.length > 0;
5402
- const [queryCount, setQueryCount] = (0, $hgUW1$useState)(0);
5403
5538
  const [queryConditions, setQueryConditions] = (0, $hgUW1$useState)([]);
5404
5539
  const [titleConditions, setTitleConditions] = (0, $hgUW1$useState)([]); // Add use effect to load conditions on first load if needed
5405
5540
  const [conditionsChanged, setConditionsChanged] = (0, $hgUW1$useState)(false);