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

Update dependency @tanstack/vue-query to v5 #1008

Merged
merged 2 commits into from
Nov 8, 2023
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
30 changes: 15 additions & 15 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"qs": "^6.11.0",
"vue": "^3.2.37",
"vue-i18n": "^9.2.2",
"@tanstack/vue-query": "^4.32.6",
"@tanstack/vue-query": "^4.32.6 || ^5.0.0",
"vue-router": "^4.1.2",
"vue-unused-components-checker": "^1.1.2"
},
Expand Down
24 changes: 12 additions & 12 deletions frontend/src/api/artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,29 @@
//
// SPDX-License-Identifier: MIT

import { useQuery } from "@tanstack/vue-query";
import { useQuery, type UseQueryReturnType } from "@tanstack/vue-query";
import type { Ref } from "vue";
import type { operations } from "./generated";
import { apiGet } from "./index";

// Get all rules
type ArtifactsOpType = operations["get_artifacts_api_v1_artifacts_get"];
type ArtifactsOutputType =
ArtifactsOpType["responses"][200]["content"]["application/json"];
type ArtifactsErrorType =
ArtifactsOpType["responses"][422]["content"]["application/json"];
export const useArtifactsQuery = (
users: Ref<string[] | undefined> | undefined,
groups: Ref<string[] | undefined> | undefined,
) => {
): UseQueryReturnType<ArtifactsOutputType, ArtifactsErrorType> => {
const url = "/api/v1/artifacts";

type OpType = operations["get_artifacts_api_v1_artifacts_get"];
type OutputType = OpType["responses"][200]["content"]["application/json"];
type ErrorType = OpType["responses"][422]["content"]["application/json"];

const queryParams = { users, groups };
const visible =
(groups && groups.value && groups.value.length > 0) ||
(users && users.value && users.value.length > 0);
return useQuery<OutputType, ErrorType>(
[url, queryParams],
apiGet<OutputType>,
{ enabled: visible },
);
return useQuery({
queryKey: [url, queryParams],
queryFn: apiGet<ArtifactsOutputType>,
enabled: visible,
});
};
11 changes: 10 additions & 1 deletion frontend/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,19 @@ export async function getApiClient() {
});
}

export const apiGet = async <Data>({ queryKey }: QueryFunctionContext) => {
interface QueryFunctionContextOrDirect
extends Omit<QueryFunctionContext, "signal" | "meta"> {
signal?: QueryFunctionContext["signal"];
meta?: QueryFunctionContext["meta"];
}
export const apiGet = async <Data>({
queryKey,
signal,
}: QueryFunctionContextOrDirect) => {
const axiosConfig = await getAxiosConfig();
const url = queryKey[0] as string;
axiosConfig["params"] = queryKey[1];
axiosConfig["signal"] = signal;
const response = await http.get<Data>(url, axiosConfig);
return response.data;
};
Expand Down
Loading