Files
supabase/apps/studio/components/interfaces/DataWarehouse/CreateWarehouseCollection.tsx
T
Jordi EnricandJoshen Lim 6e6910f82b warehouse ui/ux fixes (#29057)
* fix metadata not showing in Raw tab in log detail

* fix rows not filling up horizontal space

* show collection loader only when fetching collections, since the query can be disabled

* simplify language in create collection modal

* fix create collection modal copy in cta

* rm typecast, add tooltip on collection creation

* improve copy on empty collection

* improve copy on colelction empty state

* rm unused code

* prompt users to refresh, add button to refresh, after sending first events to a collection

* use generic mr skelington instead of supalogo

* add template for search in event message

* hide field reference when source is warehouse

* rm font bold on selected log

* update curl example

* add focusable prop to codeblock

* change focus border color in codeblock

* make codeblock focusable by default

* move refresh btn

* rm unnecessary focusable i codeblcok

* fix raw log rendering

* add search

* update plceholder

* add timerange search

* improve empty state copy in wh

* add open in warehouse explorer button

* update test conection dialog ui

* Update apps/studio/components/interfaces/DataWarehouse/TestCollectionDialog.tsx

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>

* Update apps/studio/components/interfaces/DataWarehouse/WarehouseCollectionDetail.tsx

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>

* Update apps/studio/components/interfaces/DataWarehouse/WarehouseCollectionDetail.tsx

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>

* rm clog

* Update apps/studio/components/interfaces/Settings/Logs/LogsQueryPanel.tsx

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>

* fix loading state in collections sidebar

* fix test collection sheet layout

* add some keyboard shortcuts to filters

* use isLoading in wh log detail to prevent double loaders

* make search input longr

* truncate titles

* truncat sidebar names

* rename dayjs

* update copy from warehouse to collections

* update remove collection copy

---------

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
2024-09-09 17:16:12 +02:00

124 lines
3.9 KiB
TypeScript

import { zodResolver } from '@hookform/resolvers/zod'
import { PermissionAction } from '@supabase/shared-types/out/constants'
import { PlusIcon } from 'lucide-react'
import { useRouter } from 'next/router'
import { useEffect, useState } from 'react'
import { useForm } from 'react-hook-form'
import { toast } from 'sonner'
import { z } from 'zod'
import { FormMessage } from '@ui/components/shadcn/ui/form'
import { Input } from '@ui/components/shadcn/ui/input'
import { useParams } from 'common'
import { ButtonTooltip } from 'components/ui/ButtonTooltip'
import { useCreateCollection } from 'data/analytics/warehouse-collections-create-mutation'
import { useCheckPermissions } from 'hooks/misc/useCheckPermissions'
import { Button, FormControl_Shadcn_, FormField_Shadcn_, Form_Shadcn_, Modal } from 'ui'
import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
export const CreateWarehouseCollectionModal = () => {
const [isOpen, setIsOpen] = useState(false)
const router = useRouter()
const { ref } = useParams()
const canCreateCollection = useCheckPermissions(PermissionAction.ANALYTICS_WRITE, 'logflare')
const { mutate: createCollection, isLoading } = useCreateCollection({
onSuccess: (data) => {
setIsOpen(false)
toast.success('Collection created successfully')
router.push(`/project/${ref}/logs/collections/${data.token}`)
},
onError: (error) => {
toast.error(error.message)
},
})
const FormSchema = z.object({
name: z.string().min(1),
})
const form = useForm<z.infer<typeof FormSchema>>({
resolver: zodResolver(FormSchema),
})
useEffect(() => {
if (!isOpen) {
form.reset()
}
}, [isOpen, form])
const onSubmit = form.handleSubmit(async (vals) => {
if (!ref) {
toast.error('Project ref not found')
return
}
createCollection({
projectRef: ref,
name: vals.name,
})
})
return (
<>
<ButtonTooltip
type="default"
disabled={!canCreateCollection}
className="justify-start flex-grow w-full"
icon={<PlusIcon />}
onClick={() => setIsOpen(!isOpen)}
tooltip={{
content: {
side: 'bottom',
text: 'You need additional permissions to create collections',
},
}}
>
New collection
</ButtonTooltip>
<Modal
size="medium"
onCancel={() => setIsOpen(!isOpen)}
header="Create an event collection"
visible={isOpen}
hideFooter
>
<Form_Shadcn_ {...form}>
<form onSubmit={onSubmit}>
<Modal.Content className="py-4">
<p className="pb-5 text-foreground-light text-sm">
An event collection stores time-based data and related information in Supabase's
analytics system. You can use SQL to analyze this data without affecting the
performance of your main database operations.
</p>
<FormField_Shadcn_
control={form.control}
name="name"
render={({ field }) => (
<FormItemLayout label="Collection name" layout="horizontal">
<FormControl_Shadcn_>
<Input placeholder="Events" {...field} />
</FormControl_Shadcn_>
</FormItemLayout>
)}
/>
<FormMessage />
</Modal.Content>
<Modal.Content className="py-4 border-t flex items-center justify-end gap-2">
<Button size="tiny" type="default" onClick={() => setIsOpen(!isOpen)}>
Cancel
</Button>
<Button size="tiny" loading={isLoading} disabled={isLoading} htmlType="submit">
Create collection
</Button>
</Modal.Content>
</form>
</Form_Shadcn_>
</Modal>
</>
)
}