From 4339bf1d3c36c1c0bf31fd227d159be964060330 Mon Sep 17 00:00:00 2001 From: Naveen Kumar Date: Tue, 24 Dec 2024 13:29:06 +0530 Subject: [PATCH 1/7] fix, handling use case when duplicate step name is allowed --- .../AutomationBuilder/FlowChart/FlowItemHeader.svelte | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/builder/src/components/automation/AutomationBuilder/FlowChart/FlowItemHeader.svelte b/packages/builder/src/components/automation/AutomationBuilder/FlowChart/FlowItemHeader.svelte index 0aa43f8e04..523f00b351 100644 --- a/packages/builder/src/components/automation/AutomationBuilder/FlowChart/FlowItemHeader.svelte +++ b/packages/builder/src/components/automation/AutomationBuilder/FlowChart/FlowItemHeader.svelte @@ -22,7 +22,7 @@ const dispatch = createEventDispatcher() $: blockRefs = $selectedAutomation?.blockRefs || {} - $: stepNames = automation?.definition.stepNames + $: stepNames = automation?.definition.stepNames || {} $: allSteps = automation?.definition.steps || [] $: automationName = itemName || stepNames?.[block.id] || block?.name || "" $: automationNameError = getAutomationNameError(automationName) @@ -64,7 +64,7 @@ const getAutomationNameError = name => { const duplicateError = "This name already exists, please enter a unique name" - if (stepNames && editing) { + if (editing) { for (const [key, value] of Object.entries(stepNames)) { if (name !== block.name && name === value && key !== block.id) { return duplicateError From f5ebc6b2497bbbbddf5d592209f78e1060fde9e6 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 24 Dec 2024 13:41:17 +0100 Subject: [PATCH 2/7] Type validation --- .../src/components/grid/stores/index.ts | 5 +++- .../stores/{validation.js => validation.ts} | 29 +++++++++++++------ 2 files changed, 24 insertions(+), 10 deletions(-) rename packages/frontend-core/src/components/grid/stores/{validation.js => validation.ts} (69%) diff --git a/packages/frontend-core/src/components/grid/stores/index.ts b/packages/frontend-core/src/components/grid/stores/index.ts index f2b6c973b9..90e89cbf4c 100644 --- a/packages/frontend-core/src/components/grid/stores/index.ts +++ b/packages/frontend-core/src/components/grid/stores/index.ts @@ -60,7 +60,8 @@ export type Store = BaseStore & Table.Store & ViewV2.Store & NonPlus.Store & - Datasource.Store & { + Datasource.Store & + Validation.Store & { // TODO while typing the rest of stores fetch: Writable filter: Writable @@ -76,6 +77,8 @@ export type Store = BaseStore & dispatch: (event: string, data: any) => any notifications: Writable schemaOverrides: Writable + focusedCellId: Writable + previousFocusedRowId: Writable } export const attachStores = (context: Store): Store => { diff --git a/packages/frontend-core/src/components/grid/stores/validation.js b/packages/frontend-core/src/components/grid/stores/validation.ts similarity index 69% rename from packages/frontend-core/src/components/grid/stores/validation.js rename to packages/frontend-core/src/components/grid/stores/validation.ts index 93e67e1d31..32bb1cf978 100644 --- a/packages/frontend-core/src/components/grid/stores/validation.js +++ b/packages/frontend-core/src/components/grid/stores/validation.ts @@ -1,10 +1,21 @@ -import { writable, get, derived } from "svelte/store" +import { writable, get, derived, Writable, Readable } from "svelte/store" +import { Store as StoreContext } from "." import { parseCellID } from "../lib/utils" +interface ValidationStore { + validation: Writable> +} + +interface DerivedValidationStore { + validationRowLookupMap: Readable> +} + +export type Store = ValidationStore & DerivedValidationStore + // Normally we would break out actions into the explicit "createActions" // function, but for validation all these actions are pure so can go into // "createStores" instead to make dependency ordering simpler -export const createStores = () => { +export const createStores = (): ValidationStore => { const validation = writable({}) return { @@ -12,12 +23,12 @@ export const createStores = () => { } } -export const deriveStores = context => { +export const deriveStores = (context: StoreContext): DerivedValidationStore => { const { validation } = context // Derive which rows have errors so that we can use that info later const validationRowLookupMap = derived(validation, $validation => { - let map = {} + const map: Record = {} Object.entries($validation).forEach(([key, error]) => { // Extract row ID from all errored cell IDs if (error) { @@ -36,10 +47,10 @@ export const deriveStores = context => { } } -export const createActions = context => { +export const createActions = (context: StoreContext) => { const { validation, focusedCellId, validationRowLookupMap } = context - const setError = (cellId, error) => { + const setError = (cellId: string | undefined, error: string) => { if (!cellId) { return } @@ -49,11 +60,11 @@ export const createActions = context => { })) } - const rowHasErrors = rowId => { + const rowHasErrors = (rowId: string) => { return get(validationRowLookupMap)[rowId]?.length > 0 } - const focusFirstRowError = rowId => { + const focusFirstRowError = (rowId: string) => { const errorCells = get(validationRowLookupMap)[rowId] const cellId = errorCells?.[0] if (cellId) { @@ -73,7 +84,7 @@ export const createActions = context => { } } -export const initialise = context => { +export const initialise = (context: StoreContext) => { const { validation, previousFocusedRowId, validationRowLookupMap } = context // Remove validation errors when changing rows From ad21b2e1fd10bd9c1ae8e5beeb22e5496a24b0c9 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 24 Dec 2024 13:54:16 +0100 Subject: [PATCH 3/7] Type user store --- .../src/components/grid/stores/index.ts | 3 +- .../grid/stores/{users.js => users.ts} | 37 +++++++++++++++---- packages/types/src/ui/stores/grid/index.ts | 1 + packages/types/src/ui/stores/grid/user.ts | 6 +++ 4 files changed, 38 insertions(+), 9 deletions(-) rename packages/frontend-core/src/components/grid/stores/{users.js => users.ts} (61%) create mode 100644 packages/types/src/ui/stores/grid/user.ts diff --git a/packages/frontend-core/src/components/grid/stores/index.ts b/packages/frontend-core/src/components/grid/stores/index.ts index 90e89cbf4c..8ecbc0e19c 100644 --- a/packages/frontend-core/src/components/grid/stores/index.ts +++ b/packages/frontend-core/src/components/grid/stores/index.ts @@ -61,7 +61,8 @@ export type Store = BaseStore & ViewV2.Store & NonPlus.Store & Datasource.Store & - Validation.Store & { + Validation.Store & + Users.Store & { // TODO while typing the rest of stores fetch: Writable filter: Writable diff --git a/packages/frontend-core/src/components/grid/stores/users.js b/packages/frontend-core/src/components/grid/stores/users.ts similarity index 61% rename from packages/frontend-core/src/components/grid/stores/users.js rename to packages/frontend-core/src/components/grid/stores/users.ts index 64c1e27835..f8824f8329 100644 --- a/packages/frontend-core/src/components/grid/stores/users.js +++ b/packages/frontend-core/src/components/grid/stores/users.ts @@ -1,8 +1,29 @@ -import { writable, get, derived } from "svelte/store" +import { writable, get, derived, Writable, Readable } from "svelte/store" import { helpers } from "@budibase/shared-core" +import { Store as StoreContext } from "." +import { UIUser } from "@budibase/types" -export const createStores = () => { - const users = writable([]) +interface UsersStore { + users: Writable +} + +interface DerivedUsersStore { + userCellMap: Readable> +} + +interface ActionUserStore { + users: UsersStore["users"] & { + actions: { + updateUser: (user: UIUser) => void + removeUser: (sessionId: string) => void + } + } +} + +export type Store = UsersStore & DerivedUsersStore + +export const createStores = (): UsersStore => { + const users = writable([]) const enrichedUsers = derived(users, $users => { return $users.map(user => ({ @@ -20,7 +41,7 @@ export const createStores = () => { } } -export const deriveStores = context => { +export const deriveStores = (context: StoreContext): DerivedUsersStore => { const { users, focusedCellId } = context // Generate a lookup map of cell ID to the user that has it selected, to make @@ -28,7 +49,7 @@ export const deriveStores = context => { const userCellMap = derived( [users, focusedCellId], ([$users, $focusedCellId]) => { - let map = {} + let map: Record = {} $users.forEach(user => { const cellId = user.gridMetadata?.focusedCellId if (cellId && cellId !== $focusedCellId) { @@ -44,10 +65,10 @@ export const deriveStores = context => { } } -export const createActions = context => { +export const createActions = (context: StoreContext): ActionUserStore => { const { users } = context - const updateUser = user => { + const updateUser = (user: UIUser) => { const $users = get(users) if (!$users.some(x => x.sessionId === user.sessionId)) { users.set([...$users, user]) @@ -60,7 +81,7 @@ export const createActions = context => { } } - const removeUser = sessionId => { + const removeUser = (sessionId: string) => { users.update(state => { return state.filter(x => x.sessionId !== sessionId) }) diff --git a/packages/types/src/ui/stores/grid/index.ts b/packages/types/src/ui/stores/grid/index.ts index bcd7e3267d..b6a152ed73 100644 --- a/packages/types/src/ui/stores/grid/index.ts +++ b/packages/types/src/ui/stores/grid/index.ts @@ -2,3 +2,4 @@ export * from "./columns" export * from "./datasource" export * from "./table" export * from "./view" +export * from "./user" diff --git a/packages/types/src/ui/stores/grid/user.ts b/packages/types/src/ui/stores/grid/user.ts new file mode 100644 index 0000000000..b6eb529805 --- /dev/null +++ b/packages/types/src/ui/stores/grid/user.ts @@ -0,0 +1,6 @@ +import { User } from "@budibase/types" + +export interface UIUser extends User { + sessionId: string + gridMetadata?: { focusedCellId?: string } +} From 9d5e7b14a7ac5abfd76ead22bd470c2e4348e248 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 24 Dec 2024 14:07:14 +0100 Subject: [PATCH 4/7] Type menu store --- .../src/components/grid/stores/index.ts | 8 +++++- .../grid/stores/{menu.js => menu.ts} | 26 +++++++++++++++---- 2 files changed, 28 insertions(+), 6 deletions(-) rename packages/frontend-core/src/components/grid/stores/{menu.js => menu.ts} (77%) diff --git a/packages/frontend-core/src/components/grid/stores/index.ts b/packages/frontend-core/src/components/grid/stores/index.ts index 8ecbc0e19c..d0413cb80a 100644 --- a/packages/frontend-core/src/components/grid/stores/index.ts +++ b/packages/frontend-core/src/components/grid/stores/index.ts @@ -62,7 +62,8 @@ export type Store = BaseStore & NonPlus.Store & Datasource.Store & Validation.Store & - Users.Store & { + Users.Store & + Menu.Store & { // TODO while typing the rest of stores fetch: Writable filter: Writable @@ -80,6 +81,11 @@ export type Store = BaseStore & schemaOverrides: Writable focusedCellId: Writable previousFocusedRowId: Writable + gridID: string + selectedRows: Writable + selectedRowCount: Writable + selectedCellMap: Writable + selectedCellCount: Writable } export const attachStores = (context: Store): Store => { diff --git a/packages/frontend-core/src/components/grid/stores/menu.js b/packages/frontend-core/src/components/grid/stores/menu.ts similarity index 77% rename from packages/frontend-core/src/components/grid/stores/menu.js rename to packages/frontend-core/src/components/grid/stores/menu.ts index 22bf26fff5..27e41c412b 100644 --- a/packages/frontend-core/src/components/grid/stores/menu.js +++ b/packages/frontend-core/src/components/grid/stores/menu.ts @@ -1,8 +1,24 @@ -import { writable, get } from "svelte/store" +import { writable, get, Writable } from "svelte/store" + +import { Store as StoreContext } from "." import { parseCellID } from "../lib/utils" +interface MenuStoreData { + left: number + top: number + visible: boolean + multiRowMode: boolean + multiCellMode: boolean +} + +interface MenuStore { + menu: Writable +} + +export type Store = MenuStore + export const createStores = () => { - const menu = writable({ + const menu = writable({ left: 0, top: 0, visible: false, @@ -14,7 +30,7 @@ export const createStores = () => { } } -export const createActions = context => { +export const createActions = (context: StoreContext) => { const { menu, focusedCellId, @@ -25,7 +41,7 @@ export const createActions = context => { selectedCellCount, } = context - const open = (cellId, e) => { + const open = (cellId: string, e: MouseEvent) => { e.preventDefault() e.stopPropagation() @@ -37,7 +53,7 @@ export const createActions = context => { } // Compute bounds of cell relative to outer data node - const targetBounds = e.target.getBoundingClientRect() + const targetBounds = (e.target as HTMLElement).getBoundingClientRect() const dataBounds = dataNode.getBoundingClientRect() // Check if there are multiple rows selected, and if this is one of them From 5c3922219fa132aefd004bc7dd214559237e80d0 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 24 Dec 2024 13:41:17 +0100 Subject: [PATCH 5/7] Type validation --- .../src/components/grid/stores/index.ts | 5 +++- .../stores/{validation.js => validation.ts} | 29 +++++++++++++------ 2 files changed, 24 insertions(+), 10 deletions(-) rename packages/frontend-core/src/components/grid/stores/{validation.js => validation.ts} (69%) diff --git a/packages/frontend-core/src/components/grid/stores/index.ts b/packages/frontend-core/src/components/grid/stores/index.ts index f2b6c973b9..90e89cbf4c 100644 --- a/packages/frontend-core/src/components/grid/stores/index.ts +++ b/packages/frontend-core/src/components/grid/stores/index.ts @@ -60,7 +60,8 @@ export type Store = BaseStore & Table.Store & ViewV2.Store & NonPlus.Store & - Datasource.Store & { + Datasource.Store & + Validation.Store & { // TODO while typing the rest of stores fetch: Writable filter: Writable @@ -76,6 +77,8 @@ export type Store = BaseStore & dispatch: (event: string, data: any) => any notifications: Writable schemaOverrides: Writable + focusedCellId: Writable + previousFocusedRowId: Writable } export const attachStores = (context: Store): Store => { diff --git a/packages/frontend-core/src/components/grid/stores/validation.js b/packages/frontend-core/src/components/grid/stores/validation.ts similarity index 69% rename from packages/frontend-core/src/components/grid/stores/validation.js rename to packages/frontend-core/src/components/grid/stores/validation.ts index 93e67e1d31..32bb1cf978 100644 --- a/packages/frontend-core/src/components/grid/stores/validation.js +++ b/packages/frontend-core/src/components/grid/stores/validation.ts @@ -1,10 +1,21 @@ -import { writable, get, derived } from "svelte/store" +import { writable, get, derived, Writable, Readable } from "svelte/store" +import { Store as StoreContext } from "." import { parseCellID } from "../lib/utils" +interface ValidationStore { + validation: Writable> +} + +interface DerivedValidationStore { + validationRowLookupMap: Readable> +} + +export type Store = ValidationStore & DerivedValidationStore + // Normally we would break out actions into the explicit "createActions" // function, but for validation all these actions are pure so can go into // "createStores" instead to make dependency ordering simpler -export const createStores = () => { +export const createStores = (): ValidationStore => { const validation = writable({}) return { @@ -12,12 +23,12 @@ export const createStores = () => { } } -export const deriveStores = context => { +export const deriveStores = (context: StoreContext): DerivedValidationStore => { const { validation } = context // Derive which rows have errors so that we can use that info later const validationRowLookupMap = derived(validation, $validation => { - let map = {} + const map: Record = {} Object.entries($validation).forEach(([key, error]) => { // Extract row ID from all errored cell IDs if (error) { @@ -36,10 +47,10 @@ export const deriveStores = context => { } } -export const createActions = context => { +export const createActions = (context: StoreContext) => { const { validation, focusedCellId, validationRowLookupMap } = context - const setError = (cellId, error) => { + const setError = (cellId: string | undefined, error: string) => { if (!cellId) { return } @@ -49,11 +60,11 @@ export const createActions = context => { })) } - const rowHasErrors = rowId => { + const rowHasErrors = (rowId: string) => { return get(validationRowLookupMap)[rowId]?.length > 0 } - const focusFirstRowError = rowId => { + const focusFirstRowError = (rowId: string) => { const errorCells = get(validationRowLookupMap)[rowId] const cellId = errorCells?.[0] if (cellId) { @@ -73,7 +84,7 @@ export const createActions = context => { } } -export const initialise = context => { +export const initialise = (context: StoreContext) => { const { validation, previousFocusedRowId, validationRowLookupMap } = context // Remove validation errors when changing rows From 430431203b0f469c28a7bf198d9827a9345502f6 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 30 Dec 2024 14:25:23 +0100 Subject: [PATCH 6/7] Typed enriched users --- .../src/components/grid/stores/users.ts | 17 +++++++++-------- packages/types/src/ui/stores/grid/user.ts | 5 +++++ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/packages/frontend-core/src/components/grid/stores/users.ts b/packages/frontend-core/src/components/grid/stores/users.ts index f8824f8329..dcac940088 100644 --- a/packages/frontend-core/src/components/grid/stores/users.ts +++ b/packages/frontend-core/src/components/grid/stores/users.ts @@ -1,7 +1,7 @@ import { writable, get, derived, Writable, Readable } from "svelte/store" import { helpers } from "@budibase/shared-core" import { Store as StoreContext } from "." -import { UIUser } from "@budibase/types" +import { UIEnrichedUser, UIUser } from "@budibase/types" interface UsersStore { users: Writable @@ -12,21 +12,22 @@ interface DerivedUsersStore { } interface ActionUserStore { - users: UsersStore["users"] & { - actions: { - updateUser: (user: UIUser) => void - removeUser: (sessionId: string) => void + users: UsersStore["users"] & + Readable & { + actions: { + updateUser: (user: UIUser) => void + removeUser: (sessionId: string) => void + } } - } } -export type Store = UsersStore & DerivedUsersStore +export type Store = DerivedUsersStore & ActionUserStore export const createStores = (): UsersStore => { const users = writable([]) const enrichedUsers = derived(users, $users => { - return $users.map(user => ({ + return $users.map(user => ({ ...user, color: helpers.getUserColor(user), label: helpers.getUserLabel(user), diff --git a/packages/types/src/ui/stores/grid/user.ts b/packages/types/src/ui/stores/grid/user.ts index b6eb529805..225c232d3d 100644 --- a/packages/types/src/ui/stores/grid/user.ts +++ b/packages/types/src/ui/stores/grid/user.ts @@ -4,3 +4,8 @@ export interface UIUser extends User { sessionId: string gridMetadata?: { focusedCellId?: string } } + +export interface UIEnrichedUser extends UIUser { + color: string + label: string +} From cca22fe8644a8106cfbb579d8fa51fb8e1037eda Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 30 Dec 2024 14:49:36 +0100 Subject: [PATCH 7/7] Move type --- packages/frontend-core/src/components/grid/stores/users.ts | 7 ++++++- packages/types/src/ui/stores/grid/user.ts | 5 ----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/frontend-core/src/components/grid/stores/users.ts b/packages/frontend-core/src/components/grid/stores/users.ts index dcac940088..b3dffbcb1b 100644 --- a/packages/frontend-core/src/components/grid/stores/users.ts +++ b/packages/frontend-core/src/components/grid/stores/users.ts @@ -1,7 +1,12 @@ import { writable, get, derived, Writable, Readable } from "svelte/store" import { helpers } from "@budibase/shared-core" import { Store as StoreContext } from "." -import { UIEnrichedUser, UIUser } from "@budibase/types" +import { UIUser } from "@budibase/types" + +interface UIEnrichedUser extends UIUser { + color: string + label: string +} interface UsersStore { users: Writable diff --git a/packages/types/src/ui/stores/grid/user.ts b/packages/types/src/ui/stores/grid/user.ts index 225c232d3d..b6eb529805 100644 --- a/packages/types/src/ui/stores/grid/user.ts +++ b/packages/types/src/ui/stores/grid/user.ts @@ -4,8 +4,3 @@ export interface UIUser extends User { sessionId: string gridMetadata?: { focusedCellId?: string } } - -export interface UIEnrichedUser extends UIUser { - color: string - label: string -}