Fix table selection defaulting to true, reset selected rows when unmounting tables, remove position absolute on row selection text

This commit is contained in:
Andrew Kingston 2022-02-24 09:15:37 +00:00
parent 04624ece07
commit defe725bcc
1 changed files with 12 additions and 6 deletions

View File

@ -3,6 +3,7 @@
import { Table } from "@budibase/bbui" import { Table } from "@budibase/bbui"
import SlotRenderer from "./SlotRenderer.svelte" import SlotRenderer from "./SlotRenderer.svelte"
import { UnsortableTypes } from "../../../constants" import { UnsortableTypes } from "../../../constants"
import { onDestroy } from "svelte"
export let dataProvider export let dataProvider
export let columns export let columns
@ -38,13 +39,13 @@
dataProvider?.id, dataProvider?.id,
ActionTypes.SetDataProviderSorting ActionTypes.SetDataProviderSorting
) )
$: { $: {
rowSelectionStore.actions.updateSelection( rowSelectionStore.actions.updateSelection(
$component.id, $component.id,
selectedRows.map(row => row._id) selectedRows.map(row => row._id)
) )
} }
const getFields = (schema, customColumns, showAutoColumns) => { const getFields = (schema, customColumns, showAutoColumns) => {
// Check for an invalid column selection // Check for an invalid column selection
let invalid = false let invalid = false
@ -125,6 +126,10 @@
const split = linkURL.split("/:") const split = linkURL.split("/:")
routeStore.actions.navigate(`${split[0]}/${id}`, linkPeek) routeStore.actions.navigate(`${split[0]}/${id}`, linkPeek)
} }
onDestroy(() => {
rowSelectionStore.actions.updateSelection($component.id, [])
})
</script> </script>
<div use:styleable={$component.styles} class={size}> <div use:styleable={$component.styles} class={size}>
@ -136,7 +141,7 @@
{quiet} {quiet}
{compact} {compact}
{customRenderers} {customRenderers}
{allowSelectRows} allowSelectRows={!!allowSelectRows}
bind:selectedRows bind:selectedRows
allowEditRows={false} allowEditRows={false}
allowEditColumns={false} allowEditColumns={false}
@ -148,8 +153,10 @@
> >
<slot /> <slot />
</Table> </Table>
{#if allowSelectRows} {#if allowSelectRows && selectedRows.length}
<div class="row-count">{selectedRows.length} record(s) selected</div> <div class="row-count">
{selectedRows.length} row{selectedRows.length === 1 ? "" : "s"} selected
</div>
{/if} {/if}
</div> </div>
@ -159,7 +166,6 @@
} }
.row-count { .row-count {
margin-top: calc(1.4 * var(--spacing-xl)); margin-top: var(--spacing-l);
position: absolute;
} }
</style> </style>