@operato/data-grist 10.29.45 → 10.29.49

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@operato/data-grist",
3
- "version": "10.29.45",
3
+ "version": "10.29.49",
4
4
  "description": "User interface for grid (desktop) and list (mobile)",
5
5
  "author": "heartyoh",
6
6
  "type": "module",
@@ -78,14 +78,14 @@
78
78
  "@material/web": "^2.0.0",
79
79
  "@operato/headroom": "^10.29.1",
80
80
  "@operato/i18n": "^10.29.27",
81
- "@operato/input": "^10.29.44",
82
- "@operato/list-state": "^10.29.44",
83
- "@operato/p13n": "^10.29.45",
84
- "@operato/popup": "^10.29.44",
81
+ "@operato/input": "^10.29.49",
82
+ "@operato/list-state": "^10.29.49",
83
+ "@operato/p13n": "^10.29.49",
84
+ "@operato/popup": "^10.29.49",
85
85
  "@operato/pull-to-refresh": "^10.29.23",
86
86
  "@operato/styles": "^10.29.30",
87
87
  "@operato/time-calculator": "^10.29.1",
88
- "@operato/utils": "^10.29.44",
88
+ "@operato/utils": "^10.29.49",
89
89
  "i18next": "^24.2.1",
90
90
  "json5": "^2.2.0",
91
91
  "lit": "^3.1.2",
@@ -124,5 +124,5 @@
124
124
  "prettier --write"
125
125
  ]
126
126
  },
127
- "gitHead": "665fe43472777812af4e7f6be3c64c33940b04ea"
127
+ "gitHead": "38fba85b1fa1bc1438086973dfe9ec9f6ec53879"
128
128
  }
@@ -1,5 +1,11 @@
1
1
  import { expect } from '@open-wc/testing'
2
- import { externalFilters, ownedFilterIndex, patchFilterFields } from '../src/filters/filter-ownership.js'
2
+ import {
3
+ externalFilters,
4
+ isEmptyFilterValue,
5
+ normalizeFilters,
6
+ ownedFilterIndex,
7
+ patchFilterFields
8
+ } from '../src/filters/filter-ownership.js'
3
9
  import type { ColumnConfig, FilterValue } from '../src/types.js'
4
10
 
5
11
  describe('filter field ownership', () => {
@@ -59,3 +65,28 @@ describe('search predicates', () => {
59
65
  expect(externalFilters(filters, [name])).to.deep.equal([])
60
66
  })
61
67
  })
68
+
69
+ describe('an empty filter value', () => {
70
+ it('is no value, an empty string, or a list of only those', () => {
71
+ for (const value of [undefined, null, '', [], [''], ['', null]]) expect(isEmptyFilterValue(value), String(value)).to.equal(true)
72
+ })
73
+
74
+ it('is not false, 0, or a list holding one choice', () => {
75
+ for (const value of [false, 0, 'main', ['main'], ['', 'main'], [0]]) expect(isEmptyFilterValue(value), String(value)).to.equal(false)
76
+ })
77
+ })
78
+
79
+ describe('filters entering the grid', () => {
80
+ it('drop a list operator with no choice and keep the rest', () => {
81
+ const filters = [
82
+ { name: 'type', operator: 'in', value: 'main' },
83
+ { name: 'state', operator: 'in', value: [] },
84
+ { name: 'kind', operator: 'notin', value: [''] },
85
+ { name: 'owner', operator: 'is_null', value: null }
86
+ ] as FilterValue[]
87
+ expect(normalizeFilters(filters)).to.deep.equal([
88
+ { name: 'type', operator: 'in', value: ['main'] },
89
+ { name: 'owner', operator: 'is_null', value: null }
90
+ ])
91
+ })
92
+ })
@@ -40,7 +40,8 @@ describe('list defaults and the shape of list operators', () => {
40
40
  })
41
41
 
42
42
  let reads: any[][] = []
43
- const mount = async () => {
43
+ const typeColumn = { name: 'type', header: 'type', filter: { operator: 'in', value: 'main' } }
44
+ const mount = async (columns: any[] = [typeColumn]) => {
44
45
  addressController().registerQuery()
45
46
  reads = []
46
47
  const grist = await fixture<DataGrist>(
@@ -48,7 +49,7 @@ describe('list defaults and the shape of list operators', () => {
48
49
  style="display:block;width:800px;height:400px"
49
50
  .urlParamsSensitive=${true}
50
51
  .config=${{
51
- columns: [{ name: 'type', header: 'type', filter: { operator: 'in', value: 'main' } }],
52
+ columns,
52
53
  pagination: { limit: 20 }
53
54
  }}
54
55
  .fetchHandler=${async ({ filters }: any) => {
@@ -70,6 +71,37 @@ describe('list defaults and the shape of list operators', () => {
70
71
  expect(reads.every(read => read.length === 1)).to.equal(true)
71
72
  })
72
73
 
74
+ it('a default whose list holds no choice is no condition: it is neither read nor written', async () => {
75
+ // A board list's state default was `in []`; it reached the server as `state IN ()`, which postgres refuses.
76
+ await writeAddress('?defaults=empty-list')
77
+ await mount([typeColumn, { name: 'state', header: 'state', filter: { operator: 'in', value: [] } }])
78
+ await until(() => reads.length > 0, 'first read')
79
+ expect(reads[reads.length - 1]).to.deep.equal([{ name: 'type', operator: 'in', value: ['main'] }])
80
+ await until(() => filtersInAddress() !== null, 'defaults written')
81
+ expect(filtersInAddress()).to.equal("[{name:'type',operator:'in',value:['main']}]")
82
+ })
83
+
84
+ it('an address holding a list operator with no choice reads without it', async () => {
85
+ await writeAddress("?filters=[{name:'type',operator:'in',value:['main']},{name:'state',operator:'in',value:[]}]")
86
+ await mount([typeColumn, { name: 'state', header: 'state', filter: { operator: 'in', value: [] } }])
87
+ await until(() => reads.length > 0, 'first read')
88
+ expect(reads.every(read => read.every((filter: any) => filter.name !== 'state'))).to.equal(true)
89
+ expect(reads[reads.length - 1]).to.deep.equal([{ name: 'type', operator: 'in', value: ['main'] }])
90
+ })
91
+
92
+ it('a default of false or 0 is a condition', async () => {
93
+ await writeAddress('?defaults=falsy-values')
94
+ await mount([
95
+ { name: 'active', header: 'active', type: 'boolean', filter: { operator: 'eq', value: false } },
96
+ { name: 'count', header: 'count', type: 'integer', filter: { operator: 'eq', value: 0 } }
97
+ ])
98
+ await until(() => reads.length > 0, 'first read')
99
+ expect(reads[reads.length - 1]).to.deep.equal([
100
+ { name: 'active', operator: 'eq', value: false },
101
+ { name: 'count', operator: 'eq', value: 0 }
102
+ ])
103
+ })
104
+
73
105
  it('an address with filters=[] reads with no conditions and keeps it', async () => {
74
106
  await writeAddress('?filters=[]')
75
107
  await mount()