@budibase/bbui 1.0.79-alpha.1 → 1.0.79-alpha.4

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@budibase/bbui",
3
3
  "description": "A UI solution used in the different Budibase projects.",
4
- "version": "1.0.79-alpha.1",
4
+ "version": "1.0.79-alpha.4",
5
5
  "license": "MPL-2.0",
6
6
  "svelte": "src/index.js",
7
7
  "module": "dist/bbui.es.js",
@@ -38,7 +38,7 @@
38
38
  ],
39
39
  "dependencies": {
40
40
  "@adobe/spectrum-css-workflow-icons": "^1.2.1",
41
- "@budibase/string-templates": "^1.0.79-alpha.1",
41
+ "@budibase/string-templates": "^1.0.79-alpha.4",
42
42
  "@spectrum-css/actionbutton": "^1.0.1",
43
43
  "@spectrum-css/actiongroup": "^1.0.1",
44
44
  "@spectrum-css/avatar": "^3.0.2",
@@ -84,5 +84,5 @@
84
84
  "svelte-flatpickr": "^3.2.3",
85
85
  "svelte-portal": "^1.0.0"
86
86
  },
87
- "gitHead": "ca2b3e003a76c97783492aa3f120beaf57515057"
87
+ "gitHead": "3a3f3d5a06d84231569754305daa2c9dff750690"
88
88
  }
@@ -47,7 +47,9 @@
47
47
  <use xlink:href="#spectrum-css-icon-Dash100" />
48
48
  </svg>
49
49
  </span>
50
- <span class="spectrum-Checkbox-label">{text || ""}</span>
50
+ {#if text}
51
+ <span class="spectrum-Checkbox-label">{text}</span>
52
+ {/if}
51
53
  </label>
52
54
 
53
55
  <style>
@@ -8,9 +8,21 @@
8
8
  export let allowEditRows = false
9
9
  </script>
10
10
 
11
- {#if allowSelectRows}
12
- <Checkbox value={selected} />
13
- {/if}
14
- {#if allowEditRows}
15
- <ActionButton size="S" on:click={onEdit}>Edit</ActionButton>
16
- {/if}
11
+ <div>
12
+ {#if allowSelectRows}
13
+ <Checkbox value={selected} />
14
+ {/if}
15
+ {#if allowEditRows}
16
+ <ActionButton size="S" on:click={onEdit}>Edit</ActionButton>
17
+ {/if}
18
+ </div>
19
+
20
+ <style>
21
+ div {
22
+ display: flex;
23
+ flex-direction: row;
24
+ justify-content: flex-start;
25
+ align-items: center;
26
+ gap: var(--spacing-m);
27
+ }
28
+ </style>
@@ -5,6 +5,7 @@
5
5
  import SelectEditRenderer from "./SelectEditRenderer.svelte"
6
6
  import { cloneDeep, deepGet } from "../helpers"
7
7
  import ProgressCircle from "../ProgressCircle/ProgressCircle.svelte"
8
+ import Checkbox from "../Form/Checkbox.svelte"
8
9
 
9
10
  /**
10
11
  * The expected schema is our normal couch schemas for our tables.
@@ -31,7 +32,6 @@
31
32
  export let allowEditRows = true
32
33
  export let allowEditColumns = true
33
34
  export let selectedRows = []
34
- export let editColumnTitle = "Edit"
35
35
  export let customRenderers = []
36
36
  export let disableSorting = false
37
37
  export let autoSortColumns = true
@@ -50,6 +50,8 @@
50
50
  // Table state
51
51
  let height = 0
52
52
  let loaded = false
53
+ let checkboxStatus = false
54
+
53
55
  $: schema = fixSchema(schema)
54
56
  $: if (!loading) loaded = true
55
57
  $: fields = getFields(schema, showAutoColumns, autoSortColumns)
@@ -67,6 +69,16 @@
67
69
  $: showEditColumn = allowEditRows || allowSelectRows
68
70
  $: cellStyles = computeCellStyles(schema)
69
71
 
72
+ // Deselect the "select all" checkbox when the user navigates to a new page
73
+ $: {
74
+ let checkRowCount = rows.filter(o1 =>
75
+ selectedRows.some(o2 => o1._id === o2._id)
76
+ )
77
+ if (checkRowCount.length === 0) {
78
+ checkboxStatus = false
79
+ }
80
+ }
81
+
70
82
  const fixSchema = schema => {
71
83
  let fixedSchema = {}
72
84
  Object.entries(schema || {}).forEach(([fieldName, fieldSchema]) => {
@@ -197,13 +209,32 @@
197
209
  if (!allowSelectRows) {
198
210
  return
199
211
  }
200
- if (selectedRows.includes(row)) {
201
- selectedRows = selectedRows.filter(selectedRow => selectedRow !== row)
212
+ if (selectedRows.some(selectedRow => selectedRow._id === row._id)) {
213
+ selectedRows = selectedRows.filter(
214
+ selectedRow => selectedRow._id !== row._id
215
+ )
202
216
  } else {
203
217
  selectedRows = [...selectedRows, row]
204
218
  }
205
219
  }
206
220
 
221
+ const toggleSelectAll = e => {
222
+ const select = !!e.detail
223
+ if (select) {
224
+ // Add any rows which are not already in selected rows
225
+ rows.forEach(row => {
226
+ if (selectedRows.findIndex(x => x._id === row._id) === -1) {
227
+ selectedRows.push(row)
228
+ }
229
+ })
230
+ } else {
231
+ // Remove any rows from selected rows that are in the current data set
232
+ selectedRows = selectedRows.filter(el =>
233
+ rows.every(f => f._id !== el._id)
234
+ )
235
+ }
236
+ }
237
+
207
238
  const computeCellStyles = schema => {
208
239
  let styles = {}
209
240
  Object.keys(schema || {}).forEach(field => {
@@ -244,7 +275,14 @@
244
275
  <div
245
276
  class="spectrum-Table-headCell spectrum-Table-headCell--divider spectrum-Table-headCell--edit"
246
277
  >
247
- {editColumnTitle || ""}
278
+ {#if allowSelectRows}
279
+ <Checkbox
280
+ bind:value={checkboxStatus}
281
+ on:change={toggleSelectAll}
282
+ />
283
+ {:else}
284
+ Edit
285
+ {/if}
248
286
  </div>
249
287
  {/if}
250
288
  {#each fields as field}
@@ -302,11 +340,16 @@
302
340
  {#if showEditColumn}
303
341
  <div
304
342
  class="spectrum-Table-cell spectrum-Table-cell--divider spectrum-Table-cell--edit"
343
+ on:click={e => {
344
+ toggleSelectRow(row)
345
+ e.stopPropagation()
346
+ }}
305
347
  >
306
348
  <SelectEditRenderer
307
349
  data={row}
308
- selected={selectedRows.includes(row)}
309
- onToggleSelection={() => toggleSelectRow(row)}
350
+ selected={selectedRows.findIndex(
351
+ selectedRow => selectedRow._id === row._id
352
+ ) !== -1}
310
353
  onEdit={e => editRow(e, row)}
311
354
  {allowSelectRows}
312
355
  {allowEditRows}