-
-
Notifications
You must be signed in to change notification settings - Fork 317
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use confirmation system when deleting constraints
- Loading branch information
1 parent
b340541
commit d9e25c1
Showing
6 changed files
with
43 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 0 additions & 45 deletions
45
mathesar_ui/src/sections/table-view/constraints/TableConstraint.scss
This file was deleted.
Oops, something went wrong.
131 changes: 43 additions & 88 deletions
131
mathesar_ui/src/sections/table-view/constraints/TableConstraint.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>•</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>•</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> |