SentHistory.tsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import { ProList } from "@ant-design/pro-components";
  2. import { Space, Typography } from "antd";
  3. import TimeShow from "../general/TimeShow";
  4. const { Paragraph } = Typography;
  5. interface IWidget {
  6. sentId?: string;
  7. }
  8. const SentHistoryWidget = ({ sentId }: IWidget) => {
  9. return (
  10. <ProList<ISentHistory>
  11. rowKey="id"
  12. request={async (params = {}, sorter, filter) => {
  13. if (typeof sentId === "undefined") {
  14. return {
  15. total: 0,
  16. succcess: false,
  17. data: [],
  18. };
  19. }
  20. console.log(params, sorter, filter);
  21. let url = `/v2/sent_history?view=sentence&id=${sentId}`;
  22. const offset =
  23. ((params.current ? params.current : 1) - 1) *
  24. (params.pageSize ? params.pageSize : 20);
  25. url += `&limit=${params.pageSize}&offset=${offset}`;
  26. if (typeof params.keyword !== "undefined") {
  27. url += "&search=" + (params.keyword ? params.keyword : "");
  28. }
  29. console.debug("sentence history list", url);
  30. const res = await get<ISentHistoryListResponse>(url);
  31. if (res.ok) {
  32. console.debug("sentence history list", res.data);
  33. const items: ISentHistory[] = res.data.rows.map((item, _id) => {
  34. return {
  35. content: item.content,
  36. editor: item.editor,
  37. fork_from: item.fork_from,
  38. pr_from: item.pr_from,
  39. accepter: item.accepter,
  40. createdAt: item.created_at,
  41. };
  42. });
  43. console.debug(items);
  44. return {
  45. total: res.data.count,
  46. succcess: true,
  47. data: items,
  48. };
  49. } else {
  50. console.error(res.message);
  51. return {
  52. total: 0,
  53. succcess: false,
  54. data: [],
  55. };
  56. }
  57. }}
  58. pagination={{
  59. showQuickJumper: true,
  60. showSizeChanger: true,
  61. }}
  62. metas={{
  63. title: {
  64. render: (_text, row, _index, _action) => {
  65. return (
  66. <Paragraph style={{ margin: 0 }} copyable={{ text: row.content }}>
  67. {row.content}
  68. </Paragraph>
  69. );
  70. },
  71. },
  72. avatar: {
  73. dataIndex: "image",
  74. editable: false,
  75. render: (_text, row, _index, _action) => {
  76. return <User {...row.editor} showName={false} />;
  77. },
  78. },
  79. description: {
  80. render: (_text, row, _index, _action) => {
  81. return (
  82. <Space style={{ fontSize: "80%" }}>
  83. <User {...row.editor} showAvatar={false} />
  84. <>{"edited"}</>
  85. {row.accepter ? (
  86. <>
  87. <User {...row.accepter} showAvatar={false} /> {"accept"}
  88. </>
  89. ) : (
  90. <></>
  91. )}
  92. {row.fork_from ? (
  93. <>
  94. <MergeIcon2 />
  95. {row.fork_from.name}
  96. </>
  97. ) : (
  98. <></>
  99. )}
  100. <TimeShow
  101. type="secondary"
  102. createdAt={row.createdAt}
  103. showLabel={false}
  104. />
  105. </Space>
  106. );
  107. },
  108. },
  109. actions: {
  110. render: (_text, _row, _index, _action) => [<></>],
  111. },
  112. }}
  113. />
  114. );
  115. };
  116. export default SentHistoryWidget;