Skip to content

Commit

Permalink
update npl sentence form check
Browse files Browse the repository at this point in the history
  • Loading branch information
Salam-Dalloul committed Oct 31, 2024
1 parent dfe9c18 commit f1c5685
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 14 deletions.
9 changes: 5 additions & 4 deletions frontend/src/Pages/SentenceDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import TagForm from "../components/Forms/TagForm";
import {
Sentence,
SentenceConnectivityStatement,
SentenceAvailableTransitionsEnum, ComposerSentenceListStateEnum,
SentenceAvailableTransitionsEnum,
ComposerSentenceListStateEnum,
SentenceAvailableTransitionsEnum as SentenceStates,
} from "../apiclient/backend/api";
import { userProfile } from "../services/UserService";
import CheckDuplicates from "../components/CheckForDuplicates/CheckDuplicatesDialog";
import { SentenceStateChip } from "../components/Widgets/StateChip";
import { SentenceLabels, formatDate, formatTime } from "../helpers/helpers";
Expand Down Expand Up @@ -203,7 +204,7 @@ const SentencesDetails = () => {
);
}

const isDisabled = sentence.owner?.id !== userProfile.getUser().id;
const isDisabled = sentence?.state === SentenceStates.ComposeNow;

return (
<Grid p={6} container>
Expand Down Expand Up @@ -278,7 +279,7 @@ const SentencesDetails = () => {
handleClick={handleClick}
selectedOption={
SentenceLabels[
sentence?.available_transitions[selectedIndex]
sentence?.available_transitions?.[selectedIndex]
]
}
options={sentence?.available_transitions}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/Forms/SentenceForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const SentenceForm = (props: any) => {
...schema,
"title": ""
}

console.log(data)
return (
<Paper sx={sectionStyle}>
<Box mb={3}>
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/helpers/ownershipAlert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export const checkSentenceOwnership = (
sentenceService.assignOwner(fetchedData.id, {})
.then(() => {
return onSave(fetchedData, userId)
.then(() => resolve(ChangeRequestStatus.SAVED))
.then(() => resolve(fetchedData))
.catch((error) => reject(error));
})
.catch((error) => {
Expand All @@ -75,11 +75,11 @@ export const checkSentenceOwnership = (
});
} else {
onCancel(fetchedData, userId);
resolve(ChangeRequestStatus.CANCELLED);
resolve(fetchedData);
}
} else {
onSave(fetchedData, userId)
.then(() => resolve(ChangeRequestStatus.SAVED))
.then(() => resolve(fetchedData))
.catch((error) => reject(error));
}
})
Expand Down
25 changes: 19 additions & 6 deletions frontend/src/services/SentenceService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { PaginatedSentenceList, PatchedSentence, Sentence} from '../apiclient/ba
import { AbstractService } from "./AbstractService";
import { QueryParams } from "../redux/sentenceSlice";
import { checkSentenceOwnership} from "../helpers/ownershipAlert";
import {ChangeRequestStatus} from "../helpers/settings";


class SentenceService extends AbstractService {
Expand All @@ -12,7 +11,21 @@ class SentenceService extends AbstractService {
return composerApi.composerSentenceCreate(sentence).then((response: any) => response.data)
}
else {
return composerApi.composerSentenceUpdate(sentence.id, sentence).then((response: any) => response.data)
try {
return await composerApi.composerSentenceUpdate(sentence.id, sentence).then((response: any) => response.data)
} catch (err) {
return await checkSentenceOwnership(
sentence.id,
async () => {
return await composerApi.composerSentenceUpdate(sentence.id, sentence).then((response: any) => response.data)
},
(fetchedData, userId) => {
return fetchedData;
},
(owner) =>
`This sentence is currently assigned to ${owner.first_name}. You are in read-only mode. Would you like to assign this statement to yourself and gain edit access?`
);
}
}
}
async getObject(id: string): Promise<Sentence> {
Expand All @@ -31,9 +44,9 @@ class SentenceService extends AbstractService {
async () => {
return await composerApi.composerSentenceAddTagCreate(id, tagId).then((response: any) => response.data)
},
() => {
(fetchedData) => {
onCancel();
return ChangeRequestStatus.CANCELLED;
return fetchedData;
},
(owner) =>
`This sentence is currently assigned to ${owner.first_name}. You are in read-only mode. Would you like to assign this statement to yourself and gain edit access?`
Expand All @@ -49,9 +62,9 @@ class SentenceService extends AbstractService {
async () => {
return await composerApi.composerSentenceDelTagCreate(id, tagId).then((response: any) => response.data)
},
() => {
(fetchedData) => {
onCancel();
return ChangeRequestStatus.CANCELLED;
return fetchedData;
},
(owner) =>
`This sentence is currently assigned to ${owner.first_name}. You are in read-only mode. Would you like to assign this statement to yourself and gain edit access?`
Expand Down

0 comments on commit f1c5685

Please sign in to comment.