Skip to content

Commit

Permalink
add archives error page
Browse files Browse the repository at this point in the history
  • Loading branch information
mwangggg committed Feb 26, 2024
1 parent 21b16c3 commit 01ab2b1
Showing 1 changed file with 34 additions and 3 deletions.
37 changes: 34 additions & 3 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 { 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 Down Expand Up @@ -122,6 +125,14 @@ export const AllTargetsArchivedRecordingsTable: React.FC<AllTargetsArchivedRecor
[setArchivesForTargets, setIsLoading],
);

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

/* eslint-disable @typescript-eslint/no-explicit-any */
const refreshArchivesForTargets = React.useCallback(() => {
setIsLoading(true);
Expand All @@ -145,9 +156,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 @@ -374,7 +388,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'}
message={errorMessage}
retry={isAuthFail(errorMessage) ? authRetry : undefined}
/>
</>
);
} else if (isLoading) {
view = <LoadingView />;
} else if (!searchedArchivesForTargets.length) {
view = (
Expand Down

0 comments on commit 01ab2b1

Please sign in to comment.