Skip to content
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

fix: Health check alert, stage variables empty list #484

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM epamedp/headlamp:0.22.35
FROM epamedp/headlamp:0.22.36

COPY --chown=100:101 assets/ /headlamp/frontend
COPY --chown=100:101 dist/main.js /headlamp/plugins/edp/main.js
Expand Down
149 changes: 88 additions & 61 deletions src/pages/stage-details/components/Variables/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,69 +51,70 @@ export const Variables = ({ configMap }: { configMap: ConfigMapKubeObjectInterfa

const theme = useTheme();

const onSubmit = (values) => {
const configMapCopy = { ...configMap };
configMapCopy.data = values.variables.reduce((acc, { key, value }) => {
acc[key] = value;
return acc;
}, {});
const onSubmit = React.useCallback(
(values) => {
const configMapCopy = { ...configMap };
configMapCopy.data = values.variables.reduce((acc, { key, value }) => {
acc[key] = value;
return acc;
}, {});

editConfigMap({ configMapData: configMapCopy });
reset(values, { keepValues: true });
};
editConfigMap({ configMapData: configMapCopy });
reset(values, { keepValues: true });
},
[configMap, editConfigMap, reset]
);

const appendNewRow = () => append({ key: '', value: '' });
const appendNewRow = React.useCallback(() => append({ key: '', value: '' }), [append]);

return (
<FormProvider {...form}>
{!fields?.length ? (
<EmptyList
customText="No variables found."
handleClick={appendNewRow}
linkText="Click here to add a new variable."
/>
) : (
const renderContent = React.useCallback(() => {
if (fields.length || dataEntries?.length) {
return (
<form onSubmit={handleSubmit(onSubmit)}>
<Stack spacing={4}>
<NameValueTable
rows={fields.map((field, index) => {
return {
name: (
<FormTextField
{...register(`variables.${index}.key`, {
required: 'Enter a key',
})}
placeholder={'Var name'}
label={'Key'}
control={control}
errors={errors}
key={`${field.id}-key`}
/>
),
value: (
<Stack spacing={2} direction="row" alignItems="center">
<Box flexGrow={1}>
<FormTextField
{...register(`variables.${index}.value`, {
required: 'Enter a value',
})}
label={'Value'}
placeholder={'Var value'}
control={control}
errors={errors}
key={`${field.id}-value`}
/>
</Box>
<Box sx={{ pt: (t) => t.typography.pxToRem(FORM_CONTROL_LABEL_HEIGHT) }}>
<IconButton onClick={() => handleDelete(index)} size="medium">
<Icon icon={ICONS.BUCKET} width="20" />
</IconButton>
</Box>
</Stack>
),
};
})}
/>
{fields.length ? (
<NameValueTable
rows={fields.map((field, index) => {
return {
name: (
<FormTextField
{...register(`variables.${index}.key`, {
required: 'Enter a key',
})}
placeholder={'Var name'}
label={'Key'}
control={control}
errors={errors}
key={`${field.id}-key`}
/>
),
value: (
<Stack spacing={2} direction="row" alignItems="center">
<Box flexGrow={1}>
<FormTextField
{...register(`variables.${index}.value`, {
required: 'Enter a value',
})}
label={'Value'}
placeholder={'Var value'}
control={control}
errors={errors}
key={`${field.id}-value`}
/>
</Box>
<Box sx={{ pt: (t) => t.typography.pxToRem(FORM_CONTROL_LABEL_HEIGHT) }}>
<IconButton onClick={() => handleDelete(index)} size="medium">
<Icon icon={ICONS.BUCKET} width="20" />
</IconButton>
</Box>
</Stack>
),
};
})}
/>
) : (
<EmptyList customText="Are you sure you want to save empty variable list?" />
)}
<Stack alignItems="flex-end" sx={{ pr: (t) => t.typography.pxToRem(16) }}>
<Button
type={'button'}
Expand Down Expand Up @@ -153,7 +154,33 @@ export const Variables = ({ configMap }: { configMap: ConfigMapKubeObjectInterfa
</Stack>
</Stack>
</form>
)}
</FormProvider>
);
);
}

if (!dataEntries?.length) {
return (
<EmptyList
customText="No variables found."
handleClick={appendNewRow}
linkText="Click here to add a new variable."
/>
);
}
}, [
appendNewRow,
configMapEditMutation.isLoading,
control,
dataEntries?.length,
errors,
fields,
handleDelete,
handleSubmit,
isDirty,
onSubmit,
register,
reset,
theme.palette.secondary.dark,
]);

return <FormProvider {...form}>{renderContent()}</FormProvider>;
};
Loading