@operato/app 1.0.0-beta.9 → 1.0.2

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.
Files changed (102) hide show
  1. package/CHANGELOG.md +379 -0
  2. package/demo/data-grist-test.html +1 -1
  3. package/dist/src/filters-form/filter-resource-select.d.ts +4 -0
  4. package/dist/src/filters-form/filter-resource-select.js +78 -0
  5. package/dist/src/filters-form/filter-resource-select.js.map +1 -0
  6. package/dist/src/filters-form/index.d.ts +1 -0
  7. package/dist/src/filters-form/index.js +5 -0
  8. package/dist/src/filters-form/index.js.map +1 -0
  9. package/dist/src/grist-editor/index.js +1 -9
  10. package/dist/src/grist-editor/index.js.map +1 -1
  11. package/dist/src/grist-editor/ox-grist-editor-resource-object-legacy.d.ts +10 -0
  12. package/dist/src/grist-editor/ox-grist-editor-resource-object-legacy.js +99 -0
  13. package/dist/src/grist-editor/ox-grist-editor-resource-object-legacy.js.map +1 -0
  14. package/dist/src/grist-editor/ox-grist-editor-resource-object.d.ts +0 -1
  15. package/dist/src/grist-editor/ox-grist-editor-resource-object.js +10 -13
  16. package/dist/src/grist-editor/ox-grist-editor-resource-object.js.map +1 -1
  17. package/dist/src/grist-editor/ox-grist-renderer-crontab.js +3 -3
  18. package/dist/src/grist-editor/ox-grist-renderer-crontab.js.map +1 -1
  19. package/dist/src/grist-editor/ox-grist-renderer-resource-id.js +5 -2
  20. package/dist/src/grist-editor/ox-grist-renderer-resource-id.js.map +1 -1
  21. package/dist/src/grist-editor/ox-popup-code-input.js +5 -4
  22. package/dist/src/grist-editor/ox-popup-code-input.js.map +1 -1
  23. package/dist/src/grist-editor/ox-selector-resource-id.js +5 -4
  24. package/dist/src/grist-editor/ox-selector-resource-id.js.map +1 -1
  25. package/dist/src/grist-editor/ox-selector-resource-object-adv.d.ts +36 -0
  26. package/dist/src/grist-editor/ox-selector-resource-object-adv.js +270 -0
  27. package/dist/src/grist-editor/ox-selector-resource-object-adv.js.map +1 -0
  28. package/dist/src/grist-editor/ox-selector-resource-object-legacy.d.ts +39 -0
  29. package/dist/src/grist-editor/ox-selector-resource-object-legacy.js +351 -0
  30. package/dist/src/grist-editor/ox-selector-resource-object-legacy.js.map +1 -0
  31. package/dist/src/grist-editor/ox-selector-resource-object.d.ts +3 -8
  32. package/dist/src/grist-editor/ox-selector-resource-object.js +76 -152
  33. package/dist/src/grist-editor/ox-selector-resource-object.js.map +1 -1
  34. package/dist/src/input/ox-input-background-pattern.d.ts +3 -0
  35. package/dist/src/input/ox-input-background-pattern.js +35 -7
  36. package/dist/src/input/ox-input-background-pattern.js.map +1 -1
  37. package/dist/src/input/ox-input-fill-style.d.ts +4 -2
  38. package/dist/src/input/ox-input-fill-style.js +13 -7
  39. package/dist/src/input/ox-input-fill-style.js.map +1 -1
  40. package/dist/src/input/ox-input-graphql.d.ts +1 -1
  41. package/dist/src/input/ox-input-graphql.js +7 -7
  42. package/dist/src/input/ox-input-graphql.js.map +1 -1
  43. package/dist/src/property-editor/index.d.ts +2 -1
  44. package/dist/src/property-editor/index.js +5 -2
  45. package/dist/src/property-editor/index.js.map +1 -1
  46. package/dist/src/property-editor/ox-property-editor-graphql.d.ts +2 -2
  47. package/dist/src/property-editor/ox-property-editor-graphql.js +4 -4
  48. package/dist/src/property-editor/ox-property-editor-graphql.js.map +1 -1
  49. package/dist/tsconfig.tsbuildinfo +1 -1
  50. package/package.json +25 -30
  51. package/src/filters-form/filter-resource-select.ts +94 -0
  52. package/src/filters-form/index.ts +6 -0
  53. package/src/grist-editor/index.ts +1 -9
  54. package/src/grist-editor/ox-grist-editor-resource-object-legacy.ts +123 -0
  55. package/src/grist-editor/ox-grist-editor-resource-object.ts +22 -14
  56. package/src/grist-editor/ox-grist-renderer-crontab.ts +5 -4
  57. package/src/grist-editor/ox-grist-renderer-resource-id.ts +6 -2
  58. package/src/grist-editor/ox-popup-code-input.ts +5 -4
  59. package/src/grist-editor/ox-selector-resource-id.ts +5 -4
  60. package/src/grist-editor/ox-selector-resource-object-legacy.ts +360 -0
  61. package/src/grist-editor/ox-selector-resource-object.ts +76 -166
  62. package/src/input/ox-input-background-pattern.ts +37 -7
  63. package/src/input/ox-input-fill-style.ts +18 -8
  64. package/src/input/ox-input-graphql.ts +8 -8
  65. package/src/property-editor/index.ts +5 -2
  66. package/src/property-editor/ox-property-editor-graphql.ts +5 -4
  67. package/dist/src/grist-editor/ox-grist-editor-crontab.d.ts +0 -8
  68. package/dist/src/grist-editor/ox-grist-editor-crontab.js +0 -50
  69. package/dist/src/grist-editor/ox-grist-editor-crontab.js.map +0 -1
  70. package/dist/src/grist-editor/ox-grist-editor-parameters.d.ts +0 -12
  71. package/dist/src/grist-editor/ox-grist-editor-parameters.js +0 -84
  72. package/dist/src/grist-editor/ox-grist-editor-parameters.js.map +0 -1
  73. package/dist/src/grist-editor/ox-grist-editor-partition-keys.d.ts +0 -11
  74. package/dist/src/grist-editor/ox-grist-editor-partition-keys.js +0 -74
  75. package/dist/src/grist-editor/ox-grist-editor-partition-keys.js.map +0 -1
  76. package/dist/src/grist-editor/ox-grist-editor-value-map.d.ts +0 -11
  77. package/dist/src/grist-editor/ox-grist-editor-value-map.js +0 -74
  78. package/dist/src/grist-editor/ox-grist-editor-value-map.js.map +0 -1
  79. package/dist/src/grist-editor/ox-parameters-builder.d.ts +0 -4
  80. package/dist/src/grist-editor/ox-parameters-builder.js +0 -118
  81. package/dist/src/grist-editor/ox-parameters-builder.js.map +0 -1
  82. package/dist/src/grist-editor/ox-popup-crontab-input.d.ts +0 -11
  83. package/dist/src/grist-editor/ox-popup-crontab-input.js +0 -74
  84. package/dist/src/grist-editor/ox-popup-crontab-input.js.map +0 -1
  85. package/dist/src/grist-editor/ox-popup-parameters-builder.d.ts +0 -13
  86. package/dist/src/grist-editor/ox-popup-parameters-builder.js +0 -111
  87. package/dist/src/grist-editor/ox-popup-parameters-builder.js.map +0 -1
  88. package/dist/src/grist-editor/ox-popup-partition-keys-input.d.ts +0 -12
  89. package/dist/src/grist-editor/ox-popup-partition-keys-input.js +0 -98
  90. package/dist/src/grist-editor/ox-popup-partition-keys-input.js.map +0 -1
  91. package/dist/src/grist-editor/ox-popup-value-map-input.d.ts +0 -12
  92. package/dist/src/grist-editor/ox-popup-value-map-input.js +0 -104
  93. package/dist/src/grist-editor/ox-popup-value-map-input.js.map +0 -1
  94. package/src/grist-editor/ox-grist-editor-crontab.ts +0 -62
  95. package/src/grist-editor/ox-grist-editor-parameters.ts +0 -99
  96. package/src/grist-editor/ox-grist-editor-partition-keys.ts +0 -86
  97. package/src/grist-editor/ox-grist-editor-value-map.ts +0 -86
  98. package/src/grist-editor/ox-parameters-builder.ts +0 -128
  99. package/src/grist-editor/ox-popup-crontab-input.ts +0 -74
  100. package/src/grist-editor/ox-popup-parameters-builder.ts +0 -106
  101. package/src/grist-editor/ox-popup-partition-keys-input.ts +0 -95
  102. package/src/grist-editor/ox-popup-value-map-input.ts +0 -101
