Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
part of #1022 Allow updating the show_on_leaderboard field. Add raw JSON of the user object. Add a new user message table. Also fixed style issue: hard to see reaction count when the user also reacted. Rename MessageTable to MessageConversation.
- Loading branch information
Showing
26 changed files
with
409 additions
and
135 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { forwardRef, IconButton, IconButtonProps } from "@chakra-ui/react"; | ||
import { LucideIcon } from "lucide-react"; | ||
|
||
export type DataTableActionProps = Omit<IconButtonProps, "icon" | "size"> & { icon: LucideIcon }; | ||
|
||
// need to use forwardRef from Charka to support `as` props | ||
// https://chakra-ui.com/community/recipes/as-prop | ||
export const DataTableAction = forwardRef<DataTableActionProps, "button">((props: DataTableActionProps, ref) => { | ||
return <IconButton size="sm" {...props} icon={<props.icon size="20"></props.icon>} ref={ref} />; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { useState } from "react"; | ||
|
||
export interface CursorPaginationState { | ||
/** | ||
* The user's `display_name` used for pagination. | ||
*/ | ||
cursor: string; | ||
|
||
/** | ||
* The pagination direction. | ||
*/ | ||
direction: "forward" | "back"; | ||
} | ||
|
||
export const useCursorPagination = () => { | ||
const [pagination, setPagination] = useState<CursorPaginationState>({ cursor: "", direction: "forward" }); | ||
|
||
const toPreviousPage = (data: undefined | { prev?: string; next?: string }) => { | ||
setPagination({ | ||
cursor: data?.prev || "", | ||
direction: "back", | ||
}); | ||
}; | ||
|
||
const toNextPage = (data: undefined | { prev?: string; next?: string }) => { | ||
setPagination({ | ||
cursor: data?.next || "", | ||
direction: "forward", | ||
}); | ||
}; | ||
|
||
const resetCursor = () => setPagination((old) => ({ ...old, cursor: "" })); | ||
|
||
return { | ||
pagination, | ||
toNextPage, | ||
toPreviousPage, | ||
resetCursor, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Card, CardBody } from "@chakra-ui/card"; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
export const JsonCard = ({ children }: { children: any }) => { | ||
return ( | ||
<Card variant="json"> | ||
<CardBody overflowX="auto"> | ||
<pre>{JSON.stringify(children, null, 2)}</pre> | ||
</CardBody> | ||
</Card> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import { Avatar } from "@chakra-ui/avatar"; | ||
import { Badge, Flex } from "@chakra-ui/layout"; | ||
import { Tooltip } from "@chakra-ui/react"; | ||
import { createColumnHelper } from "@tanstack/table-core"; | ||
import { formatDistanceToNow, formatISO9075 } from "date-fns"; | ||
import { Eye } from "lucide-react"; | ||
import NextLink from "next/link"; | ||
import { ROUTES } from "src/lib/routes"; | ||
import { Message } from "src/types/Conversation"; | ||
import { isKnownEmoji } from "src/types/Emoji"; | ||
import { StrictOmit } from "src/types/utils"; | ||
|
||
import { DataTable, DataTableProps } from "../DataTable/DataTable"; | ||
import { DataTableAction } from "../DataTable/DataTableAction"; | ||
import { MessageEmojiButton } from "./MessageEmojiButton"; | ||
|
||
const columnHelper = createColumnHelper<Message>(); | ||
|
||
const columns = [ | ||
columnHelper.accessor("text", { | ||
cell: ({ getValue, row }) => { | ||
const limit = 80; | ||
const text = getValue(); | ||
const renderText = text.length > limit ? `${text.slice(0, limit)}...` : text; | ||
return ( | ||
<Flex alignItems="center"> | ||
<Avatar | ||
size="xs" | ||
mr="2" | ||
src={`${row.original.is_assistant ? "/images/logos/logo.png" : "/images/temp-avatars/av1.jpg"}`} | ||
></Avatar> | ||
{renderText} | ||
{row.original.deleted && ( | ||
<Badge colorScheme="red" ml="1"> | ||
Deleted | ||
</Badge> | ||
)} | ||
</Flex> | ||
); | ||
}, | ||
}), | ||
columnHelper.accessor("lang", { | ||
header: "Language", | ||
cell: ({ getValue }) => <Badge>{getValue()}</Badge>, | ||
}), | ||
columnHelper.accessor("emojis", { | ||
header: "Reactions", | ||
cell: ({ getValue, row }) => { | ||
const emojis = getValue(); | ||
|
||
emojis["+1"] = emojis["+1"] || 0; | ||
emojis["-1"] = emojis["-1"] || 0; | ||
|
||
return ( | ||
<Flex gap="2"> | ||
{Object.entries(emojis) | ||
.filter(([emoji]) => isKnownEmoji(emoji)) | ||
.sort(([emoji]) => -emoji) | ||
.map(([emoji, count]) => { | ||
return ( | ||
<MessageEmojiButton | ||
key={emoji} | ||
emoji={{ name: emoji, count }} | ||
checked={row.original.user_emojis.includes(emoji)} | ||
userReacted={false} | ||
userIsAuthor={false} | ||
sx={{ | ||
":disabled": { | ||
opacity: 1, | ||
}, | ||
}} | ||
/> | ||
); | ||
})} | ||
</Flex> | ||
); | ||
}, | ||
}), | ||
columnHelper.accessor("created_date", { | ||
header: "Date", | ||
cell: ({ getValue }) => { | ||
return <DateDiff>{getValue()}</DateDiff>; | ||
}, | ||
}), | ||
columnHelper.accessor((row) => row.id, { | ||
header: "Actions", | ||
cell: ({ getValue }) => ( | ||
<DataTableAction | ||
as={NextLink} | ||
href={ROUTES.ADMIN_MESSAGE_DETAIL(getValue())} | ||
icon={Eye} | ||
aria-label="View message" | ||
/> | ||
), | ||
}), | ||
]; | ||
// TODO move this to somewhere | ||
const DateDiff = ({ children }: { children: string | Date | number }) => { | ||
const date = new Date(children); | ||
const diff = formatDistanceToNow(date, { addSuffix: true }); | ||
return ( | ||
<Tooltip label={formatISO9075(date)} placement="top"> | ||
{diff} | ||
</Tooltip> | ||
); | ||
}; | ||
|
||
export const AdminMessageTable = (props: StrictOmit<DataTableProps<Message>, "columns">) => { | ||
return <DataTable columns={columns} {...props}></DataTable>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 0 additions & 40 deletions
40
website/src/components/UserMessagesCell/UserMessagesCell.tsx
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.