Add view CRUD and table editing via new UI

This commit is contained in:
Andrew Kingston 2024-08-15 16:33:39 +01:00
parent fa80d99139
commit d313968eaa
No known key found for this signature in database
6 changed files with 66 additions and 46 deletions

View File

@ -9,7 +9,6 @@
import GridAddColumnModal from "components/backend/DataTable/modals/grid/GridCreateColumnModal.svelte"
import GridCreateEditRowModal from "components/backend/DataTable/modals/grid/GridCreateEditRowModal.svelte"
import GridEditUserModal from "components/backend/DataTable/modals/grid/GridEditUserModal.svelte"
import GridCreateViewButton from "components/backend/DataTable/buttons/grid/GridCreateViewButton.svelte"
import GridImportButton from "components/backend/DataTable/buttons/grid/GridImportButton.svelte"
import GridExportButton from "components/backend/DataTable/buttons/grid/GridExportButton.svelte"
import GridFilterButton from "components/backend/DataTable/buttons/grid/GridFilterButton.svelte"
@ -77,9 +76,6 @@
<GridFilterButton />
</svelte:fragment>
<svelte:fragment slot="controls">
{#if !isUsersTable}
<GridCreateViewButton />
{/if}
<GridManageAccessButton />
{#if !isUsersTable}
<GridCreateAutomationButton />

View File

@ -39,9 +39,7 @@
const selectTable = tableId => {
tables.select(tableId)
if (!$isActive("./table/:tableId")) {
$goto(`./table/${tableId}`)
}
$goto(`./table/${tableId}`)
}
function openNode(datasource) {

View File

@ -1,14 +1,11 @@
<script>
import TableNavItem from "./TableNavItem/TableNavItem.svelte"
import { alphabetical } from "./utils"
export let tables
export let selectTable
$: sortedTables = tables.sort(alphabetical)
const alphabetical = (a, b) => {
return a.name?.toLowerCase() > b.name?.toLowerCase() ? 1 : -1
}
</script>
<div class="hierarchy-items-container">

View File

@ -66,3 +66,7 @@ export const parseFile = e => {
reader.readAsText(file)
})
}
export const alphabetical = (a, b) => {
return a.name?.toLowerCase() > b.name?.toLowerCase() ? 1 : -1
}

View File

@ -1,16 +1,21 @@
<script>
import { getContext } from "svelte"
import { Input, notifications, ModalContent } from "@budibase/bbui"
import { Modal, Input, notifications, ModalContent } from "@budibase/bbui"
import { goto } from "@roxi/routify"
import { viewsV2 } from "stores/builder"
const { filter, sort, definition } = getContext("grid")
export let table
let name
let modal
$: views = Object.keys($definition?.views || {}).map(x => x.toLowerCase())
$: views = Object.keys(table?.views || {}).map(x => x.toLowerCase())
$: nameExists = views.includes(name?.trim().toLowerCase())
export const show = () => {
name = null
modal?.show()
}
const enrichSchema = schema => {
// We need to sure that "visible" is set to true for any fields which have
// not yet been saved with grid metadata attached
@ -28,33 +33,30 @@
try {
const newView = await viewsV2.create({
name,
tableId: $definition._id,
query: $filter,
sort: {
field: $sort.column,
order: $sort.order,
},
schema: enrichSchema($definition.schema),
primaryDisplay: $definition.primaryDisplay,
tableId: table._id,
schema: enrichSchema(table.schema),
primaryDisplay: table.primaryDisplay,
})
notifications.success(`View ${name} created`)
$goto(`../../view/v2/${newView.id}`)
$goto(`./${newView.id}`)
} catch (error) {
notifications.error("Error creating view")
}
}
</script>
<ModalContent
title="Create view"
confirmText="Create view"
onConfirm={saveView}
disabled={nameExists}
>
<Input
label="View name"
thin
bind:value={name}
error={nameExists ? "A view already exists with that name" : null}
/>
</ModalContent>
<Modal bind:this={modal}>
<ModalContent
title="Create view"
confirmText="Create view"
onConfirm={saveView}
disabled={nameExists}
>
<Input
label="View name"
thin
bind:value={name}
error={nameExists ? "A view already exists with that name" : null}
/>
</ModalContent>
</Modal>

View File

@ -6,7 +6,7 @@
contextMenuStore,
} from "stores/builder"
import IntegrationIcon from "components/backend/DatasourceNavigator/IntegrationIcon.svelte"
import { Icon } from "@budibase/bbui"
import { Icon, Button } from "@budibase/bbui"
import { params, url } from "@roxi/routify"
import EditViewModal from "./EditViewModal.svelte"
import DeleteViewModal from "./DeleteViewModal.svelte"
@ -16,8 +16,11 @@
import { tick } from "svelte"
import { DB_TYPE_EXTERNAL } from "constants/backend"
import { TableNames } from "constants"
import { alphabetical } from "components/backend/TableNavigator/utils"
import CreateViewModal from "./CreateViewModal.svelte"
// Editing table
let createViewModal
let editTableModal
let deleteTableModal
@ -101,10 +104,6 @@
}
)
}
const alphabetical = (a, b) => {
return a.name < b.name ? -1 : 1
}
</script>
<div class="view-nav-bar">
@ -126,7 +125,13 @@
<UserAvatars size="XS" users={tableSelectedBy} />
{/if}
{#if tableEditable}
<Icon on:click={openTableContextMenu} s hoverable name="MoreSmallList" />
<Icon
on:click={openTableContextMenu}
hoverable
name="MoreSmallList"
color="var(--spectrum-global-color-gray-600)"
hoverColor="var(--spectrum-global-color-gray-900)"
/>
{/if}
</a>
{#each views as view (view.id)}
@ -145,15 +150,33 @@
{/if}
<Icon
on:click={e => openViewContextMenu(e, view)}
s
hoverable
name="MoreSmallList"
color="var(--spectrum-global-color-gray-600)"
hoverColor="var(--spectrum-global-color-gray-900)"
/>
</a>
{/each}
{#if !views.length && tableEditable}
<Button cta on:click={createViewModal?.show}>Create a view</Button>
<span>
To create subsets of data, control access and more, create a view.
</span>
{/if}
{#if views.length}
<Icon
name="Add"
size="L"
hoverable
color="var(--spectrum-global-color-gray-600)"
hoverColor="var(--spectrum-global-color-gray-900)"
on:click={createViewModal?.show}
/>
{/if}
</div>
{#if table}
{#if table && tableEditable}
<CreateViewModal {table} bind:this={createViewModal} />
<EditTableModal {table} bind:this={editTableModal} />
<DeleteTableModal {table} bind:this={deleteTableModal} />
{/if}
@ -183,7 +206,7 @@
align-items: center;
gap: var(--spacing-m);
transition: background 130ms ease-out, color 130ms ease-out;
color: var(--spectrum-global-color-gray-700);
color: var(--spectrum-global-color-gray-600);
}
.title {
font-size: 16px;