@budibase/frontend-core 2.6.15 → 2.6.16-alpha.1

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,17 +1,17 @@
1
1
  {
2
2
  "name": "@budibase/frontend-core",
3
- "version": "2.6.15",
3
+ "version": "2.6.16-alpha.1",
4
4
  "description": "Budibase frontend core libraries used in builder and client",
5
5
  "author": "Budibase",
6
6
  "license": "MPL-2.0",
7
7
  "svelte": "src/index.js",
8
8
  "dependencies": {
9
- "@budibase/bbui": "^2.6.15",
10
- "@budibase/shared-core": "^2.6.15",
9
+ "@budibase/bbui": "2.6.16-alpha.1",
10
+ "@budibase/shared-core": "2.6.16-alpha.1",
11
11
  "dayjs": "^1.11.7",
12
12
  "lodash": "^4.17.21",
13
13
  "socket.io-client": "^4.6.1",
14
14
  "svelte": "^3.46.2"
15
15
  },
16
- "gitHead": "f66535137bdbfa0e3a4d9fca8e738a6845beeafb"
16
+ "gitHead": "f117256d4e83d59b5ac23b0070ee25591e8f6d93"
17
17
  }
package/src/api/groups.js CHANGED
@@ -52,6 +52,23 @@ export const buildGroupsEndpoints = API => {
52
52
  })
53
53
  },
54
54
 
