Skip to content

Commit

Permalink
fix: issue with invalidation of applet base info query data
Browse files Browse the repository at this point in the history
  • Loading branch information
Billie He committed Oct 30, 2024
1 parent bdefb85 commit fb6f22d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/entities/applet/model/services/RefreshAppletService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { ILogger } from '@app/shared/lib/types/logger';
import { ImageUrl } from '@app/shared/lib/types/url';
import {
getActivityDetailsKey,
getAppletBaseInfoKey,
getAppletDetailsKey,
getAssignmentsKey,
getDataFromQuery,
Expand Down Expand Up @@ -80,6 +81,13 @@ export class RefreshAppletService implements IRefreshAppletService {
}
}

private resetAppletBaseInfoQuery(appletId: string) {
this.queryClient.removeQueries({
exact: true,
queryKey: getAppletBaseInfoKey(appletId),
});
}

private resetAppletDetailsQuery(appletId: string) {
this.queryClient.removeQueries({
exact: true,
Expand Down Expand Up @@ -113,6 +121,7 @@ export class RefreshAppletService implements IRefreshAppletService {
private refreshAppletCaches(
appletInternalDtos: CollectAppletInternalsResult,
) {
this.resetAppletBaseInfoQuery(appletInternalDtos.appletId);
this.resetAppletDetailsQuery(appletInternalDtos.appletId);

for (const activityDto of appletInternalDtos.activities) {
Expand Down Expand Up @@ -195,6 +204,8 @@ export class RefreshAppletService implements IRefreshAppletService {
`[RefreshAppletService.partialRefresh]: Skip refresh for Applet "${appletDto.displayName}|${appletDto.id}" as to versions are the same`,
);

this.resetAppletBaseInfoQuery(appletDto.id);

const assignmentsResponse =
allAppletAssignments.appletAssignments[appletDto.id];
if (!assignmentsResponse) {
Expand Down
4 changes: 3 additions & 1 deletion src/shared/api/services/appletsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
AppletAndActivitiesDetailsResponse,
AppletAssignmentsRequest,
AppletAssignmentsResponse,
AppletBaseInfoRequest,
AppletBaseInfoResponse,
AppletDetailsRequest,
AppletDetailsResponse,
AppletsResponse,
Expand All @@ -20,7 +22,7 @@ export function appletsService(): IAppletService {
return {
async getAppletBaseInfo(request: AppletBaseInfoRequest) {
const apiCall = () => {
return httpService.get<AppletAndActivitiesDetailsResponse>(
return httpService.get<AppletBaseInfoResponse>(
`/applets/${request.appletId}/base_info`,
);
};
Expand Down
3 changes: 3 additions & 0 deletions src/shared/lib/utils/reactQueryHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ export const hasPendingMutations = (queryClient: QueryClient): boolean => {

export const getAppletsKey = () => ['applets'] as AppQueryKey;

export const getAppletBaseInfoKey = (appletId: string) =>
['base-info', { appletId }] as AppQueryKey;

export const getAppletDetailsKey = (appletId: string) =>
['applets', { appletId }] as AppQueryKey;

Expand Down
3 changes: 2 additions & 1 deletion src/widgets/activity-group/model/hooks/useBaseInfo.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { useBaseQuery } from '@app/shared/api/hooks/useBaseQuery';
import { ResponseType } from '@app/shared/api/services/ActivityItemDto';
import { getDefaultAppletsService } from '@app/shared/api/services/appletsServiceInstance';
import { getAppletBaseInfoKey } from '@shared/lib/utils/reactQueryHelpers.ts';

import { useTimer } from './useTimer';

export const useBaseInfo = (appletId: string) => {
useTimer();

return useBaseQuery(
['base-info', { appletId }],
getAppletBaseInfoKey(appletId),
() => getDefaultAppletsService().getAppletBaseInfo({ appletId }),
{
select: data => {
Expand Down

0 comments on commit fb6f22d

Please sign in to comment.