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

Add a developer mode 'view source' button to crashed event tiles #7537

Merged
merged 2 commits into from
Jan 14, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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