Merge branch 'master' of github.com:Budibase/budibase into autoscreen-templates

This commit is contained in:
Andrew Kingston 2020-10-16 09:17:54 +01:00
commit bb2a650eee
5 changed files with 47 additions and 12 deletions

View File

@ -24,6 +24,7 @@ import {
saveCurrentPreviewItem as _saveCurrentPreviewItem, saveCurrentPreviewItem as _saveCurrentPreviewItem,
saveScreenApi as _saveScreenApi, saveScreenApi as _saveScreenApi,
regenerateCssForCurrentScreen, regenerateCssForCurrentScreen,
regenerateCssForScreen,
generateNewIdsForComponent, generateNewIdsForComponent,
getComponentDefinition, getComponentDefinition,
} from "../storeUtils" } from "../storeUtils"
@ -98,6 +99,29 @@ const setPackage = (store, initial) => async pkg => {
}, },
} }
// if the app has just been created
// we need to build the CSS and save
if (pkg.justCreated) {
const generateInitialPageCss = async name => {
const page = pkg.pages[name]
regenerateCssForScreen(page)
for (let screen of page._screens) {
regenerateCssForScreen(screen)
}
await api.post(`/_builder/api/${pkg.application._id}/pages/${name}`, {
page: {
componentLibraries: pkg.application.componentLibraries,
...page,
},
screens: page._screens,
})
}
generateInitialPageCss("main")
generateInitialPageCss("unauthenticated")
pkg.justCreated = false
}
initial.libraries = pkg.application.componentLibraries initial.libraries = pkg.application.componentLibraries
initial.components = await fetchComponentLibDefinitions(pkg.application._id) initial.components = await fetchComponentLibDefinitions(pkg.application._id)
initial.name = pkg.application.name initial.name = pkg.application.name
@ -156,8 +180,8 @@ const createScreen = store => async screen => {
state.currentPreviewItem = screen state.currentPreviewItem = screen
state.currentComponentInfo = screen.props state.currentComponentInfo = screen.props
state.currentFrontEndType = "screen" state.currentFrontEndType = "screen"
savePromise = _saveScreen(store, state, screen)
regenerateCssForCurrentScreen(state) regenerateCssForCurrentScreen(state)
savePromise = _saveScreen(store, state, screen)
return state return state
}) })
await savePromise await savePromise

View File

@ -79,10 +79,12 @@ export const walkProps = (props, action, cancelToken = null) => {
} }
} }
export const regenerateCssForScreen = screen => {
screen._css = generate_screen_css([screen.props])
}
export const regenerateCssForCurrentScreen = state => { export const regenerateCssForCurrentScreen = state => {
state.currentPreviewItem._css = generate_screen_css([ regenerateCssForScreen(state.currentPreviewItem)
state.currentPreviewItem.props,
])
return state return state
} }

View File

@ -154,6 +154,7 @@
const pkg = await applicationPkg.json() const pkg = await applicationPkg.json()
if (applicationPkg.ok) { if (applicationPkg.ok) {
backendUiStore.actions.reset() backendUiStore.actions.reset()
pkg.justCreated = true
await store.setPackage(pkg) await store.setPackage(pkg)
automationStore.actions.fetch() automationStore.actions.fetch()
} else { } else {

View File

@ -11,6 +11,9 @@
export let screens = [] export let screens = []
$: sortedScreens = screens.sort(
(s1, s2) => s1.props._instanceName > s2.props._instanceName
)
/* /*
Using a store here seems odd.... Using a store here seems odd....
have a look in the <ComponentsHierarchyChildren /> code file to find out why. have a look in the <ComponentsHierarchyChildren /> code file to find out why.
@ -24,12 +27,15 @@
const joinPath = join("/") const joinPath = join("/")
const normalizedName = name => const normalizedName = name =>
pipe(name, [ pipe(
trimCharsStart("./"), name,
trimCharsStart("~/"), [
trimCharsStart("../"), trimCharsStart("./"),
trimChars(" "), trimCharsStart("~/"),
]) trimCharsStart("../"),
trimChars(" "),
]
)
const changeScreen = screen => { const changeScreen = screen => {
store.setCurrentScreen(screen.props._instanceName) store.setCurrentScreen(screen.props._instanceName)
@ -38,7 +44,7 @@
</script> </script>
<div class="root"> <div class="root">
{#each screens as screen} {#each sortedScreens as screen}
<div <div
class="budibase__nav-item screen-header-row" class="budibase__nav-item screen-header-row"
class:selected={$store.currentComponentInfo._id === screen.props._id} class:selected={$store.currentComponentInfo._id === screen.props._id}

View File

@ -38,7 +38,9 @@ export const screenRouter = ({ screens, onScreenSelected, window }) => {
function route(url) { function route(url) {
const _url = makeRootedPath(url.state || url) const _url = makeRootedPath(url.state || url)
current = routes.findIndex( current = routes.findIndex(
p => p !== "*" && new RegExp("^" + p + "$").test(_url) p =>
p !== "*" &&
new RegExp("^" + p.toLowerCase() + "$").test(_url.toLowerCase())
) )
const params = {} const params = {}