@operato/data-grist 2.0.0-alpha.116 → 2.0.0-alpha.118

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
@@ -29,6 +29,7 @@ import {
29
29
  GristRecord,
30
30
  GristSelectFunction,
31
31
  PaginationConfig,
32
+ PersonalGristPreference,
32
33
  SortersConfig
33
34
  } from './types'
34
35
  import { convertListParamToSearchString, convertSearchStringToListParam } from './utils'
@@ -170,7 +171,14 @@ export class DataGrist extends LitElement implements DataConsumer {
170
171
  */
171
172
  @property({ type: Boolean, attribute: 'url-params-sensitive' }) urlParamsSensitive?: boolean
172
173
 
173
- @property({ type: Object }) personalConfig?: {
174
+ @property({ type: Object }) personalConfigProvider?: {
175
+ load(): PersonalGristPreference | Promise<PersonalGristPreference | undefined> | undefined
176
+ save(
177
+ preference?: PersonalGristPreference
178
+ ): PersonalGristPreference | Promise<PersonalGristPreference | undefined> | undefined
179
+ }
180
+
181
+ @state() personalConfig?: {
174
182
  columns?: Partial<ColumnConfig>[]
175
183
  [key: string]: any
176
184
  }
@@ -552,10 +560,17 @@ export class DataGrist extends LitElement implements DataConsumer {
552
560
  await this.requestUpdate()
553
561
  }
554
562
 
555
- if (changes.has('config') || changes.has('personalConfig')) {
563
+ if (changes.has('personalConfigProvider') && this.personalConfigProvider) {
564
+ this.personalConfig = await this.personalConfigProvider.load()
565
+ this.applyUpdatedConfiguration()
566
+ } else if (changes.has('config') || changes.has('personalConfig')) {
556
567
  this.applyUpdatedConfiguration()
557
568
  }
558
569
 
570
+ // if (changes.has('config') || changes.has('personalConfig')) {
571
+ // this.applyUpdatedConfiguration()
572
+ // }
573
+
559
574
  if (changes.has('fetchHandler')) {
560
575
  this.dataProvider && (this.dataProvider.fetchHandler = this.fetchHandler)
561
576
  needToSetPullToRefresh = true
package/src/index.ts CHANGED
@@ -12,5 +12,6 @@ export * from './gutters'
12
12
  export * from './filters'
13
13
  export * from './sorters/sorters-control'
14
14
  export * from './record-view'
15
+ export * from './personalizer'
15
16
 
16
17
  export * from './utils/list-param'
@@ -0,0 +1 @@
1
+ export * from './ox-grist-personalizer'
@@ -1,18 +1,14 @@
1
- import '@material/web/icon/icon.js'
1
+ import '@material/web/button/outlined-button.js'
2
2
 
3
3
  import { css, html, LitElement } from 'lit'
4
4
  import { customElement, property, state } from 'lit/decorators.js'
5
5
 
6
+ import { i18next } from '@operato/i18n'
6
7
  import { OxPopupList } from '@operato/popup'
7
8
 
8
- import { ColumnConfig, GristConfig } from '../types'
9
+ import { GristConfig, PersonalGristPreference } from '../types'
9
10
  import { DataGrist } from '../data-grist'
10
11
 
11
- export type PersonalPagePreference = {
12
- columns?: Partial<ColumnConfig>[]
13
- [key: string]: any
14
- }
15
-
16
12
  @customElement('ox-grist-personalizer')
17
13
  export class OxGristPersonalizer extends LitElement {
18
14
  static styles = [
@@ -35,13 +31,8 @@ export class OxGristPersonalizer extends LitElement {
35
31
 
36
32
  @property({ type: String }) page!: string
37
33
  @property({ type: String }) element!: string
38
- @property({ type: Object }) saveCallback?: (
39
- page: string,
40
- element: string,
41
- preference?: PersonalPagePreference
42
- ) => void
43
34
 
44
- @state() private preference?: PersonalPagePreference
35
+ @state() private preference?: PersonalGristPreference
45
36
 
46
37
  render() {
47
38
  return html`
@@ -64,21 +55,15 @@ export class OxGristPersonalizer extends LitElement {
64
55
 
65
56
  const template = html`
66
57
  <div class="personalizer-header" slot="header">
67
- select to show<md-icon
58
+ ${i18next.t('text.column visibility setting')}<md-outlined-button
68
59
  style="margin-left: auto;"
69
- @click=${(e: MouseEvent) => {
70
- this.dispatchEvent(
71
- new CustomEvent('save', {
72
- detail: {
73
- page: this.page,
74
- element: this.element,
75
- preference: this.preference
76
- }
77
- })
78
- )
60
+ @click=${async (e: MouseEvent) => {
61
+ if (grist.personalConfigProvider) {
62
+ this.preference = await grist.personalConfigProvider.save(this.preference)
63
+ }
79
64
  ;((e.target as HTMLElement).closest('ox-popup-list') as OxPopupList)?.close()
80
65
  }}
81
- >save</md-icon
66
+ >${i18next.t('button.save')}</md-outlined-button
82
67
  >
83
68
  </div>
84
69
 
@@ -96,13 +81,17 @@ export class OxGristPersonalizer extends LitElement {
96
81
  left: e.pageX,
97
82
  styles: css`
98
83
  :host {
99
- width: 200px;
100
- max-height: 300px;
84
+ width: 240px;
85
+ max-height: 360px;
101
86
  overflow: scroll;
102
87
  }
103
88
 
104
89
  ::slotted(.personalizer-header) {
105
90
  --md-icon-size: 1.2em;
91
+ --md-outlined-button-container-height: 24px;
92
+ --md-outlined-button-container-shape: 4px;
93
+ --md-outlined-button-leading-space: 4px;
94
+ --md-outlined-button-trailing-space: 4px;
106
95
 
107
96
  display: flex;
108
97
  flex-direction: row;
@@ -115,7 +104,7 @@ export class OxGristPersonalizer extends LitElement {
115
104
  popup.onselect = (e: Event) => {
116
105
  const selected = (e as CustomEvent).detail
117
106
 
118
- const pconfig: PersonalPagePreference = grist.personalConfig || {}
107
+ const pconfig: PersonalGristPreference = grist.personalConfig || {}
119
108
  pconfig.columns = columns.map(column => {
120
109
  return {
121
110
  name: column.name,
package/src/types.ts CHANGED
@@ -761,3 +761,17 @@ export type GristData = {
761
761
  * @returns {boolean} - `true` if the record should be selected, `false` otherwise.
762
762
  */
763
763
  export type GristSelectFunction = (record: GristRecord) => boolean
764
+
765
+ /**
766
+ * Defines a type for personalized grid settings. It includes individual column settings and additional configurations specific to a user's grid view.
767
+ *
768
+ * @typedef {Object} PersonalGristPreference
769
+ * @property {Partial<ColumnConfig>[]} [columns] - Partially defines the configuration for each column in the grid.
770
+ * Each element can include only some properties of the `ColumnConfig`, used for optionally overriding column settings.
771
+ * @property {any} [key] - Allows for storing additional user-defined properties with dynamic keys.
772
+ * This property can include various custom settings beyond the grid configuration, and the keys can be freely defined.
773
+ */
774
+ export type PersonalGristPreference = {
775
+ columns?: Partial<ColumnConfig>[]
776
+ [key: string]: any
777
+ }
@@ -9,19 +9,17 @@ import '../src/personalizer/ox-grist-personalizer.js'
9
9
 
10
10
  import { html, TemplateResult } from 'lit'
11
11
 
12
- import { OxPopupList } from '@operato/popup'
13
12
  import { CommonHeaderStyles, CommonGristStyles } from '@operato/styles'
14
13
 
15
14
  import {
16
15
  ColumnConfig,
17
16
  FetchHandler,
18
17
  GristClassifier,
19
- GristConfig,
20
18
  GristEventHandlerSet,
21
19
  GristRecord,
20
+ PersonalGristPreference,
22
21
  ValidationCallback
23
22
  } from '../src/types.js'
24
- import { DataGrist } from '../src/index.js'
25
23
 
26
24
  const fetchHandler: FetchHandler = async ({ page, limit }) => {
27
25
  var total = 120993
@@ -388,8 +386,19 @@ const Template: Story<ArgTypes> = ({ config, mode = 'GRID', urlParamsSensitive =
388
386
  .mode=${mode}
389
387
  .config=${config}
390
388
  .fetchHandler=${fetchHandler}
391
- .personalConfig=${{
392
- columns: [{ name: 'description', hidden: true }]
389
+ .personalConfigProvider=${{
390
+ load() {
391
+ return {
392
+ columns: [
393
+ { name: 'name', hidden: false, width: 200 },
394
+ { name: 'description', hidden: true }
395
+ ]
396
+ }
397
+ },
398
+ save(preference: PersonalGristPreference) {
399
+ console.log('saving preference', preference)
400
+ return preference
401
+ }
393
402
  }}
394
403
  ?url-params-sensitive=${urlParamsSensitive}
395
404
  @filters-change=${(e: Event) => console.log('filters', (e.target as any).filters)}
@@ -427,15 +436,7 @@ const Template: Story<ArgTypes> = ({ config, mode = 'GRID', urlParamsSensitive =
427
436
  </ox-record-creator>
428
437
  </div>
429
438
 
430
- <ox-grist-personalizer
431
- page="sample-page"
432
- element="sample-element"
433
- slot="setting"
434
- @save=${(e: CustomEvent) => {
435
- const { page, element, preference } = e.detail as any
436
- console.log(page, element, preference)
437
- }}
438
- ></ox-grist-personalizer>
439
+ <ox-grist-personalizer slot="setting"></ox-grist-personalizer>
439
440
  </ox-grist>`
440
441
 
441
442
  export const Regular = Template.bind({})