diff --git a/awx/main/migrations/0168_jt_prompt_everything_on_launch.py b/awx/main/migrations/0169_jt_prompt_everything_on_launch.py
similarity index 99%
rename from awx/main/migrations/0168_jt_prompt_everything_on_launch.py
rename to awx/main/migrations/0169_jt_prompt_everything_on_launch.py
index 46f254f780..8704b94446 100644
--- a/awx/main/migrations/0168_jt_prompt_everything_on_launch.py
+++ b/awx/main/migrations/0169_jt_prompt_everything_on_launch.py
@@ -9,7 +9,7 @@ import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
- ('main', '0167_project_signature_validation_credential'),
+ ('main', '0168_inventoryupdate_scm_revision'),
]
operations = [
diff --git a/awx/ui/src/components/LaunchButton/LaunchButton.js b/awx/ui/src/components/LaunchButton/LaunchButton.js
index ad133d64b7..061462042b 100644
--- a/awx/ui/src/components/LaunchButton/LaunchButton.js
+++ b/awx/ui/src/components/LaunchButton/LaunchButton.js
@@ -71,12 +71,26 @@ function LaunchButton({ resource, children }) {
setSurveyConfig(data);
}
- if (launch.ask_labels_on_launch) {
- const {
- data: { results },
- } = await readLabels;
+ const relatedPromises = [];
- const allLabels = results.map((label) => ({
+ if (launch.ask_labels_on_launch) {
+ relatedPromises.push(readLabels);
+ } else {
+ relatedPromises.push(null);
+ }
+
+ if (launch.ask_instance_groups_on_launch) {
+ relatedPromises.push(JobTemplatesAPI.readInstanceGroups(resource.id));
+ } else {
+ relatedPromises.push(null);
+ }
+
+ const [labelsResponse, instanceGroupsResponse] = await Promise.all(
+ relatedPromises
+ );
+
+ if (launch.ask_labels_on_launch) {
+ const allLabels = labelsResponse?.data?.results.map((label) => ({
...label,
isReadOnly: true,
}));
@@ -85,11 +99,7 @@ function LaunchButton({ resource, children }) {
}
if (launch.ask_instance_groups_on_launch) {
- const {
- data: { results },
- } = await JobTemplatesAPI.readInstanceGroups(resource.id);
-
- setInstanceGroups(results);
+ setInstanceGroups(instanceGroupsResponse?.data?.results);
}
if (canLaunchWithoutPrompt(launch)) {
diff --git a/awx/ui/src/components/LaunchPrompt/LaunchPrompt.js b/awx/ui/src/components/LaunchPrompt/LaunchPrompt.js
index c177405e59..4bc4c8313c 100644
--- a/awx/ui/src/components/LaunchPrompt/LaunchPrompt.js
+++ b/awx/ui/src/components/LaunchPrompt/LaunchPrompt.js
@@ -2,10 +2,10 @@ import React, { useState } from 'react';
import { ExpandableSection, Wizard } from '@patternfly/react-core';
import { t } from '@lingui/macro';
import { Formik, useFormikContext } from 'formik';
-import { LabelsAPI, OrganizationsAPI } from 'api';
import { useDismissableError } from 'hooks/useRequest';
import mergeExtraVars from 'util/prompt/mergeExtraVars';
import getSurveyValues from 'util/prompt/getSurveyValues';
+import createNewLabels from 'util/labels';
import ContentLoading from '../ContentLoading';
import ContentError from '../ContentError';
import useLaunchSteps from './useLaunchSteps';
@@ -76,44 +76,10 @@ function PromptModalForm({
}
if (launchConfig.ask_labels_on_launch) {
- const labelIds = [];
- const newLabels = [];
- const labelRequests = [];
- let organizationId = resource.organization;
- values.labels.forEach((label) => {
- if (typeof label.id !== 'number') {
- newLabels.push(label);
- } else {
- labelIds.push(label.id);
- }
- });
-
- if (newLabels.length > 0) {
- if (!organizationId) {
- // eslint-disable-next-line no-useless-catch
- try {
- const {
- data: { results },
- } = await OrganizationsAPI.read();
- organizationId = results[0].id;
- } catch (err) {
- throw err;
- }
- }
- }
-
- newLabels.forEach((label) => {
- labelRequests.push(
- LabelsAPI.create({
- name: label.name,
- organization: organizationId,
- }).then(({ data }) => {
- labelIds.push(data.id);
- })
- );
- });
-
- await Promise.all(labelRequests);
+ const { labelIds } = createNewLabels(
+ values.labels,
+ resource.organization
+ );
setValue('labels', labelIds);
}
diff --git a/awx/ui/src/components/Schedule/ScheduleDetail/ScheduleDetail.js b/awx/ui/src/components/Schedule/ScheduleDetail/ScheduleDetail.js
index bbad60baa3..a5650ac238 100644
--- a/awx/ui/src/components/Schedule/ScheduleDetail/ScheduleDetail.js
+++ b/awx/ui/src/components/Schedule/ScheduleDetail/ScheduleDetail.js
@@ -473,7 +473,6 @@ function ScheduleDetail({ hasDaysToKeepField, schedule, surveyConfig }) {
)}
{ask_forks_on_launch && }
- {ask_limit_on_launch && }
{ask_verbosity_on_launch && (
{
- if (typeof label.id !== 'number') {
- newLabels.push(label);
- } else {
- labelIds.push(label.id);
- }
- });
+ const { labelIds, error } = createNewLabels(
+ values.labels,
+ resource.organization
+ );
+
+ if (error) {
+ setFormSubmitError(error);
+ } else {
+ submitValues.labels = labelIds;
}
-
- if (newLabels.length > 0) {
- if (!organizationId) {
- // eslint-disable-next-line no-useless-catch
- try {
- const {
- data: { results },
- } = await OrganizationsAPI.read();
- organizationId = results[0].id;
- } catch (err) {
- throw err;
- }
- }
- }
-
- newLabels.forEach((label) => {
- labelRequests.push(
- LabelsAPI.create({
- name: label.name,
- organization: organizationId,
- }).then(({ data }) => {
- labelIds.push(data.id);
- })
- );
- });
-
- await Promise.all(labelRequests);
-
- submitValues.labels = labelIds;
}
const ruleSet = buildRuleSet(values);
diff --git a/awx/ui/src/util/labels.js b/awx/ui/src/util/labels.js
new file mode 100644
index 0000000000..8e973d5836
--- /dev/null
+++ b/awx/ui/src/util/labels.js
@@ -0,0 +1,57 @@
+import { LabelsAPI, OrganizationsAPI } from '../api';
+
+async function createNewLabels(labels = [], organization = null) {
+ let error = null;
+ const labelIds = [];
+
+ try {
+ const newLabels = [];
+ const labelRequests = [];
+ let organizationId = organization;
+ if (labels) {
+ labels.forEach((label) => {
+ if (typeof label.id !== 'number') {
+ newLabels.push(label);
+ } else {
+ labelIds.push(label.id);
+ }
+ });
+ }
+
+ if (newLabels.length > 0) {
+ if (!organizationId) {
+ // eslint-disable-next-line no-useless-catch
+ try {
+ const {
+ data: { results },
+ } = await OrganizationsAPI.read();
+ organizationId = results[0].id;
+ } catch (err) {
+ throw err;
+ }
+ }
+ }
+
+ newLabels.forEach((label) => {
+ labelRequests.push(
+ LabelsAPI.create({
+ name: label.name,
+ organization: organizationId,
+ }).then(({ data }) => {
+ labelIds.push(data.id);
+ })
+ );
+ });
+
+ await Promise.all(labelRequests);
+ } catch (err) {
+ error = err;
+ }
+
+ return {
+ labelIds,
+ error,
+ };
+}
+
+export default createNewLabels;