Skip to content

Commit

Permalink
refactor(FieldFormatters): do a self code review
Browse files Browse the repository at this point in the history
  • Loading branch information
maxpatiiuk committed Jul 7, 2024
1 parent d295b0a commit bfdd53f
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,8 @@ export function FieldFormatterParts({
<>
{parts.length === 0 ? undefined : (
<table
/*
* REFACTOR: replace min-w-[35rem] with a container query that replaces
* table layout with list layout
*/
className={`
grid-table min-w-[35rem]
grid-table
grid-cols-[auto_4rem_auto_auto_min-content]
gap-2 [&_td]:!items-stretch
`}
Expand Down Expand Up @@ -68,7 +64,7 @@ export function FieldFormatterParts({
</tbody>
</table>
)}
{isReadOnly ? null : (
{isReadOnly ? undefined : (
<div className="flex gap-2 pt-2">
<Button.Secondary
onClick={(): void =>
Expand Down Expand Up @@ -236,7 +232,7 @@ function Part({
) : undefined}
</td>
<td>
{isReadOnly ? null : (
{isReadOnly ? undefined : (
<Button.Small
aria-label={commonText.remove()}
title={commonText.remove()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,20 @@ export const fieldFormattersRoutes = toReactRoutes([
),
children: [
{
index: true,
element: async () =>
import('./List').then(
({ FieldFormattersList }) => FieldFormattersList
),
},
{
path: ':index',
element: async () =>
import('./Element').then(
({ FieldFormatterWrapper }) => FieldFormatterWrapper
),
children: [
{ index: true },
{
path: ':index',
element: async () =>
import('./Element').then(
({ FieldFormatterWrapper }) => FieldFormatterWrapper
),
},
],
},
],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ export function resolveFieldFormatter(
);
return new UiFormatter(
formatter.isSystem,
formatter.title ?? formatter.name,
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
formatter.title || formatter.name,
parts,
formatter.table
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const fieldFormattersSpec = f.store(() =>
/**
* Specify 6 hardcoded special autonumbering behavior for a few tables.
* Accession table has special auto numbering, and collection object has
* two. Trying our best here to match the intended semantics for backwards
* two. Doing a best effort match of intended semantics for backwards
* compatibility.
*/
function inferLegacyAutoNumber(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ function ConditionalFormatter({
</Label.Block>
</div>
)}
{expandedNoCondition || isReadOnly ? null : fields.length === 0 ? (
{expandedNoCondition || isReadOnly ? undefined : fields.length === 0 ? (
<div className="flex flex-col p-2">
<span className="flex-1" />
<Button.Small
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export function XmlEditorShell<
<Dialog
buttons={
<>
{isReadOnly ? null : (
{isReadOnly ? undefined : (
<Button.Danger
onClick={(): void => {
setItems(removeItem(items, index));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export function Fields({
</tbody>
</table>
)}
{isReadOnly ? null : (
{isReadOnly ? undefined : (
<div className="flex gap-2 pt-2">
<Button.Secondary
onClick={(): void =>
Expand Down Expand Up @@ -191,7 +191,7 @@ function Field({
</td>
)}
<td>
{isReadOnly ? null : (
{isReadOnly ? undefined : (
<>
<Button.Small
aria-label={commonText.remove()}
Expand Down

0 comments on commit bfdd53f

Please sign in to comment.