mirror of
https://github.com/ansible/awx.git
synced 2026-01-12 02:19:58 -03:30
Merge pull request #6390 from marshmalien/fix-select-behavior
Fix bugs related to Job Template labels and tags Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
This commit is contained in:
commit
5272d088ed
@ -11,7 +11,7 @@ const FormActionGroup = ({ onSubmit, submitDisabled, onCancel, i18n }) => (
|
||||
<Button
|
||||
aria-label={i18n._(t`Save`)}
|
||||
variant="primary"
|
||||
type="submit"
|
||||
type="button"
|
||||
onClick={onSubmit}
|
||||
isDisabled={submitDisabled}
|
||||
>
|
||||
|
||||
@ -25,8 +25,8 @@ function TagMultiSelect({ onChange, value }) {
|
||||
onChange(arrayToString(newValue));
|
||||
};
|
||||
|
||||
const toggleExpanded = () => {
|
||||
setIsExpanded(!isExpanded);
|
||||
const toggleExpanded = toggleValue => {
|
||||
setIsExpanded(toggleValue);
|
||||
};
|
||||
|
||||
const renderOptions = opts => {
|
||||
|
||||
@ -3,7 +3,7 @@ import { useHistory } from 'react-router-dom';
|
||||
import { Card, PageSection } from '@patternfly/react-core';
|
||||
import { CardBody } from '@components/Card';
|
||||
import JobTemplateForm from '../shared/JobTemplateForm';
|
||||
import { JobTemplatesAPI } from '@api';
|
||||
import { JobTemplatesAPI, OrganizationsAPI } from '@api';
|
||||
|
||||
function JobTemplateAdd() {
|
||||
const [formSubmitError, setFormSubmitError] = useState(null);
|
||||
@ -35,10 +35,20 @@ function JobTemplateAdd() {
|
||||
}
|
||||
}
|
||||
|
||||
function submitLabels(templateId, labels = [], organizationId) {
|
||||
async function submitLabels(templateId, labels = [], formOrg) {
|
||||
let orgId = formOrg;
|
||||
|
||||
if (!orgId && labels.length > 0) {
|
||||
const {
|
||||
data: { results },
|
||||
} = await OrganizationsAPI.read();
|
||||
orgId = results[0].id;
|
||||
}
|
||||
|
||||
const associationPromises = labels.map(label =>
|
||||
JobTemplatesAPI.associateLabel(templateId, label, organizationId)
|
||||
JobTemplatesAPI.associateLabel(templateId, label, orgId)
|
||||
);
|
||||
|
||||
return Promise.all([...associationPromises]);
|
||||
}
|
||||
|
||||
|
||||
@ -4,7 +4,7 @@ import { withRouter, Redirect } from 'react-router-dom';
|
||||
import { CardBody } from '@components/Card';
|
||||
import ContentError from '@components/ContentError';
|
||||
import ContentLoading from '@components/ContentLoading';
|
||||
import { JobTemplatesAPI, ProjectsAPI } from '@api';
|
||||
import { JobTemplatesAPI, OrganizationsAPI, ProjectsAPI } from '@api';
|
||||
import { JobTemplate } from '@types';
|
||||
import { getAddedAndRemoved } from '@util/lists';
|
||||
import JobTemplateForm from '../shared/JobTemplateForm';
|
||||
@ -118,17 +118,27 @@ class JobTemplateEdit extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
async submitLabels(labels = [], organizationId) {
|
||||
async submitLabels(labels = [], formOrgId) {
|
||||
const { template } = this.props;
|
||||
let orgId = formOrgId;
|
||||
|
||||
const { added, removed } = getAddedAndRemoved(
|
||||
template.summary_fields.labels.results,
|
||||
labels
|
||||
);
|
||||
|
||||
if (!orgId && added.length > 0) {
|
||||
const {
|
||||
data: { results },
|
||||
} = await OrganizationsAPI.read();
|
||||
orgId = results[0].id;
|
||||
}
|
||||
|
||||
const disassociationPromises = removed.map(label =>
|
||||
JobTemplatesAPI.disassociateLabel(template.id, label)
|
||||
);
|
||||
const associationPromises = added.map(label => {
|
||||
return JobTemplatesAPI.associateLabel(template.id, label, organizationId);
|
||||
return JobTemplatesAPI.associateLabel(template.id, label, orgId);
|
||||
});
|
||||
|
||||
const results = await Promise.all([
|
||||
|
||||
@ -36,8 +36,8 @@ function LabelSelect({ value, placeholder, onChange, onError }) {
|
||||
);
|
||||
const [isExpanded, setIsExpanded] = useState(false);
|
||||
|
||||
const toggleExpanded = () => {
|
||||
setIsExpanded(!isExpanded);
|
||||
const toggleExpanded = toggleValue => {
|
||||
setIsExpanded(toggleValue);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user