55
+ /**
56
+ * Gets a group users by the group id
57
+ */
58
+ getGroupUsers: async ({ id, bookmark, emailSearch }) => {
59
+ let url = `/api/global/groups/${id}/users?`
60
+ if (bookmark) {
61
+ url += `bookmark=${bookmark}&`
62
+ }
63
+ if (emailSearch) {
64
+ url += `emailSearch=${emailSearch}&`
65
+ }
66
+
67
+ return await API.get({
68
+ url,
69
+ })
70
+ },
71
+
55
72
  /**
56
73
  * Adds users to a group
57
74
  * @param groupId The group to update
@@ -32,6 +32,7 @@
32
32
  $: readonly =
33
33
  column.schema.autocolumn ||
34
34
  column.schema.disabled ||
35
+ column.schema.type === "formula" ||
35
36
  (!$config.allowEditRows && row._id)
36
37
 
37
38
  // Register this cell API if the row is focused
@@ -1,12 +1,17 @@
1
1
  <script>
2
2
  import dayjs from "dayjs"
3
3
  import { CoreDatePicker, Icon } from "@budibase/bbui"
4
+ import { onMount } from "svelte"
4
5
 
5
6
  export let value
6
7
  export let schema
7
8
  export let onChange
8
9
  export let focused = false
9
10
  export let readonly = false
11
+ export let api
12
+
13
+ let flatpickr
14
+ let isOpen
10
15
 
11
16
  // adding the 0- will turn a string like 00:00:00 into a valid ISO
12
17
  // date, but will make actual ISO dates invalid
@@ -19,6 +24,26 @@
19
24
  ? "MMM D YYYY"
20
25
  : "MMM D YYYY, HH:mm"
21
26
  $: editable = focused && !readonly
27
+
28
+ // Ensure we close flatpickr when unselected
29
+ $: {
30
+ if (!focused) {
31
+ flatpickr?.close()
32
+ }
33
+ }
34
+
35
+ const onKeyDown = () => {
36
+ return isOpen
37
+ }
38
+
39
+ onMount(() => {
40
+ api = {
41
+ onKeyDown,
42
+ focus: () => flatpickr?.open(),
43
+ blur: () => flatpickr?.close(),
44
+ isActive: () => isOpen,
45
+ }
46
+ })
22
47
  </script>
23
48
 
24
49
  <div class="container">
@@ -42,6 +67,10 @@
42
67
  {timeOnly}
43
68
  time24hr
44
69
  ignoreTimezones={schema.ignoreTimezones}
70
+ bind:flatpickr
71
+ on:open={() => (isOpen = true)}
72
+ on:close={() => (isOpen = false)}
73
+ useKeyboardShortcuts={false}
45
74
  />
46
75
  </div>
47
76
  {/if}
@@ -1,6 +1,13 @@
1
1
  <script>
2
- import { clickOutside, Menu, MenuItem, notifications } from "@budibase/bbui"
2
+ import {
3
+ clickOutside,
4
+ Menu,
5
+ MenuItem,
6
+ Helpers,
7
+ notifications,
8
+ } from "@budibase/bbui"
3
9
  import { getContext } from "svelte"
10
+ import { NewRowID } from "../lib/constants"
4
11
 
5
12
  const {
6
13
  focusedRow,
@@ -14,9 +21,11 @@
14
21
  clipboard,
15
22
  dispatch,
16
23
  focusedCellAPI,
24
+ focusedRowId,
17
25
  } = getContext("grid")
18
26
 
19
27
  $: style = makeStyle($menu)
28
+ $: isNewRow = $focusedRowId === NewRowID
20
29
 
21
30
  const makeStyle = menu => {
22
31
  return `left:${menu.left}px; top:${menu.top}px;`
@@ -36,6 +45,11 @@
36
45
  $focusedCellId = `${newRow._id}-${column}`
37
46
  }
38
47
  }
48
+
49
+ const copyToClipboard = async value => {
50
+ await Helpers.copyToClipboard(value)
51
+ notifications.success("Copied to clipboard")
52
+ }
39
53
  </script>
40
54
 
41
55
  {#if $menu.visible}
@@ -58,22 +72,38 @@
58
72
  </MenuItem>
59
73
  <MenuItem
60
74
  icon="Maximize"
61
- disabled={!$config.allowEditRows}
75
+ disabled={isNewRow || !$config.allowEditRows}
62
76
  on:click={() => dispatch("edit-row", $focusedRow)}
63
77
  on:click={menu.actions.close}
64
78
  >
65
79
  Edit row in modal
66
80
  </MenuItem>
81
+ <MenuItem
82
+ icon="Copy"
83
+ disabled={isNewRow || !$focusedRow?._id}
84
+ on:click={() => copyToClipboard($focusedRow?._id)}
85
+ on:click={menu.actions.close}
86
+ >
87
+ Copy row _id
88
+ </MenuItem>
89
+ <MenuItem
90
+ icon="Copy"
91
+ disabled={isNewRow || !$focusedRow?._rev}
92
+ on:click={() => copyToClipboard($focusedRow?._rev)}
93
+ on:click={menu.actions.close}
94
+ >
95
+ Copy row _rev
96
+ </MenuItem>
67
97
  <MenuItem
68
98
  icon="Duplicate"
69
- disabled={!$config.allowAddRows}
99
+ disabled={isNewRow || !$config.allowAddRows}
70
100
  on:click={duplicate}
71
101
  >
72
102
  Duplicate row
73
103
  </MenuItem>
74
104
  <MenuItem
75
105
  icon="Delete"
76
- disabled={!$config.allowDeleteRows}
106
+ disabled={isNewRow || !$config.allowDeleteRows}
77
107
  on:click={deleteRow}
78
108
  >
79
109
  Delete row
@@ -338,15 +338,11 @@ export const deriveStores = context => {
338
338
  ...state,
339
339
  [rowId]: true,
340
340
  }))
341
- const newRow = { ...row, ...get(rowChangeCache)[rowId] }
342
- const saved = await API.saveRow(newRow)
341
+ const saved = await API.saveRow({ ...row, ...get(rowChangeCache)[rowId] })
343
342
 
344
343
  // Update state after a successful change
345
344
  rows.update(state => {
346
- state[index] = {
347
- ...newRow,
348
- _rev: saved._rev,
349
- }
345
+ state[index] = saved
350
346
  return state.slice()
351
347
  })
352
348
  rowChangeCache.update(state => {
@@ -362,13 +362,35 @@ export default class DataFetch {
362
362
  return
363
363
  }
364
364
  this.store.update($store => ({ ...$store, loading: true }))
365
- const { rows, info, error } = await this.getPage()
365
+ const { rows, info, error, cursor } = await this.getPage()
366
+
367
+ let { cursors } = get(this.store)
368
+ const { pageNumber } = get(this.store)
369
+
370
+ if (!rows.length && pageNumber > 0) {
371
+ // If the full page is gone but we have previous pages, navigate to the previous page
372
+ this.store.update($store => ({
373
+ ...$store,
374
+ loading: false,
375
+ cursors: cursors.slice(0, pageNumber),
376
+ }))
377
+ return await this.prevPage()
378
+ }
379
+
380
+ const currentNextCursor = cursors[pageNumber + 1]
381
+ if (currentNextCursor != cursor) {
382
+ // If the current cursor changed, all the next pages need to be updated, so we mark them as stale
383
+ cursors = cursors.slice(0, pageNumber + 1)
384
+ cursors[pageNumber + 1] = cursor
385
+ }
386
+
366
387
  this.store.update($store => ({
367
388
  ...$store,
368
389
  rows,
369
390
  info,
370
391
  loading: false,
371
392
  error,
393
+ cursors,
372
394
  }))
373
395
  }
374
396
 
@@ -0,0 +1,51 @@
1
+ import { get } from "svelte/store"
2
+ import DataFetch from "./DataFetch.js"
3
+ import { TableNames } from "../constants"
4
+
5
+ export default class GroupUserFetch extends DataFetch {
6
+ constructor(opts) {
7
+ super({
8
+ ...opts,
9
+ datasource: {
10
+ tableId: TableNames.USERS,
11
+ },
12
+ })
13
+ }
14
+
15
+ determineFeatureFlags() {
16
+ return {
17
+ supportsSearch: true,
18
+ supportsSort: false,
19
+ supportsPagination: true,
20
+ }
21
+ }
22
+
23
+ async getDefinition() {
24
+ return {
25
+ schema: {},
26
+ }
27
+ }
28
+
29
+ async getData() {
30
+ const { query, cursor } = get(this.store)
31
+ try {
32
+ const res = await this.API.getGroupUsers({
33
+ id: query.groupId,
34
+ emailSearch: query.emailSearch,
35
+ bookmark: cursor,
36
+ })
37
+
38
+ return {
39
+ rows: res?.users || [],
40
+ hasNextPage: res?.hasNextPage || false,
41
+ cursor: res?.bookmark || null,
42
+ }
43
+ } catch (error) {
44
+ return {
45
+ rows: [],
46
+ hasNextPage: false,
47
+ error,
48
+ }
49
+ }
50
+ }
51
+ }
@@ -6,6 +6,7 @@ import NestedProviderFetch from "./NestedProviderFetch.js"
6
6
  import FieldFetch from "./FieldFetch.js"
7
7
  import JSONArrayFetch from "./JSONArrayFetch.js"
8
8
  import UserFetch from "./UserFetch.js"
9
+ import GroupUserFetch from "./GroupUserFetch.js"
9
10
 
10
11
  const DataFetchMap = {
11
12
  table: TableFetch,
@@ -13,6 +14,7 @@ const DataFetchMap = {
13
14
  query: QueryFetch,
14
15
  link: RelationshipFetch,
15
16
  user: UserFetch,
17
+ groupUser: GroupUserFetch,
16
18
 
17
19
  // Client specific datasource types
18
20
  provider: NestedProviderFetch,