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