diff --git a/site/.storybook/preview.jsx b/site/.storybook/preview.jsx index fb13f0e7af320..8d8a37ecd2fbf 100644 --- a/site/.storybook/preview.jsx +++ b/site/.storybook/preview.jsx @@ -28,7 +28,7 @@ import { DecoratorHelpers } from "@storybook/addon-themes"; import isChromatic from "chromatic/isChromatic"; import { StrictMode } from "react"; import { HelmetProvider } from "react-helmet-async"; -import { QueryClient, QueryClientProvider, parseQueryArgs } from "react-query"; +import { QueryClient, QueryClientProvider } from "react-query"; import { withRouter } from "storybook-addon-remix-react-router"; import "theme/globalFonts"; import themes from "../src/theme"; @@ -114,20 +114,7 @@ function withQuery(Story, { parameters }) { if (parameters.queries) { for (const query of parameters.queries) { - if (query.isError) { - // Based on `setQueryData`, but modified to set the result as an error. - const cache = queryClient.getQueryCache(); - const parsedOptions = parseQueryArgs(query.key); - const defaultedOptions = queryClient.defaultQueryOptions(parsedOptions); - // Adds an uninitialized response to the cache, which we can now mutate. - const cachedQuery = cache.build(queryClient, defaultedOptions); - // Setting `manual` prevents retries. - cachedQuery.setData(undefined, { manual: true }); - // Set the `error` value and the appropriate status. - cachedQuery.setState({ error: query.data, status: "error" }); - } else { - queryClient.setQueryData(query.key, query.data); - } + queryClient.setQueryData(query.key, query.data); } } diff --git a/site/package.json b/site/package.json index 1bc2a9d3e159a..0154482e7d0d2 100644 --- a/site/package.json +++ b/site/package.json @@ -69,7 +69,7 @@ "@radix-ui/react-slot": "1.1.1", "@radix-ui/react-switch": "1.1.1", "@radix-ui/react-tooltip": "1.1.7", - "@tanstack/react-query-devtools": "4.35.3", + "@tanstack/react-query-devtools": "5.77.0", "@xterm/addon-canvas": "0.7.0", "@xterm/addon-fit": "0.10.0", "@xterm/addon-unicode11": "0.8.0", @@ -103,7 +103,7 @@ "react-dom": "18.3.1", "react-helmet-async": "2.0.5", "react-markdown": "9.0.3", - "react-query": "npm:@tanstack/react-query@4.35.3", + "react-query": "npm:@tanstack/react-query@5.77.0", "react-router-dom": "6.26.2", "react-syntax-highlighter": "15.6.1", "react-virtualized-auto-sizer": "1.0.24", diff --git a/site/pnpm-lock.yaml b/site/pnpm-lock.yaml index 442e5511ce229..d63a8af6d66c6 100644 --- a/site/pnpm-lock.yaml +++ b/site/pnpm-lock.yaml @@ -119,8 +119,8 @@ importers: specifier: 1.1.7 version: 1.1.7(@types/react-dom@18.3.1)(@types/react@18.3.12)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) '@tanstack/react-query-devtools': - specifier: 4.35.3 - version: 4.35.3(@tanstack/react-query@4.35.3(react-dom@18.3.1(react@18.3.1))(react@18.3.1))(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + specifier: 5.77.0 + version: 5.77.0(@tanstack/react-query@5.77.0(react@18.3.1))(react@18.3.1) '@xterm/addon-canvas': specifier: 0.7.0 version: 0.7.0(@xterm/xterm@5.5.0) @@ -221,8 +221,8 @@ importers: specifier: 9.0.3 version: 9.0.3(@types/react@18.3.12)(react@18.3.1) react-query: - specifier: npm:@tanstack/react-query@4.35.3 - version: '@tanstack/react-query@4.35.3(react-dom@18.3.1(react@18.3.1))(react@18.3.1)' + specifier: npm:@tanstack/react-query@5.77.0 + version: '@tanstack/react-query@5.77.0(react@18.3.1)' react-router-dom: specifier: 6.26.2 version: 6.26.2(react-dom@18.3.1(react@18.3.1))(react@18.3.1) @@ -2398,31 +2398,22 @@ packages: peerDependencies: tailwindcss: '>=3.0.0 || insiders || >=4.0.0-alpha.20 || >=4.0.0-beta.1' - '@tanstack/match-sorter-utils@8.8.4': - resolution: {integrity: sha512-rKH8LjZiszWEvmi01NR72QWZ8m4xmXre0OOwlRGnjU01Eqz/QnN+cqpty2PJ0efHblq09+KilvyR7lsbzmXVEw==, tarball: https://registry.npmjs.org/@tanstack/match-sorter-utils/-/match-sorter-utils-8.8.4.tgz} - engines: {node: '>=12'} + '@tanstack/query-core@5.77.0': + resolution: {integrity: sha512-PFeWjgMQjOsnxBwnW/TJoO0pCja2dzuMQoZ3Diho7dPz7FnTUwTrjNmdf08evrhSE5nvPIKeqV6R0fvQfmhGeg==, tarball: https://registry.npmjs.org/@tanstack/query-core/-/query-core-5.77.0.tgz} - '@tanstack/query-core@4.35.3': - resolution: {integrity: sha512-PS+WEjd9wzKTyNjjQymvcOe1yg8f3wYc6mD+vb6CKyZAKvu4sIJwryfqfBULITKCla7P9C4l5e9RXePHvZOZeQ==, tarball: https://registry.npmjs.org/@tanstack/query-core/-/query-core-4.35.3.tgz} + '@tanstack/query-devtools@5.76.0': + resolution: {integrity: sha512-1p92nqOBPYVqVDU0Ua5nzHenC6EGZNrLnB2OZphYw8CNA1exuvI97FVgIKON7Uug3uQqvH/QY8suUKpQo8qHNQ==, tarball: https://registry.npmjs.org/@tanstack/query-devtools/-/query-devtools-5.76.0.tgz} - '@tanstack/react-query-devtools@4.35.3': - resolution: {integrity: sha512-UvLT7qPzCuCZ3NfjwsOqDUVN84JvSOuW6ukrjZmSqgjPqVxD6ra/HUp1CEOatQY2TRvKCp8y1lTVu+trXM30fg==, tarball: https://registry.npmjs.org/@tanstack/react-query-devtools/-/react-query-devtools-4.35.3.tgz} + '@tanstack/react-query-devtools@5.77.0': + resolution: {integrity: sha512-Dwvs+ksXiK1tW4YnTtHwYPO5+d8IUk1l8QQJ4aGEIqKz6uTLu/67NIo7EnUF0G/Edv+UOn9P1V3tYWuVfvhbmg==, tarball: https://registry.npmjs.org/@tanstack/react-query-devtools/-/react-query-devtools-5.77.0.tgz} peerDependencies: - '@tanstack/react-query': ^4.35.3 - react: ^16.8.0 || ^17.0.0 || ^18.0.0 - react-dom: ^16.8.0 || ^17.0.0 || ^18.0.0 + '@tanstack/react-query': ^5.77.0 + react: ^18 || ^19 - '@tanstack/react-query@4.35.3': - resolution: {integrity: sha512-UgTPioip/rGG3EQilXfA2j4BJkhEQsR+KAbF+KIuvQ7j4MkgnTCJF01SfRpIRNtQTlEfz/+IL7+jP8WA8bFbsw==, tarball: https://registry.npmjs.org/@tanstack/react-query/-/react-query-4.35.3.tgz} + '@tanstack/react-query@5.77.0': + resolution: {integrity: sha512-jX52ot8WxWzWnAknpRSEWj6PTR/7nkULOfoiaVPk6nKu0otwt30UMBC9PTg/m1x0uhz1g71/imwjViTm/oYHxA==, tarball: https://registry.npmjs.org/@tanstack/react-query/-/react-query-5.77.0.tgz} peerDependencies: - react: ^16.8.0 || ^17.0.0 || ^18.0.0 - react-dom: ^16.8.0 || ^17.0.0 || ^18.0.0 - react-native: '*' - peerDependenciesMeta: - react-dom: - optional: true - react-native: - optional: true + react: ^18 || ^19 '@testing-library/dom@10.4.0': resolution: {integrity: sha512-pemlzrSESWbdAloYml3bAJMEfNh1Z7EduzqPKprCH5S341frlpYnUEW0H72dLxa6IsYr+mPno20GiSm+h9dEdQ==, tarball: https://registry.npmjs.org/@testing-library/dom/-/dom-10.4.0.tgz} @@ -3258,10 +3249,6 @@ packages: resolution: {integrity: sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w==, tarball: https://registry.npmjs.org/cookie/-/cookie-0.7.2.tgz} engines: {node: '>= 0.6'} - copy-anything@3.0.5: - resolution: {integrity: sha512-yCEafptTtb4bk7GLEQoM8KVJpxAfdBJYaXyzQEgQQQgYrZiDp8SJmGKlYza6CYjEDNstAdNdKA3UuoULlEbS6w==, tarball: https://registry.npmjs.org/copy-anything/-/copy-anything-3.0.5.tgz} - engines: {node: '>=12.13'} - core-util-is@1.0.3: resolution: {integrity: sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==, tarball: https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz} @@ -3635,6 +3622,7 @@ packages: eslint@8.52.0: resolution: {integrity: sha512-zh/JHnaixqHZsolRB/w9/02akBk9EPrOs9JwcTP2ek7yL5bVvXuRariiaAjjoJ5DvuwQ1WAE/HsMz+w17YgBCg==, tarball: https://registry.npmjs.org/eslint/-/eslint-8.52.0.tgz} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} + deprecated: This version is no longer supported. Please see https://eslint.org/version-support for other options. hasBin: true espree@9.6.1: @@ -4219,10 +4207,6 @@ packages: is-weakset@2.0.2: resolution: {integrity: sha512-t2yVvttHkQktwnNNmBQ98AhENLdPUTDTE21uPqAQ0ARwQfGeQKRVS0NNurH7bTf7RrvcVn1OOge45CnBeHCSmg==, tarball: https://registry.npmjs.org/is-weakset/-/is-weakset-2.0.2.tgz} - is-what@4.1.16: - resolution: {integrity: sha512-ZhMwEosbFJkA0YhFnNDgTM4ZxDRsS6HqTo7qsZM08fehyRYIYa0yHu5R6mgo1n/8MgaPBXiPimPD77baVFYg+A==, tarball: https://registry.npmjs.org/is-what/-/is-what-4.1.16.tgz} - engines: {node: '>=12.13'} - is-wsl@2.2.0: resolution: {integrity: sha512-fKzAra0rGJUUBwGBgNkHZuToZcn+TtXHpeCgmkMJMMYx1sQDYaCSyjJBSCa2nH1DGm7s3n1oBnohoVTBaN7Lww==, tarball: https://registry.npmjs.org/is-wsl/-/is-wsl-2.2.0.tgz} engines: {node: '>=8'} @@ -5516,9 +5500,6 @@ packages: remark-stringify@11.0.0: resolution: {integrity: sha512-1OSmLd3awB/t8qdoEOMazZkNsfVTeY4fTsgzcQFdXNq8ToTN4ZGwrMnlda4K6smTFKD+GRV6O48i6Z4iKgPPpw==, tarball: https://registry.npmjs.org/remark-stringify/-/remark-stringify-11.0.0.tgz} - remove-accents@0.4.2: - resolution: {integrity: sha512-7pXIJqJOq5tFgG1A2Zxti3Ht8jJF337m4sowbuHsW30ZnkQFnDzy9qBNhgzX8ZLW4+UBcXiiR7SwR6pokHsxiA==, tarball: https://registry.npmjs.org/remove-accents/-/remove-accents-0.4.2.tgz} - require-directory@2.1.1: resolution: {integrity: sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==, tarball: https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz} engines: {node: '>=0.10.0'} @@ -5835,10 +5816,6 @@ packages: engines: {node: '>=16 || 14 >=14.17'} hasBin: true - superjson@1.13.3: - resolution: {integrity: sha512-mJiVjfd2vokfDxsQPOwJ/PtanO87LhpYY88ubI5dUB1Ab58Txbyje3+jpm+/83R/fevaq/107NNhtYBLuoTrFg==, tarball: https://registry.npmjs.org/superjson/-/superjson-1.13.3.tgz} - engines: {node: '>=10'} - supports-color@5.5.0: resolution: {integrity: sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==, tarball: https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz} engines: {node: '>=4'} @@ -6152,11 +6129,6 @@ packages: '@types/react': optional: true - use-sync-external-store@1.2.0: - resolution: {integrity: sha512-eEgnFxGQ1Ife9bzYs6VLi8/4X6CObHMw9Qr9tPY43iKwsPw8xE8+EFsf/2cFZ5S3esXgpWgtSCtLNS41F+sKPA==, tarball: https://registry.npmjs.org/use-sync-external-store/-/use-sync-external-store-1.2.0.tgz} - peerDependencies: - react: ^16.8.0 || ^17.0.0 || ^18.0.0 - use-sync-external-store@1.4.0: resolution: {integrity: sha512-9WXSPC5fMv61vaupRkCKCxsPxBocVnwakBEkMIHHpkTTg6icbJtg6jzgtLDm4bl3cSHAca52rYWih0k4K3PfHw==, tarball: https://registry.npmjs.org/use-sync-external-store/-/use-sync-external-store-1.4.0.tgz} peerDependencies: @@ -8523,28 +8495,20 @@ snapshots: postcss-selector-parser: 6.0.10 tailwindcss: 3.4.17(ts-node@10.9.2(@swc/core@1.3.38)(@types/node@20.17.16)(typescript@5.6.3)) - '@tanstack/match-sorter-utils@8.8.4': - dependencies: - remove-accents: 0.4.2 + '@tanstack/query-core@5.77.0': {} - '@tanstack/query-core@4.35.3': {} + '@tanstack/query-devtools@5.76.0': {} - '@tanstack/react-query-devtools@4.35.3(@tanstack/react-query@4.35.3(react-dom@18.3.1(react@18.3.1))(react@18.3.1))(react-dom@18.3.1(react@18.3.1))(react@18.3.1)': + '@tanstack/react-query-devtools@5.77.0(@tanstack/react-query@5.77.0(react@18.3.1))(react@18.3.1)': dependencies: - '@tanstack/match-sorter-utils': 8.8.4 - '@tanstack/react-query': 4.35.3(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + '@tanstack/query-devtools': 5.76.0 + '@tanstack/react-query': 5.77.0(react@18.3.1) react: 18.3.1 - react-dom: 18.3.1(react@18.3.1) - superjson: 1.13.3 - use-sync-external-store: 1.2.0(react@18.3.1) - '@tanstack/react-query@4.35.3(react-dom@18.3.1(react@18.3.1))(react@18.3.1)': + '@tanstack/react-query@5.77.0(react@18.3.1)': dependencies: - '@tanstack/query-core': 4.35.3 + '@tanstack/query-core': 5.77.0 react: 18.3.1 - use-sync-external-store: 1.2.0(react@18.3.1) - optionalDependencies: - react-dom: 18.3.1(react@18.3.1) '@testing-library/dom@10.4.0': dependencies: @@ -9447,10 +9411,6 @@ snapshots: cookie@0.7.2: {} - copy-anything@3.0.5: - dependencies: - is-what: 4.1.16 - core-util-is@1.0.3: {} cosmiconfig@7.1.0: @@ -10542,8 +10502,6 @@ snapshots: call-bind: 1.0.8 get-intrinsic: 1.3.0 - is-what@4.1.16: {} - is-wsl@2.2.0: dependencies: is-docker: 2.2.1 @@ -12425,8 +12383,6 @@ snapshots: mdast-util-to-markdown: 2.1.0 unified: 11.0.5 - remove-accents@0.4.2: {} - require-directory@2.1.1: {} requires-port@1.0.0: {} @@ -12767,10 +12723,6 @@ snapshots: pirates: 4.0.6 ts-interface-checker: 0.1.13 - superjson@1.13.3: - dependencies: - copy-anything: 3.0.5 - supports-color@5.5.0: dependencies: has-flag: 3.0.0 @@ -13108,10 +13060,6 @@ snapshots: optionalDependencies: '@types/react': 18.3.12 - use-sync-external-store@1.2.0(react@18.3.1): - dependencies: - react: 18.3.1 - use-sync-external-store@1.4.0(react@18.3.1): dependencies: react: 18.3.1 diff --git a/site/src/api/queries/chats.ts b/site/src/api/queries/chats.ts index 196bf4c603597..d23f672f9cfaf 100644 --- a/site/src/api/queries/chats.ts +++ b/site/src/api/queries/chats.ts @@ -5,7 +5,7 @@ export const createChat = (queryClient: QueryClient) => { return { mutationFn: API.createChat, onSuccess: async () => { - await queryClient.invalidateQueries(["chats"]); + await queryClient.invalidateQueries({ queryKey: ["chats"] }); }, }; }; diff --git a/site/src/api/queries/debug.ts b/site/src/api/queries/debug.ts index 86dcb9a5585b2..06f5cc0a16fd6 100644 --- a/site/src/api/queries/debug.ts +++ b/site/src/api/queries/debug.ts @@ -13,7 +13,7 @@ export const health = () => ({ export const refreshHealth = (queryClient: QueryClient) => { return { mutationFn: async () => { - await queryClient.cancelQueries(HEALTH_QUERY_KEY); + await queryClient.cancelQueries({ queryKey: HEALTH_QUERY_KEY }); const newHealthData = await API.getHealth(true); queryClient.setQueryData(HEALTH_QUERY_KEY, newHealthData); }, @@ -38,7 +38,7 @@ export const updateHealthSettings = ( return { mutationFn: API.updateHealthSettings, onSuccess: async (_, newSettings) => { - await queryClient.invalidateQueries(HEALTH_QUERY_KEY); + await queryClient.invalidateQueries({ queryKey: HEALTH_QUERY_KEY }); queryClient.setQueryData(HEALTH_QUERY_SETTINGS_KEY, newSettings); }, }; diff --git a/site/src/api/queries/externalAuth.ts b/site/src/api/queries/externalAuth.ts index d02dad6b865e4..8a45791ab6a7a 100644 --- a/site/src/api/queries/externalAuth.ts +++ b/site/src/api/queries/externalAuth.ts @@ -37,7 +37,9 @@ export const exchangeExternalAuthDevice = ( queryKey: ["external-auth", providerId, "device", deviceCode], onSuccess: async () => { // Force a refresh of the Git auth status. - await queryClient.invalidateQueries(["external-auth", providerId]); + await queryClient.invalidateQueries({ + queryKey: ["external-auth", providerId], + }); }, }; }; @@ -57,7 +59,9 @@ export const unlinkExternalAuths = (queryClient: QueryClient) => { return { mutationFn: API.unlinkExternalAuthProvider, onSuccess: async () => { - await queryClient.invalidateQueries(["external-auth"]); + await queryClient.invalidateQueries({ + queryKey: ["external-auth"], + }); }, }; }; diff --git a/site/src/api/queries/groups.ts b/site/src/api/queries/groups.ts index dc6285e8d6de7..d21563db37e6e 100644 --- a/site/src/api/queries/groups.ts +++ b/site/src/api/queries/groups.ts @@ -117,10 +117,12 @@ export const createGroup = (queryClient: QueryClient, organization: string) => { mutationFn: (request: CreateGroupRequest) => API.createGroup(organization, request), onSuccess: async () => { - await queryClient.invalidateQueries(groupsQueryKey); - await queryClient.invalidateQueries( - getGroupsByOrganizationQueryKey(organization), - ); + await queryClient.invalidateQueries({ + queryKey: groupsQueryKey, + }); + await queryClient.invalidateQueries({ + queryKey: getGroupsByOrganizationQueryKey(organization), + }); }, }; }; @@ -169,11 +171,13 @@ const invalidateGroup = ( groupId: string, ) => Promise.all([ - queryClient.invalidateQueries(groupsQueryKey), - queryClient.invalidateQueries( - getGroupsByOrganizationQueryKey(organization), - ), - queryClient.invalidateQueries(getGroupQueryKey(organization, groupId)), + queryClient.invalidateQueries({ queryKey: groupsQueryKey }), + queryClient.invalidateQueries({ + queryKey: getGroupsByOrganizationQueryKey(organization), + }), + queryClient.invalidateQueries({ + queryKey: getGroupQueryKey(organization, groupId), + }), ]); function sortGroupsByName( diff --git a/site/src/api/queries/idpsync.ts b/site/src/api/queries/idpsync.ts index eca3ec496faee..be465ba96f7bf 100644 --- a/site/src/api/queries/idpsync.ts +++ b/site/src/api/queries/idpsync.ts @@ -9,7 +9,9 @@ export const patchOrganizationSyncSettings = (queryClient: QueryClient) => { mutationFn: (request: OrganizationSyncSettings) => API.patchOrganizationIdpSyncSettings(request), onSuccess: async () => - await queryClient.invalidateQueries(getOrganizationIdpSyncSettingsKey()), + await queryClient.invalidateQueries({ + queryKey: getOrganizationIdpSyncSettingsKey(), + }), }; }; diff --git a/site/src/api/queries/organizations.ts b/site/src/api/queries/organizations.ts index 608b2fa2a1ac4..9f392a204bd7b 100644 --- a/site/src/api/queries/organizations.ts +++ b/site/src/api/queries/organizations.ts @@ -22,7 +22,7 @@ import { type WorkspacePermissions, workspacePermissionChecks, } from "modules/permissions/workspaces"; -import type { QueryClient } from "react-query"; +import type { QueryClient, UseQueryOptions } from "react-query"; import { meKey } from "./users"; export const createOrganization = (queryClient: QueryClient) => { @@ -31,8 +31,8 @@ export const createOrganization = (queryClient: QueryClient) => { API.createOrganization(params), onSuccess: async () => { - await queryClient.invalidateQueries(meKey); - await queryClient.invalidateQueries(organizationsKey); + await queryClient.invalidateQueries({ queryKey: meKey }); + await queryClient.invalidateQueries({ queryKey: organizationsKey }); }, }; }; @@ -48,7 +48,7 @@ export const updateOrganization = (queryClient: QueryClient) => { API.updateOrganization(variables.organizationId, variables.req), onSuccess: async () => { - await queryClient.invalidateQueries(organizationsKey); + await queryClient.invalidateQueries({ queryKey: organizationsKey }); }, }; }; @@ -59,8 +59,8 @@ export const deleteOrganization = (queryClient: QueryClient) => { API.deleteOrganization(organizationId), onSuccess: async () => { - await queryClient.invalidateQueries(meKey); - await queryClient.invalidateQueries(organizationsKey); + await queryClient.invalidateQueries({ queryKey: meKey }); + await queryClient.invalidateQueries({ queryKey: organizationsKey }); }, }; }; @@ -117,7 +117,9 @@ export const addOrganizationMember = (queryClient: QueryClient, id: string) => { }, onSuccess: async () => { - await queryClient.invalidateQueries(["organization", id, "members"]); + await queryClient.invalidateQueries({ + queryKey: ["organization", id, "members"], + }); }, }; }; @@ -132,7 +134,9 @@ export const removeOrganizationMember = ( }, onSuccess: async () => { - await queryClient.invalidateQueries(["organization", id, "members"]); + await queryClient.invalidateQueries({ + queryKey: ["organization", id, "members"], + }); }, }; }; @@ -147,11 +151,9 @@ export const updateOrganizationMemberRoles = ( }, onSuccess: async () => { - await queryClient.invalidateQueries([ - "organization", - organizationId, - "members", - ]); + await queryClient.invalidateQueries({ + queryKey: ["organization", organizationId, "members"], + }); }, }; }; @@ -240,9 +242,9 @@ export const patchRoleSyncSettings = ( mutationFn: (request: RoleSyncSettings) => API.patchRoleIdpSyncSettings(request, organization), onSuccess: async () => - await queryClient.invalidateQueries( - getRoleIdpSyncSettingsKey(organization), - ), + await queryClient.invalidateQueries({ + queryKey: getRoleIdpSyncSettingsKey(organization), + }), }; }; @@ -269,12 +271,13 @@ export const provisionerJobs = ( export const organizationsPermissions = ( organizationIds: string[] | undefined, ) => { - if (!organizationIds) { - return { enabled: false }; - } - return { - queryKey: ["organizations", [...organizationIds.sort()], "permissions"], + enabled: !!organizationIds, + queryKey: [ + "organizations", + [...(organizationIds ?? []).sort()], + "permissions", + ], queryFn: async () => { // Only request what we need for the sidebar, which is one edit permission // per sub-link (settings, groups, roles, and members pages) that tells us @@ -283,7 +286,7 @@ export const organizationsPermissions = ( // The endpoint takes a flat array, so to avoid collisions prepend each // check with the org ID (the key can be anything we want). - const prefixedChecks = organizationIds.flatMap((orgId) => + const prefixedChecks = (organizationIds ?? []).flatMap((orgId) => Object.entries(organizationPermissionChecks(orgId)).map( ([key, val]) => [`${orgId}.${key}`, val], ), @@ -315,14 +318,15 @@ export const workspacePermissionsByOrganization = ( organizationIds: string[] | undefined, userId: string, ) => { - if (!organizationIds) { - return { enabled: false }; - } - return { - queryKey: ["workspaces", [...organizationIds.sort()], "permissions"], + enabled: !!organizationIds, + queryKey: [ + "workspaces", + [...(organizationIds ?? []).sort()], + "permissions", + ], queryFn: async () => { - const prefixedChecks = organizationIds.flatMap((orgId) => + const prefixedChecks = (organizationIds ?? []).flatMap((orgId) => Object.entries(workspacePermissionChecks(orgId, userId)).map( ([key, val]) => [`${orgId}.${key}`, val], ), @@ -346,7 +350,7 @@ export const workspacePermissionsByOrganization = ( {} as Record>, ) as Record; }, - }; + } satisfies UseQueryOptions>; }; const getOrganizationIdpSyncClaimFieldValuesKey = ( diff --git a/site/src/api/queries/roles.ts b/site/src/api/queries/roles.ts index 3d389237ff451..c7444a0c0c7e2 100644 --- a/site/src/api/queries/roles.ts +++ b/site/src/api/queries/roles.ts @@ -33,9 +33,9 @@ export const createOrganizationRole = ( mutationFn: (request: Role) => API.createOrganizationRole(organization, request), onSuccess: async (updatedRole: Role) => - await queryClient.invalidateQueries( - getRoleQueryKey(organization, updatedRole.name), - ), + await queryClient.invalidateQueries({ + queryKey: getRoleQueryKey(organization, updatedRole.name), + }), }; }; @@ -47,9 +47,9 @@ export const updateOrganizationRole = ( mutationFn: (request: Role) => API.updateOrganizationRole(organization, request), onSuccess: async (updatedRole: Role) => - await queryClient.invalidateQueries( - getRoleQueryKey(organization, updatedRole.name), - ), + await queryClient.invalidateQueries({ + queryKey: getRoleQueryKey(organization, updatedRole.name), + }), }; }; @@ -61,8 +61,8 @@ export const deleteOrganizationRole = ( mutationFn: (roleName: string) => API.deleteOrganizationRole(organization, roleName), onSuccess: async (_: unknown, roleName: string) => - await queryClient.invalidateQueries( - getRoleQueryKey(organization, roleName), - ), + await queryClient.invalidateQueries({ + queryKey: getRoleQueryKey(organization, roleName), + }), }; }; diff --git a/site/src/api/queries/settings.ts b/site/src/api/queries/settings.ts index 7605d16c41d6d..d4f8923e4c0c6 100644 --- a/site/src/api/queries/settings.ts +++ b/site/src/api/queries/settings.ts @@ -11,13 +11,11 @@ const userQuietHoursScheduleKey = (userId: string) => [ "quietHours", ]; -export const userQuietHoursSchedule = ( - userId: string, -): QueryOptions => { +export const userQuietHoursSchedule = (userId: string) => { return { queryKey: userQuietHoursScheduleKey(userId), queryFn: () => API.getUserQuietHoursSchedule(userId), - }; + } satisfies QueryOptions; }; export const updateUserQuietHoursSchedule = ( @@ -28,7 +26,9 @@ export const updateUserQuietHoursSchedule = ( mutationFn: (request: UpdateUserQuietHoursScheduleRequest) => API.updateUserQuietHoursSchedule(userId, request), onSuccess: async () => { - await queryClient.invalidateQueries(userQuietHoursScheduleKey(userId)); + await queryClient.invalidateQueries({ + queryKey: userQuietHoursScheduleKey(userId), + }); }, }; }; diff --git a/site/src/api/queries/templates.ts b/site/src/api/queries/templates.ts index a99eead5f1816..5135f2304426e 100644 --- a/site/src/api/queries/templates.ts +++ b/site/src/api/queries/templates.ts @@ -15,11 +15,11 @@ import { getTemplateVersionFiles } from "utils/templateVersion"; const templateKey = (templateId: string) => ["template", templateId]; -export const template = (templateId: string): QueryOptions