Skip to content

Commit

Permalink
PERF: Remove dynamic use of <template> (#340)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaylorhq authored Nov 26, 2024
1 parent b2ce818 commit e5d951c
Showing 1 changed file with 23 additions and 35 deletions.
58 changes: 23 additions & 35 deletions assets/javascripts/discourse/components/param-input-form.gjs
Original file line number Diff line number Diff line change
Expand Up @@ -100,46 +100,34 @@ function validationOf(info) {
}
}

const components = {
int: <template>
<@field.Input @type="number" name={{@info.identifier}} />
</template>,
boolean: <template><@field.Checkbox name={{@info.identifier}} /></template>,
boolean_three: BooleanThree,
category_id: CategoryIdInput, // TODO
user_id: UserIdInput,
user_list: UserListInput,
group_list: GroupInput,
date: <template>
<@field.Input @type="date" name={{@info.identifier}} />
</template>,
time: <template>
<@field.Input @type="time" name={{@info.identifier}} />
</template>,
datetime: <template>
<@field.Input @type="datetime-local" name={{@info.identifier}} />
</template>,
default: <template><@field.Input name={{@info.identifier}} /></template>,
};

function componentOf(info) {
let type = layoutMap[info.type] || "generic";
if (info.nullable && type === "boolean") {
type = "boolean_three";
}
switch (type) {
case "int":
return <template>
<@field.Input @type="number" name={{@info.identifier}} />
</template>;
case "boolean":
return <template><@field.Checkbox name={{@info.identifier}} /></template>;
case "boolean_three":
return BooleanThree;
case "category_id":
// TODO
return CategoryIdInput;
case "user_id":
return UserIdInput;
case "user_list":
return UserListInput;
case "group_list":
return GroupInput;
case "date":
return <template>
<@field.Input @type="date" name={{@info.identifier}} />
</template>;
case "time":
return <template>
<@field.Input @type="time" name={{@info.identifier}} />
</template>;
case "datetime":
return <template>
<@field.Input @type="datetime-local" name={{@info.identifier}} />
</template>;
case "bigint":
case "string":
default:
return <template><@field.Input name={{@info.identifier}} /></template>;
}
return components[type] || components.default;
}

export default class ParamInputForm extends Component {
Expand Down

0 comments on commit e5d951c

Please sign in to comment.