@civicactions/cmsds-open-data-components 4.0.15 → 4.0.16-alpha.1

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
@@ -2776,13 +2776,31 @@ const $7264a673914aa746$export$5f89a5ae87bc48e1 = [
2776
2776
  {
2777
2777
  label: 'Less Than',
2778
2778
  value: '<'
2779
+ },
2780
+ {
2781
+ label: 'Is Empty',
2782
+ value: 'is_empty'
2783
+ },
2784
+ {
2785
+ label: 'Not Empty',
2786
+ value: 'not_empty'
2779
2787
  }
2780
2788
  ];
2781
2789
  function $7264a673914aa746$export$d243819c3ad678fb(operatorValue) {
2782
2790
  const operator = $7264a673914aa746$export$5f89a5ae87bc48e1.find((op)=>op.value === operatorValue);
2783
2791
  return operator ? operator.label : operatorValue; // Return original value if not found
2784
2792
  }
2785
- function $7264a673914aa746$export$2b9377795161999(type) {
2793
+ function $7264a673914aa746$export$2b9377795161999(type, enableEmptyFilters = false) {
2794
+ const emptyOptions = enableEmptyFilters ? [
2795
+ {
2796
+ label: 'Is Empty',
2797
+ value: 'is_empty'
2798
+ },
2799
+ {
2800
+ label: 'Not Empty',
2801
+ value: 'not_empty'
2802
+ }
2803
+ ] : [];
2786
2804
  switch(type){
2787
2805
  case 'text':
2788
2806
  case 'string':
@@ -2806,7 +2824,8 @@ function $7264a673914aa746$export$2b9377795161999(type) {
2806
2824
  {
2807
2825
  label: 'Or',
2808
2826
  value: 'in'
2809
- }
2827
+ },
2828
+ ...emptyOptions
2810
2829
  ];
2811
2830
  case 'date':
2812
2831
  return [
@@ -2825,7 +2844,8 @@ function $7264a673914aa746$export$2b9377795161999(type) {
2825
2844
  {
2826
2845
  label: 'Less Than',
2827
2846
  value: '<'
2828
- }
2847
+ },
2848
+ ...emptyOptions
2829
2849
  ];
2830
2850
  default:
2831
2851
  // These 2 should be safe for all data types
@@ -2837,7 +2857,8 @@ function $7264a673914aa746$export$2b9377795161999(type) {
2837
2857
  {
2838
2858
  label: 'Is Not',
2839
2859
  value: '<>'
2840
- }
2860
+ },
2861
+ ...emptyOptions
2841
2862
  ];
2842
2863
  }
2843
2864
  }
@@ -3552,7 +3573,7 @@ function $eadd6431fddf4b6c$var$getStartDate(condition, schema, id) {
3552
3573
  }
3553
3574
  return new Date();
3554
3575
  }
