@operato/data-grist 1.1.14 → 1.1.15

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.
@@ -116,13 +116,15 @@ export class FiltersForm extends LitElement {
116
116
  }
117
117
 
118
118
  render(): TemplateResult {
119
- const { name: firstSearchFilterName } = this.searchColumns[0] || {}
119
+ // const { name: firstSearchFilterName } = this.searchColumns[0] || {}
120
+ // const searchValue =
121
+ // (firstSearchFilterName &&
122
+ // (this.value?.find(filter => filter.name === firstSearchFilterName)?.value as string)?.match(
123
+ // /^\%(.*)\%$/
124
+ // )?.[1]) ||
125
+ // ''
120
126
  const searchValue =
121
- (firstSearchFilterName &&
122
- (this.value?.find(filter => filter.name === firstSearchFilterName)?.value as string)?.match(
123
- /^\%(.*)\%$/
124
- )?.[1]) ||
125
- ''
127
+ (this.value?.find(filter => filter.operator === 'search')?.value as string)?.match(/^\%(.*)\%$/)?.[1] || ''
126
128
 
127
129
  return html`
128
130
  <form
@@ -268,7 +270,7 @@ export class FiltersForm extends LitElement {
268
270
  }
269
271
 
270
272
  public setInputValue(name: string, value: any) {
271
- const input = this.renderRoot.querySelector(`form > [name="${name}"]`) as HTMLInputElement
273
+ const input = this.renderRoot.querySelector(`form [name="${name}"]`) as HTMLInputElement
272
274
  if (input) {
273
275
  input.value = value
274
276
  input.dispatchEvent(new Event('change', { bubbles: true }))
package/src/index.ts CHANGED
@@ -12,3 +12,5 @@ export * from './gutters'
12
12
  export * from './filters'
13
13
  export * from './sorters/sorters-control'
14
14
  export * from './record-view'
15
+
16
+ export * from './utils/list-param'
package/src/types.ts CHANGED
@@ -111,6 +111,7 @@ export type ColumnConfig = {
111
111
  filter?: FilterConfig
112
112
  imex?: ImexConfig
113
113
  multiple?: boolean
114
+ rowCount?: boolean
114
115
  }
115
116
 
116
117
  export type ValidationCallback = (after: any, before: any, record: GristRecord, column: ColumnConfig) => boolean
@@ -1 +1,2 @@
1
1
  export * from './supports-passive'
2
+ export * from './list-param'
@@ -0,0 +1,72 @@
1
+ import json5 from 'json5'
2
+ import pickBy from 'lodash-es/pickBy'
3
+
4
+ import { FilterValue, SortersConfig } from '../types'
5
+
6
+ export function convertListParamToSearchString({
7
+ filters,
8
+ sorters,
9
+ page,
10
+ limit,
11
+ base
12
+ }: {
13
+ filters?: FilterValue[]
14
+ sorters?: SortersConfig
15
+ page?: number
16
+ limit?: number
17
+ base?: string
18
+ }) {
19
+ const urlParams = new URLSearchParams(base)
20
+
21
+ if (sorters) {
22
+ if (sorters.length > 0) {
23
+ urlParams.set('sorters', json5.stringify(sorters))
24
+ } else {
25
+ urlParams.delete('sorters')
26
+ }
27
+ }
28
+
29
+ if (filters) {
30
+ if (filters.length > 0) {
31
+ urlParams.set('filters', json5.stringify(filters))
32
+ } else {
33
+ urlParams.delete('filters')
34
+ }
35
+ }
36
+
37
+ if (!isNaN(page as any)) {
38
+ urlParams.set('page', String(page))
39
+ }
40
+
41
+ if (!isNaN(limit as any)) {
42
+ urlParams.set('limit', String(limit))
43
+ }
44
+
45
+ return String(urlParams)
46
+ }
47
+
48
+ export function convertSearchStringToListParam(searchParams: string): {
49
+ filters?: FilterValue[]
50
+ sorters?: SortersConfig
51
+ pagination?: {
52
+ page?: number
53
+ limit?: number
54
+ }
55
+ } {
56
+ const urlParams = new URLSearchParams(searchParams)
57
+
58
+ return pickBy(
59
+ {
60
+ filters: json5.parse(urlParams.get('filters') || '[]'),
61
+ sorters: json5.parse(urlParams.get('sorters') || '[]'),
62
+ pagination: pickBy(
63
+ {
64
+ page: Number(urlParams.get('page')),
65
+ limit: Number(urlParams.get('limit'))
66
+ },
67
+ v => !isNaN(v)
68
+ )
69
+ },
70
+ v => v !== undefined && !(typeof v === 'object' && Object.keys(v).length == 0)
71
+ )
72
+ }