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

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.
@@ -5,14 +5,9 @@ import { customElement, property, state } from 'lit/decorators.js'
5
5
 
6
6
  import { OxPopupList } from '@operato/popup'
7
7
 
8
- import { ColumnConfig, GristConfig } from '../types'
8
+ import { GristConfig, PersonalGristPreference } from '../types'
9
9
  import { DataGrist } from '../data-grist'
10
10
 
11
- export type PersonalPagePreference = {
12
- columns?: Partial<ColumnConfig>[]
13
- [key: string]: any
14
- }
15
-
16
11
  @customElement('ox-grist-personalizer')
17
12
  export class OxGristPersonalizer extends LitElement {
18
13
  static styles = [
@@ -35,13 +30,8 @@ export class OxGristPersonalizer extends LitElement {
35
30
 
36
31
  @property({ type: String }) page!: string
37
32
  @property({ type: String }) element!: string
38
- @property({ type: Object }) saveCallback?: (
39
- page: string,
40
- element: string,
41
- preference?: PersonalPagePreference
42
- ) => void
43
33
 
44
- @state() private preference?: PersonalPagePreference
34
+ @state() private preference?: PersonalGristPreference
45
35
 
46
36
  render() {
47
37
  return html`
@@ -66,16 +56,10 @@ export class OxGristPersonalizer extends LitElement {
66
56
  <div class="personalizer-header" slot="header">
67
57
  select to show<md-icon
68
58
  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
- )
59
+ @click=${async (e: MouseEvent) => {
60
+ if (grist.personalConfigProvider) {
61
+ this.preference = await grist.personalConfigProvider.save(this.preference)
62
+ }
79
63
  ;((e.target as HTMLElement).closest('ox-popup-list') as OxPopupList)?.close()
80
64
  }}
81
65
  >save</md-icon
@@ -115,7 +99,7 @@ export class OxGristPersonalizer extends LitElement {
115
99
  popup.onselect = (e: Event) => {
116
100
  const selected = (e as CustomEvent).detail
117
101
 
118
- const pconfig: PersonalPagePreference = grist.personalConfig || {}
102
+ const pconfig: PersonalGristPreference = grist.personalConfig || {}
119
103
  pconfig.columns = columns.map(column => {
120
104
  return {
121
105
  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({})