PR Feedback
This commit is contained in:
parent
9d49d685a3
commit
1578c1a64b
|
@ -36,8 +36,8 @@ import { utils } from "@budibase/shared-core"
|
|||
export interface ComponentState {
|
||||
components: Record<string, ComponentDefinition>
|
||||
customComponents: string[]
|
||||
selectedComponentId?: string | null
|
||||
componentToPaste?: Component | null
|
||||
selectedComponentId?: string
|
||||
componentToPaste?: Component
|
||||
settingsCache: Record<string, ComponentSetting[]>
|
||||
selectedScreenId?: string | null
|
||||
}
|
||||
|
@ -68,8 +68,6 @@ export interface ComponentSetting {
|
|||
export const INITIAL_COMPONENTS_STATE: ComponentState = {
|
||||
components: {},
|
||||
customComponents: [],
|
||||
selectedComponentId: null,
|
||||
componentToPaste: null,
|
||||
settingsCache: {},
|
||||
}
|
||||
|
||||
|
@ -443,7 +441,7 @@ export class ComponentStore extends BudiStore<ComponentState> {
|
|||
*/
|
||||
createInstance(componentName: string, presetProps: any, parent: any) {
|
||||
const screen = get(selectedScreen)
|
||||
if (!screen || !selectedScreen) {
|
||||
if (!screen) {
|
||||
throw "A valid screen must be selected"
|
||||
}
|
||||
|
||||
|
@ -548,7 +546,7 @@ export class ComponentStore extends BudiStore<ComponentState> {
|
|||
// Find the selected component
|
||||
let selectedComponentId = state.selectedComponentId
|
||||
if (selectedComponentId?.startsWith(`${screen._id}-`)) {
|
||||
selectedComponentId = screen.props._id || null
|
||||
selectedComponentId = screen.props._id
|
||||
}
|
||||
const currentComponent = findComponent(
|
||||
screen.props,
|
||||
|
@ -659,7 +657,7 @@ export class ComponentStore extends BudiStore<ComponentState> {
|
|||
// Determine the next component to select, and select it before deletion
|
||||
// to avoid an intermediate state of no component selection
|
||||
const state = get(this.store)
|
||||
let nextId: string | null = ""
|
||||
let nextId: string = ""
|
||||
if (state.selectedComponentId === component._id) {
|
||||
nextId = this.getNext()
|
||||
if (!nextId) {
|
||||
|
@ -746,7 +744,7 @@ export class ComponentStore extends BudiStore<ComponentState> {
|
|||
if (!state.componentToPaste) {
|
||||
return
|
||||
}
|
||||
let newComponentId: string | null = ""
|
||||
let newComponentId: string = ""
|
||||
|
||||
// Remove copied component if cutting, regardless if pasting works
|
||||
let componentToPaste = cloneDeep(state.componentToPaste)
|
||||
|
@ -1169,7 +1167,7 @@ export class ComponentStore extends BudiStore<ComponentState> {
|
|||
}
|
||||
|
||||
async handleEjectBlock(componentId: string, ejectedDefinition: Component) {
|
||||
let nextSelectedComponentId: string | null = null
|
||||
let nextSelectedComponentId: string | undefined
|
||||
|
||||
await screenStore.patch((screen: Screen) => {
|
||||
const block = findComponent(screen.props, componentId)
|
||||
|
@ -1205,7 +1203,7 @@ export class ComponentStore extends BudiStore<ComponentState> {
|
|||
(x: Component) => x._id === componentId
|
||||
)
|
||||
parent._children[index] = ejectedDefinition
|
||||
nextSelectedComponentId = ejectedDefinition._id ?? null
|
||||
nextSelectedComponentId = ejectedDefinition._id
|
||||
}, null)
|
||||
|
||||
// Select new root component
|
||||
|
|
|
@ -25,7 +25,6 @@ import { ComponentDefinition } from "./components"
|
|||
interface ScreenState {
|
||||
screens: Screen[]
|
||||
selectedScreenId?: string
|
||||
selected?: Screen
|
||||
}
|
||||
|
||||
export const initialScreenState: ScreenState = {
|
||||
|
@ -65,7 +64,7 @@ export class ScreenStore extends BudiStore<ScreenState> {
|
|||
if (!get(selectedComponent)) {
|
||||
this.update(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)
|
||||
) {
|
||||
delete state.selectedScreenId
|
||||
componentStore.update(state => ({
|
||||
...state,
|
||||
selectedComponentId: null,
|
||||
}))
|
||||
componentStore.update(state => {
|
||||
delete state.selectedComponentId
|
||||
return state
|
||||
})
|
||||
}
|
||||
|
||||
// Update routing
|
||||
|
|
|
@ -544,7 +544,7 @@ describe("Screens store", () => {
|
|||
await bb.screenStore.delete(existingScreens[2].json())
|
||||
|
||||
expect(bb.store.screens.length).toBe(2)
|
||||
expect(get(componentStore).selectedComponentId).toBeNull()
|
||||
expect(get(componentStore).selectedComponentId).toBeUndefined()
|
||||
expect(bb.store.selectedScreenId).toBeUndefined()
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in New Issue