Skip to content

Commit 531c3a7

Browse files
committed
feat: change the +Key button with +Index when it's search mode
1 parent 97bc155 commit 531c3a7

File tree

3 files changed

+34
-8
lines changed

3 files changed

+34
-8
lines changed

src/components/databrowser/components/header/index.tsx

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
import { useState } from "react"
22
import { useTab } from "@/tab-provider"
3-
import { IconChevronDown, IconCircleCheck, IconCirclePlus, IconSearch } from "@tabler/icons-react"
3+
import {
4+
IconChevronDown,
5+
IconCircleCheck,
6+
IconCirclePlus,
7+
IconPlus,
8+
IconSearch,
9+
} from "@tabler/icons-react"
410

511
import { queryClient } from "@/lib/clients"
612
import { cn } from "@/lib/utils"
13+
import { Button } from "@/components/ui/button"
714
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover"
815
import { Segmented } from "@/components/ui/segmented"
16+
import { SimpleTooltip } from "@/components/ui/tooltip"
917

1018
import type { TabType } from "../.."
1119
import { ReloadButton } from "../../../common/reload-button"
@@ -61,7 +69,7 @@ export const Header = ({ tabType }: { tabType: TabType }) => {
6169
<IndexSelector />
6270
) : (
6371
<>
64-
<DataTypeSelector hideSearchTab={hideSearchTab} />
72+
<DataTypeSelector />
6573
<SearchInput />
6674
</>
6775
)}
@@ -70,7 +78,7 @@ export const Header = ({ tabType }: { tabType: TabType }) => {
7078
{/* Actions */}
7179
<div className="flex items-center gap-1.5">
7280
<RefreshButton />
73-
<AddKeyModal />
81+
{isValuesSearchSelected ? <AddIndexButton /> : <AddKeyModal />}
7482
</div>
7583
</div>
7684
)
@@ -202,6 +210,26 @@ const CreateIndexButton = () => {
202210
)
203211
}
204212

213+
const AddIndexButton = () => {
214+
const [open, setOpen] = useState(false)
215+
216+
return (
217+
<>
218+
<SimpleTooltip content="Add index">
219+
<Button
220+
variant="primary"
221+
onClick={() => setOpen(true)}
222+
className="flex h-8 items-center gap-1 rounded-lg pl-2 pr-3 text-sm font-medium"
223+
>
224+
<IconPlus className="size-5" />
225+
Index
226+
</Button>
227+
</SimpleTooltip>
228+
<CreateIndexModal open={open} onOpenChange={setOpen} />
229+
</>
230+
)
231+
}
232+
205233
const RefreshButton = () => {
206234
const { query } = useKeys()
207235

src/components/databrowser/components/sidebar/type-selector.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212

1313
const ALL_TYPES_KEY = "all"
1414

15-
export function DataTypeSelector({ hideSearchTab }: { hideSearchTab?: boolean }) {
15+
export function DataTypeSelector() {
1616
const { search, setSearchType } = useTab()
1717

1818
return (
@@ -26,18 +26,17 @@ export function DataTypeSelector({ hideSearchTab }: { hideSearchTab?: boolean })
2626
}}
2727
value={search.type === undefined ? ALL_TYPES_KEY : search.type}
2828
>
29-
<SelectTrigger className="!w-auto select-none whitespace-nowrap border-zinc-300 pr-8">
29+
<SelectTrigger className="!w-auto shrink-0 select-none whitespace-nowrap border-zinc-300 pr-8">
3030
<SelectValue />
3131
</SelectTrigger>
3232

3333
<SelectContent>
3434
<SelectGroup>
3535
{(() => {
36-
let entries: Array<[string, string]> = [
36+
const entries: Array<[string, string]> = [
3737
[ALL_TYPES_KEY, "All Types"],
3838
...Object.entries(DATA_TYPE_NAMES),
3939
]
40-
if (hideSearchTab) entries = entries.filter(([key]) => key !== "search")
4140
return entries.map(([key, value]) => (
4241
<SelectItem value={key} key={key}>
4342
{value}

src/playground/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ const App = () => {
7373
<div style={{ height: "640px" }}>
7474
{credentials ? (
7575
<RedisBrowser
76-
hideSearchTab
7776
onFullScreenClick={() => {
7877
// eslint-disable-next-line no-console
7978
console.log("Fullscreen button clicked")

0 commit comments

Comments
 (0)