mirror of
https://github.com/ansible/awx.git
synced 2026-02-28 16:28:43 -03:30
add survey questions
This commit is contained in:
@@ -71,7 +71,7 @@ function LaunchPrompt({ config, resource, onLaunch, onCancel, i18n }) {
|
|||||||
if (config.survey_enabled) {
|
if (config.survey_enabled) {
|
||||||
steps.push({
|
steps.push({
|
||||||
name: i18n._(t`Survey`),
|
name: i18n._(t`Survey`),
|
||||||
component: <SurveyStep />,
|
component: <SurveyStep template={resource} />,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
steps.push({
|
steps.push({
|
||||||
|
|||||||
@@ -1,7 +1,64 @@
|
|||||||
import React from 'react';
|
import React, { useCallback, useEffect } from 'react';
|
||||||
|
import { withI18n } from '@lingui/react';
|
||||||
|
import { JobTemplatesAPI, WorkflowJobTemplatesAPI } from '@api';
|
||||||
|
import { Form } from '@patternfly/react-core';
|
||||||
|
import FormField from '@components/FormField';
|
||||||
|
import ContentLoading from '@components/ContentLoading';
|
||||||
|
import ContentError from '@components/ContentError';
|
||||||
|
import useRequest from '@util/useRequest';
|
||||||
|
import { required } from '@util/validators';
|
||||||
|
|
||||||
function InventoryStep() {
|
function InventoryStep({ template, i18n }) {
|
||||||
return <div />;
|
const { result: survey, request: fetchSurvey, isLoading, error } = useRequest(
|
||||||
|
useCallback(async () => {
|
||||||
|
const { data } =
|
||||||
|
template.type === 'workflow_job_template'
|
||||||
|
? await WorkflowJobTemplatesAPI.readSurvey(template.id)
|
||||||
|
: await JobTemplatesAPI.readSurvey(template.id);
|
||||||
|
return data;
|
||||||
|
}, [template])
|
||||||
|
);
|
||||||
|
useEffect(() => {
|
||||||
|
fetchSurvey();
|
||||||
|
}, [fetchSurvey]);
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
return <ContentError error={error} />;
|
||||||
|
}
|
||||||
|
if (isLoading || !survey) {
|
||||||
|
return <ContentLoading />;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Form>
|
||||||
|
{survey.spec.map(question => (
|
||||||
|
<SurveyQuestion
|
||||||
|
key={question.variable}
|
||||||
|
question={question}
|
||||||
|
i18n={i18n}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</Form>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default InventoryStep;
|
function SurveyQuestion({ question, i18n }) {
|
||||||
|
const isNumeric = question.type === 'number' || question.type === 'integer';
|
||||||
|
return (
|
||||||
|
<FormField
|
||||||
|
id={`survey-question-${question.variable}`}
|
||||||
|
name={question.variable}
|
||||||
|
label={question.question_name}
|
||||||
|
tooltip={question.question_description}
|
||||||
|
isRequired={question.required}
|
||||||
|
validate={question.required ? required(null, i18n) : null}
|
||||||
|
type={isNumeric ? 'number' : question.type}
|
||||||
|
min={isNumeric ? question.min : null}
|
||||||
|
max={isNumeric ? question.max : null}
|
||||||
|
minLength={!isNumeric ? question.min : null}
|
||||||
|
maxLength={!isNumeric ? question.max : null}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default withI18n()(InventoryStep);
|
||||||
|
|||||||
Reference in New Issue
Block a user