Files
50255605ec Moves inline editor from feature preview to setting (#39892)
* sidebar-manager

* storage keys

* tests

* more ai spots

* test fix

* revert to default

* remove ref

* Update apps/studio/state/sidebar-manager-state.tsx

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update apps/studio/components/ui/AIAssistantPanel/AIAssistant.tsx

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* fix ts

* fix

* fux

* fux query param

* clean

* fix

* more

* mock local storage

* simplify

* remove provider test

* remve useopensidebar

* fix(new homepage): open ai assistant on advisor card button clicks

* Update apps/studio/components/layouts/ProjectLayout/LayoutSidebar/index.tsx

Co-authored-by: Charis <26616127+charislam@users.noreply.github.com>

* Update apps/studio/state/sidebar-manager-state.tsx

Co-authored-by: Charis <26616127+charislam@users.noreply.github.com>

* refine

* editor sidebar manager

* reset results

* move inline editor to account setting

* update analytics to standard

* copy

* add tracking

* update copy

* fixes

* Update apps/studio/pages/project/[ref]/database/functions.tsx

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update apps/studio/pages/project/[ref]/auth/policies.tsx

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* zod resolver

* Nit refacotr

* Small fixes

* missed two pieces

* change event

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Charis Lam <26616127+charislam@users.noreply.github.com>
Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
2025-11-07 03:04:37 +00:00

87 lines
2.7 KiB
TypeScript

import { zodResolver } from '@hookform/resolvers/zod'
import { useForm } from 'react-hook-form'
import * as z from 'zod'
import { LOCAL_STORAGE_KEYS } from 'common'
import Panel from 'components/ui/Panel'
import { useSendEventMutation } from 'data/telemetry/send-event-mutation'
import { useLocalStorageQuery } from 'hooks/misc/useLocalStorage'
import { useSelectedOrganizationQuery } from 'hooks/misc/useSelectedOrganization'
import { FormControl_Shadcn_, FormField_Shadcn_, Form_Shadcn_, Switch } from 'ui'
import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
const InlineEditorSchema = z.object({
inlineEditorEnabled: z.boolean(),
})
export const useIsInlineEditorEnabled = () => {
const [inlineEditorEnabled] = useLocalStorageQuery(
LOCAL_STORAGE_KEYS.UI_PREVIEW_INLINE_EDITOR,
false
)
return inlineEditorEnabled ?? false
}
export const InlineEditorSettings = () => {
const [inlineEditorEnabled, setInlineEditorEnabled] = useLocalStorageQuery(
LOCAL_STORAGE_KEYS.UI_PREVIEW_INLINE_EDITOR,
false
)
const { data: org } = useSelectedOrganizationQuery()
const { mutate: sendEvent } = useSendEventMutation()
const form = useForm<z.infer<typeof InlineEditorSchema>>({
resolver: zodResolver(InlineEditorSchema),
values: {
inlineEditorEnabled: inlineEditorEnabled ?? false,
},
})
const handleToggle = (value: boolean) => {
setInlineEditorEnabled(value)
form.setValue('inlineEditorEnabled', value)
sendEvent({
action: 'inline_editor_setting_clicked',
properties: {
enabled: value,
},
groups: {
organization: org?.slug,
},
})
}
return (
<Panel title={<h5 id="inline-editor">Dashboard</h5>}>
<Panel.Content>
<Form_Shadcn_ {...form}>
<FormField_Shadcn_
control={form.control}
name="inlineEditorEnabled"
render={({ field }) => (
<FormItemLayout
layout="flex-row-reverse"
label="Edit entities in SQL"
description="When enabled, view and edit policies, triggers, and functions directly in the SQL editor instead of a more beginner-friendly UI panel. Ideal for those comfortable with SQL."
>
<FormControl_Shadcn_>
<Switch
checked={field.value}
onCheckedChange={(value) => {
field.onChange(value)
handleToggle(value)
}}
/>
</FormControl_Shadcn_>
</FormItemLayout>
)}
/>
</Form_Shadcn_>
</Panel.Content>
</Panel>
)
}