Further updates to clear out all usage of the old frontend store functions.
This commit is contained in:
parent
fe637e2309
commit
707c16c44d
|
@ -33,7 +33,7 @@ export default function(component, state) {
|
||||||
let index = 1
|
let index = 1
|
||||||
let name
|
let name
|
||||||
while (!name) {
|
while (!name) {
|
||||||
const tryName = `${capitalised} ${index}`
|
const tryName = `${capitalised || "Copy"} ${index}`
|
||||||
if (!matchingComponents.includes(tryName)) name = tryName
|
if (!matchingComponents.includes(tryName)) name = tryName
|
||||||
index++
|
index++
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ import {
|
||||||
getParent,
|
getParent,
|
||||||
// saveScreenApi as _saveScreenApi,
|
// saveScreenApi as _saveScreenApi,
|
||||||
generateNewIdsForComponent,
|
generateNewIdsForComponent,
|
||||||
getComponentDefinition,
|
getComponentDefinition, findChildComponentType, regenerateCssForScreen, savePage as _savePage,
|
||||||
} from "../storeUtils"
|
} from "../storeUtils"
|
||||||
|
|
||||||
const INITIAL_FRONTEND_STATE = {
|
const INITIAL_FRONTEND_STATE = {
|
||||||
|
@ -171,18 +171,18 @@ export const getFrontendStore = () => {
|
||||||
screen
|
screen
|
||||||
)
|
)
|
||||||
const json = await response.json()
|
const json = await response.json()
|
||||||
|
|
||||||
if (currentPageScreens.includes(screen)) return
|
|
||||||
|
|
||||||
screen._rev = json.rev
|
screen._rev = json.rev
|
||||||
screen._id = json.id
|
screen._id = json.id
|
||||||
|
const foundScreen = currentPageScreens.findIndex(el => el._id === screen._id)
|
||||||
const screens = [...currentPageScreens, screen]
|
if (currentPageScreens !== -1) {
|
||||||
|
currentPageScreens.splice(foundScreen, 1)
|
||||||
|
}
|
||||||
|
currentPageScreens.push(screen)
|
||||||
|
|
||||||
// TODO: should carry out all server updates to screen in a single call
|
// TODO: should carry out all server updates to screen in a single call
|
||||||
store.update(state => {
|
store.update(state => {
|
||||||
state.pages[pageName]._screens = screens
|
state.pages[pageName]._screens = currentPageScreens
|
||||||
state.screens = screens
|
state.screens = currentPageScreens
|
||||||
state.currentPreviewItem = screen
|
state.currentPreviewItem = screen
|
||||||
const safeProps = makePropsSafe(
|
const safeProps = makePropsSafe(
|
||||||
state.components[screen.props._component],
|
state.components[screen.props._component],
|
||||||
|
@ -481,6 +481,59 @@ export const getFrontendStore = () => {
|
||||||
|
|
||||||
return path
|
return path
|
||||||
},
|
},
|
||||||
|
links: {
|
||||||
|
save: async (url, title) => {
|
||||||
|
let savePromise
|
||||||
|
store.update(state => {
|
||||||
|
// Try to extract a nav component from the master screen
|
||||||
|
const nav = findChildComponentType(
|
||||||
|
state.pages.main,
|
||||||
|
"@budibase/standard-components/Navigation"
|
||||||
|
)
|
||||||
|
if (nav) {
|
||||||
|
let newLink
|
||||||
|
|
||||||
|
// Clone an existing link if one exists
|
||||||
|
if (nav._children && nav._children.length) {
|
||||||
|
// Clone existing link style
|
||||||
|
newLink = cloneDeep(nav._children[0])
|
||||||
|
|
||||||
|
// Manipulate IDs to ensure uniqueness
|
||||||
|
generateNewIdsForComponent(newLink, state, false)
|
||||||
|
|
||||||
|
// Set our new props
|
||||||
|
newLink._instanceName = `${title} Link`
|
||||||
|
newLink.url = url
|
||||||
|
newLink.text = title
|
||||||
|
} else {
|
||||||
|
// Otherwise create vanilla new link
|
||||||
|
const component = getComponentDefinition(
|
||||||
|
state,
|
||||||
|
"@budibase/standard-components/link"
|
||||||
|
)
|
||||||
|
const instanceId = get(backendUiStore).selectedDatabase._id
|
||||||
|
newLink = createProps(component, {
|
||||||
|
url,
|
||||||
|
text: title,
|
||||||
|
_instanceName: `${title} Link`,
|
||||||
|
_instanceId: instanceId,
|
||||||
|
}).props
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save page and regenerate all CSS because otherwise weird things happen
|
||||||
|
nav._children = [...nav._children, newLink]
|
||||||
|
state.currentPageName = "main"
|
||||||
|
store.actions.screens.regenerateCss(state.pages.main)
|
||||||
|
for (let screen of state.pages.main._screens) {
|
||||||
|
store.actions.screens.regenerateCss(screen)
|
||||||
|
}
|
||||||
|
savePromise = store.actions.pages.save()
|
||||||
|
}
|
||||||
|
return state
|
||||||
|
})
|
||||||
|
await savePromise
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -391,7 +391,7 @@ const setComponentProp = store => (name, value) => {
|
||||||
current_component[name] = value
|
current_component[name] = value
|
||||||
|
|
||||||
state.currentComponentInfo = current_component
|
state.currentComponentInfo = current_component
|
||||||
_saveCurrentPreviewItem(state)
|
//_saveCurrentPreviewItem(state)
|
||||||
return state
|
return state
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -403,7 +403,7 @@ const setPageOrScreenProp = store => (name, value) => {
|
||||||
} else {
|
} else {
|
||||||
state.currentPreviewItem[name] = value
|
state.currentPreviewItem[name] = value
|
||||||
}
|
}
|
||||||
_saveCurrentPreviewItem(state)
|
//_saveCurrentPreviewItem(state)
|
||||||
return state
|
return state
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -418,7 +418,7 @@ const setComponentStyle = store => (type, name, value) => {
|
||||||
regenerateCssForCurrentScreen(state)
|
regenerateCssForCurrentScreen(state)
|
||||||
|
|
||||||
// save without messing with the store
|
// save without messing with the store
|
||||||
_saveCurrentPreviewItem(state)
|
//_saveCurrentPreviewItem(state)
|
||||||
return state
|
return state
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -511,7 +511,7 @@ const pasteComponent = store => (targetComponent, mode) => {
|
||||||
const index = mode === "above" ? targetIndex : targetIndex + 1
|
const index = mode === "above" ? targetIndex : targetIndex + 1
|
||||||
parent._children.splice(index, 0, cloneDeep(componentToPaste))
|
parent._children.splice(index, 0, cloneDeep(componentToPaste))
|
||||||
regenerateCssForCurrentScreen(s)
|
regenerateCssForCurrentScreen(s)
|
||||||
_saveCurrentPreviewItem(s)
|
//_saveCurrentPreviewItem(s)
|
||||||
selectComponent(s, componentToPaste)
|
selectComponent(s, componentToPaste)
|
||||||
|
|
||||||
return s
|
return s
|
||||||
|
|
|
@ -31,10 +31,10 @@ export const getParent = (rootProps, child) => {
|
||||||
return parent
|
return parent
|
||||||
}
|
}
|
||||||
|
|
||||||
export const saveCurrentPreviewItem = s =>
|
// export const saveCurrentPreviewItem = s =>
|
||||||
s.currentFrontEndType === "page"
|
// s.currentFrontEndType === "page"
|
||||||
? savePage(s)
|
// ? savePage(s)
|
||||||
: store.saveScreen(s.currentPreviewItem)
|
// : store.actions.screens.save(s.currentPreviewItem)
|
||||||
|
|
||||||
export const savePage = async state => {
|
export const savePage = async state => {
|
||||||
const pageName = state.currentPageName || "main"
|
const pageName = state.currentPageName || "main"
|
||||||
|
@ -92,10 +92,10 @@ export const regenerateCssForCurrentScreen = state => {
|
||||||
return state
|
return state
|
||||||
}
|
}
|
||||||
|
|
||||||
export const generateNewIdsForComponent = (c, state, changeName = true) =>
|
export const generateNewIdsForComponent = (component, state, changeName = true) =>
|
||||||
walkProps(c, p => {
|
walkProps(component, prop => {
|
||||||
p._id = uuid()
|
prop._id = uuid()
|
||||||
if (changeName) p._instanceName = getNewComponentName(p._component, state)
|
if (changeName) prop._instanceName = getNewComponentName(prop, state)
|
||||||
})
|
})
|
||||||
|
|
||||||
export const getComponentDefinition = (state, name) =>
|
export const getComponentDefinition = (state, name) =>
|
||||||
|
|
|
@ -55,7 +55,7 @@
|
||||||
// Record the table that created this screen so we can link it later
|
// Record the table that created this screen so we can link it later
|
||||||
screen.autoTableId = table._id
|
screen.autoTableId = table._id
|
||||||
try {
|
try {
|
||||||
await store.createScreen(screen)
|
await store.actions.screens.create(screen)
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
// TODO: this is temporary
|
// TODO: this is temporary
|
||||||
// a cypress test is failing, because I added the
|
// a cypress test is failing, because I added the
|
||||||
|
@ -70,7 +70,7 @@
|
||||||
const listPage = screens.find(screen =>
|
const listPage = screens.find(screen =>
|
||||||
screen.props._instanceName.endsWith("List")
|
screen.props._instanceName.endsWith("List")
|
||||||
)
|
)
|
||||||
await store.createLink(listPage.route, table.name)
|
await store.actions.components.links.save(listPage.route, table.name)
|
||||||
|
|
||||||
// Navigate to new table
|
// Navigate to new table
|
||||||
$goto(`./table/${table._id}`)
|
$goto(`./table/${table._id}`)
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
import { getComponentDefinition } from "builderStore/storeUtils"
|
import { getComponentDefinition } from "builderStore/storeUtils"
|
||||||
import ConfirmDialog from "components/common/ConfirmDialog.svelte"
|
import ConfirmDialog from "components/common/ConfirmDialog.svelte"
|
||||||
import { last } from "lodash/fp"
|
import { last } from "lodash/fp"
|
||||||
import { getParent, saveCurrentPreviewItem } from "builderStore/storeUtils"
|
import { getParent } from "builderStore/storeUtils"
|
||||||
import { DropdownMenu } from "@budibase/bbui"
|
import { DropdownMenu } from "@budibase/bbui"
|
||||||
import { DropdownContainer, DropdownItem } from "components/common/Dropdowns"
|
import { DropdownContainer, DropdownItem } from "components/common/Dropdowns"
|
||||||
|
|
||||||
|
@ -31,44 +31,44 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
const moveUpComponent = () => {
|
const moveUpComponent = () => {
|
||||||
store.update(s => {
|
store.update(state => {
|
||||||
const parent = getParent(s.currentPreviewItem.props, component)
|
const parent = getParent(state.currentPreviewItem.props, component)
|
||||||
|
|
||||||
if (parent) {
|
if (parent) {
|
||||||
const currentIndex = parent._children.indexOf(component)
|
const currentIndex = parent._children.indexOf(component)
|
||||||
if (currentIndex === 0) return s
|
if (currentIndex === 0) return state
|
||||||
|
|
||||||
const newChildren = parent._children.filter(c => c !== component)
|
const newChildren = parent._children.filter(c => c !== component)
|
||||||
newChildren.splice(currentIndex - 1, 0, component)
|
newChildren.splice(currentIndex - 1, 0, component)
|
||||||
parent._children = newChildren
|
parent._children = newChildren
|
||||||
}
|
}
|
||||||
s.currentComponentInfo = component
|
state.currentComponentInfo = component
|
||||||
saveCurrentPreviewItem(s)
|
store.actions.preview.saveSelected()
|
||||||
|
|
||||||
return s
|
return state
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const moveDownComponent = () => {
|
const moveDownComponent = () => {
|
||||||
store.update(s => {
|
store.update(state => {
|
||||||
const parent = getParent(s.currentPreviewItem.props, component)
|
const parent = getParent(state.currentPreviewItem.props, component)
|
||||||
|
|
||||||
if (parent) {
|
if (parent) {
|
||||||
const currentIndex = parent._children.indexOf(component)
|
const currentIndex = parent._children.indexOf(component)
|
||||||
if (currentIndex === parent._children.length - 1) return s
|
if (currentIndex === parent._children.length - 1) return state
|
||||||
|
|
||||||
const newChildren = parent._children.filter(c => c !== component)
|
const newChildren = parent._children.filter(c => c !== component)
|
||||||
newChildren.splice(currentIndex + 1, 0, component)
|
newChildren.splice(currentIndex + 1, 0, component)
|
||||||
parent._children = newChildren
|
parent._children = newChildren
|
||||||
}
|
}
|
||||||
s.currentComponentInfo = component
|
state.currentComponentInfo = component
|
||||||
saveCurrentPreviewItem(s)
|
store.actions.preview.saveSelected()
|
||||||
|
|
||||||
return s
|
return state
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const copyComponent = () => {
|
const duplicateComponent = () => {
|
||||||
storeComponentForCopy(false)
|
storeComponentForCopy(false)
|
||||||
pasteComponent("below")
|
pasteComponent("below")
|
||||||
}
|
}
|
||||||
|
@ -82,7 +82,7 @@
|
||||||
selectComponent(parent)
|
selectComponent(parent)
|
||||||
}
|
}
|
||||||
|
|
||||||
saveCurrentPreviewItem(state)
|
store.actions.preview.saveSelected()
|
||||||
return state
|
return state
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -119,7 +119,7 @@
|
||||||
<DropdownItem
|
<DropdownItem
|
||||||
icon="ri-repeat-one-line"
|
icon="ri-repeat-one-line"
|
||||||
title="Duplicate"
|
title="Duplicate"
|
||||||
on:click={copyComponent} />
|
on:click={duplicateComponent} />
|
||||||
<DropdownItem
|
<DropdownItem
|
||||||
icon="ri-scissors-cut-line"
|
icon="ri-scissors-cut-line"
|
||||||
title="Cut"
|
title="Cut"
|
||||||
|
|
|
@ -58,6 +58,18 @@
|
||||||
return components
|
return components
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setPageOrScreenProp(name, value) {
|
||||||
|
store.update(state => {
|
||||||
|
if (name === "_instanceName" && state.currentFrontEndType === "screen") {
|
||||||
|
state.currentPreviewItem.props[name] = value
|
||||||
|
} else {
|
||||||
|
state.currentPreviewItem[name] = value
|
||||||
|
}
|
||||||
|
store.actions.preview.saveSelected()
|
||||||
|
return state
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
function getProps(obj, keys) {
|
function getProps(obj, keys) {
|
||||||
return keys.map((key, i) => [key, obj[key], obj.props._id + i])
|
return keys.map((key, i) => [key, obj[key], obj.props._id + i])
|
||||||
}
|
}
|
||||||
|
@ -82,7 +94,7 @@
|
||||||
{panelDefinition}
|
{panelDefinition}
|
||||||
displayNameField={displayName}
|
displayNameField={displayName}
|
||||||
onChange={store.actions.components.updateProp}
|
onChange={store.actions.components.updateProp}
|
||||||
onScreenPropChange={store.setPageOrScreenProp}
|
onScreenPropChange={setPageOrScreenProp}
|
||||||
screenOrPageInstance={$store.currentView !== 'component' && $store.currentPreviewItem} />
|
screenOrPageInstance={$store.currentView !== 'component' && $store.currentPreviewItem} />
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -71,9 +71,9 @@
|
||||||
draftScreen.props._component = baseComponent
|
draftScreen.props._component = baseComponent
|
||||||
draftScreen.route = route
|
draftScreen.route = route
|
||||||
|
|
||||||
await store.createScreen(draftScreen)
|
await store.actions.screens.create(draftScreen)
|
||||||
if (createLink) {
|
if (createLink) {
|
||||||
await store.createLink(route, name)
|
await store.actions.components.links.save(route, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (templateIndex !== undefined) {
|
if (templateIndex !== undefined) {
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
console.log(store)
|
|
||||||
if (!$store.currentPageName)
|
if (!$store.currentPageName)
|
||||||
store.actions.pages.select($params.page ? $params.page : "main")
|
store.actions.pages.select($params.page ? $params.page : "main")
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,13 @@ exports.isInvalidationComplete = async function(
|
||||||
return resp.Invalidation.Status === "Completed"
|
return resp.Invalidation.Status === "Completed"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finalises the deployment, updating the quota for the user API key
|
||||||
|
* The verification process returns the levels to update to.
|
||||||
|
* Calls the "deployment-success" lambda.
|
||||||
|
* @param {object} quota The usage quota levels returned from the verifyDeploy
|
||||||
|
* @returns {Promise<object>} The usage has been updated against the user API key.
|
||||||
|
*/
|
||||||
exports.updateDeploymentQuota = async function(quota) {
|
exports.updateDeploymentQuota = async function(quota) {
|
||||||
const DEPLOYMENT_SUCCESS_URL =
|
const DEPLOYMENT_SUCCESS_URL =
|
||||||
env.DEPLOYMENT_CREDENTIALS_URL + "deploy/success"
|
env.DEPLOYMENT_CREDENTIALS_URL + "deploy/success"
|
||||||
|
@ -67,7 +74,8 @@ exports.updateDeploymentQuota = async function(quota) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Verifies the users API key and
|
* Verifies the users API key and
|
||||||
* Verifies that the deployment fits within the quota of the user,
|
* Verifies that the deployment fits within the quota of the user
|
||||||
|
* Links to the "check-api-key" lambda.
|
||||||
* @param {String} appId - appId being deployed
|
* @param {String} appId - appId being deployed
|
||||||
* @param {String} appId - appId being deployed
|
* @param {String} appId - appId being deployed
|
||||||
* @param {quota} quota - current quota being changed with this application
|
* @param {quota} quota - current quota being changed with this application
|
||||||
|
|
Loading…
Reference in New Issue