| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- import { ProList } from "@ant-design/pro-components";
- import { Space, Typography } from "antd";
- import TimeShow from "../general/TimeShow";
- const { Paragraph } = Typography;
- interface IWidget {
- sentId?: string;
- }
- const SentHistoryWidget = ({ sentId }: IWidget) => {
- return (
- <ProList<ISentHistory>
- rowKey="id"
- request={async (params = {}, sorter, filter) => {
- if (typeof sentId === "undefined") {
- return {
- total: 0,
- succcess: false,
- data: [],
- };
- }
- console.log(params, sorter, filter);
- let url = `/v2/sent_history?view=sentence&id=${sentId}`;
- const offset =
- ((params.current ? params.current : 1) - 1) *
- (params.pageSize ? params.pageSize : 20);
- url += `&limit=${params.pageSize}&offset=${offset}`;
- if (typeof params.keyword !== "undefined") {
- url += "&search=" + (params.keyword ? params.keyword : "");
- }
- console.debug("sentence history list", url);
- const res = await get<ISentHistoryListResponse>(url);
- if (res.ok) {
- console.debug("sentence history list", res.data);
- const items: ISentHistory[] = res.data.rows.map((item, _id) => {
- return {
- content: item.content,
- editor: item.editor,
- fork_from: item.fork_from,
- pr_from: item.pr_from,
- accepter: item.accepter,
- createdAt: item.created_at,
- };
- });
- console.debug(items);
- return {
- total: res.data.count,
- succcess: true,
- data: items,
- };
- } else {
- console.error(res.message);
- return {
- total: 0,
- succcess: false,
- data: [],
- };
- }
- }}
- pagination={{
- showQuickJumper: true,
- showSizeChanger: true,
- }}
- metas={{
- title: {
- render: (_text, row, _index, _action) => {
- return (
- <Paragraph style={{ margin: 0 }} copyable={{ text: row.content }}>
- {row.content}
- </Paragraph>
- );
- },
- },
- avatar: {
- dataIndex: "image",
- editable: false,
- render: (_text, row, _index, _action) => {
- return <User {...row.editor} showName={false} />;
- },
- },
- description: {
- render: (_text, row, _index, _action) => {
- return (
- <Space style={{ fontSize: "80%" }}>
- <User {...row.editor} showAvatar={false} />
- <>{"edited"}</>
- {row.accepter ? (
- <>
- <User {...row.accepter} showAvatar={false} /> {"accept"}
- </>
- ) : (
- <></>
- )}
- {row.fork_from ? (
- <>
- <MergeIcon2 />
- {row.fork_from.name}
- </>
- ) : (
- <></>
- )}
- <TimeShow
- type="secondary"
- createdAt={row.createdAt}
- showLabel={false}
- />
- </Space>
- );
- },
- },
- actions: {
- render: (_text, _row, _index, _action) => [<></>],
- },
- }}
- />
- );
- };
- export default SentHistoryWidget;
|