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

CM-327: change the way how task updates are fetched #15

Merged
merged 1 commit into from
Sep 29, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ export const clearTaskGroup = () => (dispatch) => {
});
};

export const clearTask = () => (dispatch) => {
dispatch({
type: CLEAR(ACTION_TYPE.GET_TASK),
});
};

export function deleteTaskGroup(taskGroup, clientMutationLabel) {
const taskGroupsUuids = `ids: ["${decodeId(taskGroup?.id)}"]`;
return PERFORM_MUTATION(
Expand Down
2 changes: 0 additions & 2 deletions src/components/TaskApprovementPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ function TaskApprovementPanel({
mutation,
journalize,
confirmed,
setIsSaved,
}) {
const modulesManager = useModulesManager();
const classes = useStyles();
Expand Down Expand Up @@ -80,7 +79,6 @@ function TaskApprovementPanel({
user,
approveOrFail,
);
setIsSaved(true);
}
}
return () => confirmed && clearConfirm(false);
Expand Down
27 changes: 21 additions & 6 deletions src/pages/TaskDetailsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import _ from 'lodash';
import TaskHeadPanel from '../components/TaskHeadPanel';
import TaskPreviewPanel from '../components/TaskPreviewPanel';
import TaskApprovementPanel from '../components/TaskApprovementPanel';
import { fetchTask, updateTask } from '../actions';
import { clearTask, fetchTask, updateTask } from '../actions';
import { TASK_STATUS as taskStatus } from '../constants';

const useStyles = makeStyles((theme) => ({
Expand All @@ -27,28 +27,39 @@ function TaskDetailsPage({
fetchTask,
updateTask,
currentUser,
submittingMutation,
mutation,
clearTask,
}) {
const modulesManager = useModulesManager();
const classes = useStyles();
const history = useHistory();
const { formatMessage } = useTranslations('tasksManagement', modulesManager);
const [editedTask, setEditedTask] = useState({});
const [isSaved, setIsSaved] = useState(false);
const back = () => history.goBack();

useEffect(() => {
if (taskUuid) {
fetchTask(modulesManager, [`id: "${taskUuid}"`]);
setIsSaved(false);
}
}, [taskUuid, isSaved]);
}, [taskUuid]);

useEffect(() => {
if (submittingMutation && mutation?.clientMutationId) {
fetchTask(modulesManager, [`clientMutationId: "${mutation?.clientMutationId}"`]);
}
}, [submittingMutation]);

useEffect(() => {
if (task) {
setEditedTask(task);
}
}, [task]);

useEffect(() => () => {
clearTask();
}, []);

const doesTaskChange = () => {
if (_.isEqual(task, editedTask)) return false;
return true;
Expand All @@ -64,7 +75,6 @@ function TaskDetailsPage({
editedTask,
formatMessage('task.update.mutationLabel'),
);
setIsSaved(true);
}
};

Expand Down Expand Up @@ -98,7 +108,6 @@ function TaskDetailsPage({
HeadPanel={TaskHeadPanel}
formatMessage={formatMessage}
Panels={panels()}
setIsSaved={setIsSaved}
rights={rights}
saveTooltip={formatMessage(
`tasksManagement.saveButton.tooltip.${canSave() ? 'enabled' : 'disabled'}`,
Expand All @@ -111,13 +120,19 @@ function TaskDetailsPage({
const mapDispatchToProps = (dispatch) => bindActionCreators({
fetchTask,
updateTask,
clearTask,
}, dispatch);

const mapStateToProps = (state, props) => ({
rights: !!state.core && !!state.core.user && !!state.core.user.i_user ? state.core.user.i_user.rights : [],
currentUser: !!state.core && !!state?.core?.user ? state.core.user : null,
taskUuid: props.match.params.task_uuid,
submittingMutation: state.tasksManagement.submittingMutation,
mutation: state.tasksManagement.mutation,
task: state.tasksManagement.task,
fetchingTask: state.tasksManagement.fetchingTask,
fetchedTask: state.tasksManagement.fetchedTask,
errorTask: state.tasksManagement.errorTask,
});

export default connect(mapStateToProps, mapDispatchToProps)(TaskDetailsPage);
8 changes: 8 additions & 0 deletions src/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,14 @@ function reducer(
errorTaskGroup: null,
fetchedTaskGroup: false,
};
case CLEAR(ACTION_TYPE.GET_TASK):
return {
...state,
task: null,
fetchingTask: false,
errorTask: null,
fetchedTask: false,
};
case REQUEST(ACTION_TYPE.MUTATION):
return dispatchMutationReq(state, action);
case ERROR(ACTION_TYPE.MUTATION):
Expand Down
Loading