Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add context menu to set cell to null #1215

Merged
merged 2 commits into from
Mar 25, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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