bugfix: create screen > components not displayed

This commit is contained in:
Michael Shanks 2020-03-04 12:13:50 +00:00
parent 34665b4b93
commit 8546fd6da9
1 changed files with 50 additions and 7 deletions

View File

@ -466,8 +466,33 @@ const _saveScreen = async (store, s, screen) => {
`/_builder/api/${s.appname}/pages/${s.currentPageName}/screen`, `/_builder/api/${s.appname}/pages/${s.currentPageName}/screen`,
screen screen
) )
.then(async savedScreen => { .then(() => {
const updatedScreen = await savedScreen.json()
if(currentPageScreens.includes(screen)) return
const screens = [
...currentPageScreens,
screen,
]
store.update(innerState => {
innerState.pages[s.currentPageName]._screens = screens
innerState.screens = screens
innerState.currentPreviewItem = screen
const safeProps = makePropsSafe(
getComponentDefinition(innerState.components, screen.props._component),
screen.props
)
innerState.currentComponentInfo = safeProps
screen.props = safeProps
_savePage(innerState)
return innerState
})
/*const updatedScreen = await savedScreen.json()
const screens = [ const screens = [
...currentPageScreens.filter( ...currentPageScreens.filter(
storeScreen => storeScreen.name !== updatedScreen.name storeScreen => storeScreen.name !== updatedScreen.name
@ -477,9 +502,20 @@ const _saveScreen = async (store, s, screen) => {
store.update(innerState => { store.update(innerState => {
innerState.pages[s.currentPageName]._screens = screens innerState.pages[s.currentPageName]._screens = screens
innerState.screens = screens innerState.screens = screens
let curentComponentId
walkProps(screen.props, p => {
if(p === innerState.currentComponentInfo)
currentComponentId = p._id
})
innerState.currentPreviewItem = updatedScreen
innerState.currentComponentInfo = makePropsSafe(componentDef, component)
_savePage(innerState) _savePage(innerState)
return innerState return innerState
}) })
*/
}) })
return s return s
@ -520,10 +556,12 @@ const setCurrentScreen = store => screenName => {
s.currentFrontEndType = "screen" s.currentFrontEndType = "screen"
s.currentView = "detail" s.currentView = "detail"
s.currentComponentInfo = makePropsSafe( const safeProps = makePropsSafe(
getContainerComponent(s.components), getComponentDefinition(s.components, screen.props._component),
screen.props screen.props
) )
screen.props = safeProps
s.currentComponentInfo = safeProps
setCurrentPageFunctions(s) setCurrentPageFunctions(s)
return s return s
}) })
@ -707,10 +745,12 @@ const setCurrentPage = store => pageName => {
s.screens = Array.isArray(current_screens) s.screens = Array.isArray(current_screens)
? current_screens ? current_screens
: Object.values(current_screens) : Object.values(current_screens)
s.currentComponentInfo = makePropsSafe( const safeProps = makePropsSafe(
getContainerComponent(s.components), getComponentDefinition(s.components, s.pages[pageName].props._component),
s.pages[pageName].props s.pages[pageName].props
) )
s.currentComponentInfo = safeProps
s.pages[pageName].props = safeProps
s.currentPreviewItem = s.pages[pageName] s.currentPreviewItem = s.pages[pageName]
s.currentPreviewItem._css = generate_screen_css([ s.currentPreviewItem._css = generate_screen_css([
s.currentPreviewItem.props, s.currentPreviewItem.props,
@ -726,7 +766,10 @@ const setCurrentPage = store => pageName => {
} }
const getContainerComponent = components => const getContainerComponent = components =>
components.find(c => c.name === "@budibase/standard-components/container") getComponentDefinition(components, "@budibase/standard-components/container")
const getComponentDefinition = (components, name) =>
components.find(c => c.name === name)
/** /**
* @param {string} componentToAdd - name of the component to add to the application * @param {string} componentToAdd - name of the component to add to the application