2020-03-10 14:53:23 +01:00
|
|
|
<script>
|
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"
|
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"
|
|
|
|
import { Pagination } from "@budibase/bbui"
|
2020-03-10 17:06:30 +01:00
|
|
|
|
2021-02-16 19:29:38 +01:00
|
|
|
let hideAutocolumns = true
|
2021-09-23 17:08:47 +02:00
|
|
|
const data = fetchTableData()
|
|
|
|
|
2021-03-23 12:16:54 +01:00
|
|
|
$: isUsersTable = $tables.selected?._id === TableNames.USERS
|
2021-06-21 14:04:41 +02:00
|
|
|
$: title = $tables.selected?.name
|
|
|
|
$: 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"
|
2020-10-01 08:19:38 +02:00
|
|
|
|
2021-09-23 17:08:47 +02:00
|
|
|
// Fetch data whenever table changes
|
|
|
|
$: data.update({
|
|
|
|
tableId: $tables.selected?._id,
|
|
|
|
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 => {
|
|
|
|
data.update({
|
|
|
|
sortColumn: e.detail.column,
|
|
|
|
sortOrder: e.detail.order,
|
2021-06-15 14:32:11 +02:00
|
|
|
})
|
2020-03-16 19:54:48 +01:00
|
|
|
}
|
2020-03-10 14:53:23 +01:00
|
|
|
</script>
|
|
|
|
|
2021-09-23 17:08:47 +02:00
|
|
|
<div>
|
|
|
|
<Table
|
|
|
|
{title}
|
|
|
|
{schema}
|
|
|
|
{type}
|
|
|
|
tableId={$tables.selected?._id}
|
|
|
|
data={$data.rows}
|
|
|
|
bind:hideAutocolumns
|
|
|
|
loading={$data.loading}
|
|
|
|
on:sort={onSort}
|
|
|
|
allowEditing
|
|
|
|
disableSorting
|
|
|
|
>
|
2021-06-17 00:27:38 +02:00
|
|
|
{#if isInternal}
|
2021-09-23 17:08:47 +02:00
|
|
|
<CreateColumnButton />
|
2021-06-17 00:27:38 +02:00
|
|
|
{/if}
|
2021-09-23 17:08:47 +02: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 -->
|
|
|
|
<ExportButton view={$tables.selected?._id} />
|
2021-02-16 16:41:50 +01:00
|
|
|
{/if}
|
2021-09-23 17:08:47 +02:00
|
|
|
</Table>
|
|
|
|
<div class="pagination">
|
|
|
|
<Pagination
|
|
|
|
page={$data.pageNumber + 1}
|
|
|
|
hasPrevPage={$data.hasPrevPage}
|
|
|
|
hasNextPage={$data.hasNextPage}
|
|
|
|
goToPrevPage={$data.loading ? null : data.prevPage}
|
|
|
|
goToNextPage={$data.loading ? null : data.nextPage}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
.pagination {
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
justify-content: flex-end;
|
|
|
|
align-items: center;
|
|
|
|
margin-top: var(--spacing-xl);
|
|
|
|
}
|
|
|
|
</style>
|