PERF: Remove dynamic use of `<template>` (#340)

Context: https://github.com/discourse/discourse/pull/29942
This commit is contained in:
David Taylor 2024-11-26 19:10:23 +00:00 committed by GitHub
parent b2ce8183c1
commit e5d951c9a9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 23 additions and 35 deletions

View File

@ -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) { function componentOf(info) {
let type = layoutMap[info.type] || "generic"; let type = layoutMap[info.type] || "generic";
if (info.nullable && type === "boolean") { if (info.nullable && type === "boolean") {
type = "boolean_three"; type = "boolean_three";
} }
switch (type) { return components[type] || components.default;
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>;
}
} }
export default class ParamInputForm extends Component { export default class ParamInputForm extends Component {