Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-4.4] Bug 1807233: Pipeline Builder Error Icon Fix #4497

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from 'react';
import * as _ from 'lodash';
import { k8sList } from '@console/internal/module/k8s';
import { ClusterTaskModel, TaskModel } from '../../../models';
import {
Expand Down Expand Up @@ -181,6 +182,8 @@ export const useResourceValidation = (
resourceValues: PipelineResource[],
onError: UpdateErrors,
) => {
const [previousErrorIds, setPreviousErrorIds] = React.useState([]);

React.useEffect(() => {
const resourceNames = resourceValues.map((r) => r.name);

Expand All @@ -191,12 +194,35 @@ export const useResourceValidation = (
(r) => !resourceNames.includes(r.resource),
);

if (missingResources.length === 0) {
return acc;
}

return {
...acc,
[task.name]: missingResources.length !== 0 ? [TaskErrorType.MISSING_RESOURCES] : null,
[task.name]: [TaskErrorType.MISSING_RESOURCES],
};
}, {});

onError(errors);
}, [tasks, resourceValues, onError]);
if (!_.isEmpty(errors) || previousErrorIds.length > 0) {
const outputErrors = previousErrorIds.reduce((acc, id) => {
if (acc[id]) {
// Error exists, leave it alone
return acc;
}

// Error doesn't exist but we had it once, make sure it is cleared
return {
...acc,
[id]: null,
};
}, errors);

const currentErrorIds = Object.keys(outputErrors).filter((id) => !!outputErrors[id]);
if (!_.isEqual(currentErrorIds, previousErrorIds)) {
setPreviousErrorIds(currentErrorIds);
}
onError(outputErrors);
}
}, [tasks, resourceValues, onError, previousErrorIds, setPreviousErrorIds]);
};
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@ type TaskSidebarResourceProps = {
const TaskSidebarResource: React.FC<TaskSidebarResourceProps> = (props) => {
const { availableResources, onChange, resource, taskResource } = props;

const dropdownResources = availableResources.filter(({ type }) => resource.type === type);
const dropdownResources = availableResources.filter(
({ name, type }) => resource.type === type && !!name,
);

return (
<FormGroup
fieldId={resource.name}
label={resource.name}
helperText={`Only showing resources for this type (${resource.type}).`}
helperTextInvalid={
dropdownResources.length === 0
? `No resources of type ${resource.type} available. Add pipeline resources.`
: ''
dropdownResources.length === 0 ? `No resources available. Add pipeline resources.` : ''
}
isValid={dropdownResources.length > 0}
isRequired
>
<Dropdown
title="Select resource..."
title={`Select ${resource.type} resource...`}
items={dropdownResources.reduce((acc, { name }) => ({ ...acc, [name]: name }), {})}
disabled={dropdownResources.length === 0}
selectedKey={taskResource?.resource || ''}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,11 +328,15 @@ const updateTask: UpdateOperationAction<UpdateOperationUpdateTaskData> = (

return {
tasks: updatedTasks,
listTasks: listTasks.map(
(listTask) =>
canRename && mapReplaceRelatedInOthers(newName, thisPipelineTask.name, listTask),
),
errors: getErrors(updatedResource, taskResource),
listTasks: canRename
? listTasks.map((listTask) =>
mapReplaceRelatedInOthers(newName, thisPipelineTask.name, listTask),
)
: listTasks,
errors: {
[thisPipelineTask.name]: null,
...getErrors(updatedResource, taskResource),
},
};
};

Expand Down