Skip to content

Commit

Permalink
confirm on deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
fiskus committed Oct 1, 2024
1 parent 3fcb400 commit 06bbd84
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions catalog/app/containers/Admin/Buckets/Tabulator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as M from '@material-ui/core'

import tabulatorTableSchema from 'schemas/tabulatorTable.yml.json'

// import { useConfirm } from 'components/Dialog'
import { useConfirm } from 'components/Dialog'
import { loadMode } from 'components/FileEditor/loader'
import * as Notifications from 'containers/Notifications'
import type * as Model from 'model'
Expand All @@ -21,7 +21,7 @@ import * as yaml from 'utils/yaml'

import * as Form from '../Form'

// import * as OnDirty from './OnDirty'
import * as OnDirty from './OnDirty'

import SET_TABULATOR_TABLE_MUTATION from './gql/TabulatorTablesSet.generated'
import RENAME_TABULATOR_TABLE_MUTATION from './gql/TabulatorTablesRename.generated'
Expand Down Expand Up @@ -459,10 +459,12 @@ interface AddTableProps {

function AddTable({ disabled, onCancel, onSubmit }: AddTableProps) {
const classes = useAddTableStyles()
const { onChange: onFormSpy } = OnDirty.use()
return (
<RF.Form onSubmit={onSubmit}>
{({ handleSubmit, error, submitError, submitFailed }) => (
<form onSubmit={handleSubmit} className={classes.root}>
<OnDirty.Spy onChange={onFormSpy} />
<RF.Field
component={Form.Field}
disabled={disabled}
Expand Down Expand Up @@ -593,9 +595,19 @@ function TabulatorRow({
const error = await onDelete(tabulatorTable)
setDeleteError(error || {})
}, [onDelete, tabulatorTable])
const { onChange: onFormSpy } = OnDirty.use()
const confirm = useConfirm({
title: `You are about to delete "${tabulatorTable.name}" table`,
submitTitle: 'Delete',
onSubmit: React.useCallback(
(confirmed) => confirmed && handleDelete(),
[handleDelete],
),
})

return (
<>
{confirm.render(<></>)}
<M.ListItem button onClick={() => setOpen((x) => !x)} disabled={disabled}>
<M.ListItemIcon>
<M.Icon>{open ? 'keyboard_arrow_up' : 'keyboard_arrow_down'}</M.Icon>
Expand All @@ -604,6 +616,7 @@ function TabulatorRow({
<RF.Form initialValues={tabulatorTable} onSubmit={onRename}>
{({ handleSubmit, error, submitError, errors, submitErrors }) => (
<form onSubmit={handleSubmit} className={classes.nameForm}>
<OnDirty.Spy onChange={onFormSpy} />
<RF.Field
component={Form.Field}
className={classes.name}
Expand Down Expand Up @@ -690,7 +703,7 @@ function TabulatorRow({
<M.MenuItem
onClick={() => {
setAnchorEl(null)
handleDelete()
confirm.open()
}}
disabled={disabled}
>
Expand All @@ -714,6 +727,7 @@ function TabulatorRow({
submitFailed,
}) => (
<form onSubmit={handleSubmit} className={classes.config}>
<OnDirty.Spy onChange={onFormSpy} />
<RF.Field
className={classes.editor}
component={YamlEditorField}
Expand Down

0 comments on commit 06bbd84

Please sign in to comment.