Skip to content

Commit

Permalink
fix(archives): add archives error page (#1216)
Browse files Browse the repository at this point in the history
  • Loading branch information
mwangggg authored Feb 27, 2024
1 parent 21b16c3 commit 8c5cd31
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 8 deletions.
45 changes: 42 additions & 3 deletions src/app/Archives/AllArchivedRecordingsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { ErrorView } from '@app/ErrorView/ErrorView';
import { authFailMessage, isAuthFail } from '@app/ErrorView/types';
import { ArchivedRecordingsTable } from '@app/Recordings/ArchivedRecordingsTable';
import { LoadingView } from '@app/Shared/Components/LoadingView';
import { ArchivedRecording, RecordingDirectory, Target, NotificationCategory } from '@app/Shared/Services/api.types';
Expand Down Expand Up @@ -78,6 +80,7 @@ export const AllArchivedRecordingsTable: React.FC<AllArchivedRecordingsTableProp
const [directories, setDirectories] = React.useState<_RecordingDirectory[]>([]);
const [searchText, setSearchText] = React.useState('');
const [expandedDirectories, setExpandedDirectories] = React.useState<_RecordingDirectory[]>([]);
const [errorMessage, setErrorMessage] = React.useState('');
const [isLoading, setIsLoading] = React.useState(false);
const addSubscription = useSubscriptions();
const [sortBy, getSortParams] = useSort();
Expand All @@ -90,12 +93,23 @@ export const AllArchivedRecordingsTable: React.FC<AllArchivedRecordingsTableProp
[setDirectories, setIsLoading],
);

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

const refreshDirectoriesAndCounts = React.useCallback(() => {
setIsLoading(true);
addSubscription(
context.api.doGet<RecordingDirectory[]>('fs/recordings', 'beta').subscribe(handleDirectoriesAndCounts),
context.api.doGet<RecordingDirectory[]>('fs/recordings', 'beta').subscribe({
next: handleDirectoriesAndCounts,
error: handleError,
}),
);
}, [addSubscription, context.api, setIsLoading, handleDirectoriesAndCounts]);
}, [addSubscription, context.api, setIsLoading, handleDirectoriesAndCounts, handleError]);

const handleSearchInput = React.useCallback(
(searchInput: string) => {
Expand Down Expand Up @@ -134,6 +148,14 @@ export const AllArchivedRecordingsTable: React.FC<AllArchivedRecordingsTableProp
);
}, [directories, searchText, sortBy]);

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

React.useEffect(() => {
if (!context.settings.autoRefreshEnabled()) {
return;
Expand Down Expand Up @@ -262,7 +284,24 @@ export const AllArchivedRecordingsTable: React.FC<AllArchivedRecordingsTableProp
}, [directoryRows, recordingRows]);

let view: JSX.Element;
if (isLoading) {

const authRetry = React.useCallback(() => {
context.target.setAuthRetry();
}, [context.target]);

const isError = React.useMemo(() => errorMessage != '', [errorMessage]);

if (isError) {
view = (
<>
<ErrorView
title={'Error retrieving archived recordings in All Archives View'}
message={errorMessage}
retry={isAuthFail(errorMessage) ? authRetry : undefined}
/>
</>
);
} else if (isLoading) {
view = <LoadingView />;
} else if (!searchedDirectories.length) {
view = (
Expand Down
48 changes: 44 additions & 4 deletions src/app/Archives/AllTargetsArchivedRecordingsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { ErrorView } from '@app/ErrorView/ErrorView';
import { authFailMessage, isAuthFail } from '@app/ErrorView/types';
import { ArchivedRecordingsTable } from '@app/Recordings/ArchivedRecordingsTable';
import { LoadingView } from '@app/Shared/Components/LoadingView';
import { Target, TargetDiscoveryEvent, NotificationCategory } from '@app/Shared/Services/api.types';
Expand Down Expand Up @@ -82,6 +84,7 @@ export const AllTargetsArchivedRecordingsTable: React.FC<AllTargetsArchivedRecor
const [archivesForTargets, setArchivesForTargets] = React.useState<ArchivesForTarget[]>([]);
const [expandedTargets, setExpandedTargets] = React.useState([] as Target[]);
const [hideEmptyTargets, setHideEmptyTargets] = React.useState(true);
const [errorMessage, setErrorMessage] = React.useState('');
const [isLoading, setIsLoading] = React.useState(false);
const addSubscription = useSubscriptions();
const [sortBy, getSortParams] = useSort();
Expand All @@ -105,6 +108,7 @@ export const AllTargetsArchivedRecordingsTable: React.FC<AllTargetsArchivedRecor
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
(targetNodes: any[]) => {
setIsLoading(false);
setErrorMessage('');
setArchivesForTargets(
targetNodes.map((node) => {
const target: Target = {
Expand All @@ -119,7 +123,15 @@ export const AllTargetsArchivedRecordingsTable: React.FC<AllTargetsArchivedRecor
}),
);
},
[setArchivesForTargets, setIsLoading],
[setArchivesForTargets, setIsLoading, setErrorMessage],
);

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

/* eslint-disable @typescript-eslint/no-explicit-any */
Expand All @@ -145,9 +157,12 @@ export const AllTargetsArchivedRecordingsTable: React.FC<AllTargetsArchivedRecor
}`,
)
.pipe(map((v) => v.data.targetNodes))
.subscribe(handleArchivesForTargets),
.subscribe({
next: handleArchivesForTargets,
error: handleError,
}),
);
}, [addSubscription, context.api, setIsLoading, handleArchivesForTargets]);
}, [addSubscription, context.api, setIsLoading, handleArchivesForTargets, handleError]);

/* eslint-disable @typescript-eslint/no-explicit-any */
const getCountForNewTarget = React.useCallback(
Expand Down Expand Up @@ -260,6 +275,14 @@ export const AllTargetsArchivedRecordingsTable: React.FC<AllTargetsArchivedRecor
);
}, [searchText, archivesForTargets, sortBy, hideEmptyTargets]);

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

React.useEffect(() => {
if (!context.settings.autoRefreshEnabled()) {
return;
Expand Down Expand Up @@ -374,7 +397,24 @@ export const AllTargetsArchivedRecordingsTable: React.FC<AllTargetsArchivedRecor
}, [targetRows, recordingRows]);

let view: JSX.Element;
if (isLoading) {

const authRetry = React.useCallback(() => {
context.target.setAuthRetry();
}, [context.target]);

const isError = React.useMemo(() => errorMessage != '', [errorMessage]);

if (isError) {
view = (
<>
<ErrorView
title={'Error retrieving archived recordings in All Targets View'}
message={errorMessage}
retry={isAuthFail(errorMessage) ? authRetry : undefined}
/>
</>
);
} else if (isLoading) {
view = <LoadingView />;
} else if (!searchedArchivesForTargets.length) {
view = (
Expand Down
1 change: 0 additions & 1 deletion src/app/Shared/Services/Api.service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import {
EventProbe,
EventProbesResponse,
Recording,
AssetJwtResponse,
EventTemplate,
RuleResponse,
ArchivedRecording,
Expand Down

0 comments on commit 8c5cd31

Please sign in to comment.