Skip to content

Commit

Permalink
CM-139: fix issues from QA (#4)
Browse files Browse the repository at this point in the history
* CM-139: fix comparing edited and fetch object

* CM-139: fix formatting of taskGroup
  • Loading branch information
jdolkowski authored Jul 11, 2023
1 parent 7fc2d92 commit 04ec909
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 21 deletions.
6 changes: 3 additions & 3 deletions src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ const TASK_FULL_PROJECTION = () => [
];

export const formatTaskGroupGQL = (taskGroup) => {
const executors = taskGroup?.executors?.map((executor) => decodeId(executor.id));
const executors = taskGroup?.taskexecutorSet?.map((executor) => decodeId(executor.id));
const executorsString = executors ? `[${executors.map((executorUuid) => `"${executorUuid}"`).join(', ')}]` : '[]';
return `
${taskGroup?.code ? `code: "${formatGQLString(taskGroup.code)}"` : ''}
${taskGroup?.completionPolicy ? `completionPolicy: ${taskGroup.completionPolicy}` : ''}
${taskGroup?.id ? `id: "${decodeId(taskGroup.id)}"` : ''}
${taskGroup?.executors ? `userIds: ${executorsString}` : 'userIds: []'}
${taskGroup?.id ? `id: "${taskGroup.id}"` : ''}
${taskGroup?.taskexecutorSet ? `userIds: ${executorsString}` : 'userIds: []'}
`;
};

Expand Down
4 changes: 2 additions & 2 deletions src/components/groups-management/TaskGroupHeadPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ class TaskGroupHeadPanel extends FormPanel {
required
readOnly={readOnly}
groupId={taskGroup?.uuid}
value={taskGroup?.executors}
onChange={(executors) => this.updateAttribute('executors', executors)}
value={taskGroup?.taskexecutorSet}
onChange={(executors) => this.updateAttribute('taskexecutorSet', executors)}
/>
</Grid>
</Grid>
Expand Down
5 changes: 4 additions & 1 deletion src/components/groups-management/TaskGroupsSearcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ function TaskGroupsSearcher({
mutation,
deleteTaskGroup,
fetchTaskGroups,
fetchedTaskGroups,
fetchingTaskGroups,
errorTaskGroups,
taskGroups,
Expand Down Expand Up @@ -159,7 +160,8 @@ function TaskGroupsSearcher({
fetch={fetch}
items={taskGroups}
itemsPageInfo={taskGroupsPageInfo}
fetchedItems={fetchingTaskGroups}
fetchedItems={fetchedTaskGroups}
fetchingItems={fetchingTaskGroups}
errorItems={errorTaskGroups}
tableTitle={formatMessageWithValues('taskGroup.searcherResultsTitle', { taskGroupsTotalCount })}
headers={headers}
Expand All @@ -179,6 +181,7 @@ function TaskGroupsSearcher({

const mapStateToProps = (state) => ({
fetchingTaskGroups: state.tasksManagement.fetchingTaskGroups,
fetchedTaskGroups: state.tasksManagement.fetchedTaskGroups,
errorTaskGroups: state.tasksManagement.errorTaskGroups,
taskGroups: state.tasksManagement.taskGroups,
taskGroupsPageInfo: state.tasksManagement.taskGroupsPageInfo,
Expand Down
20 changes: 6 additions & 14 deletions src/pages/TaskGroupPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,13 @@ function TaskGroupPage({
}
}, [taskGroupUuid]);

const mandatoryFieldsEmpty = () => !editedTaskGroup?.code
|| !editedTaskGroup?.completionPolicy || !editedTaskGroup?.executors?.length;

const doesTaskGroupChange = () => {
if (_.isEqual(taskGroup, editedTaskGroup)) return false;
return true;
const mandatoryFieldsEmpty = () => {
const code = editedTaskGroup?.code?.trim();
return !code || !editedTaskGroup?.completionPolicy || !editedTaskGroup?.taskexecutorSet?.length;
};

const doesTaskGroupChange = () => !_.isEqual(taskGroup, editedTaskGroup);

const canSave = () => !mandatoryFieldsEmpty() && doesTaskGroupChange();

const handleSave = () => {
Expand Down Expand Up @@ -105,14 +104,7 @@ function TaskGroupPage({
});

useEffect(() => {
const storedTaskGroup = { ...taskGroup };
const currentExecutors = storedTaskGroup?.taskexecutorSet?.edges?.map((executor) => executor.node.user);

delete storedTaskGroup.taskexecutorSet;

const formattedTaskGroup = { ...storedTaskGroup, executors: currentExecutors };

setEditedTaskGroup(formattedTaskGroup);
setEditedTaskGroup(taskGroup);
}, [taskGroup]);

useEffect(() => () => dispatch(clearTaskGroup()), []);
Expand Down
6 changes: 5 additions & 1 deletion src/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,11 @@ function reducer(
case SUCCESS(ACTION_TYPE.GET_TASK_GROUP):
return {
...state,
taskGroup: parseData(action.payload.data.taskGroup)?.[0],
taskGroup: parseData(action.payload.data.taskGroup)?.map((taskGroup) => ({
...taskGroup,
id: decodeId(taskGroup.id),
taskexecutorSet: taskGroup?.taskexecutorSet?.edges?.map((executor) => executor.node.user),
}))?.[0],
fetchingTaskGroup: false,
errorTaskGroup: formatGraphQLError(action.payload),
fetchedTaskGroup: true,
Expand Down

0 comments on commit 04ec909

Please sign in to comment.