Skip to content
This repository was archived by the owner on Jun 13, 2024. It is now read-only.

Commit 12692de

Browse files
authored
fix: Render step names correctly (#96)
* refactor: Upgraded steps to use parsing * refactor: removed nullish from map
1 parent 006382d commit 12692de

8 files changed

Lines changed: 29 additions & 51 deletions

File tree

src/components/atoms/form/ListProperty.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ bg-white border border-circle-gray-300 rounded-md2 flex flex-row"
5454
);
5555
};
5656

57-
// TODO: Refactor
5857
const ListProperty = ({
5958
label,
6059
values,
@@ -63,6 +62,7 @@ const ListProperty = ({
6362
...props
6463
}: InspectorFieldProps & ListPropertyProps) => {
6564
const [field] = useField(props);
65+
6666
return (
6767
<CollapsibleList
6868
title={label}
@@ -91,9 +91,9 @@ const ListProperty = ({
9191
ref={provided.innerRef}
9292
className="p-2 pr-0"
9393
>
94-
{values?.map((cmd: any, index: number) => (
94+
{Object.keys(values[0]).map((cmd: any, index: number) => (
9595
<ListItem
96-
name={cmd.name}
96+
name={cmd}
9797
index={index}
9898
arrayHelper={arrayHelper}
9999
/>

src/components/containers/DefinitionsContainer.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ const DefinitionsContainer = (props: DefinitionsProps) => {
4242
props: {
4343
typePage: props.type.subtypes?.component,
4444
menuPage: InspectorDefinitionMenu,
45-
menuProps: { dataType: props.type, flatten: true },
45+
menuProps: { dataType: props.type },
4646
},
4747
}
4848
: {
4949
component: InspectorDefinitionMenuNav,
50-
props: { dataType: props.type, flatten: true },
50+
props: { dataType: props.type },
5151
},
5252
)
5353
}

src/components/containers/inspector/CommandInspector.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ const NewButton = (
1818
<button
1919
type="button"
2020
onClick={() => {
21-
2221
navigateTo({
2322
component: SubTypeMenuNav,
2423
props: {

src/components/containers/inspector/subtypes/CommandSubtypes.tsx

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
1-
import { commands } from '@circleci/circleci-config-sdk';
2-
import { Command } from '@circleci/circleci-config-sdk/dist/src/lib/Components/Commands/exports/Command';
31
import { Field } from 'formik';
42
import { ReactElement } from 'react';
53
import InspectorProperty from '../../../atoms/form/InspectorProperty';
64

75
export interface CommandSubTypes {
86
[command: string]: {
9-
text: string;
7+
name: string;
108
description?: string;
119
summary?: (command: any) => ReactElement;
1210
fields: ReactElement;
13-
generate: (values: any) => Command;
1411
};
1512
}
1613

1714
const commandSubtypes: CommandSubTypes = {
1815
run: {
19-
text: 'Run a command',
16+
name: 'Run a command',
2017
description: 'Used for invoking all command-line programs',
2118
summary: (command) => (
2219
<p className="inline">{command.parameters.command}</p>
@@ -51,17 +48,15 @@ const commandSubtypes: CommandSubTypes = {
5148
</InspectorProperty>
5249
</div>
5350
),
54-
generate: (values) => new commands.Run({ ...values.parameters }),
5551
},
5652
checkout: {
57-
text: 'Checkout',
53+
name: 'Checkout',
5854
description:
5955
'A special step used to check out source code to the configured path',
6056
fields: <InspectorProperty label="Path" name="parameters.path" />,
61-
generate: (values) => new commands.Checkout({ ...values.parameters }),
6257
},
6358
persist_to_workspace: {
64-
text: 'Persist To Workspace',
59+
name: 'Persist To Workspace',
6560
description:
6661
'Persist a temporary file to be used by another job in the workflow',
6762
fields: (
@@ -70,21 +65,14 @@ const commandSubtypes: CommandSubTypes = {
7065
<InspectorProperty label="Path" name="parameters.path" required />
7166
</div>
7267
),
73-
generate: (values) =>
74-
new commands.workspace.Persist({
75-
root: values.parameters.root,
76-
paths: [values.parameters.path],
77-
}),
7868
},
7969
attach_workspace: {
80-
text: 'Attach Workspace',
70+
name: 'Attach Workspace',
8171
description: 'Attach the workflow’s workspace to the current container',
8272
fields: <InspectorProperty label="At" name="parameters.at" required />,
83-
generate: (values) =>
84-
new commands.workspace.Attach({ ...values.parameters }),
8573
},
8674
store_artifacts: {
87-
text: 'Store Artifacts',
75+
name: 'Store Artifacts',
8876
description: 'Step to store artifacts such as logs and binaries',
8977
fields: (
9078
<div>
@@ -102,17 +90,14 @@ const commandSubtypes: CommandSubTypes = {
10290
></Field>
10391
</div>
10492
),
105-
generate: (values) => new commands.StoreArtifacts({ ...values.parameters }),
10693
},
10794
store_test_results: {
108-
text: 'Store Test Results',
95+
name: 'Store Test Results',
10996
description: 'Upload and store test results for a build',
11097
fields: <InspectorProperty label="Path" name="parameters.path" required />,
111-
generate: (values) =>
112-
new commands.StoreTestResults({ ...values.parameters }),
11398
},
11499
save_cache: {
115-
text: 'Save Cache',
100+
name: 'Save Cache',
116101
description:
117102
'Generates and stores a cache of a file or directory in object storage',
118103
fields: (
@@ -127,12 +112,6 @@ const commandSubtypes: CommandSubTypes = {
127112
</InspectorProperty>
128113
</div>
129114
),
130-
generate: (values) =>
131-
new commands.cache.Save({
132-
paths: [values.parameters.path],
133-
key: values.parameters.key,
134-
when: values.parameters.when,
135-
}),
136115
},
137116
};
138117

src/components/menus/SubTypeMenu.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export type SubTypeSelectPageProps<T> = {
1414
};
1515
export type SubTypeMenuPageProps<T> = {
1616
subtype: SubTypeReference<T>;
17-
onSelectSubtype: () => void;
17+
selectSubtype: () => void;
1818
};
1919
export interface SelectedSubType<T> {
2020
current?: SubTypeReference<T>;
@@ -42,7 +42,7 @@ const SubTypeMenu = <SubTypeRef,>(props: SubTypeMenuProps<SubTypeRef>) => {
4242
{subtype?.current ? (
4343
<SubTypeMenuPage
4444
subtype={subtype.current}
45-
onSelectSubtype={navBack}
45+
selectSubtype={navBack}
4646
{...props.menuProps}
4747
/>
4848
) : (

src/components/menus/definitions/InspectorDefinitionMenu.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { Form, Formik } from 'formik';
2-
import GenerableMapping from '../../../mappings/ComponentMapping';
32
import { useStoreActions, useStoreState } from '../../../state/Hooks';
43
import { DataModel, NavigationComponent } from '../../../state/Store';
54
import BreadCrumbs from '../../containers/BreadCrumbs';
@@ -42,8 +41,10 @@ const InspectorDefinitionMenu = (props: InspectorDefinitionProps) => {
4241
return props.values;
4342
}
4443

45-
return props.subtype ? dataMapping?.defaults[props.subtype] : dataMapping?.defaults;
46-
}
44+
return props.subtype
45+
? dataMapping?.defaults[props.subtype]
46+
: dataMapping?.defaults;
47+
};
4748

4849
const tabs = ['PROPERTIES'];
4950
const unpacked = getValues();
@@ -134,7 +135,7 @@ const InspectorDefinitionMenu = (props: InspectorDefinitionProps) => {
134135
className="p-4 mb-4 w-full border-circle-gray-300 border-2 rounded text-left"
135136
type="button"
136137
onClick={() => {
137-
props.onSelectSubtype();
138+
props.selectSubtype();
138139
}}
139140
>
140141
<p className="font-bold">

src/components/menus/definitions/StepDefinitionMenu.tsx

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,19 @@ const StepPropertiesMenu = (
2525
<h1 className="ml-6 text-2xl py-2 font-bold">New Step</h1>
2626
</header>
2727
<Formik
28-
initialValues={{}}
28+
initialValues={{ parameters: undefined }}
2929
enableReinitialize={true}
30-
onSubmit={(parameters) => {
30+
onSubmit={(step) => {
31+
3132
navigateBack({
3233
distance: 1,
3334
apply: (values: any) => {
35+
const name = builtIn ? props.subtype: customCommand?.name;
36+
3437
values.steps = [
3538
...values.steps,
3639
{
37-
[props.subtype as string]: parameters,
40+
[name as string]: step.parameters,
3841
},
3942
];
4043

@@ -51,12 +54,12 @@ const StepPropertiesMenu = (
5154
className="p-4 mb-4 w-full border-circle-gray-300 border-2 rounded text-left"
5255
type="button"
5356
onClick={() => {
54-
props.onSelectSubtype();
57+
props.selectSubtype();
5558
}}
5659
>
5760
<p className="font-bold">
5861
{builtInSubtype
59-
? builtInSubtype?.text
62+
? builtInSubtype?.name
6063
: customCommand?.name}
6164
</p>
6265
<p className="text-sm mt-1 leading-4 text-circle-gray-500">
@@ -82,9 +85,5 @@ const StepPropertiesMenu = (
8285
</div>
8386
);
8487
};
85-
// const StepPropertiesMenuNav: NavigationComponent = {
86-
// Component: StepPropertiesMenu,
87-
// Label: () => <p>New Step</p>,
88-
// };
8988

9089
export default StepPropertiesMenu;

src/components/menus/definitions/subtypes/StepTypePage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const StepTypePage = (props: SubTypeSelectPageProps<string | CustomCommand>) =>
2727
props.setSubtype(subtype);
2828
}}
2929
>
30-
<p className="font-bold">{commandSubtypes[subtype].text}</p>
30+
<p className="font-bold">{commandSubtypes[subtype].name}</p>
3131
<p className="text-sm mt-1 leading-4 text-circle-gray-500">
3232
{commandSubtypes[subtype].description}
3333
</p>

0 commit comments

Comments
 (0)