Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
riccardoperra committed Nov 11, 2024
1 parent 60bd973 commit 787395f
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 25 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ This project uses [ungh](https://github.com/unjs/ungh) from UnJS in order to cal

This project uses [statebuilder](https://github.com/riccardoperra/statebuilder) to handle local state.

The editor store uses a command-based approach which granularly update the yaml code imperatively via [yaml](https://www.npmjs.com/package/yaml) package.

See some implementations in `store` folder:

- [packages/app/src/store/editor](packages/app/src/store/editor)
Expand Down
14 changes: 10 additions & 4 deletions packages/app/src/components/Editor/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ function EditorHeaderForkButton() {
{_(
msg`Forking this source will create a new scratch remotely connected to your profile, that can be modified only by you`,
)}
<div>
<div style={{'margin-top': '8px'}}>
{/* TODO: fix this inline style */}
<form
method={'post'}
action={createScratchFork.with(
Expand All @@ -74,10 +75,15 @@ function EditorHeaderForkButton() {
<Button size={'xs'} theme={'primary'} type={'submit'}>
{_(msg`Confirm`)}
</Button>
<Button
size={'xs'}
theme={'secondary'}
type={'button'}
onClick={() => setOpen(false)}
>
{_(msg`Cancel`)}
</Button>
</form>
<Button size={'xs'} theme={'secondary'}>
{_(msg`Cancel`)}
</Button>
</div>
</PopoverContent>
</Popover>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,6 @@ export function WorkflowDispatchItemForm(props: WorkflowDispatchItemFormProps) {
/>
</FullWidthPanelRow>

<FullWidthPanelRow>
<TextArea
slotClasses={{
root: styles.inlineInputRoot,
label: styles.inlineInputLabel,
}}
options={{
autoResize: true,
}}
size={'sm'}
theme={'filled'}
label={'Deprecation message'}
value={form()?.deprecationMessage}
onChange={value => update({deprecationMessage: value})}
/>
</FullWidthPanelRow>

<FullWidthPanelRow>
<Select
aria-label={'Type'}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ export const badge = style({
});

export const currentUser = style({
fontSize: '14px',
// TODO: fix this style ordering
fontSize: '14px !important',
});
8 changes: 6 additions & 2 deletions packages/app/src/store/editor/actions/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,18 @@ export const convertEnvItemFieldToYaml = (
return value;
};

export function removeObjectYamlPrivateProperties(object: Record<string, any>) {
export function removeObjectYamlPrivateProperties<
T extends Record<string, any>,
>(object: T) {
const clone = structuredClone(object);
for (const key in clone) {
if (key[0] === '$') {
delete clone[key];
}
}
return clone;
return clone as {
[K in keyof T]: K extends `$${string}` ? never : T[K];
};
}

export function orderYamlMapItemByKey(
Expand Down
15 changes: 14 additions & 1 deletion packages/app/src/store/editor/actions/workflow-dispatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const setWorkflowDispatch =
workflowDispatch.add(new Pair(new Scalar('inputs'), inputs));
}

let {name, ...others} = removeObjectYamlPrivateProperties(data);
let {name, ...others} = removeObjectYamlPrivateProperties({...data});
const inputAtIndex = inputs.items.at(index);
const input = new YAMLMap<Scalar<string>, unknown>();
if (!name && fallbackMissingName) {
Expand All @@ -47,6 +47,19 @@ export const setWorkflowDispatch =
return;
}
const pair = new Pair(new Scalar(name), input);
switch (others.type) {
case 'boolean':
others.default =
others.default === 'true' || others.default === true;
break;
case 'string':
others.default = String(others.default);
break;
case 'number':
others.default = parseInt(others.default, 10);
break;
}

for (const [key, value] of Object.entries(others)) {
if (value !== null && value !== undefined) {
input.set(new Scalar(key), value);
Expand Down

0 comments on commit 787395f

Please sign in to comment.