Skip to content

Commit

Permalink
use additional property instead of conditional rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
fiskus committed Sep 19, 2024
1 parent fd7e1bf commit fdd0a78
Showing 1 changed file with 9 additions and 19 deletions.
28 changes: 9 additions & 19 deletions catalog/app/containers/Admin/Buckets/LongQueryConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,19 +149,16 @@ interface LongQueryConfigFormProps {
onEdited?: () => void
}

interface AddFirst extends LongQueryConfigFormProps {
onClose?: never // Don't close if no other configs
tabulatorTable?: never // We create new config, so we don't have one
}

interface AddNew extends LongQueryConfigFormProps {
onClose: () => void
tabulatorTable?: never // We create new config, so we don't have one
isLast: boolean
}

interface EditExisting extends LongQueryConfigFormProps {
onClose?: never // Don't close editing config
tabulatorTable: FormValues
isLast?: never
}

function LongQueryConfigForm({
Expand All @@ -171,7 +168,8 @@ function LongQueryConfigForm({
onEdited,
onDirty,
tabulatorTable,
}: AddFirst | AddNew | EditExisting) {
isLast,
}: AddNew | EditExisting) {
const setTabulatorTable = GQL.useMutation(SET_TABULATOR_TABLE_MUTATION)
const classes = useLongQueryConfigFormStyles()

Check warning on line 174 in catalog/app/containers/Admin/Buckets/LongQueryConfig.tsx

View check run for this annotation

Codecov / codecov/patch/informational

catalog/app/containers/Admin/Buckets/LongQueryConfig.tsx#L164-L174

Added lines #L164 - L174 were not covered by tests

Expand Down Expand Up @@ -318,7 +316,7 @@ function LongQueryConfigForm({
onClick={onClose && pristine ? onClose : confirm.open}
type="button"
className={cx(classes.delete, classes.button)}
disabled={submitting || deleting === true || (!tabulatorTable && !onClose)}
disabled={submitting || deleting === true || isLast}
variant="outlined"
>
Delete
Expand Down Expand Up @@ -401,7 +399,7 @@ export default function Configs({
}: ConfigsProps) {
const classes = useConfigsStyles()
loadMode('yaml')
const [toAdd, setToAdd] = React.useState(tabulatorTables.length === 0)
const [toAdd, setToAdd] = React.useState(false)
const [dirty, setDirty] = React.useState(0)
const confirm = useConfirm({

Check warning on line 404 in catalog/app/containers/Admin/Buckets/LongQueryConfig.tsx

View check run for this annotation

Codecov / codecov/patch/informational

catalog/app/containers/Admin/Buckets/LongQueryConfig.tsx#L394-L404

Added lines #L394 - L404 were not covered by tests
title: 'You have unsaved changes. Close anyway?',
Expand Down Expand Up @@ -434,21 +432,13 @@ export default function Configs({
tabulatorTable={tabulatorTable}
/>
))}
{!!tabulatorTables.length && toAdd && (
{((!!tabulatorTables.length && toAdd) || !tabulatorTables.length) && (
<LongQueryConfigForm

Check warning on line 436 in catalog/app/containers/Admin/Buckets/LongQueryConfig.tsx

View check run for this annotation

Codecov / codecov/patch/informational

catalog/app/containers/Admin/Buckets/LongQueryConfig.tsx#L436

Added line #L436 was not covered by tests
bucketName={bucket}
className={classes.item}
key={'new-config'}
onDirty={handleDirty}
onEdited={() => setToAdd(false)}
isLast={!tabulatorTables.length}
key={tabulatorTables.length ? 'new-config' : 'first-config'}
onClose={() => setToAdd(false)}

Check warning on line 441 in catalog/app/containers/Admin/Buckets/LongQueryConfig.tsx

View check run for this annotation

Codecov / codecov/patch/informational

catalog/app/containers/Admin/Buckets/LongQueryConfig.tsx#L441

Added line #L441 was not covered by tests
/>
)}
{!tabulatorTables.length && (
<LongQueryConfigForm
bucketName={bucket}
className={classes.item}
key={'first-config'}
onDirty={handleDirty}
onEdited={() => setToAdd(false)}

Check warning on line 443 in catalog/app/containers/Admin/Buckets/LongQueryConfig.tsx

View check run for this annotation

Codecov / codecov/patch/informational

catalog/app/containers/Admin/Buckets/LongQueryConfig.tsx#L443

Added line #L443 was not covered by tests
/>
Expand Down

0 comments on commit fdd0a78

Please sign in to comment.