SentHistory.tsx 4.2 KB

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