Fix null issues in view fetch, fix edit view popover, improve handling of nullish view params

This commit is contained in:
Andrew Kingston 2023-07-26 14:26:34 +01:00
parent 352b7ebe1c
commit 2d3da0dfcf
7 changed files with 39 additions and 27 deletions

View File

@ -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)

View File

@ -60,7 +60,7 @@
}} }}
selectedBy={$userSelectedResourceMap[name]} selectedBy={$userSelectedResourceMap[name]}
> >
<EditViewPopover view={{ name, ...table.views[name] }} /> <EditViewPopover {view} />
</NavItem> </NavItem>
{/each} {/each}
{/each} {/each}

View File

@ -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
if (view.version === 2) {
await viewsV2.save({
originalName,
...updatedView,
})
} else {
await views.save({ await views.save({
originalName, originalName,
...updatedView, ...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 {
const { tableId } = view
await views.delete(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")
} }

View File

@ -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

View File

@ -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("../")
} }

View File

@ -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()

View File

@ -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) {