-
Notifications
You must be signed in to change notification settings - Fork 18k
fix: annotation layer modal err handling #12341
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -111,9 +111,24 @@ const AnnotationModal: FunctionComponent<AnnotationModalProps> = ({ | |
| addDangerToast, | ||
| ); | ||
|
|
||
| const resetAnnotation = () => { | ||
| // Reset annotation | ||
| setCurrentAnnotation({ | ||
| short_descr: '', | ||
| start_dttm: '', | ||
| end_dttm: '', | ||
| json_metadata: '', | ||
| long_descr: '', | ||
| }); | ||
| }; | ||
|
|
||
| // Functions | ||
| const hide = () => { | ||
| setIsHidden(true); | ||
|
|
||
| // Reset annotation | ||
| resetAnnotation(); | ||
|
|
||
| onHide(); | ||
| }; | ||
|
|
||
|
|
@@ -127,7 +142,12 @@ const AnnotationModal: FunctionComponent<AnnotationModalProps> = ({ | |
| delete currentAnnotation.changed_by; | ||
| delete currentAnnotation.changed_on_delta_humanized; | ||
| delete currentAnnotation.layer; | ||
| updateResource(update_id, currentAnnotation).then(() => { | ||
| updateResource(update_id, currentAnnotation).then(response => { | ||
| // No response on error | ||
| if (!response) { | ||
| return; | ||
| } | ||
|
|
||
| if (onAnnotationAdd) { | ||
| onAnnotationAdd(); | ||
| } | ||
|
|
@@ -137,7 +157,11 @@ const AnnotationModal: FunctionComponent<AnnotationModalProps> = ({ | |
| } | ||
| } else if (currentAnnotation) { | ||
| // Create | ||
| createResource(currentAnnotation).then(() => { | ||
| createResource(currentAnnotation).then(response => { | ||
| if (!response) { | ||
| return; | ||
| } | ||
|
|
||
| if (onAnnotationAdd) { | ||
| onAnnotationAdd(); | ||
| } | ||
|
|
@@ -206,32 +230,32 @@ const AnnotationModal: FunctionComponent<AnnotationModalProps> = ({ | |
| }; | ||
|
|
||
| // Initialize | ||
| if ( | ||
| isEditMode && | ||
| (!currentAnnotation || | ||
| !currentAnnotation.id || | ||
| (annotation && annotation.id !== currentAnnotation.id) || | ||
| (isHidden && show)) | ||
| ) { | ||
| if (annotation && annotation.id !== null && !loading) { | ||
| const id = annotation.id || 0; | ||
|
|
||
| fetchResource(id).then(() => { | ||
| setCurrentAnnotation(resource); | ||
| }); | ||
| useEffect(() => { | ||
| if ( | ||
| isEditMode && | ||
| (!currentAnnotation || | ||
| !currentAnnotation.id || | ||
| (annotation && annotation.id !== currentAnnotation.id) || | ||
| (isHidden && show)) | ||
| ) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we can split these
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can also use optional chaining to help if you want. |
||
| if (annotation && annotation.id !== null && !loading) { | ||
| const id = annotation.id || 0; | ||
|
|
||
| fetchResource(id); | ||
| } | ||
| } else if ( | ||
| !isEditMode && | ||
| (!currentAnnotation || currentAnnotation.id || (isHidden && show)) | ||
| ) { | ||
| resetAnnotation(); | ||
| } | ||
| } else if ( | ||
| !isEditMode && | ||
| (!currentAnnotation || currentAnnotation.id || (isHidden && show)) | ||
| ) { | ||
| setCurrentAnnotation({ | ||
| short_descr: '', | ||
| start_dttm: '', | ||
| end_dttm: '', | ||
| json_metadata: '', | ||
| long_descr: '', | ||
| }); | ||
| } | ||
| }, [annotation]); | ||
|
|
||
| useEffect(() => { | ||
| if (resource) { | ||
| setCurrentAnnotation(resource); | ||
| } | ||
| }, [resource]); | ||
|
|
||
| // Validation | ||
| useEffect(() => { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.