From 20c4b21c3981830e801910e198918451a5167178 Mon Sep 17 00:00:00 2001 From: Alex Corey Date: Wed, 29 Sep 2021 11:56:19 -0400 Subject: [PATCH] Sufrace ALLOW_JINJA_IN_EXTRA_VARS on the job settings page --- .../Setting/Jobs/JobsDetail/JobsDetail.js | 1 - .../screens/Setting/Jobs/JobsEdit/JobsEdit.js | 21 ++++++++++++++++++- .../Setting/Jobs/JobsEdit/JobsEdit.test.js | 1 - 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/awx/ui/src/screens/Setting/Jobs/JobsDetail/JobsDetail.js b/awx/ui/src/screens/Setting/Jobs/JobsDetail/JobsDetail.js index 4d6318c7c6..487660ecff 100644 --- a/awx/ui/src/screens/Setting/Jobs/JobsDetail/JobsDetail.js +++ b/awx/ui/src/screens/Setting/Jobs/JobsDetail/JobsDetail.js @@ -30,7 +30,6 @@ function JobsDetail() { const { data } = await SettingsAPI.readCategory('jobs'); const { - ALLOW_JINJA_IN_EXTRA_VARS, STDOUT_MAX_BYTES_DISPLAY, EVENT_STDOUT_MAX_BYTES_DISPLAY, ...jobsData diff --git a/awx/ui/src/screens/Setting/Jobs/JobsEdit/JobsEdit.js b/awx/ui/src/screens/Setting/Jobs/JobsEdit/JobsEdit.js index 734b78597f..81aedde43f 100644 --- a/awx/ui/src/screens/Setting/Jobs/JobsEdit/JobsEdit.js +++ b/awx/ui/src/screens/Setting/Jobs/JobsEdit/JobsEdit.js @@ -1,4 +1,5 @@ import React, { useCallback, useEffect } from 'react'; +import { t } from '@lingui/macro'; import { useHistory } from 'react-router-dom'; import { Formik } from 'formik'; import { Form } from '@patternfly/react-core'; @@ -18,6 +19,7 @@ import { ObjectField, RevertAllAlert, RevertFormActionGroup, + ChoiceField, } from '../../shared'; function JobsEdit() { @@ -34,7 +36,6 @@ function JobsEdit() { useCallback(async () => { const { data } = await SettingsAPI.readCategory('jobs'); const { - ALLOW_JINJA_IN_EXTRA_VARS, EVENT_STDOUT_MAX_BYTES_DISPLAY, STDOUT_MAX_BYTES_DISPLAY, ...jobsData @@ -112,6 +113,23 @@ function JobsEdit() { return acc; }, {}); + // We have to rebuild the ALLOW_JINJA_IN_EXTRA_VARS object because the default value + // is 'template' but its label that comes from the api is 'Only On Job Template + // Definitions'. The problem is that this label does not match whats in the help + // text, or what is rendered on the screen in the details, 'template' is what is + // rendered in those locations. For consistency sake I have changed that label + // value below. + + const jinja = { + default: 'template', + help_text: jobs?.ALLOW_JINJA_IN_EXTRA_VARS?.help_text, + label: jobs?.ALLOW_JINJA_IN_EXTRA_VARS?.label, + }; + jinja.choices = jobs?.ALLOW_JINJA_IN_EXTRA_VARS?.choices.map( + ([value, label]) => + value === 'template' ? [value, t`Template`] : [value, label] + ); + return ( {isLoading && } @@ -157,6 +175,7 @@ function JobsEdit() { config={jobs.MAX_FORKS} type="number" /> + ', () => { }); expect(SettingsAPI.updateAll).toHaveBeenCalledTimes(1); const { - ALLOW_JINJA_IN_EXTRA_VARS, EVENT_STDOUT_MAX_BYTES_DISPLAY, STDOUT_MAX_BYTES_DISPLAY, ...jobRequest