Skip to content
Closed
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
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { useState } from "react"
import { Trash, Plus, X } from "lucide-react"
import { Trash, Plus, X, Loader2 } from "lucide-react"
import { CustomTooltip } from "../../ui/tooltip"
import { Button } from "../../ui/button"
import { Input } from "../../ui/input"
import { EditActionButtons } from "../../ui/edit-action-buttons"
import DeleteModal from "../../ui/delete-modal"
import { Typography } from "../../ui/typography"
import { useAppDispatch } from "@/hooks/hooks"
import { updateKeyRequested } from "@/state/valkey-features/keys/keyBrowserSlice"
import { useAppDispatch, useAppSelector } from "@/hooks/hooks"
import { getKeyElementsRequested, updateKeyRequested } from "@/state/valkey-features/keys/keyBrowserSlice"
import { cn } from "@/lib/utils"

interface ElementInfo {
Expand All @@ -24,9 +24,11 @@ interface KeyDetailsHashProps {
size: number;
collectionSize?: number;
elements: ElementInfo[];
cursor?: string;
hasMoreElements?: boolean;
};
connectionId: string;
readOnly:boolean;
readOnly: boolean;
}

interface NewField {
Expand All @@ -39,12 +41,28 @@ export default function KeyDetailsHash(
{ selectedKey, selectedKeyInfo, connectionId, readOnly = false }: KeyDetailsHashProps,
) {
const dispatch = useAppDispatch()
const elementsLoading = useAppSelector(
(state) => state.keyBrowser?.[connectionId]?.elementsLoading?.[selectedKey] || false,
)
const [isEditable, setIsEditable] = useState(false)
const [editedHashValue, setEditedHashValue] = useState<{ [key: string]: string }>({})
const [deletedHashFields, setDeletedHashFields] = useState<Set<string>>(new Set())
const [pendingDeleteField, setPendingDeleteField] = useState<string | null>(null)
const [newFields, setNewFields] = useState<NewField[]>([])

const handleLoadMore = () => {
if (elementsLoading) return
dispatch(
getKeyElementsRequested({
connectionId,
key: selectedKey,
keyType: "hash",
cursor: selectedKeyInfo.cursor ?? "0",
count: 100,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we drop count here and let the server default to ELEMENT_PAGE_SIZE? Same for key-details-list.tsx, key-details-set.tsx and key-details-zset.tsx

}),
)
}

const handleEdit = () => {
if (isEditable) {
// Cancel edit
Expand Down Expand Up @@ -238,6 +256,37 @@ export default function KeyDetailsHash(
</Button>
</div>
)}
{!isEditable &&
(selectedKeyInfo.hasMoreElements !== undefined
? selectedKeyInfo.hasMoreElements
: (selectedKeyInfo.cursor && selectedKeyInfo.cursor !== "0") ||
(selectedKeyInfo.collectionSize !== undefined &&
selectedKeyInfo.elements.length < selectedKeyInfo.collectionSize)) && (
<div className="flex flex-col items-center justify-center py-4 gap-2 border-t border-border">
<Typography variant="bodySm">
Showing {selectedKeyInfo.elements.length}
{selectedKeyInfo.collectionSize !== undefined
? ` of ${selectedKeyInfo.collectionSize.toLocaleString()}`
: ""}{" "}
fields
</Typography>
<Button
aria-label="Load more fields"
disabled={elementsLoading}
onClick={handleLoadMore}
size="sm"
variant="outline"
>
{elementsLoading ? (
<>
<Loader2 className="mr-2 animate-spin" size={14} /> Loading...
</>
) : (
"Load more"
)}
</Button>
</div>
)}
</div>
</div>
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { useState } from "react"
import { Trash, Plus, X } from "lucide-react"
import { Trash, Plus, X, Loader2 } from "lucide-react"
import { CustomTooltip } from "../../ui/tooltip"
import { Button } from "../../ui/button"
import { Input } from "../../ui/input"
import { EditActionButtons } from "../../ui/edit-action-buttons"
import DeleteModal from "../../ui/delete-modal"
import { Typography } from "../../ui/typography"
import { useAppDispatch } from "@/hooks/hooks"
import { updateKeyRequested } from "@/state/valkey-features/keys/keyBrowserSlice"
import { useAppDispatch, useAppSelector } from "@/hooks/hooks"
import { getKeyElementsRequested, updateKeyRequested } from "@/state/valkey-features/keys/keyBrowserSlice"
import { cn } from "@/lib/utils"

interface KeyDetailsListProps {
Expand All @@ -19,6 +19,8 @@ interface KeyDetailsListProps {
size: number;
collectionSize?: number;
elements: string[];
cursor?: string;
hasMoreElements?: boolean;
};
connectionId: string;
readOnly: boolean;
Expand All @@ -33,12 +35,28 @@ export default function KeyDetailsList(
{ selectedKey, selectedKeyInfo, connectionId, readOnly = false }: KeyDetailsListProps,
) {
const dispatch = useAppDispatch()
const elementsLoading = useAppSelector(
(state) => state.keyBrowser?.[connectionId]?.elementsLoading?.[selectedKey] || false,
)
const [isEditable, setIsEditable] = useState(false)
const [editedListValues, setEditedListValues] = useState<string[]>([])
const [deletedIndices, setDeletedIndices] = useState<Set<number>>(new Set())
const [pendingDeleteIndex, setPendingDeleteIndex] = useState<number | null>(null)
const [newItems, setNewItems] = useState<NewItem[]>([])

const handleLoadMore = () => {
if (elementsLoading) return
dispatch(
getKeyElementsRequested({
connectionId,
key: selectedKey,
keyType: "list",
offset: selectedKeyInfo.elements.length,
count: 100,
}),
)
}

const handleEdit = () => {
if (isEditable) {
// Cancel edit
Expand Down Expand Up @@ -220,6 +238,35 @@ export default function KeyDetailsList(
</Button>
</div>
)}
{!isEditable &&
(selectedKeyInfo.hasMoreElements ||
(selectedKeyInfo.collectionSize !== undefined &&
selectedKeyInfo.elements.length < selectedKeyInfo.collectionSize)) && (
<div className="flex flex-col items-center justify-center py-4 gap-2 border-t border-border">
<Typography variant="bodySm">
Showing {selectedKeyInfo.elements.length}
{selectedKeyInfo.collectionSize !== undefined
? ` of ${selectedKeyInfo.collectionSize.toLocaleString()}`
: ""}{" "}
elements
</Typography>
<Button
aria-label="Load more elements"
disabled={elementsLoading}
onClick={handleLoadMore}
size="sm"
variant="outline"
>
{elementsLoading ? (
<>
<Loader2 className="mr-2 animate-spin" size={14} /> Loading...
</>
) : (
"Load more"
)}
</Button>
</div>
)}
</div>
</div>
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { useState } from "react"
import { Trash, Plus, X } from "lucide-react"
import { Trash, Plus, X, Loader2 } from "lucide-react"
import { CustomTooltip } from "../../ui/tooltip"
import { Button } from "../../ui/button"
import { Input } from "../../ui/input"
import { EditActionButtons } from "../../ui/edit-action-buttons"
import DeleteModal from "../../ui/delete-modal"
import { Typography } from "../../ui/typography"
import { useAppDispatch } from "@/hooks/hooks"
import { updateKeyRequested } from "@/state/valkey-features/keys/keyBrowserSlice"
import { useAppDispatch, useAppSelector } from "@/hooks/hooks"
import { getKeyElementsRequested, updateKeyRequested } from "@/state/valkey-features/keys/keyBrowserSlice"
import { cn } from "@/lib/utils"

interface KeyDetailsSetProps {
Expand All @@ -19,6 +19,8 @@ interface KeyDetailsSetProps {
size: number;
collectionSize?: number;
elements: string[];
cursor?: string;
hasMoreElements?: boolean;
};
connectionId: string;
readOnly: boolean;
Expand All @@ -33,12 +35,28 @@ export default function KeyDetailsSet(
{ selectedKey, selectedKeyInfo, connectionId, readOnly = false }: KeyDetailsSetProps,
) {
const dispatch = useAppDispatch()
const elementsLoading = useAppSelector(
(state) => state.keyBrowser?.[connectionId]?.elementsLoading?.[selectedKey] || false,
)
const [isEditable, setIsEditable] = useState(false)
const [editedSetValues, setEditedSetValues] = useState<string[]>([])
const [deletedValues, setDeletedValues] = useState<Set<string>>(new Set())
const [pendingDeleteValue, setPendingDeleteValue] = useState<string | null>(null)
const [newItems, setNewItems] = useState<NewItem[]>([])

const handleLoadMore = () => {
if (elementsLoading) return
dispatch(
getKeyElementsRequested({
connectionId,
key: selectedKey,
keyType: "set",
cursor: selectedKeyInfo.cursor ?? "0",
count: 100,
}),
)
}

const handleEdit = () => {
if (isEditable) {
// Cancel edit
Expand Down Expand Up @@ -216,6 +234,37 @@ export default function KeyDetailsSet(
</Button>
</div>
)}
{!isEditable &&
(selectedKeyInfo.hasMoreElements !== undefined
? selectedKeyInfo.hasMoreElements
: (selectedKeyInfo.cursor && selectedKeyInfo.cursor !== "0") ||
(selectedKeyInfo.collectionSize !== undefined &&
selectedKeyInfo.elements.length < selectedKeyInfo.collectionSize)) && (
<div className="flex flex-col items-center justify-center py-4 gap-2 border-t border-border">
<Typography variant="bodySm">
Showing {selectedKeyInfo.elements.length}
{selectedKeyInfo.collectionSize !== undefined
? ` of ${selectedKeyInfo.collectionSize.toLocaleString()}`
: ""}{" "}
elements
</Typography>
<Button
aria-label="Load more elements"
disabled={elementsLoading}
onClick={handleLoadMore}
size="sm"
variant="outline"
>
{elementsLoading ? (
<>
<Loader2 className="mr-2 animate-spin" size={14} /> Loading...
</>
) : (
"Load more"
)}
</Button>
</div>
)}
</div>
</div>
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { useState } from "react"
import { Loader2 } from "lucide-react"
import { Button } from "../../ui/button"
import { Input } from "../../ui/input"
import { EditActionButtons } from "../../ui/edit-action-buttons"
import { Typography } from "../../ui/typography"
import { useAppDispatch } from "@/hooks/hooks"
import { updateKeyRequested } from "@/state/valkey-features/keys/keyBrowserSlice"
import { useAppDispatch, useAppSelector } from "@/hooks/hooks"
import { getKeyElementsRequested, updateKeyRequested } from "@/state/valkey-features/keys/keyBrowserSlice"
import { cn } from "@/lib/utils"

interface ZSetElement {
Expand All @@ -20,6 +22,8 @@ interface KeyDetailsZSetProps {
size: number;
collectionSize?: number;
elements: ZSetElement[];
cursor?: string;
hasMoreElements?: boolean;
};
connectionId: string;
readOnly: boolean;
Expand All @@ -29,11 +33,27 @@ export default function KeyDetailsZSet(
{ selectedKey, selectedKeyInfo, connectionId, readOnly = false }: KeyDetailsZSetProps,
) {
const dispatch = useAppDispatch()
const elementsLoading = useAppSelector(
(state) => state.keyBrowser?.[connectionId]?.elementsLoading?.[selectedKey] || false,
)
const [isEditable, setIsEditable] = useState(false)
const [editedValues, setEditedValues] = useState<number[]>([])

console.debug("selectedKeyInfo:::", selectedKeyInfo)

const handleLoadMore = () => {
if (elementsLoading) return
dispatch(
getKeyElementsRequested({
connectionId,
key: selectedKey,
keyType: "zset",
offset: selectedKeyInfo.elements.length,
count: 100,
}),
)
}

const handleEdit = () => {
if (isEditable) {
// Cancel edit
Expand Down Expand Up @@ -106,6 +126,35 @@ export default function KeyDetailsZSet(
</div>
</div>
))}
{!isEditable &&
(selectedKeyInfo.hasMoreElements ||
(selectedKeyInfo.collectionSize !== undefined &&
selectedKeyInfo.elements.length < selectedKeyInfo.collectionSize)) && (
<div className="flex flex-col items-center justify-center py-4 gap-2 border-t border-border">
<Typography variant="bodySm">
Showing {selectedKeyInfo.elements.length}
{selectedKeyInfo.collectionSize !== undefined
? ` of ${selectedKeyInfo.collectionSize.toLocaleString()}`
: ""}{" "}
elements
</Typography>
<Button
aria-label="Load more elements"
disabled={elementsLoading}
onClick={handleLoadMore}
size="sm"
variant="outline"
>
{elementsLoading ? (
<>
<Loader2 className="mr-2 animate-spin" size={14} /> Loading...
</>
) : (
"Load more"
)}
</Button>
</div>
)}
</div>
</div>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ interface BaseKeyInfo {
collectionSize?: number;
elementsWarning?: string;
isBinary?: boolean;
cursor?: string;
hasMoreElements?: boolean;
}

interface ElementInfo {
Expand Down
Loading
Loading