Merge pull request #6352 from Budibase/fix/select-table-by-id
Fix autoscreen and autoscreen link creation and deletion
This commit is contained in:
commit
8b2d125974
|
@ -190,6 +190,7 @@ export const getFrontendStore = () => {
|
||||||
|
|
||||||
// Build array of promises to speed up bulk deletions
|
// Build array of promises to speed up bulk deletions
|
||||||
const promises = []
|
const promises = []
|
||||||
|
let deleteUrls = []
|
||||||
screensToDelete.forEach(screen => {
|
screensToDelete.forEach(screen => {
|
||||||
// Delete the screen
|
// Delete the screen
|
||||||
promises.push(
|
promises.push(
|
||||||
|
@ -199,14 +200,10 @@ export const getFrontendStore = () => {
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
// Remove links to this screen
|
// Remove links to this screen
|
||||||
promises.push(
|
deleteUrls.push(screen.routing.route)
|
||||||
store.actions.components.links.delete(
|
|
||||||
screen.routing.route,
|
|
||||||
screen.props._instanceName
|
|
||||||
)
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
promises.push(store.actions.links.delete(deleteUrls))
|
||||||
await Promise.all(promises)
|
await Promise.all(promises)
|
||||||
const deletedIds = screensToDelete.map(screen => screen._id)
|
const deletedIds = screensToDelete.map(screen => screen._id)
|
||||||
store.update(state => {
|
store.update(state => {
|
||||||
|
@ -578,89 +575,38 @@ export const getFrontendStore = () => {
|
||||||
})
|
})
|
||||||
await store.actions.preview.saveSelected()
|
await store.actions.preview.saveSelected()
|
||||||
},
|
},
|
||||||
links: {
|
},
|
||||||
save: async (url, title) => {
|
links: {
|
||||||
const layout = get(mainLayout)
|
save: async (url, title) => {
|
||||||
if (!layout) {
|
const layout = get(mainLayout)
|
||||||
return
|
if (!layout) {
|
||||||
}
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Add link setting to main layout
|
// Add link setting to main layout
|
||||||
if (layout.props._component.endsWith("layout")) {
|
if (!layout.props.links) {
|
||||||
// If using a new SDK, add to the layout component settings
|
layout.props.links = []
|
||||||
if (!layout.props.links) {
|
}
|
||||||
layout.props.links = []
|
layout.props.links.push({
|
||||||
}
|
text: title,
|
||||||
layout.props.links.push({
|
url,
|
||||||
text: title,
|
})
|
||||||
url,
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
// If using an old SDK, add to the navigation component
|
|
||||||
// TODO: remove this when we can assume everyone has updated
|
|
||||||
const nav = findComponentType(
|
|
||||||
layout.props,
|
|
||||||
"@budibase/standard-components/navigation"
|
|
||||||
)
|
|
||||||
if (!nav) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
let newLink
|
await store.actions.layouts.save(layout)
|
||||||
if (nav._children && nav._children.length) {
|
},
|
||||||
// Clone an existing link if one exists
|
delete: async urls => {
|
||||||
newLink = cloneDeep(nav._children[0])
|
const layout = get(mainLayout)
|
||||||
|
if (!layout?.props.links?.length) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Set our new props
|
// Filter out the URLs to delete
|
||||||
newLink._id = Helpers.uuid()
|
urls = Array.isArray(urls) ? urls : [urls]
|
||||||
newLink._instanceName = `${title} Link`
|
layout.props.links = layout.props.links.filter(
|
||||||
newLink.url = url
|
link => !urls.includes(link.url)
|
||||||
newLink.text = title
|
)
|
||||||
} else {
|
|
||||||
// Otherwise create vanilla new link
|
|
||||||
newLink = {
|
|
||||||
...store.actions.components.createInstance("link"),
|
|
||||||
url,
|
|
||||||
text: title,
|
|
||||||
_instanceName: `${title} Link`,
|
|
||||||
}
|
|
||||||
nav._children = [...nav._children, newLink]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save layout
|
await store.actions.layouts.save(layout)
|
||||||
await store.actions.layouts.save(layout)
|
|
||||||
},
|
|
||||||
delete: async (url, title) => {
|
|
||||||
const layout = get(mainLayout)
|
|
||||||
if (!layout) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add link setting to main layout
|
|
||||||
if (layout.props._component.endsWith("layout")) {
|
|
||||||
// If using a new SDK, add to the layout component settings
|
|
||||||
layout.props.links = layout.props.links.filter(
|
|
||||||
link => !(link.text === title && link.url === url)
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
// If using an old SDK, add to the navigation component
|
|
||||||
// TODO: remove this when we can assume everyone has updated
|
|
||||||
const nav = findComponentType(
|
|
||||||
layout.props,
|
|
||||||
"@budibase/standard-components/navigation"
|
|
||||||
)
|
|
||||||
if (!nav) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
nav._children = nav._children.filter(
|
|
||||||
child => !(child.url === url && child.text === title)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
// Save layout
|
|
||||||
await store.actions.layouts.save(layout)
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
settings: {
|
settings: {
|
||||||
|
|
|
@ -15,7 +15,7 @@ export default function (tables) {
|
||||||
name: `${table.name} - New`,
|
name: `${table.name} - New`,
|
||||||
create: () => createScreen(table),
|
create: () => createScreen(table),
|
||||||
id: NEW_ROW_TEMPLATE,
|
id: NEW_ROW_TEMPLATE,
|
||||||
table: table.name,
|
table: table._id,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ export default function (tables) {
|
||||||
name: `${table.name} - Detail`,
|
name: `${table.name} - Detail`,
|
||||||
create: () => createScreen(table),
|
create: () => createScreen(table),
|
||||||
id: ROW_DETAIL_TEMPLATE,
|
id: ROW_DETAIL_TEMPLATE,
|
||||||
table: table.name,
|
table: table._id,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ export default function (tables) {
|
||||||
name: `${table.name} - List`,
|
name: `${table.name} - List`,
|
||||||
create: () => createScreen(table),
|
create: () => createScreen(table),
|
||||||
id: ROW_LIST_TEMPLATE,
|
id: ROW_LIST_TEMPLATE,
|
||||||
table: table.name,
|
table: table._id,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,14 +14,14 @@
|
||||||
let selectedScreens = [...initalScreens]
|
let selectedScreens = [...initalScreens]
|
||||||
|
|
||||||
const toggleScreenSelection = (table, datasource) => {
|
const toggleScreenSelection = (table, datasource) => {
|
||||||
if (selectedScreens.find(s => s.table === table.name)) {
|
if (selectedScreens.find(s => s.table === table._id)) {
|
||||||
selectedScreens = selectedScreens.filter(
|
selectedScreens = selectedScreens.filter(
|
||||||
screen => screen.table !== table.name
|
screen => screen.table !== table._id
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
let partialTemplates = getTemplates($store, $tables.list).reduce(
|
let partialTemplates = getTemplates($store, $tables.list).reduce(
|
||||||
(acc, template) => {
|
(acc, template) => {
|
||||||
if (template.table === table.name) {
|
if (template.table === table._id) {
|
||||||
template.datasource = datasource.name
|
template.datasource = datasource.name
|
||||||
acc.push(template)
|
acc.push(template)
|
||||||
}
|
}
|
||||||
|
@ -88,7 +88,7 @@
|
||||||
<div
|
<div
|
||||||
class="data-source-entry"
|
class="data-source-entry"
|
||||||
class:selected={selectedScreens.find(
|
class:selected={selectedScreens.find(
|
||||||
x => x.table === table.name
|
x => x.table === table._id
|
||||||
)}
|
)}
|
||||||
on:click={() => toggleScreenSelection(table, datasource)}
|
on:click={() => toggleScreenSelection(table, datasource)}
|
||||||
>
|
>
|
||||||
|
@ -102,8 +102,7 @@
|
||||||
<use xlink:href="#spectrum-icon-18-Table" />
|
<use xlink:href="#spectrum-icon-18-Table" />
|
||||||
</svg>
|
</svg>
|
||||||
{table.name}
|
{table.name}
|
||||||
|
{#if selectedScreens.find(x => x.table === table._id)}
|
||||||
{#if selectedScreens.find(x => x.table === table.name)}
|
|
||||||
<span class="data-source-check">
|
<span class="data-source-check">
|
||||||
<Icon size="S" name="CheckmarkCircle" />
|
<Icon size="S" name="CheckmarkCircle" />
|
||||||
</span>
|
</span>
|
||||||
|
@ -116,7 +115,7 @@
|
||||||
<div
|
<div
|
||||||
class="data-source-entry"
|
class="data-source-entry"
|
||||||
class:selected={selectedScreens.find(
|
class:selected={selectedScreens.find(
|
||||||
x => x.table === datasource.entities[table_key].name
|
x => x.table === datasource.entities[table_key]._id
|
||||||
)}
|
)}
|
||||||
on:click={() =>
|
on:click={() =>
|
||||||
toggleScreenSelection(
|
toggleScreenSelection(
|
||||||
|
@ -134,8 +133,7 @@
|
||||||
<use xlink:href="#spectrum-icon-18-Table" />
|
<use xlink:href="#spectrum-icon-18-Table" />
|
||||||
</svg>
|
</svg>
|
||||||
{datasource.entities[table_key].name}
|
{datasource.entities[table_key].name}
|
||||||
|
{#if selectedScreens.find(x => x.table === datasource.entities[table_key]._id)}
|
||||||
{#if selectedScreens.find(x => x.table === datasource.entities[table_key].name)}
|
|
||||||
<span class="data-source-check">
|
<span class="data-source-check">
|
||||||
<Icon size="S" name="CheckmarkCircle" />
|
<Icon size="S" name="CheckmarkCircle" />
|
||||||
</span>
|
</span>
|
||||||
|
|
|
@ -66,7 +66,7 @@
|
||||||
|
|
||||||
// Add link in layout for list screens
|
// Add link in layout for list screens
|
||||||
if (screen.props._instanceName.endsWith("List")) {
|
if (screen.props._instanceName.endsWith("List")) {
|
||||||
await store.actions.components.links.save(
|
await store.actions.links.save(
|
||||||
screen.routing.route,
|
screen.routing.route,
|
||||||
screen.routing.route.split("/")[1]
|
screen.routing.route.split("/")[1]
|
||||||
)
|
)
|
||||||
|
@ -131,6 +131,7 @@
|
||||||
const screens = selectedTemplates.map(template => {
|
const screens = selectedTemplates.map(template => {
|
||||||
let screenTemplate = template.create()
|
let screenTemplate = template.create()
|
||||||
screenTemplate.datasource = template.datasource
|
screenTemplate.datasource = template.datasource
|
||||||
|
screenTemplate.autoTableId = template.table
|
||||||
return screenTemplate
|
return screenTemplate
|
||||||
})
|
})
|
||||||
await createScreens({ screens, screenAccessRole })
|
await createScreens({ screens, screenAccessRole })
|
||||||
|
|
Loading…
Reference in New Issue