Skip to content

Commit e6844c0

Browse files
authored
feat: add "open in new tab" to the keys right click menu (#24)
* feat: add "open in new tab" to the keys right click menu * fix: open in new tab for items list
1 parent e87f50b commit e6844c0

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

src/components/databrowser/components/item-context-menu.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { useState, type PropsWithChildren } from "react"
2+
import { useDatabrowserStore } from "@/store"
23
import { type ListDataType } from "@/types"
34
import { ContextMenuSeparator } from "@radix-ui/react-context-menu"
45

@@ -25,6 +26,7 @@ export const ItemContextMenu = ({
2526
const { mutate: editItem } = useEditListItem()
2627
const [isAlertOpen, setAlertOpen] = useState(false)
2728
const [data, setData] = useState<ItemData | undefined>()
29+
const { addTab, setSelectedKey, selectTab, setSelectedListItem } = useDatabrowserStore()
2830

2931
return (
3032
<>
@@ -90,6 +92,19 @@ export const ItemContextMenu = ({
9092
Copy value
9193
</ContextMenuItem>
9294
)}
95+
<ContextMenuItem
96+
onClick={() => {
97+
if (!data) return
98+
const newTabId = addTab()
99+
selectTab(newTabId)
100+
setSelectedKey(newTabId, dataKey)
101+
setSelectedListItem(newTabId, {
102+
key: data.key,
103+
})
104+
}}
105+
>
106+
Open in new tab
107+
</ContextMenuItem>
93108
<ContextMenuSeparator />
94109
<ContextMenuItem disabled={type === "stream"} onClick={() => setAlertOpen(true)}>
95110
Delete item

src/components/databrowser/components/sidebar-context-menu.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { useState, type PropsWithChildren } from "react"
2+
import { useDatabrowserStore } from "@/store"
3+
import { useTab } from "@/tab-provider"
24
import { ContextMenuSeparator } from "@radix-ui/react-context-menu"
35

46
import {
@@ -16,6 +18,8 @@ export const SidebarContextMenu = ({ children }: PropsWithChildren) => {
1618
const { mutate: deleteKey } = useDeleteKey()
1719
const [isAlertOpen, setAlertOpen] = useState(false)
1820
const [dataKey, setDataKey] = useState("")
21+
const { addTab, setSelectedKey, selectTab, setSearch } = useDatabrowserStore()
22+
const { search: currentSearch } = useTab()
1923

2024
return (
2125
<>
@@ -56,6 +60,16 @@ export const SidebarContextMenu = ({ children }: PropsWithChildren) => {
5660
>
5761
Copy key
5862
</ContextMenuItem>
63+
<ContextMenuItem
64+
onClick={() => {
65+
const newTabId = addTab()
66+
setSelectedKey(newTabId, dataKey)
67+
setSearch(newTabId, currentSearch)
68+
selectTab(newTabId)
69+
}}
70+
>
71+
Open in new tab
72+
</ContextMenuItem>
5973
<ContextMenuSeparator />
6074
<ContextMenuItem onClick={() => setAlertOpen(true)}>Delete key</ContextMenuItem>
6175
</ContextMenuContent>

src/store.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { createContext, useContext, useMemo, type PropsWithChildren } from "react"
22
import type { StoreApi, UseBoundStore } from "zustand"
33
import { create, useStore, type StateCreator } from "zustand"
4-
5-
import type { DataType } from "./types"
64
import { persist } from "zustand/middleware"
5+
76
import type { RedisBrowserStorage } from "./components/databrowser"
7+
import type { DataType } from "./types"
88

99
// Re-export for backward compatibility
1010
export type { RedisCredentials } from "./redis-context"
@@ -95,7 +95,7 @@ type DatabrowserStore = {
9595
selectedTab: TabId | undefined
9696
tabs: [TabId, TabData][]
9797

98-
addTab: () => void
98+
addTab: () => TabId
9999
removeTab: (id: TabId) => void
100100
selectTab: (id: TabId) => void
101101

@@ -129,6 +129,8 @@ const storeCreator: StateCreator<DatabrowserStore> = (set, get) => ({
129129
tabs: [...old.tabs, [id, newTabData]],
130130
selectedTab: id,
131131
}))
132+
133+
return id
132134
},
133135

134136
removeTab: (id) => {

0 commit comments

Comments
 (0)