Skip to content

Commit

Permalink
- back to ternary operator
Browse files Browse the repository at this point in the history
  • Loading branch information
jashanbhullar committed Aug 31, 2023
1 parent 34fdad6 commit 5e8ecec
Showing 1 changed file with 33 additions and 38 deletions.
71 changes: 33 additions & 38 deletions web/src/beta/components/fields/PropertyFields/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,44 +20,39 @@ const PropertyFields: React.FC<Props> = ({ propertyId, item }) => {
const isList = item && "items" in item;
const value = !isList ? item.fields.find(f => f.id === sf.id)?.value : sf.defaultValue;

switch (sf.type) {
case "string":
// TODO: Can also be turned into a switch and infact bunch of props are common
return sf.ui === "color" ? (
<ColorField
key={sf.id}
name={sf.name}
value={(value as string) ?? ""}
description={sf.description}
onChange={handlePropertyValueUpdate(item.schemaGroup, propertyId, sf.id, sf.type)}
/>
) : sf.ui === "selection" || sf.choices ? (
<p key={sf.id}>Selection or choices field</p>
) : sf.ui === "buttons" ? (
<p key={sf.id}>Button radio field</p>
) : (
<TextInput
key={sf.id}
name={sf.name}
value={(value as string) ?? ""}
description={sf.description}
onChange={handlePropertyValueUpdate(item.schemaGroup, propertyId, sf.id, sf.type)}
/>
);
case "bool":
return (
<ToggleField
key={sf.id}
name={sf.name}
checked={value as boolean}
description={sf.description}
onChange={handlePropertyValueUpdate(item.schemaGroup, propertyId, sf.id, sf.type)}
/>
);

default:
return <p key={sf.id}>{sf.name} field</p>;
}
return sf.type === "string" ? (
sf.ui === "color" ? (
<ColorField
key={sf.id}
name={sf.name}
value={(value as string) ?? ""}
description={sf.description}
onChange={handlePropertyValueUpdate(item.schemaGroup, propertyId, sf.id, sf.type)}
/>
) : sf.ui === "selection" || sf.choices ? (
<p key={sf.id}>Selection or choices field</p>
) : sf.ui === "buttons" ? (
<p key={sf.id}>Button radio field</p>
) : (
<TextInput
key={sf.id}
name={sf.name}
value={(value as string) ?? ""}
description={sf.description}
onChange={handlePropertyValueUpdate(item.schemaGroup, propertyId, sf.id, sf.type)}
/>
)
) : sf.type == "bool" ? (
<ToggleField
key={sf.id}
name={sf.name}
checked={value as boolean}
description={sf.description}
onChange={handlePropertyValueUpdate(item.schemaGroup, propertyId, sf.id, sf.type)}
/>
) : (
<p key={sf.id}>{sf.name} field</p>
);
})}
</>
);
Expand Down

0 comments on commit 5e8ecec

Please sign in to comment.