@@ -0,0 +1,360 @@
1
+ import '@operato/data-grist'
2
+ import '@operato/form/ox-search-form.js'
3
+
4
+ import gql from 'graphql-tag'
5
+ import { css, html, LitElement } from 'lit'
6
+ import { customElement, property, query } from 'lit/decorators.js'
7
+
8
+ import {
9
+ ColumnConfig,
10
+ DataGrist,
11
+ FetchHandler,
12
+ FetchOption,
13
+ GristData,
14
+ GristEventHandler,
15
+ GristRecord,
16
+ ZERO_DATA
17
+ } from '@operato/data-grist'
18
+ import { MultiColumnFormStyles, SearchForm } from '@operato/form'
19
+ import { buildArgs, client, gqlContext } from '@operato/graphql'
20
+ import { i18next } from '@operato/i18n'
21
+ import { closePopup } from '@operato/popup'
22
+ import { isMobileDevice } from '@operato/utils'
23
+
24
+ @customElement('ox-selector-resource-object-legacy')
25
+ export class OxSelectorResourceObjectLegacy extends LitElement {
26
+ static styles = [
27
+ MultiColumnFormStyles,
28
+ css`
29
+ :host {
30
+ display: flex;
31
+ flex-direction: column;
32
+
33
+ background-color: #fff;
34
+ }
35
+
36
+ ox-grist {
37
+ flex: 1;
38
+ }
39
+
40
+ .button-container {
41
+ display: flex;
42
+ margin-left: auto;
43
+ }
44
+
45
+ form {
46
+ position: relative;
47
+ }
48
+
49
+ [search] {
50
+ position: absolute;
51
+ right: 0;
52
+ }
53
+ `
54
+ ]
55
+
56
+ @property({ type: String }) value?: string
57
+ @property({ type: Object }) config: any
58
+ @property({ type: Object }) data: GristData = ZERO_DATA
59
+ @property({ type: String }) queryName!: string
60
+ @property({ type: Object }) basicArgs: any
61
+ @property({ type: Object }) confirmCallback?: (record?: GristRecord | null) => void
62
+ @property({ type: Array }) selectedRecords: GristRecord[] = []
63
+
64
+ @property({ type: Array }) searchFields: any
65
+ @property({ type: Array }) select: {
66
+ type: string
67
+ name: string
68
+ header: string
69
+ subFields?: string[]
70
+ hidden: boolean
71
+ ignoreCondition: boolean
72
+ queryName: string
73
+ width: number
74
+ }[] = []
75
+ @property({ type: Object }) list: any
76
+ @property({ type: String }) valueField: string | ((item: any) => any) = 'id'
77
+
78
+ @query('ox-grist') grist!: DataGrist
79
+ @query('ox-search-form') searchForm!: SearchForm
80
+
81
+ render() {
82
+ return html`
83
+ <ox-search-form
84
+ id="search-form"
85
+ @keypress=${(e: KeyboardEvent) => {
86
+ if (e.key === 'Enter') {
87
+ this.grist.fetch()
88
+ }
89
+ }}
90
+ @submit=${(e: SubmitEvent) => this.grist.fetch()}
91
+ .fields=${this.searchFields}
92
+ autofocus
93
+ ></ox-search-form>
94
+
95
+ <ox-grist
96
+ .mode=${isMobileDevice() ? 'LIST' : 'GRID'}
97
+ .config=${this.config}
98
+ .data=${this.data}
99
+ .fetchHandler=${this.fetchHandler.bind(this)}
100
+ .selectedRecords=${this.selectedRecords}
101
+ >
102
+ <div slot="headroom" id="headroom">
103
+ <div id="filters">
104
+ <ox-filters-form></ox-filters-form>
105
+ </div>
106
+ </div>
107
+ </ox-grist>
108
+
109
+ <div class="button-container">
110
+ <mwc-button @click=${this.onempty.bind(this)}>${i18next.t('button.empty')}</mwc-button>
111
+ <mwc-button @click=${this.oncancel.bind(this)}>${i18next.t('button.cancel')}</mwc-button>
112
+ <mwc-button @click=${this.onconfirm.bind(this)}>${i18next.t('button.confirm')}</mwc-button>
113
+ </div>
114
+ `
115
+ }
116
+
117
+ onempty() {
118
+ this.confirmCallback && this.confirmCallback()
119
+ closePopup(this)
120
+ }
121
+
122
+ oncancel() {
123
+ closePopup(this)
124
+ }
125
+
126
+ onconfirm() {
127
+ this.confirmCallback && this.confirmCallback(this.selected)
128
+ closePopup(this)
129
+ }
130
+
131
+ fetchHandler: FetchHandler = async ({ filters, page, limit, sorters = [] }) => {
132
+ const response = await client.query({
133
+ query: gql`
134
+ query {
135
+ fetch: ${this.queryName} (${buildArgs(await this._buildConditions({ filters, page, limit, sorters }))}) {
136
+ ${this.getSelectFields()}
137
+ }
138
+ }
139
+ `,
140
+ context: gqlContext()
141
+ })
142
+
143
+ if (!response.errors) {
144
+ const records = response.data.fetch.items.map((item: any) => {
145
+ let rowValue
146
+
147
+ if (this.valueField && typeof this.valueField === 'function') {
148
+ rowValue = this.valueField(item)
149
+ } else if (this.valueField) {
150
+ rowValue = item[this.valueField]
151
+ } else {
152
+ rowValue = item.id
153
+ }
154
+
155
+ if (this.value && this.value === rowValue) {
156
+ this.selectedRecords = [item]
157
+ item['__selected__'] = true
158
+ }
159
+
160
+ return item
161
+ })
162
+ const total = response.data.fetch.total
163
+
164
+ return {
165
+ records,
166
+ total,
167
+ limit,
168
+ page
169
+ }
170
+ }
171
+ }
172
+
173
+ async firstUpdated() {
174
+ this.config = {
175
+ columns: [
176
+ {
177
+ type: 'gutter',
178
+ gutterName: 'sequence'
179
+ },
180
+ {
181
+ type: 'gutter',
182
+ gutterName: 'row-selector',
183
+ multiple: false
184
+ }
185
+ ],
186
+ rows: {
187
+ selectable: {
188
+ multiple: false
189
+ },
190
+ handlers: {
191
+ click: 'select-row',
192
+ dblclick: ((columns, data, column, record, rowIndex, field) => {
193
+ this.onconfirm()
194
+ }) as GristEventHandler
195
+ },
196
+ appendable: false
197
+ }
198
+ }
199
+
200
+ if (this.select && this.select.length > 0) {
201
+ let _searchFields = this.select.filter(selectField => !selectField.hidden && !selectField.ignoreCondition)
202
+ if (this.list && this.list.fields && this.list.fields.length > 0) {
203
+ _searchFields = _searchFields.filter(searchField => this.list.fields.indexOf(searchField.name) >= 0)
204
+ } else {
205
+ _searchFields = _searchFields.slice(0, 4)
206
+ }
207
+
208
+ this.searchFields = _searchFields.map(selectField => {
209
+ const fieldType = (selectField.type && selectField.type.toLowerCase()) || 'string'
210
+ const numberTypes = ['integer', 'float']
211
+ return {
212
+ label: selectField.header || i18next.t(`field.${selectField.name}`),
213
+ name: selectField.name,
214
+ type:
215
+ fieldType === 'string'
216
+ ? 'text'
217
+ : numberTypes.indexOf(fieldType) >= 0
218
+ ? 'number'
219
+ : fieldType === 'boolean'
220
+ ? 'checkbox'
221
+ : fieldType,
222
+ queryName: selectField.queryName,
223
+ props:
224
+ fieldType === 'string'
225
+ ? { searchOper: 'i_like' }
226
+ : fieldType === 'object'
227
+ ? { searchOper: 'in' }
228
+ : { searchOper: 'eq' },
229
+ attrs: fieldType === 'boolean' ? ['indeterminated'] : []
230
+ }
231
+ })
232
+ this.config = {
233
+ ...this.config,
234
+ columns: [
235
+ ...this.config.columns,
236
+ ...this.select.map(selectField => {
237
+ return {
238
+ ...selectField,
239
+ type: selectField.type || 'string',
240
+ width: selectField.width || 160,
241
+ header: selectField.header || i18next.t(`field.${selectField.name}`)
242
+ }
243
+ })
244
+ ]
245
+ }
246
+ } else {
247
+ this.searchFields = [
248
+ {
249
+ label: i18next.t('field.name'),
250
+ name: 'name',
251
+ type: 'text',
252
+ props: { searchOper: 'i_like' }
253
+ },
254
+ {
255
+ label: i18next.t('field.description'),
256
+ name: 'description',
257
+ type: 'text',
258
+ props: { searchOper: 'i_like' }
259
+ }
260
+ ]
261
+
262
+ this.config = {
263
+ ...this.config,
264
+ columns: [
265
+ ...this.config.columns,
266
+ {
267
+ type: 'string',
268
+ name: 'id',
269
+ header: i18next.t('field.id'),
270
+ hidden: true
271
+ },
272
+ {
273
+ type: 'string',
274
+ name: 'name',
275
+ header: i18next.t('field.name'),
276
+ record: {
277
+ align: 'left'
278
+ },
279
+ sortable: true,
280
+ width: 160
281
+ },
282
+ {
283
+ type: 'string',
284
+ name: 'description',
285
+ header: i18next.t('field.description'),
286
+ record: {
287
+ align: 'left'
288
+ },
289
+ sortable: true,
290
+ width: 300
291
+ }
292
+ ]
293
+ }
294
+ }
295
+
296
+ this.config = {
297
+ ...this.config,
298
+ list: {
299
+ ...this.list,
300
+ fields:
301
+ this.list && this.list.fields && this.list.fields.length > 0
302
+ ? this.list.fields
303
+ : (this.config.columns as ColumnConfig[])
304
+ .filter(column => column.type !== 'gutter')
305
+ .slice(0, 3)
306
+ .map(column => column.name)
307
+ }
308
+ }
309
+
310
+ await this.updateComplete
311
+ this.grist && this.grist.focus()
312
+ }
313
+
314
+ getSelectFields() {
315
+ if (this.select && this.select.length > 0) {
316
+ return `items {
317
+ ${this.select.map(selectField => {
318
+ return selectField.type === 'object'
319
+ ? `${selectField.name} { ${
320
+ selectField.subFields && selectField.subFields.length > 0
321
+ ? selectField.subFields.join(' ')
322
+ : `id name description`
323
+ } }`
324
+ : `${selectField.name}`
325
+ })}
326
+ }
327
+ total`
328
+ } else {
329
+ return `
330
+ items {
331
+ id
332
+ name
333
+ description
334
+ }
335
+ total
336
+ `
337
+ }
338
+ }
339
+
340
+ async _buildConditions({ filters, page, limit, sorters }: FetchOption) {
341
+ const queryConditions = {
342
+ filters: [],
343
+ ...this.basicArgs
344
+ }
345
+
346
+ queryConditions.filters = [...queryConditions.filters, ...(await this.searchForm.getQueryFilters())]
347
+ queryConditions.pagination = { page, limit }
348
+ queryConditions.sortings = sorters
349
+
350
+ return queryConditions
351
+ }
352
+
353
+ get selected() {
354
+ var grist = this.renderRoot.querySelector('ox-grist') as DataGrist
355
+
356
+ var selected = grist.selected
357
+
358
+ return selected && selected.length > 0 ? selected[0] : undefined
359
+ }
360
+ }
@@ -1,53 +1,46 @@
1
1
  import '@operato/data-grist'
