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: issue with invalidation of applet base info query data (M2-8151) #885

Merged
merged 2 commits into from
Nov 4, 2024
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
20 changes: 20 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,26 @@ jobs:
prettier: true
prettier_extensions: js,jsx,ts,tsx
continue_on_error: false
tsc:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}

- name: Install deps
run: yarn install --frozen-lockfile

- uses: actions/cache@v4
with:
path: |
~/node_modules
key: ${{ runner.os }}-node-modules-${{ hashFiles('**/yarn.lock') }}

- name: Running tsc
run: yarn tsc
tests:
runs-on: ubuntu-latest
steps:
Expand Down
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,
farmerpaul marked this conversation as resolved.
Show resolved Hide resolved
AppletDetailsRequest,
AppletDetailsResponse,
AppletsResponse,
Expand All @@ -20,7 +22,7 @@ export function appletsService(): IAppletService {
return {
async getAppletBaseInfo(request: AppletBaseInfoRequest) {
const apiCall = () => {
return httpService.get<AppletAndActivitiesDetailsResponse>(
farmerpaul marked this conversation as resolved.
Show resolved Hide resolved
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
Loading