1
0
Fork 0
mirror of synced 2024-09-15 08:47:37 +12:00

Add row deletion and fix sizing

This commit is contained in:
Andrew Kingston 2022-11-24 20:06:31 +00:00
parent 6471464971
commit fafb8ec938
3 changed files with 64 additions and 31 deletions

View file

@ -115,8 +115,7 @@
justify-content: flex-start; justify-content: flex-start;
align-items: stretch; align-items: stretch;
box-shadow: 0 0 8px 4px rgba(0, 0, 0, 0.15); box-shadow: 0 0 8px 4px rgba(0, 0, 0, 0.15);
border-radius: 4px; max-height: 191px;
max-height: 192px;
overflow-y: auto; overflow-y: auto;
} }
.option { .option {

View file

@ -11,7 +11,8 @@
export let sortColumn export let sortColumn
export let sortOrder export let sortOrder
const { styleable, API } = getContext("sdk") const { styleable, API, confirmationStore, notificationStore } =
getContext("sdk")
const component = getContext("component") const component = getContext("component")
const limit = 100 const limit = 100
const defaultWidth = 200 const defaultWidth = 200
@ -121,6 +122,47 @@
await fetch.refresh() await fetch.refresh()
delete changeCache[rowId] delete changeCache[rowId]
} }
const deleteRows = () => {
// Fetch full row objects to be deleted
const rows = Object.entries(selectedRows)
.map(entry => {
if (entry[1] === true) {
return $fetch.rows.find(x => x._id === entry[0])
} else {
return null
}
})
.filter(x => x != null)
// Deletion callback when confirmed
const performDeletion = async () => {
await API.deleteRows({
tableId: table.tableId,
rows,
})
await fetch.refresh()
notificationStore.actions.success(
`${selectedRowCount} row${
selectedRowCount === 1 ? "" : "s"
} deleted successfully`
)
// Refresh state
selectedCell = null
hoveredRow = null
selectedRows = {}
}
// Show confirmation
confirmationStore.actions.showConfirmation(
"Delete rows",
`Are you sure you want to delete ${selectedRowCount} row${
selectedRowCount === 1 ? "" : "s"
}?`,
performDeletion
)
}
</script> </script>
<div use:styleable={$component.styles}> <div use:styleable={$component.styles}>
@ -133,12 +175,14 @@
<ActionButton icon="VisibilityOff" size="S">Hide fields</ActionButton> <ActionButton icon="VisibilityOff" size="S">Hide fields</ActionButton>
</div> </div>
<div class="title">Sales Records</div> <div class="title">Sales Records</div>
<div class="search"> <div class="delete">
<Icon {#if selectedRowCount}
name="Search" <ActionButton icon="Delete" size="S" on:click={deleteRows}>
size="S" Delete {selectedRowCount} row{selectedRowCount === 1 ? "" : "s"}
color="var(--spectrum-global-color-gray-400" </ActionButton>
/> {:else}
{rowCount} row{rowCount === 1 ? "" : "s"}
{/if}
</div> </div>
</div> </div>
<div class="spreadsheet" on:scroll={handleScroll} style={gridStyles}> <div class="spreadsheet" on:scroll={handleScroll} style={gridStyles}>
@ -221,13 +265,6 @@
/> />
{/each} {/each}
</div> </div>
<div class="footer">
{#if selectedRowCount}
{selectedRowCount} row{selectedRowCount === 1 ? "" : "s"} selected
{:else}
{rowCount} row{rowCount === 1 ? "" : "s"}
{/if}
</div>
</div> </div>
</div> </div>
@ -247,9 +284,9 @@
justify-content: flex-start; justify-content: flex-start;
align-items: stretch; align-items: stretch;
overflow: auto; overflow: auto;
height: 800px; max-height: 800px;
position: relative; position: relative;
padding-bottom: 100px; padding-bottom: 80px;
padding-right: 100px; padding-right: 100px;
} }
@ -277,11 +314,18 @@
align-items: center; align-items: center;
gap: 4px; gap: 4px;
} }
.search { .delete {
display: flex; display: flex;
flex-direction: row; flex-direction: row;
justify-content: flex-end; justify-content: flex-end;
align-items: center; align-items: center;
color: var(--spectrum-global-color-gray-700);
}
.delete :global(.spectrum-ActionButton) {
color: var(--spectrum-global-color-red-600);
}
.delete :global(.spectrum-Icon) {
fill: var(--spectrum-global-color-red-600);
} }
.cell { .cell {
@ -360,16 +404,4 @@
input[type="checkbox"] { input[type="checkbox"] {
margin: 0; margin: 0;
} }
.footer {
height: 32px;
width: 100%;
border-top: 1px solid var(--spectrum-global-color-gray-400);
padding: 0 12px;
display: flex;
flex-direction: row;
justify-content: flex-start;
align-items: center;
background: var(--spectrum-global-color-gray-50);
}
</style> </style>

View file

@ -12,6 +12,7 @@ import {
environmentStore, environmentStore,
sidePanelStore, sidePanelStore,
dndIsDragging, dndIsDragging,
confirmationStore,
} from "stores" } from "stores"
import { styleable } from "utils/styleable" import { styleable } from "utils/styleable"
import { linkable } from "utils/linkable" import { linkable } from "utils/linkable"
@ -35,6 +36,7 @@ export default {
sidePanelStore, sidePanelStore,
dndIsDragging, dndIsDragging,
currentRole, currentRole,
confirmationStore,
styleable, styleable,
linkable, linkable,
getAction, getAction,