Skip to content

Commit

Permalink
Merge pull request #1215 from centerofci/930_set_null
Browse files Browse the repository at this point in the history
Add context menu to set cell to null
  • Loading branch information
pavish committed Mar 25, 2022
2 parents b94bfa8 + ab5b4ca commit 444d1e6
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions mathesar_ui/src/sections/table-view/row/RowCell.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<script lang="ts">
import { tick } from 'svelte';
import { faBackspace } from '@fortawesome/free-solid-svg-icons';
import { ContextMenu, MenuItem } from '@mathesar-component-library';
import {
isCellActive,
scrollBasedOnActiveCell,
Expand All @@ -12,6 +14,7 @@
RecordsData,
} from '@mathesar/stores/table-data/types';
import Cell from '@mathesar/components/cell/Cell.svelte';
import Null from '@mathesar/components/Null.svelte';
export let recordsData: RecordsData;
export let display: Display;
Expand All @@ -23,6 +26,7 @@
$: ({ activeCell } = display);
$: isActive = $activeCell && isCellActive($activeCell, row, column);
$: isLoading = !row.__state || row.__state === 'loading';
$: canSetNull = column.nullable && value !== null;
// TODO: Set individual cell states and errors in recordsData
Expand All @@ -46,8 +50,7 @@
}
}
async function valueUpdated(e: CustomEvent<{ value: unknown }>) {
const newValue = e.detail.value;
async function setValue(newValue: unknown) {
if (newValue !== value) {
value = newValue;
if (row.__isNew) {
Expand All @@ -57,6 +60,10 @@
}
}
}
async function valueUpdated(e: CustomEvent<{ value: unknown }>) {
await setValue(e.detail.value);
}
</script>

<div
Expand All @@ -77,6 +84,15 @@
on:activate={() => display.selectCell(row, column)}
on:update={valueUpdated}
/>
<ContextMenu>
<MenuItem
icon={{ data: faBackspace }}
disabled={!canSetNull}
on:click={() => setValue(null)}
>
Set to <Null />
</MenuItem>
</ContextMenu>
</div>

<style lang="scss">
Expand Down

0 comments on commit 444d1e6

Please sign in to comment.