Skip to content

Commit

Permalink
add fix in all archives view
Browse files Browse the repository at this point in the history
  • Loading branch information
mwangggg committed Feb 26, 2024
1 parent f516e29 commit 4a0f9a9
Show file tree
Hide file tree
Showing 2 changed files with 56 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
19 changes: 14 additions & 5 deletions src/app/Archives/AllTargetsArchivedRecordingsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/
import { ErrorView } from '@app/ErrorView/ErrorView';
import { isAuthFail } from '@app/ErrorView/types';
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 @@ -108,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 @@ -122,7 +123,7 @@ export const AllTargetsArchivedRecordingsTable: React.FC<AllTargetsArchivedRecor
}),
);
},
[setArchivesForTargets, setIsLoading],
[setArchivesForTargets, setIsLoading, setErrorMessage],
);

const handleError = React.useCallback(
Expand Down Expand Up @@ -274,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 @@ -351,7 +360,7 @@ export const AllTargetsArchivedRecordingsTable: React.FC<AllTargetsArchivedRecor
{target.alias == target.connectUrl || !target.alias
? `${target.connectUrl}`
: `${target.alias} (${target.connectUrl})`}
</Td>
</Td>
<Td key={`target-table-row-${idx}_3`} dataLabel={tableColumns[1].title}>
<Badge key={`${idx}_count`}>{archiveCount}</Badge>
</Td>
Expand Down Expand Up @@ -399,9 +408,9 @@ export const AllTargetsArchivedRecordingsTable: React.FC<AllTargetsArchivedRecor
view = (
<>
<ErrorView
title={'Error retrieving archived recordings in target view'}
title={'Error retrieving archived recordings in All Targets View'}
message={errorMessage}
retry={isAuthFail(errorMessage) ? authRetry : undefined}
retry={isAuthFail(errorMessage) ? authRetry : undefined}
/>
</>
);
Expand Down

0 comments on commit 4a0f9a9

Please sign in to comment.