Improve sheet loading state
This commit is contained in:
parent
ffd3e5d008
commit
8aff208acd
|
@ -3,11 +3,11 @@
|
||||||
import { Modal, ActionButton } from "@budibase/bbui"
|
import { Modal, ActionButton } from "@budibase/bbui"
|
||||||
import CreateViewModal from "../../modals/CreateViewModal.svelte"
|
import CreateViewModal from "../../modals/CreateViewModal.svelte"
|
||||||
|
|
||||||
const { rows, columns, loaded } = getContext("sheet")
|
const { rows, columns } = getContext("sheet")
|
||||||
|
|
||||||
let modal
|
let modal
|
||||||
|
|
||||||
$: disabled = !$loaded || !$columns.length || !$rows.length
|
$: disabled = !$columns.length || !$rows.length
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<ActionButton {disabled} icon="CollectionAdd" quiet on:click={modal.show}>
|
<ActionButton {disabled} icon="CollectionAdd" quiet on:click={modal.show}>
|
||||||
|
|
|
@ -2,10 +2,10 @@
|
||||||
import ExportButton from "../ExportButton.svelte"
|
import ExportButton from "../ExportButton.svelte"
|
||||||
import { getContext } from "svelte"
|
import { getContext } from "svelte"
|
||||||
|
|
||||||
const { rows, columns, tableId, sort, selectedRows, filter, loaded } =
|
const { rows, columns, tableId, sort, selectedRows, filter } =
|
||||||
getContext("sheet")
|
getContext("sheet")
|
||||||
|
|
||||||
$: disabled = !$loaded || !$rows.length || !$columns.length
|
$: disabled = !$rows.length || !$columns.length
|
||||||
$: selectedRowArray = Object.keys($selectedRows).map(id => ({ _id: id }))
|
$: selectedRowArray = Object.keys($selectedRows).map(id => ({ _id: id }))
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
import TableFilterButton from "../TableFilterButton.svelte"
|
import TableFilterButton from "../TableFilterButton.svelte"
|
||||||
import { getContext } from "svelte"
|
import { getContext } from "svelte"
|
||||||
|
|
||||||
const { columns, config, filter, table, loaded } = getContext("sheet")
|
const { columns, config, filter, table } = getContext("sheet")
|
||||||
|
|
||||||
const onFilter = e => {
|
const onFilter = e => {
|
||||||
filter.set(e.detail || [])
|
filter.set(e.detail || [])
|
||||||
|
@ -14,7 +14,7 @@
|
||||||
schema={$table?.schema}
|
schema={$table?.schema}
|
||||||
filters={$filter}
|
filters={$filter}
|
||||||
on:change={onFilter}
|
on:change={onFilter}
|
||||||
disabled={!$loaded || !$columns.length}
|
disabled={!$columns.length}
|
||||||
tableId={$config.tableId}
|
tableId={$config.tableId}
|
||||||
/>
|
/>
|
||||||
{/key}
|
{/key}
|
||||||
|
|
|
@ -2,11 +2,7 @@
|
||||||
import ImportButton from "../ImportButton.svelte"
|
import ImportButton from "../ImportButton.svelte"
|
||||||
import { getContext } from "svelte"
|
import { getContext } from "svelte"
|
||||||
|
|
||||||
const { rows, tableId, loaded } = getContext("sheet")
|
const { rows, tableId } = getContext("sheet")
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<ImportButton
|
<ImportButton tableId={$tableId} on:importrows={rows.actions.refreshData} />
|
||||||
tableId={$tableId}
|
|
||||||
on:importrows={rows.actions.refreshData}
|
|
||||||
disabled={!$loaded}
|
|
||||||
/>
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
import ManageAccessButton from "../ManageAccessButton.svelte"
|
import ManageAccessButton from "../ManageAccessButton.svelte"
|
||||||
import { getContext } from "svelte"
|
import { getContext } from "svelte"
|
||||||
|
|
||||||
const { config, loaded } = getContext("sheet")
|
const { config } = getContext("sheet")
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<ManageAccessButton disabled={!$loaded} resourceId={$config.tableId} />
|
<ManageAccessButton resourceId={$config.tableId} />
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
import { ActionButton } from "@budibase/bbui"
|
import { ActionButton } from "@budibase/bbui"
|
||||||
import { getContext } from "svelte"
|
import { getContext } from "svelte"
|
||||||
|
|
||||||
const { config, dispatch, loaded } = getContext("sheet")
|
const { config, dispatch } = getContext("sheet")
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<ActionButton
|
<ActionButton
|
||||||
|
@ -10,7 +10,7 @@
|
||||||
quiet
|
quiet
|
||||||
size="M"
|
size="M"
|
||||||
on:click={() => dispatch("add-column")}
|
on:click={() => dispatch("add-column")}
|
||||||
disabled={!$loaded || !$config.allowAddColumns}
|
disabled={!$config.allowAddColumns}
|
||||||
>
|
>
|
||||||
Create column
|
Create column
|
||||||
</ActionButton>
|
</ActionButton>
|
||||||
|
|
|
@ -46,7 +46,7 @@
|
||||||
size="M"
|
size="M"
|
||||||
on:click={() => (open = !open)}
|
on:click={() => (open = !open)}
|
||||||
selected={open || anyHidden}
|
selected={open || anyHidden}
|
||||||
disabled={!$loaded || !$columns.length}
|
disabled={!$columns.length}
|
||||||
>
|
>
|
||||||
Hide columns
|
Hide columns
|
||||||
</ActionButton>
|
</ActionButton>
|
||||||
|
|
|
@ -41,7 +41,6 @@
|
||||||
size="M"
|
size="M"
|
||||||
on:click={() => (open = !open)}
|
on:click={() => (open = !open)}
|
||||||
selected={open}
|
selected={open}
|
||||||
disabled={!$loaded}
|
|
||||||
>
|
>
|
||||||
Row height
|
Row height
|
||||||
</ActionButton>
|
</ActionButton>
|
||||||
|
|
|
@ -67,7 +67,7 @@
|
||||||
size="M"
|
size="M"
|
||||||
on:click={() => (open = !open)}
|
on:click={() => (open = !open)}
|
||||||
selected={open || $sort.column}
|
selected={open || $sort.column}
|
||||||
disabled={!$loaded || !columnOptions.length}
|
disabled={!columnOptions.length}
|
||||||
>
|
>
|
||||||
Sort
|
Sort
|
||||||
</ActionButton>
|
</ActionButton>
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
DefaultRowHeight,
|
DefaultRowHeight,
|
||||||
} from "../lib/constants"
|
} from "../lib/constants"
|
||||||
import RowHeightButton from "../controls/RowHeightButton.svelte"
|
import RowHeightButton from "../controls/RowHeightButton.svelte"
|
||||||
|
import { fade } from "svelte/transition"
|
||||||
|
|
||||||
export let API
|
export let API
|
||||||
export let tableId
|
export let tableId
|
||||||
|
@ -62,8 +63,15 @@
|
||||||
context = attachStores(context)
|
context = attachStores(context)
|
||||||
|
|
||||||
// Reference some stores for local use
|
// Reference some stores for local use
|
||||||
const { isResizing, isReordering, ui, loaded, rowHeight, contentLines } =
|
const {
|
||||||
context
|
isResizing,
|
||||||
|
isReordering,
|
||||||
|
ui,
|
||||||
|
loaded,
|
||||||
|
loading,
|
||||||
|
rowHeight,
|
||||||
|
contentLines,
|
||||||
|
} = context
|
||||||
|
|
||||||
// Keep stores up to date
|
// Keep stores up to date
|
||||||
$: tableIdStore.set(tableId)
|
$: tableIdStore.set(tableId)
|
||||||
|
@ -124,8 +132,9 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{:else}
|
{/if}
|
||||||
<div class="sheet-loading">
|
{#if $loading}
|
||||||
|
<div in:fade|local={{ duration: 130 }} class="sheet-loading">
|
||||||
<ProgressCircle />
|
<ProgressCircle />
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
@ -222,5 +231,16 @@
|
||||||
height: 100%;
|
height: 100%;
|
||||||
display: grid;
|
display: grid;
|
||||||
place-items: center;
|
place-items: center;
|
||||||
|
z-index: 10;
|
||||||
|
}
|
||||||
|
.sheet-loading:before {
|
||||||
|
content: "";
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
background: var(--background);
|
||||||
|
opacity: 0.6;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
@ -11,6 +11,7 @@ export const createStores = () => {
|
||||||
const rows = writable([])
|
const rows = writable([])
|
||||||
const table = writable(null)
|
const table = writable(null)
|
||||||
const filter = writable([])
|
const filter = writable([])
|
||||||
|
const loading = writable(false)
|
||||||
const loaded = writable(false)
|
const loaded = writable(false)
|
||||||
const sort = writable(initialSortState)
|
const sort = writable(initialSortState)
|
||||||
const rowChangeCache = writable({})
|
const rowChangeCache = writable({})
|
||||||
|
@ -29,12 +30,23 @@ export const createStores = () => {
|
||||||
{}
|
{}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Mark loaded as true if we've ever stopped loading
|
||||||
|
let hasStartedLoading = false
|
||||||
|
loading.subscribe($loading => {
|
||||||
|
if ($loading) {
|
||||||
|
hasStartedLoading = true
|
||||||
|
} else if (hasStartedLoading) {
|
||||||
|
loaded.set(true)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
rows,
|
rows,
|
||||||
rowLookupMap,
|
rowLookupMap,
|
||||||
table,
|
table,
|
||||||
filter,
|
filter,
|
||||||
loaded,
|
loaded,
|
||||||
|
loading,
|
||||||
sort,
|
sort,
|
||||||
rowChangeCache,
|
rowChangeCache,
|
||||||
inProgressChanges,
|
inProgressChanges,
|
||||||
|
@ -47,7 +59,7 @@ export const deriveStores = context => {
|
||||||
rowLookupMap,
|
rowLookupMap,
|
||||||
table,
|
table,
|
||||||
filter,
|
filter,
|
||||||
loaded,
|
loading,
|
||||||
sort,
|
sort,
|
||||||
tableId,
|
tableId,
|
||||||
API,
|
API,
|
||||||
|
@ -86,6 +98,7 @@ export const deriveStores = context => {
|
||||||
unsubscribe?.()
|
unsubscribe?.()
|
||||||
fetch.set(null)
|
fetch.set(null)
|
||||||
instanceLoaded.set(false)
|
instanceLoaded.set(false)
|
||||||
|
loading.set(true)
|
||||||
|
|
||||||
// Reset state
|
// Reset state
|
||||||
filter.set([])
|
filter.set([])
|
||||||
|
@ -136,7 +149,7 @@ export const deriveStores = context => {
|
||||||
handleNewRows($fetch.rows, resetRows)
|
handleNewRows($fetch.rows, resetRows)
|
||||||
|
|
||||||
// Notify that we're loaded
|
// Notify that we're loaded
|
||||||
loaded.set(true)
|
loading.set(false)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue