Skip to content

feat: create dynamic parameter component #17351

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Apr 16, 2025
Prev Previous commit
Next Next commit
fix: remove filters
  • Loading branch information
jaaydenh committed Apr 11, 2025
commit dd5147d1478fc8d7654a7afda5bd65c27ce94500
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,6 @@ const ParameterField: FC<ParameterFieldProps> = ({
</SelectTrigger>
<SelectContent>
{parameter.options
.filter(
(option): option is NonNullable<typeof option> =>
option !== null,
)
.map((option) => (
<SelectItem key={option.value.value} value={option.value.value}>
<OptionDisplay option={option} />
Expand All @@ -190,7 +186,6 @@ const ParameterField: FC<ParameterFieldProps> = ({
case "multi-select": {
// Map parameter options to MultiSelectCombobox options format
const comboboxOptions: Option[] = parameter.options
.filter((opt): opt is NonNullable<typeof opt> => opt !== null)
.map((opt) => ({
value: opt.value.value,
label: opt.name,
Expand All @@ -200,7 +195,6 @@ const ParameterField: FC<ParameterFieldProps> = ({
const defaultOptions: Option[] = JSON.parse(defaultValue).map(
(val: string) => {
const option = parameter.options
.filter((o): o is NonNullable<typeof o> => o !== null)
.find((o) => o.value.value === val);
return {
value: val,
Expand Down Expand Up @@ -252,9 +246,6 @@ const ParameterField: FC<ParameterFieldProps> = ({
defaultValue={defaultValue}
>
{parameter.options
.filter(
(option): option is NonNullable<typeof option> => option !== null,
)
.map((option) => (
<div
key={option.value.value}
Expand Down Expand Up @@ -294,10 +285,7 @@ const ParameterField: FC<ParameterFieldProps> = ({
const inputProps: Record<string, unknown> = {};

if (parameter.type === "number") {
const validations =
parameter.validations.filter(
(v): v is NonNullable<typeof v> => v !== null,
)[0] || {};
const validations = parameter.validations[0] || {};
const { validation_min, validation_max } = validations;

if (validation_min !== null) {
Expand Down Expand Up @@ -366,10 +354,6 @@ const ParameterDiagnostics: FC<ParameterDiagnosticsProps> = ({
return (
<div className="flex flex-col gap-2">
{diagnostics
.filter(
(diagnostic): diagnostic is NonNullable<typeof diagnostic> =>
diagnostic !== null,
)
.map((diagnostic, index) => (
<div
key={`diagnostic-${diagnostic.summary}-${index}`}
Expand Down Expand Up @@ -425,7 +409,6 @@ const isValidValue = (
) => {
if (previewParam.options.length > 0) {
const validValues = previewParam.options
.filter((option): option is NonNullable<typeof option> => option !== null)
.map((option) => option.value.value);
return validValues.includes(buildParam.value);
}
Expand Down Expand Up @@ -455,10 +438,8 @@ export const useValidationSchemaForDynamicParameters = (
switch (parameter.type) {
case "number": {
const minValidation = parameter.validations
.filter((v): v is NonNullable<typeof v> => v !== null)
.find((v) => v.validation_min !== null);
const maxValidation = parameter.validations
.filter((v): v is NonNullable<typeof v> => v !== null)
.find((v) => v.validation_max !== null);

if (
Expand Down Expand Up @@ -506,7 +487,6 @@ export const useValidationSchemaForDynamicParameters = (
}

const monotonic = parameter.validations
.filter((v): v is NonNullable<typeof v> => v !== null)
.find(
(v) =>
v.validation_monotonic !== null &&
Expand Down Expand Up @@ -542,7 +522,6 @@ export const useValidationSchemaForDynamicParameters = (
}
case "string": {
const regex = parameter.validations
.filter((v): v is NonNullable<typeof v> => v !== null)
.find(
(v) =>
v.validation_regex !== null &&
Expand Down Expand Up @@ -574,13 +553,10 @@ const parameterError = (
value?: string,
): string | undefined => {
const validation_error = parameter.validations
.filter((v): v is NonNullable<typeof v> => v !== null)
.find((v) => v.validation_error !== null);
const minValidation = parameter.validations
.filter((v): v is NonNullable<typeof v> => v !== null)
.find((v) => v.validation_min !== null);
const maxValidation = parameter.validations
.filter((v): v is NonNullable<typeof v> => v !== null)
.find((v) => v.validation_max !== null);

if (!validation_error || !value) {
Expand Down
Loading