Skip to content

Commit

Permalink
POST to job_templates/{id}/labels endpoint rather than /labels endpoint.
Browse files Browse the repository at this point in the history
  • Loading branch information
kialam committed Jul 20, 2023
1 parent fc1b74a commit 10806e8
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 12 deletions.
10 changes: 2 additions & 8 deletions awx/ui/src/components/LaunchPrompt/LaunchPrompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Formik, useFormikContext } from 'formik';
import { useDismissableError } from 'hooks/useRequest';
import mergeExtraVars from 'util/prompt/mergeExtraVars';
import getSurveyValues from 'util/prompt/getSurveyValues';
import createNewLabels from 'util/labels';
import { createNewLabelsOnLaunch } from 'util/labels';
import ContentLoading from '../ContentLoading';
import ContentError from '../ContentError';
import useLaunchSteps from './useLaunchSteps';
Expand Down Expand Up @@ -67,7 +67,6 @@ function PromptModalForm({
setValue('forks', values.forks);
setValue('job_slice_count', values.job_slice_count);
setValue('execution_environment', values.execution_environment?.id);

if (launchConfig.ask_instance_groups_on_launch) {
const instanceGroupIds = [];
values.instance_groups.forEach((instance_group) => {
Expand All @@ -77,14 +76,9 @@ function PromptModalForm({
}

if (launchConfig.ask_labels_on_launch) {
const { labelIds } = createNewLabels(
values.labels,
resource.organization
);

const { labelIds } = createNewLabelsOnLaunch(values.labels, resource);
setValue('labels', labelIds);
}

onSubmit(postValues);
};
const { error, dismissError } = useDismissableError(contentError);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { getAddedAndRemoved } from 'util/lists';
import { parseVariableField } from 'util/yaml';
import mergeExtraVars from 'util/prompt/mergeExtraVars';
import getSurveyValues from 'util/prompt/getSurveyValues';
import createNewLabels from 'util/labels';
import { createNewLabels } from 'util/labels';
import ScheduleForm from '../shared/ScheduleForm';
import buildRuleSet from '../shared/buildRuleSet';
import { CardBody } from '../../Card';
Expand Down
34 changes: 31 additions & 3 deletions awx/ui/src/util/labels.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { LabelsAPI, OrganizationsAPI } from '../api';
import { LabelsAPI, OrganizationsAPI, JobTemplatesAPI } from '../api';

async function createNewLabels(labels = [], organization = null) {
export async function createNewLabels(labels = [], organization = null) {
let error = null;
const labelIds = [];

Expand Down Expand Up @@ -54,4 +54,32 @@ async function createNewLabels(labels = [], organization = null) {
};
}

export default createNewLabels;
export async function createNewLabelsOnLaunch(labels = [], resource = null) {
let error = null;
const labelIds = [];

try {
const labelRequests = [];
const jobTemplateId = resource.id;
const orgId = resource.organization;

labels.forEach((label) => {
labelRequests.push(
JobTemplatesAPI.associateLabel(jobTemplateId, label, orgId).then(
({ data }) => {
labelIds.push(data.id);
}
)
);
});

await Promise.all(labelRequests);
} catch (err) {
error = err;
}

return {
labelIds,
error,
};
}

0 comments on commit 10806e8

Please sign in to comment.