Skip to content

Review fixes 2 #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"@radix-ui/react-dropdown-menu": "^2.1.2",
"@radix-ui/react-icons": "1.3.0",
"@radix-ui/react-popover": "^1.0.7",
"@radix-ui/react-portal": "^1.1.2",
"@radix-ui/react-scroll-area": "^1.0.3",
"@radix-ui/react-select": "^2.0.0",
"@radix-ui/react-slot": "^1.0.2",
Expand Down
26 changes: 9 additions & 17 deletions src/components/databrowser/components/add-key-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
SelectValue,
} from "@/components/ui/select"
import { Spinner } from "@/components/ui/spinner"
import { toast } from "@/components/ui/use-toast"
import { TypeTag } from "@/components/databrowser/components/type-tag"
import { useAddKey } from "@/components/databrowser/hooks/use-add-key"

Expand All @@ -43,23 +42,16 @@ export function AddKeyModal() {
})

const onSubmit = handleSubmit(async ({ key, type }) => {
try {
await addKey({ key, type })
setSelectedKey(key)
setOpen(false)
setTimeout(() => {
window.document.querySelector(`[data-key="${key}"]`)?.scrollIntoView({
behavior: "smooth",
block: "start",
inline: "nearest",
})
}, 100)
} catch (error) {
toast({
description: error instanceof Error ? error.message : "An error occurred",
variant: "destructive",
await addKey({ key, type })
setSelectedKey(key)
setOpen(false)
setTimeout(() => {
window.document.querySelector(`[data-key="${key}"]`)?.scrollIntoView({
behavior: "smooth",
block: "start",
inline: "nearest",
})
}
}, 100)
})

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,24 @@ const ListEditForm = ({
<form onSubmit={onSubmit} className="flex flex-col gap-2">
<div className="flex grow flex-col gap-2">
{type !== "list" && (
<FormItem name="key" height={type === "set" ? 250 : 100} label={keyLabel} />
<FormItem
readOnly={type === "stream"}
name="key"
height={type === "set" ? 250 : 100}
label={keyLabel}
/>
)}

{type === "zset" ? (
<NumberFormItem name="value" label={valueLabel} />
) : (
type !== "set" && (
<FormItem name="value" height={type === "list" ? 250 : 100} label={valueLabel} />
<FormItem
readOnly={type === "stream"}
name="value"
height={type === "list" ? 250 : 100}
label={valueLabel}
/>
)
)}
</div>
Expand Down Expand Up @@ -131,18 +141,21 @@ const FormItem = ({
name,
label,
height,
readOnly,
}: {
name: string
label: string
isNumber?: boolean
height?: number
readOnly?: boolean
}) => {
const form = useFormContext()
const { editor, selector } = useField({
name,
form,
height: height,
showCopyButton: true,
readOnly,
})

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ export const CustomEditor = ({
onChange,
height,
showCopyButton,
readOnly,
}: {
language: string
value: string
onChange: (value: string) => void
height?: number
showCopyButton?: boolean
readOnly?: boolean
}) => {
const monaco = useMonaco()
const editorRef = useRef()
Expand Down Expand Up @@ -48,6 +50,7 @@ export const CustomEditor = ({
}}
defaultLanguage={language}
options={{
readOnly: readOnly,
wordWrap: "on",
overviewRulerBorder: false,
overviewRulerLanes: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ export const useField = ({
form,
height,
showCopyButton,
readOnly,
}: {
name: string
form: UseFormReturn<any>
height?: number
showCopyButton?: boolean
readOnly?: boolean
}) => {
const { field, fieldState } = useController<Record<string, string>>({
name,
Expand Down Expand Up @@ -60,6 +62,7 @@ export const useField = ({
onChange={field.onChange}
height={height}
showCopyButton={showCopyButton}
readOnly={readOnly}
/>
</>
),
Expand Down
2 changes: 2 additions & 0 deletions src/components/databrowser/hooks/use-add-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export const useAddKey = () => {

const mutation = useMutation({
mutationFn: async ({ key, type }: { key: string; type: DataType }) => {
if (await redis.exists(key)) throw new Error(`Key "${key}" already exists`)

switch (type) {
case "set": {
await redis.sadd(key, "value")
Expand Down
6 changes: 5 additions & 1 deletion src/components/databrowser/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import "@/globals.css"

import { useMemo } from "react"
import { useEffect, useMemo } from "react"
import { DatabrowserProvider, type RedisCredentials } from "@/store"
import { TooltipProvider } from "@radix-ui/react-tooltip"
import { IconDotsVertical } from "@tabler/icons-react"
Expand All @@ -17,6 +17,10 @@ import { KeysProvider } from "./hooks/use-keys"
export const RedisBrowser = ({ token, url }: RedisCredentials) => {
const credentials = useMemo(() => ({ token, url }), [token, url])

useEffect(() => {
queryClient.resetQueries()
}, [credentials.url])

return (
<QueryClientProvider client={queryClient}>
<TooltipProvider>
Expand Down
31 changes: 18 additions & 13 deletions src/components/ui/toaster.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { Portal } from "@radix-ui/react-portal"

import { portalRoot } from "@/lib/portal-root"
import {
Toast,
ToastClose,
Expand All @@ -12,18 +15,20 @@ export function Toaster() {
const { toasts } = useToast()

return (
<ToastProvider>
{toasts.map(({ id, title, description, action, ...props }) => (
<Toast key={id} {...props}>
<div className="grid gap-1">
{title && <ToastTitle>{title}</ToastTitle>}
{description && <ToastDescription>{description}</ToastDescription>}
</div>
{action}
<ToastClose />
</Toast>
))}
<ToastViewport />
</ToastProvider>
<Portal container={portalRoot}>
<ToastProvider>
{toasts.map(({ id, title, description, action, ...props }) => (
<Toast key={id} {...props}>
<div className="grid gap-1">
{title && <ToastTitle>{title}</ToastTitle>}
{description && <ToastDescription>{description}</ToastDescription>}
</div>
{action}
<ToastClose />
</Toast>
))}
<ToastViewport />
</ToastProvider>
</Portal>
)
}
Loading