Add copy button to View Source screen (#8278)
Co-authored-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
parent
9ba55d1d14
commit
7b2f1e22e1
2 changed files with 42 additions and 7 deletions
|
@ -34,8 +34,13 @@ limitations under the License.
|
||||||
padding: 0.5em 1em 0.5em 1em;
|
padding: 0.5em 1em 0.5em 1em;
|
||||||
word-wrap: break-word;
|
word-wrap: break-word;
|
||||||
white-space: pre-wrap;
|
white-space: pre-wrap;
|
||||||
|
overflow-wrap: anywhere;
|
||||||
}
|
}
|
||||||
|
|
||||||
.mx_ViewSource_details {
|
.mx_ViewSource_details {
|
||||||
margin-top: 0.8em;
|
margin-top: 0.8em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.mx_ViewSource_container {
|
||||||
|
max-width: calc(100% - 24px);
|
||||||
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@ import BaseDialog from "../views/dialogs/BaseDialog";
|
||||||
import { DevtoolsContext } from "../views/dialogs/devtools/BaseTool";
|
import { DevtoolsContext } from "../views/dialogs/devtools/BaseTool";
|
||||||
import { StateEventEditor } from "../views/dialogs/devtools/RoomState";
|
import { StateEventEditor } from "../views/dialogs/devtools/RoomState";
|
||||||
import { stringify, TimelineEventEditor } from "../views/dialogs/devtools/Event";
|
import { stringify, TimelineEventEditor } from "../views/dialogs/devtools/Event";
|
||||||
|
import CopyableText from "../views/elements/CopyableText";
|
||||||
|
|
||||||
interface IProps extends IDialogProps {
|
interface IProps extends IDialogProps {
|
||||||
mxEvent: MatrixEvent; // the MatrixEvent associated with the context menu
|
mxEvent: MatrixEvent; // the MatrixEvent associated with the context menu
|
||||||
|
@ -63,29 +64,58 @@ export default class ViewSource extends React.Component<IProps, IState> {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const decryptedEventSource = mxEvent.clearEvent; // FIXME: clearEvent is private
|
const decryptedEventSource = mxEvent.clearEvent; // FIXME: clearEvent is private
|
||||||
const originalEventSource = mxEvent.event;
|
const originalEventSource = mxEvent.event;
|
||||||
|
const copyOriginalFunc = (): string => {
|
||||||
|
return stringify(originalEventSource);
|
||||||
|
};
|
||||||
if (isEncrypted) {
|
if (isEncrypted) {
|
||||||
|
const copyDecryptedFunc = (): string => {
|
||||||
|
return stringify(decryptedEventSource);
|
||||||
|
};
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<details open className="mx_ViewSource_details">
|
<details open className="mx_ViewSource_details">
|
||||||
<summary>
|
<summary>
|
||||||
<span className="mx_ViewSource_heading">{ _t("Decrypted event source") }</span>
|
<span className="mx_ViewSource_heading">
|
||||||
|
{ _t("Decrypted event source") }
|
||||||
|
</span>
|
||||||
</summary>
|
</summary>
|
||||||
<SyntaxHighlight language="json">{ stringify(decryptedEventSource) }</SyntaxHighlight>
|
<div className="mx_ViewSource_container">
|
||||||
|
<CopyableText getTextToCopy={copyDecryptedFunc}>
|
||||||
|
<SyntaxHighlight language="json">
|
||||||
|
{ stringify(decryptedEventSource) }
|
||||||
|
</SyntaxHighlight>
|
||||||
|
</CopyableText>
|
||||||
|
</div>
|
||||||
</details>
|
</details>
|
||||||
<details className="mx_ViewSource_details">
|
<details className="mx_ViewSource_details">
|
||||||
<summary>
|
<summary>
|
||||||
<span className="mx_ViewSource_heading">{ _t("Original event source") }</span>
|
<span className="mx_ViewSource_heading">
|
||||||
|
{ _t("Original event source") }
|
||||||
|
</span>
|
||||||
</summary>
|
</summary>
|
||||||
<SyntaxHighlight language="json">{ stringify(originalEventSource) }</SyntaxHighlight>
|
<div className="mx_ViewSource_container">
|
||||||
|
<CopyableText getTextToCopy={copyOriginalFunc}>
|
||||||
|
<SyntaxHighlight language="json">
|
||||||
|
{ stringify(originalEventSource) }
|
||||||
|
</SyntaxHighlight>
|
||||||
|
</CopyableText>
|
||||||
|
</div>
|
||||||
</details>
|
</details>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className="mx_ViewSource_heading">{ _t("Original event source") }</div>
|
<div className="mx_ViewSource_heading">
|
||||||
<SyntaxHighlight language="json">{ stringify(originalEventSource) }</SyntaxHighlight>
|
{ _t("Original event source") }
|
||||||
|
</div>
|
||||||
|
<div className="mx_ViewSource_container">
|
||||||
|
<CopyableText getTextToCopy={copyOriginalFunc}>
|
||||||
|
<SyntaxHighlight language="json">
|
||||||
|
{ stringify(originalEventSource) }
|
||||||
|
</SyntaxHighlight>
|
||||||
|
</CopyableText>
|
||||||
|
</div>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue