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:
softwarefactory-project-zuul[bot]
2020-03-24 17:53:01 +00:00
committed by GitHub
5 changed files with 31 additions and 11 deletions

View File

@@ -11,7 +11,7 @@ const FormActionGroup = ({ onSubmit, submitDisabled, onCancel, i18n }) => (
<Button <Button
aria-label={i18n._(t`Save`)} aria-label={i18n._(t`Save`)}
variant="primary" variant="primary"
type="submit" type="button"
onClick={onSubmit} onClick={onSubmit}
isDisabled={submitDisabled} isDisabled={submitDisabled}
> >

View File

@@ -25,8 +25,8 @@ function TagMultiSelect({ onChange, value }) {
onChange(arrayToString(newValue)); onChange(arrayToString(newValue));
}; };
const toggleExpanded = () => { const toggleExpanded = toggleValue => {
setIsExpanded(!isExpanded); setIsExpanded(toggleValue);
}; };
const renderOptions = opts => { const renderOptions = opts => {

View File

@@ -3,7 +3,7 @@ import { useHistory } from 'react-router-dom';
import { Card, PageSection } from '@patternfly/react-core'; import { Card, PageSection } from '@patternfly/react-core';
import { CardBody } from '@components/Card'; import { CardBody } from '@components/Card';
import JobTemplateForm from '../shared/JobTemplateForm'; import JobTemplateForm from '../shared/JobTemplateForm';
import { JobTemplatesAPI } from '@api'; import { JobTemplatesAPI, OrganizationsAPI } from '@api';
function JobTemplateAdd() { function JobTemplateAdd() {
const [formSubmitError, setFormSubmitError] = useState(null); 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 => const associationPromises = labels.map(label =>
JobTemplatesAPI.associateLabel(templateId, label, organizationId) JobTemplatesAPI.associateLabel(templateId, label, orgId)
); );
return Promise.all([...associationPromises]); return Promise.all([...associationPromises]);
} }

View File

@@ -4,7 +4,7 @@ import { withRouter, Redirect } from 'react-router-dom';
import { CardBody } from '@components/Card'; import { CardBody } from '@components/Card';
import ContentError from '@components/ContentError'; import ContentError from '@components/ContentError';
import ContentLoading from '@components/ContentLoading'; import ContentLoading from '@components/ContentLoading';
import { JobTemplatesAPI, ProjectsAPI } from '@api'; import { JobTemplatesAPI, OrganizationsAPI, ProjectsAPI } from '@api';
import { JobTemplate } from '@types'; import { JobTemplate } from '@types';
import { getAddedAndRemoved } from '@util/lists'; import { getAddedAndRemoved } from '@util/lists';
import JobTemplateForm from '../shared/JobTemplateForm'; 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; const { template } = this.props;
let orgId = formOrgId;
const { added, removed } = getAddedAndRemoved( const { added, removed } = getAddedAndRemoved(
template.summary_fields.labels.results, template.summary_fields.labels.results,
labels labels
); );
if (!orgId && added.length > 0) {
const {
data: { results },
} = await OrganizationsAPI.read();
orgId = results[0].id;
}
const disassociationPromises = removed.map(label => const disassociationPromises = removed.map(label =>
JobTemplatesAPI.disassociateLabel(template.id, label) JobTemplatesAPI.disassociateLabel(template.id, label)
); );
const associationPromises = added.map(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([ const results = await Promise.all([

View File

@@ -36,8 +36,8 @@ function LabelSelect({ value, placeholder, onChange, onError }) {
); );
const [isExpanded, setIsExpanded] = useState(false); const [isExpanded, setIsExpanded] = useState(false);
const toggleExpanded = () => { const toggleExpanded = toggleValue => {
setIsExpanded(!isExpanded); setIsExpanded(toggleValue);
}; };
useEffect(() => { useEffect(() => {