Skip to content

Commit

Permalink
Simplify dispatch logic
Browse files Browse the repository at this point in the history
  • Loading branch information
dokempf committed Jul 18, 2024
1 parent b6d2940 commit 0212900
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions src/components/FieldDispatch.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@
const fieldtype = findSchemaColumn(table, field).type;
const componentMapping = {
"custom:base.custom-data-type-ubhdgnd.ubhdgnd": CustomDataTypeUbhdgnd,
"date": Date,
"daterange": Daterange,
"eas": Eas,
"text": TextField,
"string": TextField,
"text_l10n": L10nTextField,
"text_l10n_oneline": OnelineL10nTextField,
"text_oneline": OnelineTextField,
};
</script>

<!-- Some fields are omitted from the detail view -->
Expand All @@ -36,23 +47,8 @@
<FieldLabel table={table} field={field}/>
</P>
{/if}
<!-- Dispath based on the detected field type -->
{#if fieldtype === "custom:base.custom-data-type-ubhdgnd.ubhdgnd"}
<CustomDataTypeUbhdgnd data={data} field={field} table={table}/>
{:else if fieldtype === "date" }
<Date data={data} field={field} table={table}/>
{:else if fieldtype === "daterange" }
<Daterange data={data} field={field} table={table}/>
{:else if fieldtype === "eas" }
<Eas data={data} field={field} table={table} />
{:else if fieldtype === "text" || fieldtype === "string" }
<TextField data={data} field={field} table={table}/>
{:else if fieldtype === "text_l10n" }
<L10nTextField data={data} field={field} table={table}/>
{:else if fieldtype === "text_l10n_oneline" }
<OnelineL10nTextField data={data} field={field} table={table}/>
{:else if fieldtype === "text_oneline" }
<OnelineTextField data={data} field={field} table={table}/>
{#if fieldtype in componentMapping}
<svelte:component this={componentMapping[fieldtype]} data={data} field={field} table={table}/>
{:else}
<NotImplemented message="Field Type {fieldtype} not yet implemented." />
{/if}
Expand Down

0 comments on commit 0212900

Please sign in to comment.