Add dedicated route for routes v1, improve view creation modal, fix selection state
This commit is contained in:
parent
150961fcf2
commit
352b7ebe1c
|
@ -1,22 +1,19 @@
|
||||||
<script>
|
<script>
|
||||||
import { Input, notifications, ModalContent } from "@budibase/bbui"
|
import { Input, notifications, ModalContent } from "@budibase/bbui"
|
||||||
import { goto } from "@roxi/routify"
|
import { goto } from "@roxi/routify"
|
||||||
import { views as viewsStore } from "stores/backend"
|
import { viewsV2 } from "stores/backend"
|
||||||
import { tables } from "stores/backend"
|
import { tables } from "stores/backend"
|
||||||
|
|
||||||
let name
|
let name
|
||||||
let field
|
let field
|
||||||
|
|
||||||
$: views = $tables.list.flatMap(table => Object.keys(table.views || {}))
|
$: views = Object.keys($tables.selected?.views || {})
|
||||||
|
$: nameExists = views.includes(name?.trim())
|
||||||
|
|
||||||
const saveView = async () => {
|
const saveView = async () => {
|
||||||
name = name?.trim()
|
name = name?.trim()
|
||||||
if (views.includes(name)) {
|
|
||||||
notifications.error(`View exists with name ${name}`)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
const newView = await viewsStore.create({
|
const newView = await viewsV2.create({
|
||||||
name,
|
name,
|
||||||
tableId: $tables.selected._id,
|
tableId: $tables.selected._id,
|
||||||
field,
|
field,
|
||||||
|
@ -33,6 +30,12 @@
|
||||||
title="Create View"
|
title="Create View"
|
||||||
confirmText="Create View"
|
confirmText="Create View"
|
||||||
onConfirm={saveView}
|
onConfirm={saveView}
|
||||||
|
disabled={nameExists}
|
||||||
>
|
>
|
||||||
<Input label="View Name" thin bind:value={name} />
|
<Input
|
||||||
|
label="View Name"
|
||||||
|
thin
|
||||||
|
bind:value={name}
|
||||||
|
error={nameExists ? "A view already exists with that name" : null}
|
||||||
|
/>
|
||||||
</ModalContent>
|
</ModalContent>
|
||||||
|
|
|
@ -7,9 +7,6 @@
|
||||||
import { goto, isActive } from "@roxi/routify"
|
import { goto, isActive } from "@roxi/routify"
|
||||||
import { userSelectedResourceMap } from "builderStore"
|
import { userSelectedResourceMap } from "builderStore"
|
||||||
|
|
||||||
const alphabetical = (a, b) =>
|
|
||||||
a.name?.toLowerCase() > b.name?.toLowerCase() ? 1 : -1
|
|
||||||
|
|
||||||
export let sourceId
|
export let sourceId
|
||||||
export let selectTable
|
export let selectTable
|
||||||
|
|
||||||
|
@ -18,6 +15,17 @@
|
||||||
table => table.sourceId === sourceId && table._id !== TableNames.USERS
|
table => table.sourceId === sourceId && table._id !== TableNames.USERS
|
||||||
)
|
)
|
||||||
.sort(alphabetical)
|
.sort(alphabetical)
|
||||||
|
|
||||||
|
const alphabetical = (a, b) => {
|
||||||
|
return a.name?.toLowerCase() > b.name?.toLowerCase() ? 1 : -1
|
||||||
|
}
|
||||||
|
|
||||||
|
const isViewActive = (view, isActive, views, viewsV2) => {
|
||||||
|
return (
|
||||||
|
(isActive("./view/v1") && views.selected?.name === view.name) ||
|
||||||
|
(isActive("./view/v2") && viewsV2.selected?.id === view.id)
|
||||||
|
)
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if $database?._id}
|
{#if $database?._id}
|
||||||
|
@ -37,28 +45,22 @@
|
||||||
<EditTablePopover {table} />
|
<EditTablePopover {table} />
|
||||||
{/if}
|
{/if}
|
||||||
</NavItem>
|
</NavItem>
|
||||||
{#each [...Object.entries(table.views || {})].sort() as [viewName, view], idx (idx)}
|
{#each [...Object.entries(table.views || {})].sort() as [name, view], idx (idx)}
|
||||||
{@const viewSelected =
|
|
||||||
$isActive("./view") && $views.selected?.name === viewName}
|
|
||||||
{@const viewV2Selected =
|
|
||||||
$isActive("./view/v2") && $viewsV2.selected?.name === viewName}
|
|
||||||
<NavItem
|
<NavItem
|
||||||
indentLevel={2}
|
indentLevel={2}
|
||||||
icon="Remove"
|
icon="Remove"
|
||||||
text={viewName}
|
text={name}
|
||||||
selected={viewSelected || viewV2Selected}
|
selected={isViewActive(view, $isActive, $views, $viewsV2)}
|
||||||
on:click={() => {
|
on:click={() => {
|
||||||
if (view.version === 2) {
|
if (view.version === 2) {
|
||||||
$goto(`./view/v2/${view.id}`)
|
$goto(`./view/v2/${view.id}`)
|
||||||
} else {
|
} else {
|
||||||
$goto(`./view/${encodeURIComponent(viewName)}`)
|
$goto(`./view/v1/${encodeURIComponent(name)}`)
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
selectedBy={$userSelectedResourceMap[viewName]}
|
selectedBy={$userSelectedResourceMap[name]}
|
||||||
>
|
>
|
||||||
<EditViewPopover
|
<EditViewPopover view={{ name, ...table.views[name] }} />
|
||||||
view={{ name: viewName, ...table.views[viewName] }}
|
|
||||||
/>
|
|
||||||
</NavItem>
|
</NavItem>
|
||||||
{/each}
|
{/each}
|
||||||
{/each}
|
{/each}
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
stateKey: "selectedViewName",
|
stateKey: "selectedViewName",
|
||||||
validate: name => $views.list?.some(view => view.name === name),
|
validate: name => $views.list?.some(view => view.name === name),
|
||||||
update: views.select,
|
update: views.select,
|
||||||
fallbackUrl: "../",
|
fallbackUrl: "../../",
|
||||||
store: views,
|
store: views,
|
||||||
routify,
|
routify,
|
||||||
decode: decodeURIComponent,
|
decode: decodeURIComponent,
|
|
@ -0,0 +1,5 @@
|
||||||
|
<script>
|
||||||
|
import { redirect } from "@roxi/routify"
|
||||||
|
|
||||||
|
$redirect("../")
|
||||||
|
</script>
|
|
@ -9,7 +9,7 @@
|
||||||
$: store.actions.websocket.selectResource(id)
|
$: store.actions.websocket.selectResource(id)
|
||||||
|
|
||||||
const stopSyncing = syncURLToState({
|
const stopSyncing = syncURLToState({
|
||||||
urlParam: "id",
|
urlParam: "viewId",
|
||||||
stateKey: "selectedViewId",
|
stateKey: "selectedViewId",
|
||||||
validate: id => $viewsV2.list?.some(view => view.id === id),
|
validate: id => $viewsV2.list?.some(view => view.id === id),
|
||||||
update: viewsV2.select,
|
update: viewsV2.select,
|
|
@ -0,0 +1,5 @@
|
||||||
|
<script>
|
||||||
|
import { redirect } from "@roxi/routify"
|
||||||
|
|
||||||
|
$redirect("../")
|
||||||
|
</script>
|
|
@ -111,7 +111,7 @@ export const deriveStores = context => {
|
||||||
// Create new fetch model
|
// Create new fetch model
|
||||||
const newFetch = fetchData({
|
const newFetch = fetchData({
|
||||||
API,
|
API,
|
||||||
datasource,
|
datasource: $datasource,
|
||||||
options: {
|
options: {
|
||||||
filter: $filter,
|
filter: $filter,
|
||||||
sortColumn: $sort.column,
|
sortColumn: $sort.column,
|
||||||
|
|
Loading…
Reference in New Issue