mirror of
https://github.com/simstudioai/sim.git
synced 2026-02-11 23:14:58 -05:00
make it autoselect personal secret when create secret is clicked
This commit is contained in:
@@ -9,6 +9,7 @@ import {
|
||||
PopoverSection,
|
||||
} from '@/components/emcn'
|
||||
import { cn } from '@/lib/core/utils/cn'
|
||||
import { writePendingCredentialCreateRequest } from '@/lib/credentials/client-state'
|
||||
import {
|
||||
usePersonalEnvironment,
|
||||
useWorkspaceEnvironment,
|
||||
@@ -168,6 +169,14 @@ export const EnvVarDropdown: React.FC<EnvVarDropdownProps> = ({
|
||||
}, [searchTerm])
|
||||
|
||||
const openEnvironmentSettings = () => {
|
||||
if (workspaceId) {
|
||||
writePendingCredentialCreateRequest({
|
||||
workspaceId,
|
||||
type: 'env_personal',
|
||||
envKey: searchTerm.trim(),
|
||||
requestedAt: Date.now(),
|
||||
})
|
||||
}
|
||||
window.dispatchEvent(new CustomEvent('open-settings', { detail: { tab: 'credentials' } }))
|
||||
onClose?.()
|
||||
}
|
||||
|
||||
@@ -283,7 +283,7 @@ export function CredentialsManager() {
|
||||
const request = readPendingCredentialCreateRequest()
|
||||
if (!request) return
|
||||
|
||||
if (request.workspaceId !== workspaceId || request.type !== 'oauth') {
|
||||
if (request.workspaceId !== workspaceId) {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -293,10 +293,22 @@ export function CredentialsManager() {
|
||||
}
|
||||
|
||||
setShowCreateModal(true)
|
||||
setCreateType('oauth')
|
||||
setCreateOAuthProviderId(request.providerId)
|
||||
setCreateDisplayName(request.displayName)
|
||||
setShowCreateOAuthRequiredModal(false)
|
||||
setCreateError(null)
|
||||
setCreateEnvValue('')
|
||||
|
||||
if (request.type === 'oauth') {
|
||||
setCreateType('oauth')
|
||||
setCreateOAuthProviderId(request.providerId)
|
||||
setCreateDisplayName(request.displayName)
|
||||
setCreateEnvKey('')
|
||||
} else {
|
||||
setCreateType(request.type)
|
||||
setCreateOAuthProviderId('')
|
||||
setCreateDisplayName('')
|
||||
setCreateEnvKey(request.envKey || '')
|
||||
}
|
||||
|
||||
clearPendingCredentialCreateRequest()
|
||||
}, [workspaceId])
|
||||
|
||||
@@ -635,7 +647,7 @@ export function CredentialsManager() {
|
||||
) : sortedCredentials.length === 0 ? (
|
||||
<div className='rounded-[8px] border border-[var(--border-1)] px-[12px] py-[10px] text-[12px] text-[var(--text-tertiary)]'>
|
||||
{bootstrapCredentials.isPending
|
||||
? 'Syncing credentials from connected accounts and env vars...'
|
||||
? 'Syncing credentials from connected accounts and secrets...'
|
||||
: 'No credentials available for this workspace.'}
|
||||
</div>
|
||||
) : (
|
||||
@@ -1031,14 +1043,14 @@ export function CredentialsManager() {
|
||||
{selectedExistingEnvCredential && (
|
||||
<div className='rounded-[8px] border border-[var(--brand-9)]/40 bg-[var(--surface-3)] px-[10px] py-[8px]'>
|
||||
<p className='text-[12px] text-[var(--text-primary)]'>
|
||||
This env key already maps to credential{' '}
|
||||
This secret key already maps to credential{' '}
|
||||
<span className='font-medium'>
|
||||
{selectedExistingEnvCredential.displayName}
|
||||
</span>
|
||||
.
|
||||
</p>
|
||||
<p className='mt-[4px] text-[11px] text-[var(--text-tertiary)]'>
|
||||
Create will update the env value and reuse the existing credential.
|
||||
Create will update the secret value and reuse the existing credential.
|
||||
</p>
|
||||
<Button
|
||||
variant='ghost'
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
'use client'
|
||||
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import { environmentKeys } from '@/hooks/queries/environment'
|
||||
import { fetchJson } from '@/hooks/selectors/helpers'
|
||||
|
||||
export type WorkspaceCredentialType = 'oauth' | 'env_workspace' | 'env_personal'
|
||||
@@ -186,6 +187,7 @@ export function useDeleteWorkspaceCredential() {
|
||||
onSuccess: (_data, credentialId) => {
|
||||
queryClient.invalidateQueries({ queryKey: workspaceCredentialKeys.detail(credentialId) })
|
||||
queryClient.invalidateQueries({ queryKey: workspaceCredentialKeys.all })
|
||||
queryClient.invalidateQueries({ queryKey: environmentKeys.all })
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ export interface PendingOAuthCredentialDraft {
|
||||
requestedAt: number
|
||||
}
|
||||
|
||||
export interface PendingCredentialCreateRequest {
|
||||
interface PendingOAuthCredentialCreateRequest {
|
||||
workspaceId: string
|
||||
type: 'oauth'
|
||||
providerId: string
|
||||
@@ -22,6 +22,17 @@ export interface PendingCredentialCreateRequest {
|
||||
requestedAt: number
|
||||
}
|
||||
|
||||
interface PendingSecretCredentialCreateRequest {
|
||||
workspaceId: string
|
||||
type: 'env_personal' | 'env_workspace'
|
||||
envKey?: string
|
||||
requestedAt: number
|
||||
}
|
||||
|
||||
export type PendingCredentialCreateRequest =
|
||||
| PendingOAuthCredentialCreateRequest
|
||||
| PendingSecretCredentialCreateRequest
|
||||
|
||||
function parseJson<T>(raw: string | null): T | null {
|
||||
if (!raw) return null
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user