Fix null issues in view fetch, fix edit view popover, improve handling of nullish view params
This commit is contained in:
parent
352b7ebe1c
commit
2d3da0dfcf
|
@ -1,5 +1,5 @@
|
|||
<script>
|
||||
import { datasources, viewsV2 } from "stores/backend"
|
||||
import { viewsV2 } from "stores/backend"
|
||||
import { Grid } from "@budibase/frontend-core"
|
||||
import { API } from "api"
|
||||
import GridCreateEditRowModal from "components/backend/DataTable/modals/grid/GridCreateEditRowModal.svelte"
|
||||
|
@ -12,7 +12,6 @@
|
|||
id,
|
||||
tableId: id?.split("_").slice(0, -1).join("_"),
|
||||
}
|
||||
$: console.log(datasource)
|
||||
|
||||
const handleGridViewUpdate = async e => {
|
||||
viewsV2.replace(id, e.detail)
|
||||
|
|
|
@ -60,7 +60,7 @@
|
|||
}}
|
||||
selectedBy={$userSelectedResourceMap[name]}
|
||||
>
|
||||
<EditViewPopover view={{ name, ...table.views[name] }} />
|
||||
<EditViewPopover {view} />
|
||||
</NavItem>
|
||||
{/each}
|
||||
{/each}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
<script>
|
||||
import { goto } from "@roxi/routify"
|
||||
import { views } from "stores/backend"
|
||||
import { views, viewsV2 } from "stores/backend"
|
||||
import { cloneDeep } from "lodash/fp"
|
||||
import ConfirmDialog from "components/common/ConfirmDialog.svelte"
|
||||
import {
|
||||
|
@ -24,25 +23,29 @@
|
|||
const updatedView = cloneDeep(view)
|
||||
updatedView.name = updatedName
|
||||
|
||||
await views.save({
|
||||
originalName,
|
||||
...updatedView,
|
||||
})
|
||||
if (view.version === 2) {
|
||||
await viewsV2.save({
|
||||
originalName,
|
||||
...updatedView,
|
||||
})
|
||||
} else {
|
||||
await views.save({
|
||||
originalName,
|
||||
...updatedView,
|
||||
})
|
||||
}
|
||||
|
||||
notifications.success("View renamed successfully")
|
||||
}
|
||||
|
||||
async function deleteView() {
|
||||
try {
|
||||
const isSelected =
|
||||
view.tableId === $views.selected.tableId &&
|
||||
view.name === $views.selected.name
|
||||
|
||||
const { tableId } = view
|
||||
await views.delete(view)
|
||||
notifications.success("View deleted")
|
||||
if (isSelected) {
|
||||
$goto(`./table/${tableId}`)
|
||||
if (view.version === 2) {
|
||||
await viewsV2.delete(view)
|
||||
} else {
|
||||
await views.delete(view)
|
||||
}
|
||||
notifications.success("View deleted")
|
||||
} catch (error) {
|
||||
notifications.error("Error deleting view")
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ export const syncURLToState = options => {
|
|||
let cachedRedirect = get(routify.redirect)
|
||||
let cachedPage = get(routify.page)
|
||||
let previousParamsHash = null
|
||||
let debug = true
|
||||
let debug = false
|
||||
const log = (...params) => debug && console.log(`[${urlParam}]`, ...params)
|
||||
|
||||
// Navigate to a certain URL
|
||||
|
|
|
@ -1,14 +1,17 @@
|
|||
<script>
|
||||
import { onMount } from "svelte"
|
||||
import { views } from "stores/backend"
|
||||
import { views, viewsV2 } from "stores/backend"
|
||||
import { redirect } from "@roxi/routify"
|
||||
|
||||
onMount(async () => {
|
||||
const { list, selected } = $views
|
||||
if (selected) {
|
||||
$redirect(`./${encodeURIComponent(selected?.name)}`)
|
||||
} else if (list?.length) {
|
||||
$redirect(`./${encodeURIComponent(list[0].name)}`)
|
||||
if ($viewsV2.selected) {
|
||||
$redirect(`./v2/${$viewsV2.selected.id}`)
|
||||
} else if ($viewsV2.list?.length) {
|
||||
$redirect(`./v2/${$viewsV2.list[0].id}`)
|
||||
} else if ($views.selected) {
|
||||
$redirect(`./${encodeURIComponent($views.selected?.name)}`)
|
||||
} else if ($views.list?.length) {
|
||||
$redirect(`./${encodeURIComponent($views.list[0].name)}`)
|
||||
} else {
|
||||
$redirect("../")
|
||||
}
|
||||
|
|
|
@ -102,6 +102,11 @@ export const deriveStores = context => {
|
|||
instanceLoaded.set(false)
|
||||
loading.set(true)
|
||||
|
||||
// Abandon if we don't have a valid datasource
|
||||
if (!$datasource?.tableId) {
|
||||
return
|
||||
}
|
||||
|
||||
// Tick to allow other reactive logic to update stores when table ID changes
|
||||
// before proceeding. This allows us to wipe filters etc if needed.
|
||||
await tick()
|
||||
|
|
|
@ -2,13 +2,15 @@ import DataFetch from "./DataFetch.js"
|
|||
|
||||
export default class ViewV2Fetch extends DataFetch {
|
||||
async getSchema(datasource, definition) {
|
||||
return definition.schema
|
||||
return definition?.schema
|
||||
}
|
||||
|
||||
async getDefinition(datasource) {
|
||||
try {
|
||||
const table = await this.API.fetchTableDefinition(datasource.tableId)
|
||||
const view = Object.values(table.views).find(v => v.id === datasource.id)
|
||||
const view = Object.values(table.views || {}).find(
|
||||
view => view.id === datasource.id
|
||||
)
|
||||
const { schema } = view
|
||||
return { schema }
|
||||
} catch (error) {
|
||||
|
|
Loading…
Reference in New Issue