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

refactor: [M3-7437] - Prepare Profile Queries for React Query v5 #9991

Closed
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
1 change: 1 addition & 0 deletions packages/manager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
"tss-react": "^4.8.2",
"typescript-fsa": "^3.0.0",
"typescript-fsa-reducers": "^1.2.0",
"@bnussman/query-key": "0.0.7",
"xterm": "^4.2.0",
"yup": "^0.32.9",
"zxcvbn": "^4.4.2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { TextField } from 'src/components/TextField';
import { Typography } from 'src/components/Typography';
import { InputAdornment } from 'src/components/InputAdornment';
import {
queryKey,
profileQueries,
updateProfileData,
useProfile,
useSendPhoneVerificationCodeMutation,
Expand Down Expand Up @@ -94,7 +94,7 @@ export const PhoneVerification = () => {
);
} else {
// Cloud Manager does not know about the country, so lets refetch the user's phone number so we know it's displaying correctly
queryClient.invalidateQueries(queryKey);
queryClient.invalidateQueries(profileQueries.profile.queryKey);
}

// reset form states
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { useQueryClient } from 'react-query';
import { StyledLinkButton } from 'src/components/Button/StyledLinkButton';
import { Notice } from 'src/components/Notice/Notice';
import { Typography } from 'src/components/Typography';
import { queryKey } from 'src/queries/profile';
import { useSecurityQuestions } from 'src/queries/securityQuestions';
import { getAPIErrorOrDefault } from 'src/utilities/errorUtils';
import { getAPIErrorFor } from 'src/utilities/getAPIErrorFor';
Expand All @@ -20,6 +19,7 @@ import {
StyledRootContainer,
} from './TwoFactor.styles';
import { TwoFactorToggle } from './TwoFactorToggle';
import { profileQueries } from 'src/queries/profile';

export interface TwoFactorProps {
disabled?: boolean;
Expand Down Expand Up @@ -61,7 +61,7 @@ export const TwoFactor = (props: TwoFactorProps) => {
*/
const handleEnableSuccess = (scratchCode: string) => {
// Refetch Profile with React Query so profile is up to date
queryClient.invalidateQueries(queryKey);
queryClient.invalidateQueries(profileQueries.profile.queryKey);
setSuccess('Two-factor authentication has been enabled.');
setShowQRCode(false);
setTwoFactorEnabled(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ import {
withQueryClient,
} from 'src/containers/withQueryClient.container';
import { StackScriptForm } from 'src/features/StackScripts/StackScriptForm/StackScriptForm';
import { queryKey } from 'src/queries/profile';
import { filterImagesByType } from 'src/store/image/image.helpers';
import { getAPIErrorFor } from 'src/utilities/getAPIErrorFor';
import { scrollErrorIntoView } from 'src/utilities/scrollErrorIntoView';
import { storage } from 'src/utilities/storage';
import { profileQueries } from 'src/queries/profile';

interface State {
apiResponse?: StackScript;
Expand Down Expand Up @@ -361,7 +361,9 @@ export class StackScriptCreate extends React.Component<CombinedProps, State> {
return;
}
if (profile.data?.restricted) {
queryClient.invalidateQueries([queryKey, 'grants']);
queryClient.invalidateQueries(
profileQueries.profile().grants.queryKey
);
}
this.setState({ isSubmitting: false });
this.resetAllFields();
Expand Down
4 changes: 2 additions & 2 deletions packages/manager/src/queries/databases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import { EventWithStore } from 'src/events';
import { getAll } from 'src/utilities/getAll';

import { queryPresets, updateInPaginatedStore } from './base';
import { queryKey as PROFILE_QUERY_KEY } from './profile';
import { profileQueries } from './profile';

export const queryKey = 'databases';

Expand Down Expand Up @@ -116,7 +116,7 @@ export const useCreateDatabaseMutation = () => {
// Add database to the cache
queryClient.setQueryData([queryKey, data.id], data);
// If a restricted user creates an entity, we must make sure grants are up to date.
queryClient.invalidateQueries([PROFILE_QUERY_KEY, 'grants']);
queryClient.invalidateQueries(profileQueries.profile().grants.queryKey);
},
}
);
Expand Down
5 changes: 2 additions & 3 deletions packages/manager/src/queries/domains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ import { useMutation, useQuery, useQueryClient } from 'react-query';

import { EventWithStore } from 'src/events';
import { getAll } from 'src/utilities/getAll';

import { queryKey as PROFILE_QUERY_KEY } from './profile';
import { profileQueries } from './profile';

export const queryKey = 'domains';

Expand Down Expand Up @@ -57,7 +56,7 @@ export const useCreateDomainMutation = () => {
queryClient.invalidateQueries([queryKey, 'paginated']);
queryClient.setQueryData([queryKey, 'domain', domain.id], domain);
// If a restricted user creates an entity, we must make sure grants are up to date.
queryClient.invalidateQueries([PROFILE_QUERY_KEY, 'grants']);
queryClient.invalidateQueries(profileQueries.profile().grants.queryKey);
},
});
};
Expand Down
4 changes: 2 additions & 2 deletions packages/manager/src/queries/firewalls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { queryKey as linodesQueryKey } from 'src/queries/linodes/linodes';
import { getAll } from 'src/utilities/getAll';

