mirror of
https://github.com/ansible/awx.git
synced 2026-05-11 11:27:36 -02: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:
@@ -9,7 +9,7 @@ import django.db.models.deletion
|
|||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
('main', '0167_project_signature_validation_credential'),
|
('main', '0168_inventoryupdate_scm_revision'),
|
||||||
]
|
]
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
@@ -71,12 +71,26 @@ function LaunchButton({ resource, children }) {
|
|||||||
setSurveyConfig(data);
|
setSurveyConfig(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (launch.ask_labels_on_launch) {
|
const relatedPromises = [];
|
||||||
const {
|
|
||||||
data: { results },
|
|
||||||
} = await readLabels;
|
|
||||||
|
|
||||||
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,
|
...label,
|
||||||
isReadOnly: true,
|
isReadOnly: true,
|
||||||
}));
|
}));
|
||||||
@@ -85,11 +99,7 @@ function LaunchButton({ resource, children }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (launch.ask_instance_groups_on_launch) {
|
if (launch.ask_instance_groups_on_launch) {
|
||||||
const {
|
setInstanceGroups(instanceGroupsResponse?.data?.results);
|
||||||
data: { results },
|
|
||||||
} = await JobTemplatesAPI.readInstanceGroups(resource.id);
|
|
||||||
|
|
||||||
setInstanceGroups(results);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (canLaunchWithoutPrompt(launch)) {
|
if (canLaunchWithoutPrompt(launch)) {
|
||||||
|
|||||||
@@ -2,10 +2,10 @@ import React, { useState } from 'react';
|
|||||||
import { ExpandableSection, Wizard } from '@patternfly/react-core';
|
import { ExpandableSection, Wizard } from '@patternfly/react-core';
|
||||||
import { t } from '@lingui/macro';
|
import { t } from '@lingui/macro';
|
||||||
import { Formik, useFormikContext } from 'formik';
|
import { Formik, useFormikContext } from 'formik';
|
||||||
import { LabelsAPI, OrganizationsAPI } from 'api';
|
|
||||||
import { useDismissableError } from 'hooks/useRequest';
|
import { useDismissableError } from 'hooks/useRequest';
|
||||||
import mergeExtraVars from 'util/prompt/mergeExtraVars';
|
import mergeExtraVars from 'util/prompt/mergeExtraVars';
|
||||||
import getSurveyValues from 'util/prompt/getSurveyValues';
|
import getSurveyValues from 'util/prompt/getSurveyValues';
|
||||||
|
import createNewLabels from 'util/labels';
|
||||||
import ContentLoading from '../ContentLoading';
|
import ContentLoading from '../ContentLoading';
|
||||||
import ContentError from '../ContentError';
|
import ContentError from '../ContentError';
|
||||||
import useLaunchSteps from './useLaunchSteps';
|
import useLaunchSteps from './useLaunchSteps';
|
||||||
@@ -76,44 +76,10 @@ function PromptModalForm({
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (launchConfig.ask_labels_on_launch) {
|
if (launchConfig.ask_labels_on_launch) {
|
||||||
const labelIds = [];
|
const { labelIds } = createNewLabels(
|
||||||
const newLabels = [];
|
values.labels,
|
||||||
const labelRequests = [];
|
resource.organization
|
||||||
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);
|
|
||||||
|
|
||||||
setValue('labels', labelIds);
|
setValue('labels', labelIds);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -473,7 +473,6 @@ function ScheduleDetail({ hasDaysToKeepField, schedule, surveyConfig }) {
|
|||||||
<Detail label={t`Limit`} value={limit} dataCy="schedule-limit" />
|
<Detail label={t`Limit`} value={limit} dataCy="schedule-limit" />
|
||||||
)}
|
)}
|
||||||
{ask_forks_on_launch && <Detail label={t`Forks`} value={forks} />}
|
{ask_forks_on_launch && <Detail label={t`Forks`} value={forks} />}
|
||||||
{ask_limit_on_launch && <Detail label={t`Limit`} value={limit} />}
|
|
||||||
{ask_verbosity_on_launch && (
|
{ask_verbosity_on_launch && (
|
||||||
<Detail
|
<Detail
|
||||||
label={t`Verbosity`}
|
label={t`Verbosity`}
|
||||||
|
|||||||
@@ -3,11 +3,12 @@ import { useHistory, useLocation } from 'react-router-dom';
|
|||||||
import { shape } from 'prop-types';
|
import { shape } from 'prop-types';
|
||||||
import { Card } from '@patternfly/react-core';
|
import { Card } from '@patternfly/react-core';
|
||||||
import yaml from 'js-yaml';
|
import yaml from 'js-yaml';
|
||||||
import { LabelsAPI, OrganizationsAPI, SchedulesAPI } from 'api';
|
import { OrganizationsAPI, SchedulesAPI } from 'api';
|
||||||
import { getAddedAndRemoved } from 'util/lists';
|
import { getAddedAndRemoved } from 'util/lists';
|
||||||
import { parseVariableField } from 'util/yaml';
|
import { parseVariableField } from 'util/yaml';
|
||||||
import mergeExtraVars from 'util/prompt/mergeExtraVars';
|
import mergeExtraVars from 'util/prompt/mergeExtraVars';
|
||||||
import getSurveyValues from 'util/prompt/getSurveyValues';
|
import getSurveyValues from 'util/prompt/getSurveyValues';
|
||||||
|
import createNewLabels from 'util/labels';
|
||||||
import ScheduleForm from '../shared/ScheduleForm';
|
import ScheduleForm from '../shared/ScheduleForm';
|
||||||
import buildRuleSet from '../shared/buildRuleSet';
|
import buildRuleSet from '../shared/buildRuleSet';
|
||||||
import { CardBody } from '../../Card';
|
import { CardBody } from '../../Card';
|
||||||
@@ -85,48 +86,16 @@ function ScheduleEdit({
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (launchConfiguration?.ask_labels_on_launch) {
|
if (launchConfiguration?.ask_labels_on_launch) {
|
||||||
const labelIds = [];
|
const { labelIds, error } = createNewLabels(
|
||||||
const newLabels = [];
|
values.labels,
|
||||||
const labelRequests = [];
|
resource.organization
|
||||||
let organizationId = resource.organization;
|
);
|
||||||
if (values.labels) {
|
|
||||||
values.labels.forEach((label) => {
|
if (error) {
|
||||||
if (typeof label.id !== 'number') {
|
setFormSubmitError(error);
|
||||||
newLabels.push(label);
|
} else {
|
||||||
} else {
|
submitValues.labels = labelIds;
|
||||||
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);
|
|
||||||
|
|
||||||
submitValues.labels = labelIds;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const ruleSet = buildRuleSet(values);
|
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;
|
||||||
Reference in New Issue
Block a user