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

fix(recordings): correctly update recording tables on errors #604

Merged
merged 2 commits into from
Nov 2, 2022
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
12 changes: 9 additions & 3 deletions src/app/Recordings/ActiveRecordingsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,9 @@ export const ActiveRecordingsTable: React.FunctionComponent<ActiveRecordingsTabl
(error) => {
setIsLoading(false);
setErrorMessage(error.message);
setRecordings([]);
},
[setIsLoading, setErrorMessage]
[setIsLoading, setErrorMessage, setRecordings]
);

const refreshRecordingList = React.useCallback(() => {
Expand Down Expand Up @@ -258,8 +259,13 @@ export const ActiveRecordingsTable: React.FunctionComponent<ActiveRecordingsTabl
}, [addSubscription, context, context.notificationChannel, setRecordings]);

React.useEffect(() => {
addSubscription(context.target.authFailure().subscribe(() => setErrorMessage(authFailMessage)));
}, [context, context.target, setErrorMessage, addSubscription]);
addSubscription(
context.target.authFailure().subscribe(() => {
setErrorMessage(authFailMessage);
setRecordings([]);
})
);
}, [context, context.target, setErrorMessage, addSubscription, setRecordings]);

React.useEffect(() => {
addSubscription(
Expand Down
41 changes: 27 additions & 14 deletions src/app/Recordings/ArchivedRecordingsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,7 @@
* SOFTWARE.
*/
import * as React from 'react';
import {
ArchivedRecording,
Recording,
RecordingDirectory,
UPLOADS_SUBDIRECTORY,
} from '@app/Shared/Services/Api.service';
import { ArchivedRecording, RecordingDirectory, UPLOADS_SUBDIRECTORY } from '@app/Shared/Services/Api.service';
import { ServiceContext } from '@app/Shared/Services/Services';
import { NotificationCategory } from '@app/Shared/Services/NotificationChannel.service';
import { useSubscriptions } from '@app/utils/useSubscriptions';
Expand Down Expand Up @@ -106,6 +101,7 @@ export const ArchivedRecordingsTable: React.FunctionComponent<ArchivedRecordings
const [showUploadModal, setShowUploadModal] = React.useState(false);
const [showDetailsPanel, setShowDetailsPanel] = React.useState(false);
const [isLoading, setIsLoading] = React.useState(false);
const [errorMessage, setErrorMessage] = React.useState('');

const targetRecordingFilters = useSelector((state: RootState) => {
const filters = state.recordingFilters.list.filter(
Expand Down Expand Up @@ -148,6 +144,15 @@ export const ArchivedRecordingsTable: React.FunctionComponent<ArchivedRecordings
[setRecordings, setIsLoading]
);

const handleError = React.useCallback(
(error) => {
setIsLoading(false);
setErrorMessage(error.message);
setRecordings([]);
},
[setIsLoading, setErrorMessage, setRecordings]
);

const queryTargetRecordings = React.useCallback(
(connectUrl: string) => {
return context.api.graphql<any>(`
Expand Down Expand Up @@ -193,7 +198,10 @@ export const ArchivedRecordingsTable: React.FunctionComponent<ArchivedRecordings
addSubscription(
queryUploadedRecordings()
.pipe(map((v) => v.data.archivedRecordings.data as ArchivedRecording[]))
.subscribe(handleRecordings)
.subscribe({
next: handleRecordings,
error: handleError,
})
);
} else {
addSubscription(
Expand All @@ -204,14 +212,18 @@ export const ArchivedRecordingsTable: React.FunctionComponent<ArchivedRecordings
concatMap((target) => queryTargetRecordings(target.connectUrl)),
map((v) => v.data.archivedRecordings.data as ArchivedRecording[])
)
.subscribe(handleRecordings)
.subscribe({
next: handleRecordings,
error: handleError,
})
);
}
}, [
addSubscription,
context.api,
setIsLoading,
handleRecordings,
handleError,
queryTargetRecordings,
queryUploadedRecordings,
props.directoryRecordings,
Expand Down Expand Up @@ -520,10 +532,9 @@ export const ArchivedRecordingsTable: React.FunctionComponent<ArchivedRecordings
));
}, [filteredRecordings, expandedRows, checkedIndices]);

const handleModalClose = React.useCallback(() => {
setShowUploadModal(false);
refreshRecordingList();
}, [setShowUploadModal, refreshRecordingList]);
const handleUploadModalClose = React.useCallback(() => {
setShowUploadModal(false); // Do nothing else as notifications will handle update
}, [setShowUploadModal]);

const LabelsPanel = React.useMemo(
() => (
Expand Down Expand Up @@ -574,12 +585,14 @@ export const ArchivedRecordingsTable: React.FunctionComponent<ArchivedRecordings
isEmptyFilterResult={!filteredRecordings.length}
clearFilters={handleClearFilters}
isNestedTable={props.isNestedTable}
errorMessage={''}
errorMessage={errorMessage}
>
{recordingRows}
</RecordingsTable>

{props.isUploadsTable ? <ArchiveUploadModal visible={showUploadModal} onClose={handleModalClose} /> : null}
{props.isUploadsTable ? (
<ArchiveUploadModal visible={showUploadModal} onClose={handleUploadModalClose} />
) : null}
</DrawerContentBody>
</DrawerContent>
</Drawer>
Expand Down
22 changes: 22 additions & 0 deletions src/test/Recordings/ArchivedRecordingsTable.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -647,4 +647,26 @@ describe('<ArchivedRecordingsTable />', () => {
expect(uploadSpy).toHaveBeenCalled();
expect(uploadSpy).toHaveBeenCalledWith(mockFileUpload, mockUploadedRecordingLabels, expect.anything());
});

it('should show error view if failing to retrieve recordings', async () => {
jest.spyOn(defaultServices.api, 'graphql').mockImplementationOnce((query) => {
throw new Error('Something wrong');
});

renderWithServiceContextAndReduxStoreWithRouter(
<ArchivedRecordingsTable target={of(mockTarget)} isUploadsTable={false} isNestedTable={false} />,
{
preloadState: preloadedState,
history: history,
}
);

const failTitle = screen.getByText('Error retrieving recordings');
expect(failTitle).toBeInTheDocument();
expect(failTitle).toBeVisible();

const authFailText = screen.getByText('Something wrong');
expect(authFailText).toBeInTheDocument();
expect(authFailText).toBeVisible();
});
});