EditInfo.tsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. import { List, Popover, Typography, notification } from "antd";
  2. import { Space } from "antd";
  3. import User from "../../auth/User";
  4. import Channel from "../../channel/Channel";
  5. import TimeShow from "../../general/TimeShow";
  6. import type { ISentence } from "../SentEdit"
  7. import { MergeIcon2 } from "../../../assets/icon";
  8. import { useEffect, useState } from "react";
  9. import { get } from "../../../request";
  10. import type {
  11. ISentHistoryData,
  12. ISentHistoryListResponse,
  13. } from "../../corpus/SentHistory";
  14. import moment from "moment";
  15. const { Text } = Typography;
  16. interface IFork {
  17. sentId?: string;
  18. highlight?: boolean;
  19. }
  20. const Fork = ({ sentId, highlight = false }: IFork) => {
  21. const [data, setData] = useState<ISentHistoryData[]>();
  22. useEffect(() => {
  23. if (sentId) {
  24. const url = `/v2/sent_history?view=sentence&id=${sentId}&fork=1`;
  25. get<ISentHistoryListResponse>(url).then((json) => {
  26. if (json.ok) {
  27. setData(json.data.rows);
  28. } else {
  29. notification.error({ message: json.message });
  30. }
  31. });
  32. }
  33. }, [sentId]);
  34. return (
  35. <Popover
  36. placement="bottom"
  37. content={
  38. <List
  39. size="small"
  40. header={highlight ? false : "已被修改"}
  41. footer={false}
  42. dataSource={data}
  43. renderItem={(item) => (
  44. <List.Item>
  45. <Text type="secondary" style={{ fontSize: "85%" }}>
  46. <Space>
  47. <User {...item.accepter} showAvatar={false} />
  48. {"fork from"}
  49. <Text>
  50. {item.fork_studio?.nickName}-{item.fork_from?.name}
  51. </Text>
  52. {"on"}
  53. <TimeShow
  54. type="secondary"
  55. title="复制"
  56. showLabel={false}
  57. createdAt={item.created_at}
  58. />
  59. </Space>
  60. </Text>
  61. </List.Item>
  62. )}
  63. />
  64. }
  65. >
  66. <span style={{ color: highlight ? "#1890ff" : "unset" }}>
  67. <MergeIcon2 />
  68. </span>
  69. </Popover>
  70. );
  71. };
  72. interface IMergeButton {
  73. data: ISentence;
  74. }
  75. const MergeButton = ({ data }: IMergeButton) => {
  76. if (data.forkAt) {
  77. const fork = moment(data.forkAt);
  78. const updated = moment(data.updateAt);
  79. if (fork.isSame(updated)) {
  80. return <Fork sentId={data.id} highlight />;
  81. } else {
  82. return <Fork sentId={data.id} />;
  83. }
  84. } else {
  85. return <></>;
  86. }
  87. };
  88. interface IDetailsWidget {
  89. data: ISentence;
  90. isPr?: boolean;
  91. }
  92. export const Details = ({ data, isPr }: IDetailsWidget) => (
  93. <Space wrap>
  94. {isPr ? <></> : <Channel {...data.channel} />}
  95. <User {...data.editor} showAvatar={false} />
  96. {data.prEditAt ? (
  97. <TimeShow
  98. type="secondary"
  99. updatedAt={data.prEditAt}
  100. createdAt={data.createdAt}
  101. />
  102. ) : (
  103. <TimeShow
  104. type="secondary"
  105. updatedAt={data.updateAt}
  106. createdAt={data.createdAt}
  107. />
  108. )}
  109. <MergeButton data={data} />
  110. <span style={{ display: "none" }}>
  111. {data.acceptor ? (
  112. <User {...data.acceptor} showAvatar={false} />
  113. ) : undefined}
  114. {data.acceptor ? "accept at" : undefined}
  115. {data.prEditAt ? (
  116. <TimeShow
  117. type="secondary"
  118. updatedAt={data.updateAt}
  119. showLabel={false}
  120. />
  121. ) : undefined}
  122. </span>
  123. </Space>
  124. );
  125. interface IWidget {
  126. data: ISentence;
  127. isPr?: boolean;
  128. compact?: boolean;
  129. }
  130. const EditInfoWidget = ({ data, isPr = false, compact = false }: IWidget) => {
  131. return (
  132. <div style={{ fontSize: "80%" }}>
  133. <Text type="secondary">
  134. {compact ? undefined : <Details data={data} isPr={isPr} />}
  135. </Text>
  136. </div>
  137. );
  138. };
  139. export default EditInfoWidget;