2
- import '@operato/form/ox-search-form.js'
3
2
 
4
3
  import gql from 'graphql-tag'
5
4
  import { css, html, LitElement } from 'lit'
6
5
  import { customElement, property, query } from 'lit/decorators.js'
7
6
 
8
- import {
9
- ColumnConfig,
10
- DataGrist,
11
- FetchHandler,
12
- FetchOption,
13
- GristData,
14
- GristEventHandler,
15
- GristRecord,
16
- ZERO_DATA
17
- } from '@operato/data-grist'
18
- import { MultiColumnFormStyles, SearchForm } from '@operato/form'
19
- import { buildArgs, client, gqlContext } from '@operato/graphql'
7
+ import { DataGrist, FetchHandler, GristData, GristEventHandler, GristRecord, ZERO_DATA } from '@operato/data-grist'
8
+ import { client, gqlContext } from '@operato/graphql'
20
9
  import { i18next } from '@operato/i18n'
21
- import { isMobileDevice } from '@operato/utils'
10
+ import { closePopup } from '@operato/popup'
11
+ import { adjustFilters, isMobileDevice } from '@operato/utils'
22
12
 
23
13
  @customElement('ox-selector-resource-object')
24
14
  export class OxSelectorResourceObject extends LitElement {
25
15
  static styles = [
26
- MultiColumnFormStyles,
27
16
  css`
28
17
  :host {
29
18
  display: flex;
30
19
  flex-direction: column;
31
20
 
32
21
  background-color: #fff;
22
+
23
+ width: var(--overlay-center-normal-width, 50%);
24
+ height: var(--overlay-center-normal-height, 50%);
33
25
  }
34
26
 
35
27
  ox-grist {
36
28
  flex: 1;
37
29
  }
38
30
 
39
- .button-container {
31
+ #filters {
40
32
  display: flex;
41
- margin-left: auto;
33
+ flex-direction: row;
34
+ justify-content: space-between;
42
35
  }
43
36
 
44
- form {
45
- position: relative;
37
+ #filters > * {
38
+ padding: var(--padding-default) var(--padding-wide);
46
39
  }
47
40
 
48
- [search] {
49
- position: absolute;
50
- right: 0;
41
+ .button-container {
42
+ display: flex;
43
+ margin-left: auto;
51
44
  }
52
45
  `
53
46
  ]
@@ -61,13 +54,12 @@ export class OxSelectorResourceObject extends LitElement {
61
54
  @property({ type: Array }) selectedRecords: GristRecord[] = []
62
55
 
63
56
  @property({ type: Array }) searchFields: any
64
- @property({ type: Array }) select: {
57
+ @property({ type: Array }) columns: {
65
58
  type: string
66
59
  name: string
67
60
  header: string
68
61
  subFields?: string[]
69
62
  hidden: boolean
70
- ignoreCondition: boolean
71
63
  queryName: string
72
64
  width: number
73
65
  }[] = []
@@ -75,28 +67,20 @@ export class OxSelectorResourceObject extends LitElement {
75
67
  @property({ type: String }) valueField: string | ((item: any) => any) = 'id'
76
68
 
77
69
  @query('ox-grist') grist!: DataGrist
78
- @query('ox-search-form') searchForm!: SearchForm
79
70
 
80
71
  render() {
81
72
  return html`
82
- <ox-search-form
83
- id="search-form"
84
- @keypress=${(e: KeyboardEvent) => {
85
- if (e.key === 'Enter') {
86
- this.grist.fetch()
87
- }
88
- }}
89
- @submit=${(e: SubmitEvent) => this.grist.fetch()}
90
- .fields=${this.searchFields}
91
- ></ox-search-form>
92
-
93
73
  <ox-grist
94
74
  .mode=${isMobileDevice() ? 'LIST' : 'GRID'}
95
75
  .config=${this.config}
96
76
  .data=${this.data}
97
77
  .fetchHandler=${this.fetchHandler.bind(this)}
98
78
  .selectedRecords=${this.selectedRecords}
99
- ></ox-grist>
79
+ >
80
+ <div id="filters" slot="headroom">
81
+ <ox-filters-form autofocus></ox-filters-form>
82
+ </div>
83
+ </ox-grist>
100
84
 
101
85
  <div class="button-container">
102
86
  <mwc-button @click=${this.onempty.bind(this)}>${i18next.t('button.empty')}</mwc-button>
@@ -108,27 +92,33 @@ export class OxSelectorResourceObject extends LitElement {
108
92
 
109
93
  onempty() {
110
94
  this.confirmCallback && this.confirmCallback()
111
- history.back()
95
+ closePopup(this)
112
96
  }
113
97
 
114
98
  oncancel() {
115
- history.back()
99
+ closePopup(this)
116
100
  }
117
101
 
118
102
  onconfirm() {
119
103
  this.confirmCallback && this.confirmCallback(this.selected)
120
- history.back()
104
+ closePopup(this)
121
105
  }
122
106
 
123
- fetchHandler: FetchHandler = async ({ filters, page, limit, sorters = [] }) => {
107
+ fetchHandler: FetchHandler = async ({ filters = [], page, limit, sortings = [] }) => {
108
+ if (this.basicArgs) {
109
+ filters = adjustFilters(filters, this.basicArgs)
110
+ }
111
+ const pagination = { page, limit }
112
+
124
113
  const response = await client.query({
125
114
  query: gql`
126
- query {
127
- fetch: ${this.queryName} (${buildArgs(await this._buildConditions({ filters, page, limit, sorters }))}) {
128
- ${this.getSelectFields()}
115
+ query($filters: [Filter!], $pagination: Pagination, $sortings: [Sorting!]) {
116
+ fetch: ${this.queryName} (filters: $filters, pagination: $pagination, sortings: $sortings) {
117
+ ${this.getQueryFields()}
129
118
  }
130
119
  }
131
120
  `,
121
+ variables: { filters, pagination, sortings },
132
122
  context: gqlContext()
133
123
  })
134
124
 
@@ -189,124 +179,57 @@ export class OxSelectorResourceObject extends LitElement {
189
179
  }
190
180
  }
191
181
 
192
- if (this.select && this.select.length > 0) {
193
- let _searchFields = this.select.filter(selectField => !selectField.hidden && !selectField.ignoreCondition)
194
- if (this.list && this.list.fields && this.list.fields.length > 0) {
195
- _searchFields = _searchFields.filter(searchField => this.list.fields.indexOf(searchField.name) >= 0)
196
- } else {
197
- _searchFields = _searchFields.slice(0, 4)
198
- }
199
-
200
- this.searchFields = _searchFields.map(selectField => {
201
- const fieldType = (selectField.type && selectField.type.toLowerCase()) || 'string'
202
- const numberTypes = ['integer', 'float']
203
- return {
204
- label: selectField.header || i18next.t(`field.${selectField.name}`),
205
- name: selectField.name,
206
- type:
207
- fieldType === 'string'
208
- ? 'text'
209
- : numberTypes.indexOf(fieldType) >= 0
210
- ? 'number'
211
- : fieldType === 'boolean'
212
- ? 'checkbox'
213
- : fieldType,
214
- queryName: selectField.queryName,
215
- props:
216
- fieldType === 'string'
217
- ? { searchOper: 'i_like' }
218
- : fieldType === 'object'
219
- ? { searchOper: 'in' }
220
- : { searchOper: 'eq' },
221
- attrs: fieldType === 'boolean' ? ['indeterminated'] : []
222
- }
223
- })
224
- this.config = {
225
- ...this.config,
226
- columns: [
227
- ...this.config.columns,
228
- ...this.select.map(selectField => {
229
- return {
230
- ...selectField,
231
- type: selectField.type || 'string',
232
- width: selectField.width || 160,
233
- header: selectField.header || i18next.t(`field.${selectField.name}`)
234
- }
235
- })
236
- ]
237
- }
238
- } else {
239
- this.searchFields = [
240
- {
241
- label: i18next.t('field.name'),
242
- name: 'name',
243
- type: 'text',
244
- props: { searchOper: 'i_like' }
182
+ const columns = this.columns || [
183
+ {
184
+ type: 'string',
185
+ name: 'id',
186
+ header: i18next.t('field.id'),
187
+ hidden: true
188
+ },
189
+ {
190
+ type: 'string',
191
+ name: 'name',
192
+ header: i18next.t('field.name'),
193
+ record: {
194
+ align: 'left'
245
195
  },
246
- {
247
- label: i18next.t('field.description'),
248
- name: 'description',
249
- type: 'text',
250
- props: { searchOper: 'i_like' }
251
- }
252
- ]
253
-
254
- this.config = {
255
- ...this.config,
256
- columns: [
257
- ...this.config.columns,
258
- {
259
- type: 'string',
260
- name: 'id',
261
- header: i18next.t('field.id'),
262
- hidden: true
263
- },
264
- {
265
- type: 'string',
266
- name: 'name',
267
- header: i18next.t('field.name'),
268
- record: {
269
- align: 'left'
270
- },
271
- sortable: true,
272
- width: 160
273
- },
274
- {
275
- type: 'string',
276
- name: 'description',
277
- header: i18next.t('field.description'),
278
- record: {
279
- align: 'left'
280
- },
281
- sortable: true,
282
- width: 300
283
- }
284
- ]
196
+ sortable: true,
197
+ filter: 'search',
198
+ width: 160
199
+ },
200
+ {
201
+ type: 'string',
202
+ name: 'description',
203
+ header: i18next.t('field.description'),
204
+ record: {
205
+ align: 'left'
206
+ },
207
+ sortable: true,
208
+ filter: 'search',
209
+ width: 300
285
210
  }
286
- }
211
+ ]
287
212
 
288
213
  this.config = {
289
214
  ...this.config,
290
- list: {
291
- ...this.list,
292
- fields:
293
- this.list && this.list.fields && this.list.fields.length > 0
294
- ? this.list.fields
295
- : (this.config.columns as ColumnConfig[])
296
- .filter(column => column.type !== 'gutter')
297
- .slice(0, 3)
298
- .map(column => column.name)
299
- }
215
+ columns: [
216
+ ...this.config.columns,
217
+ ...columns.map(selectField => {
218
+ return {
219
+ ...selectField,
220
+ type: selectField.type || 'string',
221
+ width: selectField.width || 160,
222
+ header: selectField.header || i18next.t(`field.${selectField.name}`)
223
+ }
224
+ })
225
+ ]
300
226
  }
301
-
302
- await this.updateComplete
303
- this.grist && this.grist.focus()
304
227
  }
305
228
 
306
- getSelectFields() {
307
- if (this.select && this.select.length > 0) {
229
+ getQueryFields() {
230
+ if (this.columns && this.columns.length > 0) {
308
231
  return `items {
309
- ${this.select.map(selectField => {
232
+ ${this.columns.map(selectField => {
310
233
  return selectField.type === 'object'
311
234
  ? `${selectField.name} { ${
312
235
  selectField.subFields && selectField.subFields.length > 0
@@ -329,19 +252,6 @@ export class OxSelectorResourceObject extends LitElement {
329
252
  }
330
253
  }
331
254
 
332
- async _buildConditions({ filters, page, limit, sorters }: FetchOption) {
333
- const queryConditions = {
334
- filters: [],
335
- ...this.basicArgs
336
- }
337
-
338
- queryConditions.filters = [...queryConditions.filters, ...(await this.searchForm.getQueryFilters())]
339
- queryConditions.pagination = { page, limit }
340
- queryConditions.sortings = sorters
341
-
342
- return queryConditions
343
- }
344
-
345
255
  get selected() {
346
256
  var grist = this.renderRoot.querySelector('ox-grist') as DataGrist
347
257