Skip to content

Commit

Permalink
Enhanced column dropdown functionality and user interaction and added…
Browse files Browse the repository at this point in the history
… csv helper to escape new lines
  • Loading branch information
bekossy committed May 14, 2024
1 parent 4579cce commit 0210178
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
18 changes: 15 additions & 3 deletions agenta-web/src/components/ServerTable/components.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {GenericObject, JSSTheme, PaginationQuery} from "@/lib/Types"
import {Button, Dropdown, Input, Space} from "antd"
import {Button, Dropdown, DropdownProps, Input, Space} from "antd"
import {ColumnsType} from "antd/es/table"
import {FilterDropdownProps} from "antd/es/table/interface"
import dayjs from "dayjs"
import React, {ReactNode, useMemo} from "react"
import React, {ReactNode, useMemo, useState} from "react"
import {createUseStyles} from "react-jss"
import {Resizable} from "react-resizable"
import EnforceAntdStyles from "../EnforceAntdStyles/EnforceAntdStyles"
Expand Down Expand Up @@ -100,6 +100,13 @@ interface ColsDropdownProps<T> {

export const ColsDropdown = <T,>({columns, hiddenCols, setHiddenCols}: ColsDropdownProps<T>) => {
const classes = useStyles()
const [isFilterColsDropdownOpen, setIsFilterColsDropdownOpen] = useState(false)

const handleOpenChangeFilterCols: DropdownProps["onOpenChange"] = (nextOpen, info) => {
if (info.source === "trigger" || nextOpen) {
setIsFilterColsDropdownOpen(nextOpen)
}
}
const shownCols = useMemo(
() =>
columns
Expand All @@ -119,6 +126,8 @@ export const ColsDropdown = <T,>({columns, hiddenCols, setHiddenCols}: ColsDropd
return (
<Dropdown
trigger={["click"]}
open={isFilterColsDropdownOpen}
onOpenChange={handleOpenChangeFilterCols}
menu={{
selectedKeys: shownCols,
items: columns.map((item) => ({
Expand All @@ -130,7 +139,10 @@ export const ColsDropdown = <T,>({columns, hiddenCols, setHiddenCols}: ColsDropd
</Space>
),
})) as any,
onClick: ({key}) => onColToggle(key),
onClick: ({key}) => {
onColToggle(key)
setIsFilterColsDropdownOpen(true)
},
className: classes.dropdownMenu,
}}
>
Expand Down
2 changes: 2 additions & 0 deletions agenta-web/src/lib/helpers/fileManipulations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ export const convertToCsv = (rows: GenericObject[], header: string[]) => {
return Papa.unparse({fields: header.filter((item) => !!item), data: rows})
}

export const escapeNewlines = (value: string) => value.replace(/\n/g, "\\n")

export const downloadCsv = (csvContent: string, filename: string): void => {
if (typeof window === "undefined") return

Expand Down

0 comments on commit 0210178

Please sign in to comment.