feat(ui): updated api changes made

This commit is contained in:
Akhil Mohan
2024-03-26 14:10:25 +05:30
parent a7d2ec80c6
commit 8a7774f9ac
15 changed files with 120 additions and 116 deletions
@@ -141,7 +141,7 @@ export const SecretMainPage = () => {
const { data: dynamicSecrets, isLoading: isDynamicSecretLoading } = useGetDynamicSecrets({
projectSlug,
environment,
environmentSlug: environment,
path: secretPath
});
@@ -54,7 +54,9 @@ const formSchema = z.object({
if (valMs > 24 * 60 * 60 * 1000)
ctx.addIssue({ code: z.ZodIssueCode.custom, message: "TTL must be less than a day" });
}),
slug: z.string().toLowerCase()
name: z
.string()
.refine((val) => val.toLowerCase() === val, "Must be lowercase")
});
type TForm = z.infer<typeof formSchema>;
@@ -92,18 +94,18 @@ export const SqlDatabaseInputForm = ({
const { createNotification } = useNotificationContext();
const createDynamicSecret = useCreateDynamicSecret();
const handleCreateDynamicSecret = async ({ slug, maxTTL, provider, defaultTTL }: TForm) => {
const handleCreateDynamicSecret = async ({ name, maxTTL, provider, defaultTTL }: TForm) => {
// wait till previous request is finished
if (createDynamicSecret.isLoading) return;
try {
await createDynamicSecret.mutateAsync({
provider: { type: DynamicSecretProviders.SqlDatabase, inputs: provider },
maxTTL,
slug,
name,
path: secretPath,
defaultTTL,
projectSlug,
environment
environmentSlug: environment
});
onCompleted();
} catch (err) {
@@ -122,7 +124,7 @@ export const SqlDatabaseInputForm = ({
<Controller
control={control}
defaultValue=""
name="slug"
name="name"
render={({ field, fieldState: { error } }) => (
<FormControl
label="Secret Name"
@@ -168,9 +170,11 @@ export const SqlDatabaseInputForm = ({
</div>
</div>
<div>
<div className="mb-4 border-b border-mineshaft-500 pb-2 text-mineshaft-200 pl-1 mt-4 font-medium">Configuration</div>
<div className="mb-4 mt-4 border-b border-mineshaft-500 pb-2 pl-1 font-medium text-mineshaft-200">
Configuration
</div>
<div className="flex flex-col">
<div className="text-sm text-mineshaft-400 pl-1 pb-0.5">Service</div>
<div className="pl-1 pb-0.5 text-sm text-mineshaft-400">Service</div>
<Controller
control={control}
name="provider.client"
@@ -279,11 +283,7 @@ export const SqlDatabaseInputForm = ({
</FormControl>
)}
/>
<Accordion
type="single"
collapsible
className="w-full bg-mineshaft-700 mb-2"
>
<Accordion type="single" collapsible className="mb-2 w-full bg-mineshaft-700">
<AccordionItem value="advance-statements">
<AccordionTrigger>Modify SQL Statements</AccordionTrigger>
<AccordionContent>
@@ -77,7 +77,7 @@ type TForm = z.infer<typeof formSchema>;
type Props = {
onClose: () => void;
slug: string;
dynamicSecretName: string;
provider: DynamicSecretProviders;
projectSlug: string;
environment: string;
@@ -87,7 +87,7 @@ type Props = {
export const CreateDynamicSecretLease = ({
onClose,
projectSlug,
slug,
dynamicSecretName,
provider,
secretPath,
environment
@@ -110,11 +110,11 @@ export const CreateDynamicSecretLease = ({
if (createDynamicSecretLease.isLoading) return;
try {
await createDynamicSecretLease.mutateAsync({
environment,
environmentSlug: environment,
projectSlug,
path: secretPath,
ttl,
slug
dynamicSecretName
});
createNotification({
type: "success",
@@ -34,7 +34,7 @@ import { DynamicSecretLeaseStatus } from "@app/hooks/api/dynamicSecretLease/type
import { RenewDynamicSecretLease } from "./RenewDynamicSecretLease";
type Props = {
slug: string;
dynamicSecretName: string;
projectSlug: string;
environment: string;
secretPath: string;
@@ -44,7 +44,7 @@ type Props = {
export const DynamicSecretLease = ({
projectSlug,
slug,
dynamicSecretName,
environment,
secretPath,
onClickNewLease,
@@ -56,9 +56,9 @@ export const DynamicSecretLease = ({
] as const);
const { data: leases, isLoading: isLeaseLoading } = useGetDynamicSecretLeases({
projectSlug,
environment,
environmentSlug: environment,
path: secretPath,
slug
dynamicSecretName
});
const { createNotification } = useNotificationContext();
@@ -71,10 +71,10 @@ export const DynamicSecretLease = ({
isForced?: boolean;
};
await deleteDynamicSecretLease.mutateAsync({
environment,
environmentSlug: environment,
projectSlug,
path: secretPath,
slug,
dynamicSecretName,
leaseId,
isForced
});
@@ -226,7 +226,7 @@ export const DynamicSecretLease = ({
onClose={() => handlePopUpClose("renewSecret")}
projectSlug={projectSlug}
leaseId={(popUp.renewSecret?.data as { leaseId: string })?.leaseId}
slug={slug}
dynamicSecretName={dynamicSecretName}
secretPath={secretPath}
environment={environment}
/>
@@ -64,14 +64,14 @@ export const DynamicSecretListView = ({
const handleDynamicSecretDelete = async () => {
try {
const { slug, isForced } = popUp.deleteDynamicSecret.data as TDynamicSecret & {
const { name, isForced } = popUp.deleteDynamicSecret.data as TDynamicSecret & {
isForced?: boolean;
};
await deleteDynamicSecret.mutateAsync({
environment,
environmentSlug: environment,
projectSlug,
path: secretPath,
slug,
name,
isForced
});
handlePopUpClose("deleteDynamicSecret");
@@ -93,8 +93,8 @@ export const DynamicSecretListView = ({
{dynamicSecrets
.sort((a, b) =>
sortDir === SortDir.ASC
? a.slug.toLowerCase().localeCompare(b.slug.toLowerCase())
: b.slug.toLowerCase().localeCompare(a.slug.toLowerCase())
? a.name.toLowerCase().localeCompare(b.name.toLowerCase())
: b.name.toLowerCase().localeCompare(a.name.toLowerCase())
)
.map((secret) => {
const isRevocking = secret.status === DynamicSecretStatus.Deleting;
@@ -124,11 +124,11 @@ export const DynamicSecretListView = ({
<FontAwesomeIcon icon={faFingerprint} />
</div>
<div
className="flex flex-grow items-center px-4 py-3 uppercase"
className="flex flex-grow items-center px-4 py-3"
role="button"
tabIndex={0}
>
{secret.slug}{" "}
{secret.name}
<Tag className="ml-4 py-0 px-2 text-xs normal-case">
{formatProviderName(secret.type)}
</Tag>
@@ -234,7 +234,7 @@ export const DynamicSecretListView = ({
onClose={() => handlePopUpClose("dynamicSecretLeases")}
projectSlug={projectSlug}
key={secret.id}
slug={secret.slug}
dynamicSecretName={secret.name}
secretPath={secretPath}
environment={environment}
/>
@@ -253,7 +253,7 @@ export const DynamicSecretListView = ({
}
onClose={() => handlePopUpClose("createDynamicSecretLease")}
projectSlug={projectSlug}
slug={(popUp.createDynamicSecretLease?.data as { slug: string })?.slug}
dynamicSecretName={(popUp.createDynamicSecretLease?.data as { name: string })?.name}
secretPath={secretPath}
environment={environment}
/>
@@ -267,7 +267,7 @@ export const DynamicSecretListView = ({
<EditDynamicSecretForm
onClose={() => handlePopUpClose("updateDynamicSecret")}
projectSlug={projectSlug}
slug={(popUp.updateDynamicSecret?.data as TDynamicSecret)?.slug}
dynamicSecretName={(popUp.updateDynamicSecret?.data as TDynamicSecret)?.name}
secretPath={secretPath}
environment={environment}
/>
@@ -275,7 +275,7 @@ export const DynamicSecretListView = ({
</Modal>
<DeleteActionModal
isOpen={popUp.deleteDynamicSecret.isOpen}
deleteKey={(popUp.deleteDynamicSecret?.data as TDynamicSecret)?.slug}
deleteKey={(popUp.deleteDynamicSecret?.data as TDynamicSecret)?.name}
title={
(popUp.deleteDynamicSecret?.data as { isForced?: boolean })?.isForced
? "Do you want to force delete this dynamic secret?"
@@ -8,14 +8,14 @@ import { EditDynamicSecretSqlProviderForm } from "./EditDynamicSecretSqlProvider
type Props = {
onClose: () => void;
slug: string;
dynamicSecretName: string;
projectSlug: string;
environment: string;
secretPath: string;
};
export const EditDynamicSecretForm = ({
slug,
dynamicSecretName,
environment,
projectSlug,
onClose,
@@ -24,8 +24,8 @@ export const EditDynamicSecretForm = ({
const { data: dynamicSecretDetails, isLoading: isDynamicSecretLoading } =
useGetDynamicSecretDetails({
projectSlug,
environment,
slug,
environmentSlug: environment,
name: dynamicSecretName,
path: secretPath
});
@@ -57,7 +57,10 @@ const formSchema = z.object({
ctx.addIssue({ code: z.ZodIssueCode.custom, message: "TTL must be less than a day" });
})
.nullable(),
newSlug: z.string().toLowerCase().optional()
newName: z
.string()
.refine((val) => val.toLowerCase() === val, "Must be lowercase")
.optional()
});
type TForm = z.infer<typeof formSchema>;
@@ -85,7 +88,7 @@ export const EditDynamicSecretSqlProviderForm = ({
values: {
defaultTTL: dynamicSecret.defaultTTL,
maxTTL: dynamicSecret.maxTTL,
newSlug: dynamicSecret.slug,
newName: dynamicSecret.name,
inputs: {
...(dynamicSecret.inputs as TForm["inputs"])
}
@@ -94,31 +97,31 @@ export const EditDynamicSecretSqlProviderForm = ({
const { createNotification } = useNotificationContext();
const updateDynamicSecret = useUpdateDynamicSecret();
const handleUpdateDynamicSecret = async ({ inputs, maxTTL, defaultTTL, newSlug }: TForm) => {
const handleUpdateDynamicSecret = async ({ inputs, maxTTL, defaultTTL, newName }: TForm) => {
// wait till previous request is finished
if (updateDynamicSecret.isLoading) return;
try {
await updateDynamicSecret.mutateAsync({
slug: dynamicSecret.slug,
name: dynamicSecret.name,
path: secretPath,
projectSlug,
environment,
environmentSlug: environment,
data: {
maxTTL: maxTTL || undefined,
defaultTTL,
inputs,
newSlug: newSlug === dynamicSecret.slug ? undefined : newSlug
newName: newName === dynamicSecret.name ? undefined : newName
}
});
onClose();
createNotification({
type: "success",
text: "Successfully updated dynamic secret"
text: "Successfully update dynamic secret"
});
} catch (err) {
createNotification({
type: "error",
text: "Failed to create dynamic secret"
text: "Failed to update dynamic secret"
});
}
};
@@ -130,7 +133,7 @@ export const EditDynamicSecretSqlProviderForm = ({
<div className="flex-grow">
<Controller
control={control}
name="newSlug"
name="newName"
render={({ field, fieldState: { error } }) => (
<FormControl
label="Secret Name"
@@ -24,7 +24,7 @@ type TForm = z.infer<typeof formSchema>;
type Props = {
onClose: () => void;
leaseId: string;
slug: string;
dynamicSecretName: string;
projectSlug: string;
environment: string;
secretPath: string;
@@ -33,7 +33,7 @@ type Props = {
export const RenewDynamicSecretLease = ({
onClose,
projectSlug,
slug,
dynamicSecretName,
leaseId,
secretPath,
environment
@@ -56,11 +56,11 @@ export const RenewDynamicSecretLease = ({
if (renewDynamicSecretLease.isLoading) return;
try {
await renewDynamicSecretLease.mutateAsync({
environment,
environmentSlug: environment,
projectSlug,
path: secretPath,
ttl,
slug,
dynamicSecretName,
leaseId
});
onClose();