From c8c2937bbab0704572d2f00247ebaead14e4bb57 Mon Sep 17 00:00:00 2001 From: Francesco Sansalvadore Date: Wed, 5 Nov 2025 16:39:28 +0100 Subject: [PATCH] add nuqs params to db functions crud panels --- .../Database/Functions/DeleteFunction.tsx | 6 ++-- .../project/[ref]/database/functions.tsx | 35 +++++++++++++++---- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/apps/studio/components/interfaces/Database/Functions/DeleteFunction.tsx b/apps/studio/components/interfaces/Database/Functions/DeleteFunction.tsx index 5bae47e0cb6..a054acb74a9 100644 --- a/apps/studio/components/interfaces/Database/Functions/DeleteFunction.tsx +++ b/apps/studio/components/interfaces/Database/Functions/DeleteFunction.tsx @@ -8,7 +8,7 @@ import TextConfirmModal from 'ui-patterns/Dialogs/TextConfirmModal' interface DeleteFunctionProps { func?: DatabaseFunction visible: boolean - setVisible: (value: boolean) => void + setVisible: (value: string) => void } export const DeleteFunction = ({ func, visible, setVisible }: DeleteFunctionProps) => { @@ -18,7 +18,7 @@ export const DeleteFunction = ({ func, visible, setVisible }: DeleteFunctionProp const { mutate: deleteDatabaseFunction, isLoading } = useDatabaseFunctionDeleteMutation({ onSuccess: () => { toast.success(`Successfully removed function ${name}`) - setVisible(false) + setVisible('') }, }) @@ -38,7 +38,7 @@ export const DeleteFunction = ({ func, visible, setVisible }: DeleteFunctionProp setVisible(!visible)} + onCancel={() => setVisible('')} onConfirm={handleDelete} title="Delete this function" loading={isLoading} diff --git a/apps/studio/pages/project/[ref]/database/functions.tsx b/apps/studio/pages/project/[ref]/database/functions.tsx index 02e68b6ee14..1ccfbb56909 100644 --- a/apps/studio/pages/project/[ref]/database/functions.tsx +++ b/apps/studio/pages/project/[ref]/database/functions.tsx @@ -1,5 +1,6 @@ import { PermissionAction } from '@supabase/shared-types/out/constants' import { useState } from 'react' +import { parseAsBoolean, parseAsString, useQueryState } from 'nuqs' import { useIsInlineEditorEnabled } from 'components/interfaces/App/FeaturePreview/FeaturePreviewContext' import { CreateFunction } from 'components/interfaces/Database/Functions/CreateFunction' @@ -20,8 +21,18 @@ import type { NextPageWithLayout } from 'types' const DatabaseFunctionsPage: NextPageWithLayout = () => { const [selectedFunction, setSelectedFunction] = useState() - const [showCreateFunctionForm, setShowCreateFunctionForm] = useState(false) - const [showDeleteFunctionForm, setShowDeleteFunctionForm] = useState(false) + const [showCreateFunctionForm, setShowCreateFunctionForm] = useQueryState( + 'new', + parseAsBoolean.withDefault(false).withOptions({ history: 'push', clearOnDefault: true }) + ) + const [showEditFunctionForm, setShowEditFunctionForm] = useQueryState( + 'edit', + parseAsString.withDefault('').withOptions({ history: 'push', clearOnDefault: true }) + ) + const [showDeleteFunctionForm, setShowDeleteFunctionForm] = useQueryState( + 'delete', + parseAsString.withDefault('').withOptions({ history: 'push', clearOnDefault: true }) + ) const [isDuplicating, setIsDuplicating] = useState(false) const isInlineEditorEnabled = useIsInlineEditorEnabled() const { openSidebar } = useSidebarManagerSnapshot() @@ -71,7 +82,7 @@ $$;`) openSidebar(SIDEBAR_KEYS.EDITOR_PANEL) } else { setSelectedFunction(dupFn) - setShowCreateFunctionForm(true) + setShowEditFunctionForm(dupFn.id.toString()) } } @@ -83,13 +94,13 @@ $$;`) openSidebar(SIDEBAR_KEYS.EDITOR_PANEL) } else { setSelectedFunction(fn) - setShowCreateFunctionForm(true) + setShowEditFunctionForm(fn.id.toString()) } } const deleteFunction = (fn: any) => { setSelectedFunction(fn) - setShowDeleteFunctionForm(true) + setShowDeleteFunctionForm(fn.id.toString()) } if (isPermissionsLoaded && !canReadFunctions) { @@ -114,6 +125,7 @@ $$;`) + + + { + setShowEditFunctionForm('') + setIsDuplicating(false) + }} + isDuplicating={isDuplicating} + /> +