This repository was archived by the owner on Jun 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathParamListContainer.tsx
More file actions
102 lines (96 loc) · 2.61 KB
/
ParamListContainer.tsx
File metadata and controls
102 lines (96 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import { parameters } from '@circleci/circleci-config-sdk';
import { AnyParameterLiteral } from '@circleci/circleci-config-sdk/dist/src/lib/Components/Parameters/types/CustomParameterLiterals.types';
import { Fragment } from 'react';
import InspectorProperty from '../atoms/form/InspectorProperty';
import { MatrixProperty } from '../atoms/form/MatrixProperty';
export type ParamListContainerProps = {
paramList: parameters.CustomParametersList<AnyParameterLiteral>;
parent?: string;
props?: any;
values?: any;
matrix?: boolean;
};
type ParamInspector = {
[K in AnyParameterLiteral]: (
parameter: parameters.CustomParameter<AnyParameterLiteral>,
) => any;
};
const subtypes: ParamInspector = {
integer: (parameter) => {
return {
className: 'w-full',
type: 'number',
placeholder: parameter.defaultValue || 'No default value',
};
},
enum: (parameter) => {
const enumParam = parameter as parameters.CustomEnumParameter;
return {
as: 'select',
className: 'w-full',
children: enumParam.enumValues.map((value) => (
<option value={value}>{value}</option>
)),
placeholder: 'No default option',
};
},
string: (parameter) => {
return {
placeholder: (parameter.defaultValue as string) || 'No default value',
};
},
boolean: (parameter) => {
return {
type: 'checkbox',
};
},
executor: (parameter) => {
return {};
},
steps: (parameter) => {
return {};
},
env_var_name: (parameter) => {
return {};
},
};
const ParamListContainer = ({
paramList,
parent,
values,
matrix,
...props
}: ParamListContainerProps) => {
return (
<>
{paramList.parameters.map((parameter, index) => {
console.log(subtypes[parameter.type](parameter));
return (
<Fragment key={index}>
{matrix ? (
<MatrixProperty
{...props}
label={parameter.name}
values={values}
namePrefix={parent}
description={parameter.description}
name={parameter.name}
{...subtypes[parameter.type](parameter)}
/>
) : (
<InspectorProperty
{...props}
label={parameter.name}
description={parameter.description}
values={values}
name={parent ? `${parent}.${parameter.name}` : parameter.name}
{...subtypes[parameter.type](parameter)}
/>
)}
</Fragment>
);
})}
</>
);
};
export default ParamListContainer;