PR Feedback

This commit is contained in:
Dean 2025-01-20 10:48:00 +00:00
parent 9d49d685a3
commit 1578c1a64b
3 changed files with 14 additions and 17 deletions

View File

@ -36,8 +36,8 @@ import { utils } from "@budibase/shared-core"
export interface ComponentState { export interface ComponentState {
components: Record<string, ComponentDefinition> components: Record<string, ComponentDefinition>
customComponents: string[] customComponents: string[]
selectedComponentId?: string | null selectedComponentId?: string
componentToPaste?: Component | null componentToPaste?: Component
settingsCache: Record<string, ComponentSetting[]> settingsCache: Record<string, ComponentSetting[]>
selectedScreenId?: string | null selectedScreenId?: string | null
} }
@ -68,8 +68,6 @@ export interface ComponentSetting {
export const INITIAL_COMPONENTS_STATE: ComponentState = { export const INITIAL_COMPONENTS_STATE: ComponentState = {
components: {}, components: {},
customComponents: [], customComponents: [],
selectedComponentId: null,
componentToPaste: null,
settingsCache: {}, settingsCache: {},
} }
@ -443,7 +441,7 @@ export class ComponentStore extends BudiStore<ComponentState> {
*/ */
createInstance(componentName: string, presetProps: any, parent: any) { createInstance(componentName: string, presetProps: any, parent: any) {
const screen = get(selectedScreen) const screen = get(selectedScreen)
if (!screen || !selectedScreen) { if (!screen) {
throw "A valid screen must be selected" throw "A valid screen must be selected"
} }
@ -548,7 +546,7 @@ export class ComponentStore extends BudiStore<ComponentState> {
// Find the selected component // Find the selected component
let selectedComponentId = state.selectedComponentId let selectedComponentId = state.selectedComponentId
if (selectedComponentId?.startsWith(`${screen._id}-`)) { if (selectedComponentId?.startsWith(`${screen._id}-`)) {
selectedComponentId = screen.props._id || null selectedComponentId = screen.props._id
} }
const currentComponent = findComponent( const currentComponent = findComponent(
screen.props, screen.props,
@ -659,7 +657,7 @@ export class ComponentStore extends BudiStore<ComponentState> {
// Determine the next component to select, and select it before deletion // Determine the next component to select, and select it before deletion
// to avoid an intermediate state of no component selection // to avoid an intermediate state of no component selection
const state = get(this.store) const state = get(this.store)
let nextId: string | null = "" let nextId: string = ""
if (state.selectedComponentId === component._id) { if (state.selectedComponentId === component._id) {
nextId = this.getNext() nextId = this.getNext()
if (!nextId) { if (!nextId) {
@ -746,7 +744,7 @@ export class ComponentStore extends BudiStore<ComponentState> {
if (!state.componentToPaste) { if (!state.componentToPaste) {
return return
} }
let newComponentId: string | null = "" let newComponentId: string = ""
// Remove copied component if cutting, regardless if pasting works // Remove copied component if cutting, regardless if pasting works
let componentToPaste = cloneDeep(state.componentToPaste) let componentToPaste = cloneDeep(state.componentToPaste)
@ -1169,7 +1167,7 @@ export class ComponentStore extends BudiStore<ComponentState> {
} }
async handleEjectBlock(componentId: string, ejectedDefinition: Component) { async handleEjectBlock(componentId: string, ejectedDefinition: Component) {
let nextSelectedComponentId: string | null = null let nextSelectedComponentId: string | undefined
await screenStore.patch((screen: Screen) => { await screenStore.patch((screen: Screen) => {
const block = findComponent(screen.props, componentId) const block = findComponent(screen.props, componentId)
@ -1205,7 +1203,7 @@ export class ComponentStore extends BudiStore<ComponentState> {
(x: Component) => x._id === componentId (x: Component) => x._id === componentId
) )
parent._children[index] = ejectedDefinition parent._children[index] = ejectedDefinition
nextSelectedComponentId = ejectedDefinition._id ?? null nextSelectedComponentId = ejectedDefinition._id
}, null) }, null)
// Select new root component // Select new root component

View File

@ -25,7 +25,6 @@ import { ComponentDefinition } from "./components"
interface ScreenState { interface ScreenState {
screens: Screen[] screens: Screen[]
selectedScreenId?: string selectedScreenId?: string
selected?: Screen
} }
export const initialScreenState: ScreenState = { export const initialScreenState: ScreenState = {
@ -65,7 +64,7 @@ export class ScreenStore extends BudiStore<ScreenState> {
if (!get(selectedComponent)) { if (!get(selectedComponent)) {
this.update(state => ({ this.update(state => ({
...state, ...state,
selectedComponentId: get(this.store).selected?.props._id, selectedComponentId: get(selectedScreen)?.props._id,
})) }))
} }
}, },
@ -400,10 +399,10 @@ export class ScreenStore extends BudiStore<ScreenState> {
deletedIds.includes(state.selectedScreenId) deletedIds.includes(state.selectedScreenId)
) { ) {
delete state.selectedScreenId delete state.selectedScreenId
componentStore.update(state => ({ componentStore.update(state => {
...state, delete state.selectedComponentId
selectedComponentId: null, return state
})) })
} }
// Update routing // Update routing

View File

@ -544,7 +544,7 @@ describe("Screens store", () => {
await bb.screenStore.delete(existingScreens[2].json()) await bb.screenStore.delete(existingScreens[2].json())
expect(bb.store.screens.length).toBe(2) expect(bb.store.screens.length).toBe(2)
expect(get(componentStore).selectedComponentId).toBeNull() expect(get(componentStore).selectedComponentId).toBeUndefined()
expect(bb.store.selectedScreenId).toBeUndefined() expect(bb.store.selectedScreenId).toBeUndefined()
}) })