@@ -4,26 +4,31 @@ import { computed, ref, watch } from 'vue'
44import { useI18n } from ' vue-i18n'
55import { AI_ACTIONS , aiPreset , getAiPolicy , resolveAiPermissions } from ' @/common'
66import { Button } from ' @/components/ui/button'
7- import { Checkbox } from ' @/components/ui/checkbox'
8- import { Dialog , DialogContent , DialogDescription , DialogFooter , DialogHeader , DialogTitle } from ' @/components/ui/dialog'
7+ import { Dialog , DialogContent , DialogFooter , DialogHeader , DialogTitle } from ' @/components/ui/dialog'
98import { Label } from ' @/components/ui/label'
10- import { Select , SelectContent , SelectItem , SelectTrigger , SelectValue } from ' @/components/ui/select '
9+ import { Switch } from ' @/components/ui/switch '
1110import { useDataStudioStore } from ' @/store/dataStudioStore'
1211
12+ type SourceMode = ' inherit' | ' custom'
13+
1314const props = defineProps <{ open: boolean , sourceIdx: number }>()
1415const emit = defineEmits <{ ' update:open' : [value : boolean ] }>()
1516const { t } = useI18n ()
1617const store = useDataStudioStore ()
1718const source = computed (() => store .activeSession ?.sources .filter (s => ! s .detached )[props .sourceIdx ])
1819const base = ref <AiPermissions >({})
1920const local = ref <AiPermissions >({})
20- const mode = ref <' inherit ' | ' custom ' >(' inherit' )
21+ const mode = ref <SourceMode >(' inherit' )
2122const loaded = ref (false )
2223const failedAction = ref <' load' | ' save' | ' detach' >(' load' )
2324const loading = ref (false )
2425const saving = ref (false )
2526const error = ref (' ' )
2627const detachConfirming = ref (false )
28+ const modeOptions: { value: SourceMode , label: string }[] = [
29+ { value: ' inherit' , label: ' dataStudio.modifySource.inheritTitle' },
30+ { value: ' custom' , label: ' aiPermissions.custom' },
31+ ]
2732const allowed = computed (() => AI_ACTIONS .filter (action => base .value [action ] && (mode .value === ' inherit' || local .value [action ] === true )))
2833let request = 0
2934const load = async () => {
@@ -105,19 +110,21 @@ const retry = () => failedAction.value === 'load' ? load() : failedAction.value
105110
106111<template >
107112 <Dialog :open =" open " @update :open =" emit (' update:open' , $event )" >
108- <DialogContent class="max-h-[85vh] max-w-[calc(100vw-2rem)] overflow-y-auto sm:max-w- [480px]">
109- <DialogHeader class="text-left space-y-2">
110- <DialogTitle class="pr-6">
111- {{ t('dataStudio.modifySource.title') }}
112- </DialogTitle >
113- <p v-if =" source?.alias" class =" text-sm font-medium break-all" >
114- {{ source.alias }}
115- </p >
116- <DialogDescription class="text-xs leading-relaxed">
117- {{ t('aiPermissions.conversationHelp') }}
118- </DialogDescription >
113+ <DialogContent class="max-h-[90vh] overflow-y-auto sm:max-w- [480px]">
114+ <DialogHeader >
115+ <div class =" flex gap-3 items-center" >
116+ <div class =" border border-border rounded-xl bg-muted flex shrink-0 h-10 w-10 items-center justify-center" >
117+ <span class =" i-lucide-database h-5 w-5" />
118+ </div >
119+ <div class =" min-w-0" >
120+ <DialogTitle >{{ t('dataStudio.modifySource.title') }}</DialogTitle >
121+ <p v-if =" source?.alias" class =" text-sm text-muted-foreground mt-0.5 truncate" >
122+ {{ source.alias }}
123+ </p >
124+ </div >
125+ </div >
119126 </DialogHeader >
120- <p v-if =" loading" role =" status" class =" text-sm text-muted-foreground py-3 " >
127+ <p v-if =" loading" role =" status" class =" text-sm text-muted-foreground py-2 " >
121128 {{ t('aiPermissions.loading') }}
122129 </p >
123130 <div v-if =" error" role =" alert" class =" space-y-2" >
@@ -128,56 +135,80 @@ const retry = () => failedAction.value === 'load' ? load() : failedAction.value
128135 {{ t('aiPermissions.retry') }}
129136 </Button >
130137 </div >
131- <fieldset v-if =" !loading && loaded" :disabled =" saving" class =" py-2 border-0 min-w-0 space-y-3" >
138+ <fieldset v-if =" !loading && loaded" :disabled =" saving" class =" m-0 p-0 border-0 min-w-0 space-y-3" >
132139 <div class =" space-y-2" >
133- <Label for="conversation-permission-mode">{{ t('aiPermissions.title') }}</Label >
134- <Select v-model =" mode " :disabled =" saving " >
135- <SelectTrigger id="conversation-permission-mode" class="text-left" aria-describedby="conversation-effective">
136- <SelectValue />
137- </SelectTrigger >
138- <SelectContent >
139- <SelectItem value="inherit">
140- {{ t('aiPermissions.useConnection') }}
141- </SelectItem >
142- <SelectItem value="custom">
143- {{ t('aiPermissions.limitConversation') }}
144- </SelectItem >
145- </SelectContent >
146- </Select >
140+ <Label id="conversation-permission-mode">
141+ {{ t('dataStudio.modifySource.accessPermissions') }}
142+ </Label >
143+ <div class =" gap-2 grid grid-cols-2" role =" group" aria-labelledby =" conversation-permission-mode" >
144+ <button
145+ v-for =" option in modeOptions"
146+ :key =" option.value"
147+ type =" button"
148+ class =" px-3 py-2.5 text-left border rounded-lg flex gap-2.5 cursor-pointer transition-colors items-center focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
149+ :class =" mode === option.value ? 'border-primary bg-primary/5' : 'border-input hover:bg-accent/50'"
150+ :aria-pressed =" mode === option.value"
151+ @click =" mode = option.value"
152+ >
153+ <span
154+ class =" border-2 rounded-full flex shrink-0 h-4 w-4 items-center justify-center"
155+ :class =" mode === option.value ? 'border-primary' : 'border-muted-foreground/40'"
156+ >
157+ <span v-if =" mode === option.value" class =" rounded-full bg-primary h-2 w-2" />
158+ </span >
159+ <span class =" text-sm leading-snug font-medium" >{{ t(option.label) }}</span >
160+ </button >
161+ </div >
147162 <p id =" conversation-effective" class =" text-xs text-muted-foreground leading-relaxed" aria-live =" polite" >
148163 {{ t('aiPermissions.effective') }}: {{ allowed.map(action => t(`aiPermissions.${action}`)).join(', ') || t('aiPermissions.none') }}
149164 </p >
150165 </div >
151166 <div v-if =" mode === 'custom'" class =" border-t border-border" >
152- <div v-for =" action in AI_ACTIONS" :key =" action" class =" py-3 border-b border-border flex gap-3 items-center last:pb-0 last:border-b-0" >
153- <Checkbox :id =" ` conversation-${action } ` " class="shrink-0" :checked =" local [action ] === true && base [action ] === true " :disabled =" ! base [action ] || saving " :aria-describedby =" ! base [action ] ? ` conversation-denied-${action } ` : undefined " @update :checked =" update (action , $event === true )" />
154- <div class =" min-w-0 space-y-1" >
155- <Label :for =" ` conversation-${action } ` " class="leading-snug" :class =" { ' text-muted-foreground' : ! base [action ] } " >{{ t(`aiPermissions.${action}`) }}</Label >
156- <p v-if =" !base[action]" :id =" `conversation-denied-${action}`" class =" text-xs text-muted-foreground leading-snug" >
167+ <div v-for =" action in AI_ACTIONS" :key =" action" class =" py-2 border-b border-border flex gap-3 items-center justify-between last:pb-0 last:border-b-0" >
168+ <div class =" min-w-0 space-y-0.5" >
169+ <Label :for =" ` conversation-${action } ` " class="leading-snug" :class =" { ' text-muted-foreground' : ! base [action ] } " >
170+ {{ t(`aiPermissions.${action}`) }}
171+ </Label >
172+ <p v-if =" !base[action]" class =" text-xs text-muted-foreground leading-snug" >
157173 {{ t('aiPermissions.deniedByConnection') }}
158174 </p >
159175 </div >
176+ <div class =" flex shrink-0 gap-3 items-center" >
177+ <span class =" text-xs text-muted-foreground" >
178+ {{ t(local[action] === true ? 'aiPermissions.allow' : 'aiPermissions.deny') }}
179+ </span >
180+ <Switch
181+ :id =" ` conversation-${action } ` "
182+ :checked =" local [action ] === true "
183+ :disabled =" ! base [action ] || saving "
184+ @update :checked =" update (action , $event )"
185+ />
186+ </div >
160187 </div >
161188 </div >
162189 </fieldset >
163- <p v-if =" detachConfirming" class =" text-sm leading-relaxed" >
164- {{ t('dataStudio.detachSource.message') }}
165- </p >
166- <DialogFooter class="pt-3 border-t border-border flex flex-wrap gap-2">
167- <template v-if =" detachConfirming " >
168- <Button type="button" variant="outline" :disabled =" saving " @click =" detachConfirming = false " >
169- {{ t('aiPermissions.cancel') }}
170- </Button >
171- <Button type="button" variant="destructive" :disabled =" saving " @click =" detach " >
172- {{ t('dataStudio.detachSource.confirm') }}
173- </Button >
174- </template >
190+ <DialogFooter class="flex flex-wrap gap-2 items-center justify-between sm:justify-between ">
191+ <div v-if =" detachConfirming" class =" mr-auto flex flex-col gap-1.5 min-w-0" >
192+ <span class =" text-xs text-muted-foreground leading-snug" >
193+ {{ t('dataStudio.detachSource.message') }}
194+ </span >
195+ <div class =" flex gap-1.5" >
196+ <Button type="button" variant="destructive" size="sm" :disabled =" saving " @click =" detach " >
197+ <span class =" i-lucide-unlink mr-1 h-3.5 w-3.5" />
198+ {{ t('dataStudio.detachSource.confirm') }}
199+ </Button >
200+ <Button type="button" variant="outline" size="sm" :disabled =" saving " @click =" detachConfirming = false " >
201+ {{ t('common.buttons.cancel') }}
202+ </Button >
203+ </div >
204+ </div >
175205 <template v-else >
176- <Button type="button" variant="ghost" :disabled =" saving " class="mr-auto" @click =" detachConfirming = true " >
206+ <Button type="button" variant="ghost" class="text-destructive-text mr-auto" :disabled =" saving " @click =" detachConfirming = true " >
207+ <span class =" i-lucide-unlink mr-1.5 h-4 w-4" />
177208 {{ t('dataStudio.detachSource.title') }}
178209 </Button >
179210 <Button type="button" variant="outline" :disabled =" saving " @click =" emit (' update:open' , false )" >
180- {{ t('aiPermissions .cancel') }}
211+ {{ t('common.buttons .cancel') }}
181212 </Button >
182213 <Button type="button" :disabled =" loading || saving || ! loaded " @click =" save " >
183214 {{ t(saving ? 'aiPermissions.saving' : 'dataStudio.modifySource.saveChanges') }}
0 commit comments