Skip to content

Commit

Permalink
Use confirmation system when deleting constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
seancolsen committed Jan 21, 2022
1 parent b340541 commit d9e25c1
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 167 deletions.
1 change: 0 additions & 1 deletion mathesar_ui/src/component-library/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export { default as NumberInput } from './number-input/NumberInput.svelte';
export { default as Progress } from './progress/Progress.svelte';
export { default as Radio } from './radio/Radio.svelte';
export { default as RadioGroup } from './radio-group/RadioGroup.svelte';
export { default as Seesaw } from './seesaw/Seesaw.svelte';
export { default as Skeleton } from './skeleton/Skeleton.svelte';
export { default as Spinner } from './spinner/Spinner.svelte';
export { default as SpinnerArea } from './spinner-area/SpinnerArea.svelte';
Expand Down
15 changes: 0 additions & 15 deletions mathesar_ui/src/component-library/seesaw/Seesaw.scss

This file was deleted.

17 changes: 0 additions & 17 deletions mathesar_ui/src/component-library/seesaw/Seesaw.svelte

This file was deleted.

1 change: 0 additions & 1 deletion mathesar_ui/src/component-library/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
@import 'labeled-input/LabeledInput.scss';
@import 'progress/Progress.scss';
@import 'radio/Radio.scss';
@import 'seesaw/Seesaw.scss';
@import 'skeleton/Skeleton.scss';
@import 'text-avatar/TextAvatar.scss';
@import 'spinner-area/SpinnerArea.scss';
Expand Down

This file was deleted.

131 changes: 43 additions & 88 deletions mathesar_ui/src/sections/table-view/constraints/TableConstraint.svelte
Original file line number Diff line number Diff line change
@@ -1,103 +1,58 @@
<script lang="ts">
import { fly } from 'svelte/transition';
import type { FlyParams } from 'svelte/transition';
import { Icon, Seesaw, Button, Spinner } from '@mathesar-component-library';
import { Icon, Button } from '@mathesar-component-library';
import type { Constraint } from '@mathesar/stores/table-data/types';
import {
faTrash,
faCheck,
faArrowLeft,
faExclamationTriangle,
} from '@fortawesome/free-solid-svg-icons';
import { toast } from '@mathesar/stores/toast';
import { faTrash } from '@fortawesome/free-solid-svg-icons';
import { confirmDelete } from '@mathesar/stores/confirmation';
export let constraint: Constraint;
export let drop: () => Promise<void>;
let isConfirmingDrop = false;
let isSubmittingDrop = false;
let useTransitionOut = false;
async function handleDrop() {
isSubmittingDrop = true;
useTransitionOut = true;
try {
await drop();
} catch (error) {
toast.fromError(error);
useTransitionOut = false;
} finally {
isSubmittingDrop = false;
}
function handleDrop() {
void confirmDelete({
identifierType: 'Constraint',
identifierName: constraint.name,
body: ['Are you sure you want to proceed?'],
onProceed: drop,
});
}
$: columnSummary = constraint.columns.join(', ');
$: transitionDuration = useTransitionOut ? 200 : (0 as number);
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
$: transition = { x: 200, duration: transitionDuration } as FlyParams;
$: dropTitle = `Delete constraint '${constraint.name}'`;
</script>

<div class="table-constraint" class:is-submitting-drop={isSubmittingDrop}>
<Seesaw position={isConfirmingDrop ? 'left' : 'right'}>
<div class="view" slot="right">
<div>
<div><span class="name">{constraint.name}</span></div>
<div>
<span class="type">{constraint.type}</span>
<span>&bull;</span>
<span class="columns">{columnSummary}</span>
</div>
</div>
<div>
<Button
on:click={() => {
isConfirmingDrop = true;
}}
class="drop"
title={`Drop constraint '${constraint.name}'`}
>
<Icon data={faTrash} />
</Button>
</div>
</div>

<div class="confirm-drop" slot="left" out:fly={transition}>
<div class="warning-icon">
<Icon data={faExclamationTriangle} size="3em" />
</div>
<div>
<div>Drop constaint '<span class="name">{constraint.name}</span>'?</div>
<div class="buttons">
<Button
size="small"
on:click={() => {
isConfirmingDrop = false;
}}
class="cancel"
title="Cancel"
>
<Icon data={faArrowLeft} />
<span>Cancel</span>
</Button>
<Button
size="small"
on:click={handleDrop}
title="Confirm drop constraint"
disabled={isSubmittingDrop}
>
{#if isSubmittingDrop}
<Spinner />
{:else}
<Icon data={faCheck} />
{/if}
<span>Drop</span>
</Button>
</div>
</div>
<div class="table-constraint">
<div>
<div><span class="name">{constraint.name}</span></div>
<div>
<span class="type">{constraint.type}</span>
<span>&bull;</span>
<span class="columns">{columnSummary}</span>
</div>
</Seesaw>
</div>
<div class="drop">
<Button on:click={handleDrop} title={dropTitle}>
<Icon data={faTrash} />
</Button>
</div>
</div>

<style global lang="scss">
@import 'TableConstraint.scss';
<style>
.table-constraint {
line-height: 1.4;
padding: 10px 15px;
display: flex;
justify-content: space-between;
align-items: center;
}
.type {
text-transform: uppercase;
color: #666;
}
.drop {
color: #f47171;
}
.columns {
color: #666;
font-size: 0.9rem;
}
</style>

0 comments on commit d9e25c1

Please sign in to comment.