fix: old credentials are not accessible (#4358)
This commit is contained in:
@@ -1,6 +1,16 @@
|
|||||||
import { Skeleton } from "@/components/ui/skeleton";
|
import { Skeleton } from "@/components/ui/skeleton";
|
||||||
import { CredentialItem } from "./CredentialItem";
|
import { CredentialItem } from "./CredentialItem";
|
||||||
import { useCredentialsQuery } from "@/routes/workflows/hooks/useCredentialsQuery";
|
import { useCredentialsQuery } from "@/routes/workflows/hooks/useCredentialsQuery";
|
||||||
|
import {
|
||||||
|
Pagination,
|
||||||
|
PaginationContent,
|
||||||
|
PaginationItem,
|
||||||
|
PaginationLink,
|
||||||
|
PaginationNext,
|
||||||
|
PaginationPrevious,
|
||||||
|
} from "@/components/ui/pagination";
|
||||||
|
import { cn } from "@/util/utils";
|
||||||
|
import { useState } from "react";
|
||||||
|
|
||||||
type CredentialFilter = "password" | "credit_card" | "secret";
|
type CredentialFilter = "password" | "credit_card" | "secret";
|
||||||
|
|
||||||
@@ -14,8 +24,14 @@ const EMPTY_MESSAGE: Record<CredentialFilter, string> = {
|
|||||||
secret: "No secrets stored yet.",
|
secret: "No secrets stored yet.",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const PAGE_SIZE = 25;
|
||||||
|
|
||||||
function CredentialsList({ filter }: Props = {}) {
|
function CredentialsList({ filter }: Props = {}) {
|
||||||
const { data: credentials, isLoading } = useCredentialsQuery();
|
const [page, setPage] = useState(1);
|
||||||
|
const { data: credentials, isLoading } = useCredentialsQuery({
|
||||||
|
page,
|
||||||
|
page_size: PAGE_SIZE,
|
||||||
|
});
|
||||||
|
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
return (
|
return (
|
||||||
@@ -42,7 +58,7 @@ function CredentialsList({ filter }: Props = {}) {
|
|||||||
);
|
);
|
||||||
})();
|
})();
|
||||||
|
|
||||||
if (filteredCredentials.length === 0) {
|
if (filteredCredentials.length === 0 && page === 1) {
|
||||||
return (
|
return (
|
||||||
<div className="rounded-md border border-slate-700 bg-slate-elevation1 p-6 text-sm text-slate-300">
|
<div className="rounded-md border border-slate-700 bg-slate-elevation1 p-6 text-sm text-slate-300">
|
||||||
{filter ? EMPTY_MESSAGE[filter] : "No credentials stored yet."}
|
{filter ? EMPTY_MESSAGE[filter] : "No credentials stored yet."}
|
||||||
@@ -50,14 +66,47 @@ function CredentialsList({ filter }: Props = {}) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const hasNextPage = credentials.length === PAGE_SIZE;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-5">
|
<div className="space-y-5">
|
||||||
{filteredCredentials.map((credential) => (
|
<div className="space-y-5">
|
||||||
<CredentialItem
|
{filteredCredentials.map((credential) => (
|
||||||
key={credential.credential_id}
|
<CredentialItem
|
||||||
credential={credential}
|
key={credential.credential_id}
|
||||||
/>
|
credential={credential}
|
||||||
))}
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
{(page > 1 || hasNextPage) && (
|
||||||
|
<Pagination>
|
||||||
|
<PaginationContent>
|
||||||
|
<PaginationItem>
|
||||||
|
<PaginationPrevious
|
||||||
|
className={cn({ "cursor-not-allowed": page === 1 })}
|
||||||
|
onClick={() => {
|
||||||
|
if (page > 1) {
|
||||||
|
setPage((prev) => Math.max(1, prev - 1));
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</PaginationItem>
|
||||||
|
<PaginationItem>
|
||||||
|
<PaginationLink>{page}</PaginationLink>
|
||||||
|
</PaginationItem>
|
||||||
|
<PaginationItem>
|
||||||
|
<PaginationNext
|
||||||
|
className={cn({ "cursor-not-allowed": !hasNextPage })}
|
||||||
|
onClick={() => {
|
||||||
|
if (hasNextPage) {
|
||||||
|
setPage((prev) => prev + 1);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</PaginationItem>
|
||||||
|
</PaginationContent>
|
||||||
|
</Pagination>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,7 +73,9 @@ function CredentialsModal({ onCredentialCreated }: Props) {
|
|||||||
const credentialGetter = useCredentialGetter();
|
const credentialGetter = useCredentialGetter();
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
const { isOpen, type, setIsOpen } = useCredentialModalState();
|
const { isOpen, type, setIsOpen } = useCredentialModalState();
|
||||||
const { data: credentials } = useCredentialsQuery();
|
const { data: credentials } = useCredentialsQuery({
|
||||||
|
page_size: 100,
|
||||||
|
});
|
||||||
const [passwordCredentialValues, setPasswordCredentialValues] = useState(
|
const [passwordCredentialValues, setPasswordCredentialValues] = useState(
|
||||||
PASSWORD_CREDENTIAL_INITIAL_VALUES,
|
PASSWORD_CREDENTIAL_INITIAL_VALUES,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -22,7 +22,9 @@ type Props = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function CredentialParameterSourceSelector({ value, onChange }: Props) {
|
function CredentialParameterSourceSelector({ value, onChange }: Props) {
|
||||||
const { data: credentials, isFetching } = useCredentialsQuery();
|
const { data: credentials, isFetching } = useCredentialsQuery({
|
||||||
|
page_size: 100, // Reasonable limit for dropdown selector
|
||||||
|
});
|
||||||
const { setIsOpen, setType } = useCredentialModalState();
|
const { setIsOpen, setType } = useCredentialModalState();
|
||||||
const { parameters: workflowParameters } = useWorkflowParametersStore();
|
const { parameters: workflowParameters } = useWorkflowParametersStore();
|
||||||
const workflowParametersOfTypeCredentialId = workflowParameters.filter(
|
const workflowParametersOfTypeCredentialId = workflowParameters.filter(
|
||||||
|
|||||||
@@ -23,7 +23,9 @@ type Props = {
|
|||||||
|
|
||||||
function CredentialSelector({ value, onChange }: Props) {
|
function CredentialSelector({ value, onChange }: Props) {
|
||||||
const { setIsOpen, setType } = useCredentialModalState();
|
const { setIsOpen, setType } = useCredentialModalState();
|
||||||
const { data: credentials, isFetching } = useCredentialsQuery();
|
const { data: credentials, isFetching } = useCredentialsQuery({
|
||||||
|
page_size: 100, // Reasonable limit for dropdown selector
|
||||||
|
});
|
||||||
|
|
||||||
if (isFetching) {
|
if (isFetching) {
|
||||||
return <Skeleton className="h-10 w-full" />;
|
return <Skeleton className="h-10 w-full" />;
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ function LoginBlockCredentialSelector({ nodeId, value, onChange }: Props) {
|
|||||||
const isCloud = useContext(CloudContext);
|
const isCloud = useContext(CloudContext);
|
||||||
const { data: credentials = [], isFetching } = useCredentialsQuery({
|
const { data: credentials = [], isFetching } = useCredentialsQuery({
|
||||||
enabled: isCloud,
|
enabled: isCloud,
|
||||||
|
page_size: 100,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (isCloud && isFetching) {
|
if (isCloud && isFetching) {
|
||||||
|
|||||||
@@ -9,20 +9,25 @@ type UseQueryOptions = Omit<
|
|||||||
"queryKey" | "queryFn"
|
"queryKey" | "queryFn"
|
||||||
>;
|
>;
|
||||||
|
|
||||||
type Props = UseQueryOptions;
|
type Props = UseQueryOptions & {
|
||||||
|
page?: number;
|
||||||
|
page_size?: number;
|
||||||
|
};
|
||||||
|
|
||||||
function useCredentialsQuery(props: Props = {}) {
|
function useCredentialsQuery(props: Props = {}) {
|
||||||
|
const { page = 1, page_size = 25, ...queryOptions } = props;
|
||||||
const credentialGetter = useCredentialGetter();
|
const credentialGetter = useCredentialGetter();
|
||||||
|
|
||||||
return useQuery<Array<CredentialApiResponse>>({
|
return useQuery<Array<CredentialApiResponse>>({
|
||||||
queryKey: ["credentials"],
|
queryKey: ["credentials", page, page_size],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
const client = await getClient(credentialGetter);
|
const client = await getClient(credentialGetter);
|
||||||
const params = new URLSearchParams();
|
const params = new URLSearchParams();
|
||||||
params.set("page_size", "25");
|
params.set("page", String(page));
|
||||||
|
params.set("page_size", String(page_size));
|
||||||
return client.get("/credentials", { params }).then((res) => res.data);
|
return client.get("/credentials", { params }).then((res) => res.data);
|
||||||
},
|
},
|
||||||
...props,
|
...queryOptions,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user