@bexis2/bexis2-core-ui 0.4.15 → 0.4.17

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/README.md CHANGED
@@ -1,4 +1,12 @@
1
1
  # bexis-core-ui
2
+ ## 0.4.17
3
+ - Table
4
+ - Fix client-side search
5
+ ## 0.4.16
6
+ - Facets
7
+ - Replaces groups array with a writable store to re-render component on data manipulation.
8
+ - Adds selected attribute to the type so that Facets can be initialized with some selected values.
9
+
2
10
  ## 0.4.15
3
11
  - Update Facets with new params and add onChange action
4
12
  - Changes structure of Facets data
@@ -5,31 +5,9 @@ export let groupSelection = false;
5
5
  export let groups;
6
6
  export let showAll = false;
7
7
  export let open = false;
8
- let displayedGroups = structuredClone(groups);
9
- let selected = groups.reduce((acc, g) => {
10
- const children = g.children.reduce((acc2, c) => {
11
- acc2[c.name] = {
12
- ...c,
13
- selected: false
14
- };
15
- return acc2;
16
- }, {});
17
- acc[g.name] = {
18
- ...g,
19
- children,
20
- selected: false
21
- };
22
- return acc;
23
- }, {});
8
+ let selected;
24
9
  let selectedItems = {};
25
10
  let selectedGroups = {};
26
- Object.keys(selected).forEach((groupName) => {
27
- selectedItems[groupName] = {};
28
- Object.keys(selected[groupName].children).forEach((itemName) => {
29
- selectedItems[groupName][itemName] = false;
30
- });
31
- selectedGroups[groupName] = false;
32
- });
33
11
  const dispatch = createEventDispatcher();
34
12
  const modalStore = getModalStore();
35
13
  const showMore = (group) => {
@@ -48,7 +26,7 @@ const showMore = (group) => {
48
26
  };
49
27
  const handleSave = (group) => {
50
28
  Object.keys(group.children).forEach((key) => {
51
- selectedItems[group.name][key] = group.children[key].selected;
29
+ selectedItems[group.name][key] = group.children[key].selected || false;
52
30
  });
53
31
  modalStore.close();
54
32
  };
@@ -80,7 +58,7 @@ const mapSelected = (type) => {
80
58
  }
81
59
  });
82
60
  }
83
- dispatch("change", changed);
61
+ changed.length && dispatch("change", changed);
84
62
  };
85
63
  const sortOptions = () => {
86
64
  Object.keys(selected).forEach((group) => {
@@ -104,6 +82,31 @@ const sortOptions = () => {
104
82
  ];
105
83
  });
106
84
  };
85
+ groups.subscribe((data) => {
86
+ selected = data.reduce((acc, g) => {
87
+ const children = g.children.reduce((acc2, c) => {
88
+ acc2[c.name] = {
89
+ ...c,
90
+ selected: c.selected || false
91
+ };
92
+ return acc2;
93
+ }, {});
94
+ acc[g.name] = {
95
+ ...g,
96
+ children,
97
+ selected: g.selected || false
98
+ };
99
+ return acc;
100
+ }, {});
101
+ Object.keys(selected).forEach((groupName) => {
102
+ selectedItems[groupName] = {};
103
+ Object.keys(selected[groupName].children).forEach((itemName) => {
104
+ selectedItems[groupName][itemName] = selected[groupName].children[itemName].selected || false;
105
+ });
106
+ selectedGroups[groupName] = selected[groupName].selected || false;
107
+ });
108
+ });
109
+ $: displayedGroups = structuredClone($groups);
107
110
  $: selectedItems, mapSelected("items"), sortOptions();
108
111
  $: selectedGroups, mapSelected("groups");
109
112
  </script>
@@ -118,7 +121,9 @@ $: selectedGroups, mapSelected("groups");
118
121
  bind:checked={selectedGroups[group.name]}
119
122
  bind:group={selectedGroups}
120
123
  >
121
- <p class="font-semibold">{group.displayName}</p>
124
+ <p class="font-semibold">
125
+ {group.displayName}{group.count !== undefined ? ` (${group.count})` : ''}
126
+ </p>
122
127
 
123
128
  <svelte:fragment slot="children">
124
129
  <!-- If more than 5 choices, show the remaining in the Modal -->
