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

Share UI Submit fix #1403

Merged
merged 3 commits into from
Jul 12, 2024
Merged
Changes from 1 commit
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
76 changes: 43 additions & 33 deletions frontend/src/modules/Shared/Shares/ShareEditForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,15 +221,28 @@ export const ShareEditForm = (props) => {
const [requestPurpose, setRequestPurpose] = useState('');
const [smthChanged, setSmthChanged] = useState(false);

const canUpdateRequestPurpose = () => {
return (
(share.userRoleForShareObject === 'Requesters' ||
share.userRoleForShareObject === 'ApproversAndRequesters') &&
(share.status === 'Draft' ||
share.status === 'Processed' ||
share.status === 'Rejected' ||
share.status === 'Submitted')
);
};

const handlePageChange = async (event, value) => {
if (value <= sharedItems.pages && value !== sharedItems.page) {
await setFilter({ ...filter, page: value });
}
};

const beforeClose = async () => {
if (smthChanged || requestPurpose !== share.requestPurpose) {
if (requestPurpose !== share.requestPurpose) {
Copy link
Contributor

@noah-paige noah-paige Jul 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to add setSmthChanged(true); for if no response errors for updateRequestPurpose then

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updateRequestPurpose doesn't change the state of Share. So, basically, there is nothing to submit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@noah-paige may be we should change that, but not before 2.6

Copy link
Contributor

@noah-paige noah-paige Jul 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

onApply just refreshed the ShareObject and associated share items in the view right?

If we do not run onApply() then I can update the request purpose --> hit Save & Close --> the share view is not updated and the old request purpose still shows

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, yes, you are right.

await updateRequestPurpose();
}
if (smthChanged) {
onApply();
} else {
onCancel();
Expand Down Expand Up @@ -447,12 +460,7 @@ export const ShareEditForm = (props) => {
name="requestPurpose"
multiline
rows={3}
disabled={
shareStatus !== 'Draft' &&
shareStatus !== 'Processed' &&
shareStatus !== 'Rejected' &&
shareStatus !== 'Submitted'
}
disabled={!canUpdateRequestPurpose()}
value={requestPurpose}
variant="outlined"
onChange={(event) => {
Expand All @@ -462,32 +470,34 @@ export const ShareEditForm = (props) => {
</CardContent>
</Box>
</Box>
{shareStatus.toUpperCase() === 'DRAFT' && (
<CardContent>
<Tooltip
title={
sharedItems.nodes.filter((item) => item.status).length === 0
? 'There is no items added into the request.'
: ''
}
>
<span>
<Button
onClick={sendRequest}
fullWidth
startIcon={<SendIcon fontSize="small" />}
color="primary"
variant="contained"
disabled={
sharedItems.nodes.filter((item) => item.status).length === 0
}
>
Submit request
</Button>
</span>
</Tooltip>
</CardContent>
)}
{shareStatus.toUpperCase() === 'DRAFT' &&
(share.userRoleForShareObject === 'Requesters' ||
share.userRoleForShareObject === 'ApproversAndRequesters') && (
<CardContent>
<Tooltip
title={
sharedItems.nodes.filter((item) => item.status).length === 0
? 'There is no items added into the request.'
: ''
}
>
<span>
<Button
onClick={sendRequest}
fullWidth
startIcon={<SendIcon fontSize="small" />}
color="primary"
variant="contained"
disabled={
sharedItems.nodes.filter((item) => item.status).length === 0
}
>
Submit request
</Button>
</span>
</Tooltip>
</CardContent>
)}
{shareStatus.toUpperCase() === 'DRAFT' && (
<CardContent>
<Button
Expand Down
Loading