Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Add a developer mode 'view source' button to crashed event tiles (#7537)
Browse files Browse the repository at this point in the history
* Add a developer mode 'view source' button to crashed event tiles

* appease the linter
  • Loading branch information
turt2live committed Jan 14, 2022
1 parent 52dd590 commit aa4131e
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/components/views/messages/TileErrorBoundary.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2020 - 2021 The Matrix.org Foundation C.I.C.
Copyright 2020 - 2022 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -24,6 +24,8 @@ import SdkConfig from "../../../SdkConfig";
import { replaceableComponent } from "../../../utils/replaceableComponent";
import BugReportDialog from '../dialogs/BugReportDialog';
import AccessibleButton from '../elements/AccessibleButton';
import SettingsStore from "../../../settings/SettingsStore";
import ViewSource from "../../structures/ViewSource";

interface IProps {
mxEvent: MatrixEvent;
Expand Down Expand Up @@ -56,6 +58,12 @@ export default class TileErrorBoundary extends React.Component<IProps, IState> {
});
};

private onViewSource = (): void => {
Modal.createTrackedDialog('View Event Source', 'from crash', ViewSource, {
mxEvent: this.props.mxEvent,
}, 'mx_Dialog_viewsource');
};

render() {
if (this.state.error) {
const { mxEvent } = this.props;
Expand All @@ -73,12 +81,20 @@ export default class TileErrorBoundary extends React.Component<IProps, IState> {
</AccessibleButton>;
}

let viewSourceButton;
if (mxEvent && SettingsStore.getValue("developerMode")) {
viewSourceButton = <AccessibleButton onClick={this.onViewSource} kind="link_inline">
{ _t("View Source") }
</AccessibleButton>;
}

return (<div className={classNames(classes)}>
<div className="mx_EventTile_line">
<span>
{ _t("Can't load this message") }
{ mxEvent && ` (${mxEvent.getType()})` }
{ submitLogsButton }
{ viewSourceButton }
</span>
</div>
</div>);
Expand Down

0 comments on commit aa4131e

Please sign in to comment.