Repository: supabase/supabase
File: apps/studio/components/interfaces/Storage/AnalyticsBuckets/AnalyticsBucketDetails/NamespaceWithTables/TableRowComponent.tsx (TypeScript)

Code before:
    try {
      setIsRemovingTable(true)

      const serverName = `${snakeCase(bucketId)}_fdw_server`
      const serverOptions = await getDecryptedParameters({
        ref: project?.ref,
        connectionString: project?.connectionString ?? undefined,
        wrapper: wrapperInstance,
      })
      const formValues: Record<string, string> = {
        wrapper_name: wrapperInstance.name,
        server_name: wrapperInstance.server_name,
        ...serverOptions,
      }
      const targetSchemas = (formValues['supabase_target_schema'] || '')
        .split(',')
        .map((s) => s.trim())
      const wrapperTables = formatWrapperTables(wrapperInstance, wrapperMeta).filter(
        (x) => x.table_name !== table.name
      )

      await updateFDW({
        projectRef: project?.ref,
        connectionString: project?.connectionString,
        wrapper: wrapperInstance,
        wrapperMeta,
        formState: {
          ...formValues,
          server_name: serverName,
          supabase_target_schema: uniq([...targetSchemas])
            .filter(Boolean)
            .join(','),
        },
        tables: wrapperTables,
      })

      const wrapperValues = convertKVStringArrayToJson(wrapperInstance?.server_options ?? [])
      await deleteNamespaceTable({
        token,
        catalogUri: wrapperValues.catalog_uri,
        warehouse: wrapperValues.warehouse,
        namespace: namespace,
        table: table.name,
      })

      toast.success('Successfully removed table!')
      setShowRemoveTableModal(false)
    } catch (error: any) {
      toast.error(`Failed to remove table: ${error.message}`)
    } finally {
      setIsRemovingTable(false)

Review comment (suggestion):
If you're doing all this just to delete a table, you can use this from my PR https://github.com/supabase/supabase/pull/40206/files#diff-d65d8f2c348d632d033616d2e15c0bed1a32ed4416c21892d02ad98511475a10

Code after:
    if (!wrapperInstance || !wrapperMeta) return toast.error('Unable to find wrapper')

    try {
      setIsRemovingTable(true)

      const serverName = getAnalyticsBucketFDWServerName(bucketId)
      const serverOptions = await getDecryptedParameters({
        ref: project?.ref,
        connectionString: project?.connectionString ?? undefined,
        wrapper: wrapperInstance,
      })
      const formValues: Record<string, string> = {
        wrapper_name: wrapperInstance.name,
        server_name: wrapperInstance.server_name,
        ...serverOptions,
      }
      const targetSchemas = (formValues['supabase_target_schema'] || '')
        .split(',')
        .map((s) => s.trim())
      const wrapperTables = formatWrapperTables(wrapperInstance, wrapperMeta).filter(
        (x) => x.table_name !== table.name
      )

      // [Joshen] Once Ivan's PR goes through, swap these out to just use useFDWDropForeignTableMutation
      // https://github.com/supabase/supabase/pull/40206
      await updateFDW({
        projectRef: project?.ref,
        connectionString: project?.connectionString,
        wrapper: wrapperInstance,
        wrapperMeta,
        formState: {
          ...formValues,
          server_name: serverName,
          supabase_target_schema: uniq([...targetSchemas])
            .filter(Boolean)
            .join(','),
        },
        tables: wrapperTables,
      })

      const wrapperValues = convertKVStringArrayToJson(wrapperInstance?.server_options ?? [])
      await deleteNamespaceTable({
        token,
        catalogUri: wrapperValues.catalog_uri,
        warehouse: wrapperValues.warehouse,
        namespace: namespace,
        table: table.name,
      })

      toast.success('Successfully removed table!')
      setShowRemoveTableModal(false)