@operato/data-grist 2.0.0-alpha.132 → 2.0.0-alpha.133

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/src/data-grist.ts CHANGED
@@ -10,6 +10,7 @@ import isEqual from 'lodash-es/isEqual'
10
10
  import Headroom from '@operato/headroom'
11
11
  import { pulltorefresh } from '@operato/pull-to-refresh'
12
12
  import { HeadroomStyles, ScrollbarStyles, SpinnerStyles } from '@operato/styles'
13
+ import { PagePreferenceProvider } from '@operato/p13n'
13
14
  import { SnapshotTaker, TimeCapsule } from '@operato/utils'
14
15
 
15
16
  import { buildConfig } from './configure/config-builder'
@@ -171,12 +172,12 @@ export class DataGrist extends LitElement implements DataConsumer {
171
172
  */
172
173
  @property({ type: Boolean, attribute: 'url-params-sensitive' }) urlParamsSensitive?: boolean
173
174
 
174
- @property({ type: Object }) personalConfigProvider?: {
175
- load(): PersonalGristPreference | Promise<PersonalGristPreference | undefined> | undefined
176
- save(
177
- preference?: PersonalGristPreference
178
- ): PersonalGristPreference | Promise<PersonalGristPreference | undefined> | undefined
179
- reset(): void | Promise<void>
175
+ @property({ type: Object }) personalConfigProvider: PagePreferenceProvider = {
176
+ load: () => {
177
+ return {}
178
+ },
179
+ save: preference => preference,
180
+ reset: () => {}
180
181
  }
181
182
 
182
183
  @state() personalConfig?: {
@@ -202,6 +203,9 @@ export class DataGrist extends LitElement implements DataConsumer {
202
203
  private originMarginTop?: string
203
204
  private lastLocation: { origin?: string; pathname?: string; search?: string } = {}
204
205
 
206
+ /* 그리드가 준비되기 전에 fetch 요청이 있었음을 나타내는 플래그임 */
207
+ private pendingFetch?: boolean
208
+
205
209
  private popstateEventHandler: EventListener = ((e: Event) => {
206
210
  const { origin, pathname, search } = window.location
207
211
  if (
@@ -315,7 +319,7 @@ export class DataGrist extends LitElement implements DataConsumer {
315
319
  }
316
320
 
317
321
  public applyUpdatedConfiguration() {
318
- if (!this.config?.columns) {
322
+ if (!this.personalConfig) {
319
323
  return
320
324
  }
321
325
 
@@ -323,7 +327,7 @@ export class DataGrist extends LitElement implements DataConsumer {
323
327
  const columns: Partial<ColumnConfig>[] = config.columns
324
328
 
325
329
  if (this.personalConfig) {
326
- const { columns: personalColumns } = this.personalConfig
330
+ const { columns: personalColumns, sorters, pagination, mode } = this.personalConfig
327
331
 
328
332
  if (personalColumns) {
329
333
  const xcolumns = columns.map((column: Partial<ColumnConfig>) => {
@@ -355,6 +359,18 @@ export class DataGrist extends LitElement implements DataConsumer {
355
359
  // 배열 재정렬 실행
356
360
  config.columns = reorderList(xcolumns as any, personalColumns as any)
357
361
  }
362
+
363
+ if (pagination) {
364
+ config.pagination = pagination
365
+ }
366
+
367
+ if (sorters) {
368
+ config.sorters = sorters
369
+ }
370
+
371
+ if (mode) {
372
+ this.mode = mode
373
+ }
358
374
  }
359
375
 
360
376
  this._config = buildConfig({
@@ -404,7 +420,8 @@ export class DataGrist extends LitElement implements DataConsumer {
404
420
  this.dataProvider.limit = limit || pages[0] || ZERO_PAGES[0]
405
421
  }
406
422
 
407
- if (!this.urlParamsSensitive && !this.explicitFetch) {
423
+ if (this.pendingFetch || (!this.urlParamsSensitive && !this.explicitFetch)) {
424
+ this.pendingFetch = false
408
425
  this.fetch()
409
426
  }
410
427
  }
@@ -546,9 +563,10 @@ export class DataGrist extends LitElement implements DataConsumer {
546
563
  * @param {boolean} reset - If true, the method resets the scroll position to the top.
547
564
  */
548
565
  async fetch(reset = true) {
549
- if (!this.compiledConfig) {
566
+ if (this.compiledConfig === ZERO_CONFIG) {
550
567
  /* avoid to be here */
551
568
  console.warn('grist is not configured yet.')
569
+ this.pendingFetch = true
552
570
  return
553
571
  }
554
572
 
@@ -574,6 +592,8 @@ export class DataGrist extends LitElement implements DataConsumer {
574
592
  sortings: this.sorters || this.compiledConfig?.sorters,
575
593
  filters: this.filters
576
594
  })
595
+
596
+ this.pagination && (this.pagination!.limit = limit)
577
597
  }
578
598
  }
579
599
  }
@@ -589,9 +609,9 @@ export class DataGrist extends LitElement implements DataConsumer {
589
609
  await this.requestUpdate()
590
610
  }
591
611
 
592
- if (changes.has('personalConfigProvider') && this.personalConfigProvider) {
612
+ if (changes.has('personalConfigProvider')) {
593
613
  this.personalConfig = await this.personalConfigProvider.load()
594
- } else if (changes.has('config') || changes.has('personalConfig')) {
614
+ } else if (changes.has('personalConfig')) {
595
615
  this.applyUpdatedConfiguration()
596
616
  }
597
617
 
@@ -1151,4 +1171,8 @@ export class DataGrist extends LitElement implements DataConsumer {
1151
1171
  })
1152
1172
  )
1153
1173
  }
1174
+
1175
+ getCurrentLimit() {
1176
+ return this.dataProvider?.limit || ZERO_PAGINATION.limit
1177
+ }
1154
1178
  }
@@ -30,8 +30,6 @@ export class OxGristPersonalizer extends LitElement {
30
30
  `
31
31
  ]
32
32
 
33
- @property({ type: String }) page!: string
34
- @property({ type: String }) element!: string
35
33
  @property({ type: Boolean, attribute: true }) debug: boolean = false
36
34
 
37
35
  @state() private preference?: PersonalGristPreference
@@ -42,7 +40,7 @@ export class OxGristPersonalizer extends LitElement {
42
40
  @click=${(e: MouseEvent) => {
43
41
  const grist = this.closest('ox-grist') as DataGrist
44
42
 
45
- const { config, compiledConfig } = grist
43
+ const { config, compiledConfig, sorters, pagination, mode } = grist
46
44
  const { columns: compiledColumns } = compiledConfig
47
45
 
48
46
  const columns = compiledColumns
@@ -59,7 +57,13 @@ export class OxGristPersonalizer extends LitElement {
59
57
  hidden: column.hidden,
60
58
  width: column.width
61
59
  }
62
- })
60
+ }),
61
+ sorters,
62
+ pagination: {
63
+ ...pagination,
64
+ limit: grist.getCurrentLimit()
65
+ },
66
+ mode
63
67
  }
64
68
 
65
69
  const template = html`
@@ -403,7 +403,11 @@ const Template: Story<ArgTypes> = ({
403
403
  columns: [
404
404
  { name: 'name', hidden: false, width: 200 },
405
405
  { name: 'description', hidden: true }
406
- ]
406
+ ],
407
+ pagination: {
408
+ pages: [20, 30, 50, 100, 200],
409
+ limit: 30
410
+ }
407
411
  }
408
412
  },
409
413
  async save(preference: PersonalGristPreference) {