3555
- const $eadd6431fddf4b6c$var$FilterItem = ({ id: id, condition: condition, index: index, update: update, remove: remove, propertyOptions: propertyOptions, schema: schema, className: className = '' })=>{
3576
+ const $eadd6431fddf4b6c$var$FilterItem = ({ id: id, condition: condition, index: index, update: update, remove: remove, propertyOptions: propertyOptions, schema: schema, className: className = '', enableEmptyFilters: enableEmptyFilters })=>{
3556
3577
  const [operator, setOperator] = (0, $hgUW1$useState)(condition.operator);
3557
3578
  const [property, setProperty] = (0, $hgUW1$useState)(condition.property);
3558
3579
  const [value, setValue] = (0, $hgUW1$useState)(condition.value);
@@ -3621,7 +3642,7 @@ const $eadd6431fddf4b6c$var$FilterItem = ({ id: id, condition: condition, index:
3621
3642
  onChange: (e)=>setProperty(e.target.value)
3622
3643
  }),
3623
3644
  /*#__PURE__*/ (0, $hgUW1$jsx)((0, $hgUW1$Dropdown), {
3624
- options: (0, $7264a673914aa746$export$2b9377795161999)(schema[id].fields[property].mysql_type),
3645
+ options: (0, $7264a673914aa746$export$2b9377795161999)(schema[id].fields[property].mysql_type, enableEmptyFilters),
3625
3646
  className: "ds-u-padding-x--0",
3626
3647
  value: operator,
3627
3648
  label: "Condition",
@@ -3718,7 +3739,7 @@ function $6f4318b1e14124e5$var$updateQueryForDatastore(condition) {
3718
3739
  return cond;
3719
3740
  }
3720
3741
  const $6f4318b1e14124e5$var$FilterDataset = ()=>{
3721
- const { distribution: distribution, resource: resource, customColumns: customColumns = [] } = (0, $hgUW1$useContext)((0, $43a30d745a7bbc86$export$2e2bcd8739ae039));
3742
+ const { distribution: distribution, resource: resource, customColumns: customColumns = [], enableEmptyFilters: enableEmptyFilters } = (0, $hgUW1$useContext)((0, $43a30d745a7bbc86$export$2e2bcd8739ae039));
3722
3743
  const { setPage: setPage } = (0, $hgUW1$useContext)((0, $ee0d4d4f34048447$export$f814ea079e65d8fe));
3723
3744
  if (!resource) return null;
3724
3745
  const customColumnHeaders = (0, $7264a673914aa746$export$8049e8f40a9bdfb8)(customColumns, resource.columns, resource.schema[distribution.identifier]);
@@ -3741,7 +3762,7 @@ const $6f4318b1e14124e5$var$FilterDataset = ()=>{
3741
3762
  {
3742
3763
  property: fields[0],
3743
3764
  value: '',
3744
- operator: (0, $7264a673914aa746$export$2b9377795161999)(schema[id].fields[fields[0]].mysql_type)[0].value,
3765
+ operator: (0, $7264a673914aa746$export$2b9377795161999)(schema[id].fields[fields[0]].mysql_type, enableEmptyFilters)[0].value,
3745
3766
  key: Date.now().toString()
3746
3767
  }
3747
3768
  ]);
@@ -3758,7 +3779,7 @@ const $6f4318b1e14124e5$var$FilterDataset = ()=>{
3758
3779
  {
3759
3780
  property: fields[0],
3760
3781
  value: '',
3761
- operator: (0, $7264a673914aa746$export$2b9377795161999)(schema[id].fields[fields[0]].mysql_type)[0].value,
3782
+ operator: (0, $7264a673914aa746$export$2b9377795161999)(schema[id].fields[fields[0]].mysql_type, enableEmptyFilters)[0].value,
3762
3783
  key: Date.now().toString()
3763
3784
  }
3764
3785
  ]);
@@ -3792,14 +3813,14 @@ const $6f4318b1e14124e5$var$FilterDataset = ()=>{
3792
3813
  };
3793
3814
  const submitConditions = ()=>{
3794
3815
  // only update the data conditions when "Apply filters" is pressed
3795
- const submitConditions = queryConditions.filter((oc)=>{
3816
+ const filteredConditions = queryConditions.filter((oc)=>{
3796
3817
  if (oc.property) return oc;
3797
3818
  return false;
3798
- }).map((oc)=>{
3819
+ });
3820
+ const completeConditions = conditionsReadyToSubmit(filteredConditions).map((oc)=>{
3799
3821
  let cond = Object.assign({}, oc);
3800
3822
  return $6f4318b1e14124e5$var$updateQueryForDatastore(cond);
3801
3823
  });
3802
- const completeConditions = conditionsReadyToSubmit(submitConditions);
3803
3824
  if (completeConditions.length) {
3804
3825
  setConditions(completeConditions);
3805
3826
  setPage(1);
@@ -3818,7 +3839,8 @@ const $6f4318b1e14124e5$var$FilterDataset = ()=>{
3818
3839
  };
3819
3840
  const completeConditions = conditions.filter((condition)=>{
3820
3841
  if (condition) {
3821
- if (!isEmpty(condition.property) && !isEmpty(condition.operator) && !isEmpty(condition.value)) return condition;
3842
+ const isEmptyOperator = condition.operator === 'is_empty' || condition.operator === 'not_empty';
3843
+ if (!isEmpty(condition.property) && !isEmpty(condition.operator) && (isEmptyOperator || !isEmpty(condition.value))) return condition;
3822
3844
  }
3823
3845
  });
3824
3846
  return completeConditions;
@@ -3863,9 +3885,9 @@ const $6f4318b1e14124e5$var$FilterDataset = ()=>{
3863
3885
  children: [
3864
3886
  /*#__PURE__*/ (0, $hgUW1$jsx)("span", {
3865
3887
  className: "dkan-dataset-toolbar-button-label",
3866
- children: conditions.length > 0 ? `Edit Filters` : 'Filter Dataset'
3888
+ children: conditions && conditions.length > 0 ? `Edit Filters` : 'Filter Dataset'
3867
3889
  }),
3868
- conditions.length > 0 && ` (${conditions.length})`
3890
+ conditions && conditions.length > 0 && ` (${conditions.length})`
3869
3891
  ]
3870
3892
  })
3871
3893
  ]
@@ -3946,7 +3968,8 @@ const $6f4318b1e14124e5$var$FilterDataset = ()=>{
3946
3968
  propertyOptions: propertyOptions,
3947
3969
  update: updateCondition,
3948
3970
  remove: removeCondition,
3949
- className: index !== 0 ? "ds-u-border-top--1" : "ds-u-border--0"
3971
+ className: index !== 0 ? "ds-u-border-top--1" : "ds-u-border--0",
3972
+ enableEmptyFilters: enableEmptyFilters
3950
3973
  }, qf.key))
3951
3974
  }),
3952
3975
  /*#__PURE__*/ (0, $hgUW1$jsx)("div", {
@@ -4247,7 +4270,7 @@ const $85f8ff1ff89899c7$var$DataTableToolbar = ({ resource: resource, id: id, co
4247
4270
  children: [
4248
4271
  conditions.length > 0 ? conditions.map((condition, index)=>/*#__PURE__*/ (0, $hgUW1$jsx)((0, $c5b172e8d1a8197c$export$2e2bcd8739ae039), {
4249
4272
  iconClass: "far fa-filter",
4250
- text: `"${condition.property}" ${(0, $7264a673914aa746$export$d243819c3ad678fb)(condition.operator).toLowerCase()} ${condition.value}`,
4273
+ text: `"${condition.property}" ${(0, $7264a673914aa746$export$d243819c3ad678fb)(condition.operator).toLowerCase()}${condition.value === '' ? '' : ` ${condition.value}`}`,
4251
4274
  onClick: ()=>{
4252
4275
  removeCondition(index);
4253
4276
  }
@@ -5284,11 +5307,24 @@ const $1d3d480a9cfaabe0$var$useDatastore = (resourceId, rootAPIUrl, options, add
5284
5307
  const datasetID = additionalParams.datasetID;
5285
5308
  // Remove datasetID from params to avoid sending it to the API
5286
5309
  const { datasetID: _, ...restAdditionalParams } = additionalParams;
5310
+ const apiConditions = conditions?.map((c)=>{
5311
+ if (c.operator === 'is_empty') return {
5312
+ ...c,
5313
+ operator: '=',
5314
+ value: ''
5315
+ };
5316
+ if (c.operator === 'not_empty') return {
5317
+ ...c,
5318
+ operator: '<>',
5319
+ value: ''
5320
+ };
5321
+ return c;
5322
+ });
5287
5323
  let params = {
5288
5324
  keys: keys,
5289
5325
  limit: limit,
5290
5326
  offset: offset,
5291
- conditions: conditions,
5327
+ conditions: apiConditions,
5292
5328
  sorts: sort,
5293
5329
  properties: properties,
5294
5330
  groupings: groupings,
@@ -6428,7 +6464,7 @@ const $a0f13962e513caa1$var$getDataDictionary = (dataDictionaryUrl)=>{
6428
6464
  dataDictionaryLoading: isPending
6429
6465
  };
6430
6466
  };
6431
- const $a0f13962e513caa1$var$Dataset = ({ id: id, rootUrl: rootUrl, customColumns: customColumns, setDatasetTitle: setDatasetTitle, customMetadataMapping: customMetadataMapping, apiPageUrl: apiPageUrl = "/api", dataDictionaryUrl: dataDictionaryUrl, borderlessTabs: borderlessTabs = false, defaultPageSize: defaultPageSize = 25, dataDictionaryCSV: dataDictionaryCSV = false, dataDictionaryBanner: dataDictionaryBanner = false, disableTableControls: disableTableControls = false, hideDataDictionary: hideDataDictionary = false, customDescription: customDescription, updateAriaLive: updateAriaLive, showRowLimitNotice: showRowLimitNotice = false })=>{
6467
+ const $a0f13962e513caa1$var$Dataset = ({ id: id, rootUrl: rootUrl, customColumns: customColumns, setDatasetTitle: setDatasetTitle, customMetadataMapping: customMetadataMapping, apiPageUrl: apiPageUrl = "/api", dataDictionaryUrl: dataDictionaryUrl, borderlessTabs: borderlessTabs = false, defaultPageSize: defaultPageSize = 25, dataDictionaryCSV: dataDictionaryCSV = false, dataDictionaryBanner: dataDictionaryBanner = false, disableTableControls: disableTableControls = false, hideDataDictionary: hideDataDictionary = false, customDescription: customDescription, updateAriaLive: updateAriaLive, showRowLimitNotice: showRowLimitNotice = false, enableEmptyFilters: enableEmptyFilters = false })=>{
6432
6468
  const options = location.search ? {
6433
6469
  ...(0, $hgUW1$qs).parse(location.search, {
6434
6470
  ignoreQueryPrefix: true
@@ -6586,7 +6622,8 @@ const $a0f13962e513caa1$var$Dataset = ({ id: id, rootUrl: rootUrl, customColumns
6586
6622
  rootUrl: rootUrl,
6587
6623
  customColumns: customColumns,
6588
6624
  dataDictionaryBanner: dataDictionaryBanner && displayDataDictionaryTab,
6589
- datasetTableControls: !disableTableControls
6625
+ datasetTableControls: !disableTableControls,
6626
+ enableEmptyFilters: enableEmptyFilters
6590
6627
  },
6591
6628
  children: /*#__PURE__*/ (0, $hgUW1$jsx)((0, $39bc4d98030a5599$export$2e2bcd8739ae039), {})
6592
6629
  }) : /*#__PURE__*/ (0, $hgUW1$jsx)("p", {