import { updateInPaginatedStore } from './base';
import { queryKey as PROFILE_QUERY_KEY } from './profile';
import { profileQueries } from './profile';

export const queryKey = 'firewall';

Expand Down Expand Up @@ -123,7 +123,7 @@ export const useCreateFirewall = () => {
queryClient.invalidateQueries([queryKey, 'paginated']);
queryClient.setQueryData([queryKey, 'firewall', firewall.id], firewall);
// If a restricted user creates an entity, we must make sure grants are up to date.
queryClient.invalidateQueries([PROFILE_QUERY_KEY, 'grants']);
queryClient.invalidateQueries(profileQueries.profile().grants.queryKey);
},
}
);
Expand Down
4 changes: 2 additions & 2 deletions packages/manager/src/queries/images.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { EventWithStore } from 'src/events';
import { getAll } from 'src/utilities/getAll';

import { doesItemExistInPaginatedStore, updateInPaginatedStore } from './base';
import { queryKey as PROFILE_QUERY_KEY } from './profile';
import { profileQueries } from './profile';

export const queryKey = 'images';

Expand Down Expand Up @@ -55,7 +55,7 @@ export const useCreateImageMutation = () => {
onSuccess() {
queryClient.invalidateQueries(`${queryKey}-list`);
// If a restricted user creates an entity, we must make sure grants are up to date.
queryClient.invalidateQueries([PROFILE_QUERY_KEY, 'grants']);
queryClient.invalidateQueries(profileQueries.profile().grants.queryKey);
},
}
);
Expand Down
4 changes: 2 additions & 2 deletions packages/manager/src/queries/kubernetes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { useMutation, useQuery, useQueryClient } from 'react-query';
import { getAll } from 'src/utilities/getAll';

import { queryPresets, updateInPaginatedStore } from './base';
import { queryKey as PROFILE_QUERY_KEY } from './profile';
import { profileQueries } from './profile';

export const queryKey = `kubernetes`;

Expand Down Expand Up @@ -141,7 +141,7 @@ export const useCreateKubernetesClusterMutation = () => {
onSuccess() {
queryClient.invalidateQueries([`${queryKey}-list`]);
// If a restricted user creates an entity, we must make sure grants are up to date.
queryClient.invalidateQueries([PROFILE_QUERY_KEY, 'grants']);
queryClient.invalidateQueries(profileQueries.profile().grants.queryKey);
},
}
);
Expand Down
4 changes: 2 additions & 2 deletions packages/manager/src/queries/linodes/linodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ import { manuallySetVPCConfigInterfacesToActive } from 'src/utilities/configs';

import { queryKey as accountNotificationsQueryKey } from '../accountNotifications';
import { queryPresets } from '../base';
import { queryKey as PROFILE_QUERY_KEY } from '../profile';
import { getAllLinodeKernelsRequest, getAllLinodesRequest } from './requests';
import { profileQueries } from '../profile';

export const queryKey = 'linodes';

Expand Down Expand Up @@ -159,7 +159,7 @@ export const useCreateLinodeMutation = () => {
linode
);
// If a restricted user creates an entity, we must make sure grants are up to date.
queryClient.invalidateQueries([PROFILE_QUERY_KEY, 'grants']);
queryClient.invalidateQueries(profileQueries.profile().grants.queryKey);
},
});
};
Expand Down
4 changes: 2 additions & 2 deletions packages/manager/src/queries/nodebalancers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import { getAll } from 'src/utilities/getAll';

import { queryPresets } from './base';
import { itemInListCreationHandler, itemInListMutationHandler } from './base';
import { queryKey as PROFILE_QUERY_KEY } from './profile';
import { profileQueries } from './profile';

export const queryKey = 'nodebalancers';

Expand Down Expand Up @@ -114,7 +114,7 @@ export const useNodebalancerCreateMutation = () => {
queryClient.invalidateQueries([queryKey]);
queryClient.setQueryData([queryKey, 'nodebalancer', data.id], data);
// If a restricted user creates an entity, we must make sure grants are up to date.
queryClient.invalidateQueries([PROFILE_QUERY_KEY, 'grants']);
queryClient.invalidateQueries(profileQueries.profile().grants.queryKey);
},
}
);
Expand Down
Loading
Loading