mirror of
https://github.com/ansible/awx.git
synced 2026-01-11 10:00:01 -03:30
Remove duplicate Limit detail on schedule
Bumps migration number from 0168 to 0169 Make labels and IGs requests synchronously when getting launch data Moves label creation out to a util
This commit is contained in:
parent
816e491d17
commit
23f4f7bb00
@ -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 = [
|
||||
@ -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)) {
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -473,7 +473,6 @@ function ScheduleDetail({ hasDaysToKeepField, schedule, surveyConfig }) {
|
||||
<Detail label={t`Limit`} value={limit} dataCy="schedule-limit" />
|
||||
)}
|
||||
{ask_forks_on_launch && <Detail label={t`Forks`} value={forks} />}
|
||||
{ask_limit_on_launch && <Detail label={t`Limit`} value={limit} />}
|
||||
{ask_verbosity_on_launch && (
|
||||
<Detail
|
||||
label={t`Verbosity`}
|
||||
|
||||
@ -3,11 +3,12 @@ import { useHistory, useLocation } from 'react-router-dom';
|
||||
import { shape } from 'prop-types';
|
||||
import { Card } from '@patternfly/react-core';
|
||||
import yaml from 'js-yaml';
|
||||
import { LabelsAPI, OrganizationsAPI, SchedulesAPI } from 'api';
|
||||
import { OrganizationsAPI, SchedulesAPI } from 'api';
|
||||
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 ScheduleForm from '../shared/ScheduleForm';
|
||||
import buildRuleSet from '../shared/buildRuleSet';
|
||||
import { CardBody } from '../../Card';
|
||||
@ -85,48 +86,16 @@ function ScheduleEdit({
|
||||
|
||||
try {
|
||||
if (launchConfiguration?.ask_labels_on_launch) {
|
||||
const labelIds = [];
|
||||
const newLabels = [];
|
||||
const labelRequests = [];
|
||||
let organizationId = resource.organization;
|
||||
if (values.labels) {
|
||||
values.labels.forEach((label) => {
|
||||
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);
|
||||
|
||||
57
awx/ui/src/util/labels.js
Normal file
57
awx/ui/src/util/labels.js
Normal file
@ -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;
|
||||
Loading…
x
Reference in New Issue
Block a user