Skip to content

Commit

Permalink
Merge pull request #1 from ibolton336/small-changes
Browse files Browse the repository at this point in the history
Add more space to code editor/ Change table name/ RM unused imports/ Prettier
  • Loading branch information
djzager authored Feb 8, 2023
2 parents d967dd5 + 4c82f73 commit de364c8
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 104 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import React, { useEffect, useState } from "react";
import YAML from 'yaml'
import { CodeEditor, Language } from '@patternfly/react-code-editor';
import React from "react";
import YAML from "yaml";
import { CodeEditor, Language } from "@patternfly/react-code-editor";
import { useTranslation } from "react-i18next";
import { AxiosError, AxiosResponse } from "axios";
import * as yup from "yup";
import {
ActionGroup,
Alert,
Button,
ButtonVariant,
FileUpload,
Form,
} from "@patternfly/react-core";
import { FormState, useForm } from "react-hook-form";
import { useForm } from "react-hook-form";
import { yupResolver } from "@hookform/resolvers/yup";

import {
Expand All @@ -21,7 +18,7 @@ import {
} from "@app/queries/taskgroups";
import { SimpleSelect } from "@app/shared/components";
import { Application, Addon, Taskgroup, TaskgroupTask } from "@app/api/models";
import { getAxiosErrorMessage, getValidatedFromErrorTouched } from "@app/utils/utils";
import { getValidatedFromErrorTouched } from "@app/utils/utils";
import { toAddonDropdownOptionWithValue } from "@app/utils/model-utils";
import { NotificationsContext } from "@app/shared/notifications-context";
import { HookFormPFGroupController } from "@app/shared/components/hook-form-pf-fields";
Expand Down Expand Up @@ -74,14 +71,14 @@ export const RunAddonForm: React.FC<RunAddonFormProps> = ({
variant: "info",
});
onSaved();
}
};

const onSubmitTaskgroupError = (error: Error | unknown) => {
pushNotification({
title: "Taskgroup submit failed",
variant: "danger",
});
}
};

const { mutate: submitTaskgroup } = useSubmitTaskgroupMutation(
onSubmitTaskgroupSuccess,
Expand All @@ -97,7 +94,7 @@ export const RunAddonForm: React.FC<RunAddonFormProps> = ({
};

const onSubmit = (formValues: RunAddonFormValues) => {
const addon = formValues.addon.trim()
const addon = formValues.addon.trim();
const data = YAML.parse(formValues.data.trim());
var payload: Taskgroup;
if (!applications?.length || applications.length < 1) {
Expand All @@ -109,7 +106,7 @@ export const RunAddonForm: React.FC<RunAddonFormProps> = ({
name: `${formValues.addon.trim()}`,
addon: addon,
data: data,
tasks: applications?.map((application) => initTask(addon, application))
tasks: applications?.map((application) => initTask(addon, application)),
};
createTaskgroup(payload);
};
Expand All @@ -118,14 +115,17 @@ export const RunAddonForm: React.FC<RunAddonFormProps> = ({
if (!applications?.length || applications.length < 1) {
return false;
}
const addonTasks = tasks.filter((task) => task.addon === addon)
const addonTasks = tasks.filter((task) => task.addon === addon);
const runningTasks = addonTasks.filter((task) => {
return applications.some((app) => {
return task.application?.id === app.id && task.state?.match(/(Created|Running|Ready|Pending)/)
})
})
return (
task.application?.id === app.id &&
task.state?.match(/(Created|Running|Ready|Pending)/)
);
});
});
return runningTasks.length !== 0;
}
};

const validationSchema: yup.SchemaOf<RunAddonFormValues> = yup
.object()
Expand All @@ -139,9 +139,7 @@ export const RunAddonForm: React.FC<RunAddonFormProps> = ({
"Task(s) running for at least one of selected applications.",
(value) => !isAppRunningAddon(value || "")
),
data: yup
.string()
.required(t("validation.required")),
data: yup.string().required(t("validation.required")),
});

const {
Expand All @@ -159,32 +157,32 @@ export const RunAddonForm: React.FC<RunAddonFormProps> = ({

return (
<Form onSubmit={handleSubmit(onSubmit)}>

<HookFormPFGroupController
control={control}
name="addon"
label="Addon"
fieldId="addon-select"
isRequired
renderInput={
({
field: { onChange, onBlur, value, name },
fieldState: { isTouched, error },
}) => (
<SimpleSelect
id="addon-select"
toggleId="addon-select-toggle"
toggleAriaLabel="Addon select dropdown toggle"
aria-label={name}
value={value ? value : undefined}
options={addons?.map((addon) => toAddonDropdownOptionWithValue(addon))}
onChange={(value) => {
onChange(value);
onBlur();
}}
validated={getValidatedFromErrorTouched(error, isTouched)}
/>
)}
renderInput={({
field: { onChange, onBlur, value, name },
fieldState: { isTouched, error },
}) => (
<SimpleSelect
id="addon-select"
toggleId="addon-select-toggle"
toggleAriaLabel="Addon select dropdown toggle"
aria-label={name}
value={value ? value : undefined}
options={addons?.map((addon) =>
toAddonDropdownOptionWithValue(addon)
)}
onChange={(value) => {
onChange(value);
onBlur();
}}
validated={getValidatedFromErrorTouched(error, isTouched)}
/>
)}
/>

<HookFormPFGroupController
Expand All @@ -203,7 +201,7 @@ export const RunAddonForm: React.FC<RunAddonFormProps> = ({
editor.focus();
monaco.editor.getModels()[0].updateOptions({ tabSize: 4 });
}}
height="sizeToFit"
height="20em"
/>
)}
/>
Expand All @@ -213,9 +211,7 @@ export const RunAddonForm: React.FC<RunAddonFormProps> = ({
type="submit"
aria-label="submit"
variant={ButtonVariant.primary}
isDisabled={
!isValid || isSubmitting || isValidating
}
isDisabled={!isValid || isSubmitting || isValidating}
>
{"Run"}
</Button>
Expand All @@ -229,6 +225,6 @@ export const RunAddonForm: React.FC<RunAddonFormProps> = ({
Cancel
</Button>
</ActionGroup>
</Form >
</Form>
);
};
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import React from "react";
import { AxiosResponse } from "axios";

import { Modal, ModalVariant } from "@patternfly/react-core";
import { RunAddonForm } from "./run-addon-form";
import { Application, Addon, Taskgroup } from "@app/api/models";
import { Application, Addon } from "@app/api/models";

export interface RunAddonModalProps {
applications?: Application[];
addons: Addon[];
isOpen: boolean;
onSaved: (response: AxiosResponse<Taskgroup>) => void;
onSaved: () => void;
onCancel: () => void;
}

Expand Down
Loading

0 comments on commit de364c8

Please # to comment.