From 8a0be5b111c1c693fb09b5449121efab3380ca0b Mon Sep 17 00:00:00 2001 From: Keith Grant Date: Thu, 9 Apr 2020 11:35:56 -0700 Subject: [PATCH] add survey questions --- .../components/LaunchPrompt/LaunchPrompt.jsx | 2 +- .../components/LaunchPrompt/SurveyStep.jsx | 65 +++++++++++++++++-- 2 files changed, 62 insertions(+), 5 deletions(-) diff --git a/awx/ui_next/src/components/LaunchPrompt/LaunchPrompt.jsx b/awx/ui_next/src/components/LaunchPrompt/LaunchPrompt.jsx index 4dfac93e23..f130e7f2d8 100644 --- a/awx/ui_next/src/components/LaunchPrompt/LaunchPrompt.jsx +++ b/awx/ui_next/src/components/LaunchPrompt/LaunchPrompt.jsx @@ -71,7 +71,7 @@ function LaunchPrompt({ config, resource, onLaunch, onCancel, i18n }) { if (config.survey_enabled) { steps.push({ name: i18n._(t`Survey`), - component: , + component: , }); } steps.push({ diff --git a/awx/ui_next/src/components/LaunchPrompt/SurveyStep.jsx b/awx/ui_next/src/components/LaunchPrompt/SurveyStep.jsx index c0b8e6ec14..5d18040037 100644 --- a/awx/ui_next/src/components/LaunchPrompt/SurveyStep.jsx +++ b/awx/ui_next/src/components/LaunchPrompt/SurveyStep.jsx @@ -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() { - return
; +function InventoryStep({ template, i18n }) { + 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 ; + } + if (isLoading || !survey) { + return ; + } + + return ( +
+ {survey.spec.map(question => ( + + ))} + + ); } -export default InventoryStep; +function SurveyQuestion({ question, i18n }) { + const isNumeric = question.type === 'number' || question.type === 'integer'; + return ( + + ); +} + +export default withI18n()(InventoryStep);