@@ -1,9 +1,10 @@
1
1
  import { SvelteComponent } from "svelte";
2
+ import type { Writable } from 'svelte/store';
2
3
  import type { FacetGroup } from '../../models/Models';
3
4
  declare const __propDef: {
4
5
  props: {
5
6
  groupSelection?: boolean;
6
- groups: FacetGroup[];
7
+ groups: Writable<FacetGroup[]>;
7
8
  showAll?: boolean;
8
9
  open?: boolean;
9
10
  };
@@ -321,9 +321,11 @@ $: $hiddenColumnIds = shownColumns.filter((col) => !col.visible).map((col) => co
321
321
  <form
322
322
  class="flex gap-2"
323
323
  on:submit|preventDefault={() => {
324
- if (!sendModel) throw new Error('Server-side configuration is missing');
325
-
326
- sendModel.q = searchValue;
324
+ if (serverSide && !sendModel) {
325
+ throw new Error('Server-side configuration is missing');
326
+ } else {
327
+ sendModel.q = searchValue;
328
+ }
327
329
  $filterValue = searchValue;
328
330
  }}
329
331
  >
@@ -339,10 +341,15 @@ $: $hiddenColumnIds = shownColumns.filter((col) => !col.visible).map((col) => co
339
341
  id="{tableId}-searchReset"
340
342
  class="absolute right-3 items-center"
341
343
  on:click|preventDefault={() => {
342
- if (!sendModel) throw new Error('Server-side configuration is missing');
344
+ if (serverSide && !sendModel) {
345
+ throw new Error('Server-side configuration is missing');
346
+ } else {
347
+ sendModel.q = '';
348
+ }
349
+
350
+ $filterValue = searchValue;
343
351
 
344
352
  searchValue = '';
345
- sendModel.q = '';
346
353
  $filterValue = '';
347
354
  }}><Fa icon={faXmark} /></button
348
355
  >
@@ -352,10 +359,13 @@ $: $hiddenColumnIds = shownColumns.filter((col) => !col.visible).map((col) => co
352
359
  id="{tableId}-searchSubmit"
353
360
  class="btn variant-filled-primary"
354
361
  on:click|preventDefault={() => {
355
- if (!sendModel) throw new Error('Server-side configuration is missing');
362
+ if (serverSide && !sendModel) {
363
+ throw new Error('Server-side configuration is missing');
364
+ } else {
365
+ sendModel.q = searchValue;
366
+ }
356
367
 
357
368
  $filterValue = searchValue;
358
- sendModel.q = searchValue;
359
369
  }}>Search</button
360
370
  >
361
371
  </form>
package/dist/index.d.ts CHANGED
@@ -20,6 +20,7 @@ import TableFilter from './components/Table/TableFilter.svelte';
20
20
  import { columnFilter, searchFilter } from './components/Table/filter';
21
21
  import type { TableConfig, Columns, Column } from './models/Models';
22
22
  import Facets from './components/Facets/Facets.svelte';
23
+ import type { FacetGroup, FacetOption, SelectedFacetGroup } from './models/Models';
23
24
  import CodeEditor from './components/CodeEditor/CodeEditor.svelte';
24
25
  import Notification from './components/page/Notification.svelte';
25
26
  import TablePlaceholder from './components/page/TablePlaceholder.svelte';
@@ -40,6 +41,7 @@ export { TablePlaceholder };
40
41
  export { positionType, pageContentLayoutType, decimalCharacterType, orientationType, textMarkerType, textSeperatorType } from './models/Enums';
41
42
  export { Table, TableFilter, columnFilter, searchFilter };
42
43
  export { Facets };
44
+ export type { FacetGroup, FacetOption, SelectedFacetGroup };
43
45
  export { CodeEditor };
44
46
  export type { TableConfig, Columns, Column };
45
47
  export { bexis2theme };
@@ -155,20 +155,18 @@ export interface FacetOption {
155
155
  name: string;
156
156
  displayName: string;
157
157
  count?: number;
158
+ selected?: boolean;
158
159
  }
159
160
  export interface FacetGroup {
160
161
  name: string;
161
162
  displayName: string;
163
+ selected?: boolean;
162
164
  children: FacetOption[];
163
165
  count?: number;
164
166
  }
165
- export interface SelectedFacetOption extends FacetOption {
166
- selected: boolean;
167
- }
168
167
  export interface SelectedFacetGroup extends Omit<FacetGroup, 'children'> {
169
- selected: boolean;
170
168
  children: {
171
- [key: string]: SelectedFacetOption;
169
+ [key: string]: FacetOption;
172
170
  };
173
171
  }
174
172
  export declare class Send {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bexis2/bexis2-core-ui",
3
- "version": "0.4.15",
3
+ "version": "0.4.17",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "dev": "vite dev",
@@ -1,34 +1,17 @@
1
1
  <script lang="ts">
2
2
  import { createEventDispatcher } from 'svelte';
3
3
  import { getModalStore, Modal, TreeView, TreeViewItem } from '@skeletonlabs/skeleton';
4
+ import type { Writable } from 'svelte/store';
4
5
 
5
6
  import ShowMore from './ShowMore.svelte';
6
7
  import type { FacetGroup, SelectedFacetGroup } from '$models/Models';
7
8
 
8
9
  export let groupSelection = false;
9
- export let groups: FacetGroup[];
10
+ export let groups: Writable<FacetGroup[]>;
10
11
  export let showAll = false;
11
12
  export let open = false;
12
13
 
13
- let displayedGroups = structuredClone(groups);
14
-
15
- let selected: { [key: string]: SelectedFacetGroup } = groups.reduce((acc, g) => {
16
- const children = g.children.reduce((acc, c) => {
17
- acc[c.name] = {
18
- ...c,
19
- selected: false
20
- };
21
- return acc;
22
- }, {});
23
-
24
- acc[g.name] = {
25
- ...g,
26
- children,
27
- selected: false
28
- };
29
-
30
- return acc;
31
- }, {});
14
+ let selected: { [key: string]: SelectedFacetGroup };
32
15
  let selectedItems: {
33
16
  [key: string]: {
34
17
  [key: string]: boolean;
@@ -36,16 +19,8 @@
36
19
  } = {};
37
20
  let selectedGroups: { [key: string]: boolean } = {};
38
21
 
39
- Object.keys(selected).forEach((groupName) => {
40
- selectedItems[groupName] = {};
41
- Object.keys(selected[groupName].children).forEach((itemName) => {
42
- selectedItems[groupName][itemName] = false;
43
- });
44
- selectedGroups[groupName] = false;
45
- });
46
-
47
22
  const dispatch = createEventDispatcher();
48
-
23
+
49
24
  const modalStore = getModalStore();
50
25
  const showMore = (group: SelectedFacetGroup) => {
51
26
  modalStore.trigger({
@@ -64,7 +39,7 @@
64
39
 
65
40
  const handleSave = (group: SelectedFacetGroup) => {
66
41
  Object.keys(group.children).forEach((key) => {
67
- selectedItems[group.name][key] = group.children[key].selected;
42
+ selectedItems[group.name][key] = group.children[key].selected || false;
68
43
  });
69
44
  modalStore.close();
70
45
  };
@@ -100,7 +75,7 @@
100
75
  });
101
76
  }
102
77
 
103
- dispatch('change', changed);
78
+ changed.length && dispatch('change', changed);
104
79
  };
105
80
 
106
81
  const sortOptions = () => {
@@ -134,6 +109,36 @@
134
109
  });
135
110
  };
136
111
 
112
+ groups.subscribe((data) => {
113
+ selected = data.reduce((acc, g) => {
114
+ const children = g.children.reduce((acc, c) => {
115
+ acc[c.name] = {
116
+ ...c,
117
+ selected: c.selected || false
118
+ };
119
+ return acc;
120
+ }, {});
121
+
122
+ acc[g.name] = {
123
+ ...g,
124
+ children,
125
+ selected: g.selected || false
126
+ };
127
+
128
+ return acc;
129
+ }, {});
130
+
131
+ Object.keys(selected).forEach((groupName) => {
132
+ selectedItems[groupName] = {};
133
+ Object.keys(selected[groupName].children).forEach((itemName) => {
134
+ selectedItems[groupName][itemName] =
135
+ selected[groupName].children[itemName].selected || false;
136
+ });
137
+ selectedGroups[groupName] = selected[groupName].selected || false;
138
+ });
139
+ });
140
+
141
+ $: displayedGroups = structuredClone($groups);
137
142
  $: selectedItems, mapSelected('items'), sortOptions();
138
143
  $: selectedGroups, mapSelected('groups');
139
144
  </script>
@@ -148,7 +153,9 @@
148
153
  bind:checked={selectedGroups[group.name]}
149
154
  bind:group={selectedGroups}
150
155
  >
151
- <p class="font-semibold">{group.displayName}</p>
156
+ <p class="font-semibold">
157
+ {group.displayName}{group.count !== undefined ? ` (${group.count})` : ''}
158
+ </p>
152
159
 
153
160
  <svelte:fragment slot="children">
154
161
  <!-- If more than 5 choices, show the remaining in the Modal -->
@@ -389,9 +389,11 @@
389
389
  <form
390
390
  class="flex gap-2"
391
391
  on:submit|preventDefault={() => {
392
- if (!sendModel) throw new Error('Server-side configuration is missing');
393
-
394
- sendModel.q = searchValue;
392
+ if (serverSide && !sendModel) {
393
+ throw new Error('Server-side configuration is missing');
394
+ } else {
395
+ sendModel.q = searchValue;
396
+ }
395
397
  $filterValue = searchValue;
396
398
  }}
397
399
  >
@@ -407,10 +409,15 @@
407
409
  id="{tableId}-searchReset"
408
410
  class="absolute right-3 items-center"
409
411
  on:click|preventDefault={() => {
410
- if (!sendModel) throw new Error('Server-side configuration is missing');
412
+ if (serverSide && !sendModel) {
413
+ throw new Error('Server-side configuration is missing');
414
+ } else {
415
+ sendModel.q = '';
416
+ }
417
+
418
+ $filterValue = searchValue;
411
419
 
412
420
  searchValue = '';
413
- sendModel.q = '';
414
421
  $filterValue = '';
415
422
  }}><Fa icon={faXmark} /></button
416
423
  >
@@ -420,10 +427,13 @@
420
427
  id="{tableId}-searchSubmit"
421
428
  class="btn variant-filled-primary"
422
429
  on:click|preventDefault={() => {
423
- if (!sendModel) throw new Error('Server-side configuration is missing');
430
+ if (serverSide && !sendModel) {
431
+ throw new Error('Server-side configuration is missing');
432
+ } else {
433
+ sendModel.q = searchValue;
434
+ }
424
435
 
425
436
  $filterValue = searchValue;
426
- sendModel.q = searchValue;
427
437
  }}>Search</button
428
438
  >
429
439
  </form>
package/src/lib/index.ts CHANGED
@@ -32,6 +32,7 @@ import type { TableConfig, Columns, Column } from './models/Models';
32
32
 
33
33
  //Facets
34
34
  import Facets from './components/Facets/Facets.svelte';
35
+ import type { FacetGroup, FacetOption, SelectedFacetGroup } from './models/Models';
35
36
 
36
37
  // CodeEditor
37
38
  import CodeEditor from './components/CodeEditor/CodeEditor.svelte';
@@ -108,6 +109,7 @@ export { Table, TableFilter, columnFilter, searchFilter };
108
109
 
109
110
  // Facets
110
111
  export { Facets };
112
+ export type { FacetGroup, FacetOption, SelectedFacetGroup };
111
113
 
112
114
  // CodeEditor
113
115
  export { CodeEditor };
@@ -195,23 +195,20 @@ export interface FacetOption {
195
195
  name: string;
196
196
  displayName: string;
197
197
  count?: number;
198
+ selected?: boolean;
198
199
  }
199
200
 
200
201
  export interface FacetGroup {
201
202
  name: string;
202
203
  displayName: string;
204
+ selected?: boolean;
203
205
  children: FacetOption[];
204
206
  count?: number;
205
207
  }
206
208
 
207
- export interface SelectedFacetOption extends FacetOption {
208
- selected: boolean;
209
- }
210
-
211
209
  export interface SelectedFacetGroup extends Omit<FacetGroup, 'children'> {
212
- selected: boolean;
213
210
  children: {
214
- [key: string]: SelectedFacetOption;
211
+ [key: string]: FacetOption;
215
212
  };
216
213
  }
217
214