2020-03-10 14:53:23 +01:00
|
|
|
<script>
|
2021-09-29 11:33:55 +02:00
|
|
|
import { fade } from "svelte/transition"
|
2021-09-23 17:08:47 +02:00
|
|
|
import { tables } from "stores/backend"
|
2020-10-02 13:00:17 +02:00
|
|
|
import CreateRowButton from "./buttons/CreateRowButton.svelte"
|
|
|
|
import CreateColumnButton from "./buttons/CreateColumnButton.svelte"
|
|
|
|
import CreateViewButton from "./buttons/CreateViewButton.svelte"
|
2020-10-03 22:06:58 +02:00
|
|
|
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"
|
2021-09-29 10:05:04 +02:00
|
|
|
import TableFilterButton from "./buttons/TableFilterButton.svelte"
|
2020-10-01 08:19:38 +02:00
|
|
|
import Table from "./Table.svelte"
|
2020-12-04 09:27:42 +01:00
|
|
|
import { TableNames } from "constants"
|
2020-12-07 20:05:39 +01:00
|
|
|
import CreateEditRow from "./modals/CreateEditRow.svelte"
|
2021-09-23 17:08:47 +02:00
|
|
|
import { fetchTableData } from "helpers/fetchTableData"
|
2021-09-29 10:05:04 +02:00
|
|
|
import { Pagination } from "@budibase/bbui"
|
2020-03-10 17:06:30 +01:00
|
|
|
|
2021-09-23 18:04:12 +02:00
|
|
|
let hideAutocolumns = true
|
2021-09-23 17:08:47 +02:00
|
|
|
|
2021-03-23 12:16:54 +01:00
|
|
|
$: isUsersTable = $tables.selected?._id === TableNames.USERS
|
2021-06-21 14:04:41 +02:00
|
|
|
$: schema = $tables.selected?.schema
|
2021-06-21 14:41:58 +02:00
|
|
|
$: type = $tables.selected?.type
|
2021-07-07 18:21:56 +02:00
|
|
|
$: isInternal = type !== "external"
|
2021-09-24 17:13:25 +02:00
|
|
|
$: id = $tables.selected?._id
|
2021-09-29 11:17:12 +02:00
|
|
|
$: search = searchTable(id)
|
2021-09-28 16:29:15 +02:00
|
|
|
$: columnOptions = Object.keys($search.schema || {})
|
2020-10-01 08:19:38 +02:00
|
|
|
|
2021-09-28 16:29:15 +02:00
|
|
|
// Fetches new data whenever the table changes
|
2021-09-29 11:17:12 +02:00
|
|
|
const searchTable = tableId => {
|
|
|
|
return fetchTableData({
|
2021-09-23 18:04:12 +02:00
|
|
|
tableId,
|
|
|
|
schema,
|
|
|
|
limit: 10,
|
|
|
|
paginate: true,
|
|
|
|
})
|
|
|
|
}
|
2021-04-13 16:10:49 +02:00
|
|
|
|
2021-09-23 17:08:47 +02:00
|
|
|
// Fetch data whenever sorting option changes
|
|
|
|
const onSort = e => {
|
2021-09-27 16:36:18 +02:00
|
|
|
search.update({
|
2021-09-23 17:08:47 +02:00
|
|
|
sortColumn: e.detail.column,
|
|
|
|
sortOrder: e.detail.order,
|
2021-06-15 14:32:11 +02:00
|
|
|
})
|
2020-03-16 19:54:48 +01:00
|
|
|
}
|
2021-09-29 11:17:12 +02:00
|
|
|
|
|
|
|
// Fetch data whenever filters change
|
|
|
|
const onFilter = e => {
|
|
|
|
search.update({
|
|
|
|
filters: e.detail,
|
|
|
|
})
|
|
|
|
}
|
2021-09-29 13:07:35 +02:00
|
|
|
|
2021-09-29 13:29:26 +02:00
|
|
|
// Fetch data whenever schema changes
|
2021-09-29 13:07:35 +02:00
|
|
|
const onUpdateColumns = () => {
|
|
|
|
search.update({
|
|
|
|
schema,
|
|
|
|
})
|
|
|
|
}
|
2020-03-10 14:53:23 +01:00
|
|
|
</script>
|
|
|
|
|
2021-09-23 17:08:47 +02:00
|
|
|
<div>
|
|
|
|
<Table
|
2021-09-29 11:17:12 +02:00
|
|
|
title={$tables.selected?.name}
|
2021-09-23 17:08:47 +02:00
|
|
|
{schema}
|
|
|
|
{type}
|
2021-09-29 11:17:12 +02:00
|
|
|
tableId={id}
|
2021-09-27 16:36:18 +02:00
|
|
|
data={$search.rows}
|
2021-09-23 17:08:47 +02:00
|
|
|
bind:hideAutocolumns
|
2021-09-27 16:36:18 +02:00
|
|
|
loading={$search.loading}
|
2021-09-23 17:08:47 +02:00
|
|
|
on:sort={onSort}
|
|
|
|
allowEditing
|
|
|
|
disableSorting
|
2021-09-29 13:07:35 +02:00
|
|
|
on:updatecolumns={onUpdateColumns}
|
|
|
|
on:updaterows={search.refresh}
|
2021-09-23 17:08:47 +02:00
|
|
|
>
|
2021-09-29 10:05:04 +02:00
|
|
|
{#if isInternal}
|
2021-09-29 13:07:35 +02:00
|
|
|
<CreateColumnButton on:updatecolumns={onUpdateColumns} />
|
2021-09-29 10:05:04 +02:00
|
|
|
{/if}
|
|
|
|
{#if schema && Object.keys(schema).length > 0}
|
|
|
|
{#if !isUsersTable}
|
|
|
|
<CreateRowButton
|
2021-09-29 13:29:26 +02:00
|
|
|
on:updaterows={search.refresh}
|
2021-09-29 10:05:04 +02:00
|
|
|
title={"Create row"}
|
|
|
|
modalContentComponent={CreateEditRow}
|
2021-09-23 17:08:47 +02:00
|
|
|
/>
|
2021-09-29 10:05:04 +02:00
|
|
|
{/if}
|
|
|
|
{#if isInternal}
|
|
|
|
<CreateViewButton />
|
|
|
|
{/if}
|
|
|
|
<ManageAccessButton resourceId={$tables.selected?._id} />
|
|
|
|
{#if isUsersTable}
|
|
|
|
<EditRolesButton />
|
|
|
|
{/if}
|
|
|
|
<HideAutocolumnButton bind:hideAutocolumns />
|
|
|
|
<!-- always have the export last -->
|
|
|
|
<ExportButton view={$tables.selected?._id} />
|
2021-09-29 11:17:12 +02:00
|
|
|
{#key id}
|
|
|
|
<TableFilterButton {schema} on:change={onFilter} />
|
|
|
|
{/key}
|
2021-09-29 10:05:04 +02:00
|
|
|
{/if}
|
2021-09-23 17:08:47 +02:00
|
|
|
</Table>
|
2021-09-29 11:33:55 +02:00
|
|
|
{#key id}
|
|
|
|
<div in:fade={{ delay: 200, duration: 100 }}>
|
|
|
|
<div class="pagination">
|
|
|
|
<Pagination
|
|
|
|
page={$search.pageNumber + 1}
|
|
|
|
hasPrevPage={$search.hasPrevPage}
|
|
|
|
hasNextPage={$search.hasNextPage}
|
|
|
|
goToPrevPage={$search.loading ? null : search.prevPage}
|
|
|
|
goToNextPage={$search.loading ? null : search.nextPage}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{/key}
|
2021-09-23 17:08:47 +02:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
.pagination {
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
justify-content: flex-end;
|
|
|
|
align-items: center;
|
|
|
|
margin-top: var(--spacing-xl);
|
|
|
|
}
|
|
|
|
</style>
|