budibase/packages/builder/src/components/backend/DataTable/DataTable.svelte

80 lines
2.2 KiB
Svelte
Raw Normal View History

2020-03-10 14:53:23 +01:00
<script>
2021-04-01 11:29:47 +02:00
import { tables, views } from "stores/backend"
import CreateRowButton from "./buttons/CreateRowButton.svelte"
import CreateColumnButton from "./buttons/CreateColumnButton.svelte"
import CreateViewButton from "./buttons/CreateViewButton.svelte"
import ExportButton from "./buttons/ExportButton.svelte"
2020-12-04 09:27:42 +01:00
import EditRolesButton from "./buttons/EditRolesButton.svelte"
2021-02-10 19:18:31 +01:00
import ManageAccessButton from "./buttons/ManageAccessButton.svelte"
2021-02-16 14:56:40 +01:00
import HideAutocolumnButton from "./buttons/HideAutocolumnButton.svelte"
2020-03-12 15:23:29 +01:00
import * as api from "./api"
import Table from "./Table.svelte"
2020-12-04 09:27:42 +01:00
import { TableNames } from "constants"
import CreateEditRow from "./modals/CreateEditRow.svelte"
2020-03-10 17:06:30 +01:00
let hideAutocolumns = true
2020-03-24 12:35:46 +01:00
let data = []
let loading = false
$: isUsersTable = $tables.selected?._id === TableNames.USERS
$: title = $tables.selected?.name
$: schema = $tables.selected?.schema
$: tableView = {
schema,
2021-03-23 12:27:10 +01:00
name: $views.selected?.name,
}
$: type = $tables.selected?.type
$: isInternal = type === "internal"
// Fetch rows for specified table
$: {
loading = true
const loadingTableId = $tables.selected?._id
api.fetchDataForTable($tables.selected?._id).then(rows => {
loading = false
// If we started a slow request then quickly change table, sometimes
// the old data overwrites the new data.
// This check ensures that we don't do that.
if (loadingTableId !== $tables.selected?._id) {
return
}
data = rows || []
})
}
2020-03-10 14:53:23 +01:00
</script>
<Table
{title}
{schema}
tableId={$tables.selected?._id}
{data}
{type}
allowEditing={true}
2021-02-16 14:56:40 +01:00
bind:hideAutocolumns
{loading}
>
{#if isInternal}
<CreateColumnButton />
{/if}
2020-11-23 13:12:03 +01:00
{#if schema && Object.keys(schema).length > 0}
{#if !isUsersTable}
<CreateRowButton
title={"Create row"}
modalContentComponent={CreateEditRow}
/>
{/if}
{#if isInternal}
<CreateViewButton />
{/if}
<ManageAccessButton resourceId={$tables.selected?._id} />
{#if isUsersTable}
<EditRolesButton />
{/if}
<HideAutocolumnButton bind:hideAutocolumns />
<!-- always have the export last -->
2021-06-17 15:45:08 +02:00
<ExportButton view={$tables.selected?._id} />
{/if}
</Table>