From ee9d4a404ae7a2a3a3d89bcae62fda47e78c842c Mon Sep 17 00:00:00 2001 From: Ephraim Date: Tue, 26 Apr 2022 16:57:49 +0300 Subject: [PATCH] Mitigate bad url creation in ToolsButton by adding explicit param --- static/js/ConnectionsPanel.jsx | 37 ++++++++++++++++++---------------- static/js/sefaria/util.js | 1 + 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/static/js/ConnectionsPanel.jsx b/static/js/ConnectionsPanel.jsx index 33c3fdcbe8..03b4560c5e 100644 --- a/static/js/ConnectionsPanel.jsx +++ b/static/js/ConnectionsPanel.jsx @@ -315,9 +315,9 @@ class ConnectionsPanel extends Component { masterPanelSheetId={this.props.masterPanelSheetId} /> :
- this.props.setConnectionsMode("About")} /> - this.props.setConnectionsMode("Navigation")} /> - this.props.setConnectionsMode("Translations")} count={resourcesButtonCounts.translations} /> + this.props.setConnectionsMode("About")} /> + this.props.setConnectionsMode("Navigation")} /> + this.props.setConnectionsMode("Translations")} count={resourcesButtonCounts.translations} />
} {showConnectionSummary ? @@ -348,8 +348,8 @@ class ConnectionsPanel extends Component { // looked at (this.props.masterPanelMode == "Sheet" && this.props.title !== "Sheet") ? <> - this.props.setConnectionsMode("About")} /> - this.props.setConnectionsMode("Translations")} /> + this.props.setConnectionsMode("About")} /> + this.props.setConnectionsMode("Translations")} /> : null @@ -756,11 +756,11 @@ const ResourcesList = ({ masterPanelMode, setConnectionsMode, counts }) => { // A list of Resources in addition to connection return (
- setConnectionsMode("Sheets")} /> - setConnectionsMode("WebPages")} /> - setConnectionsMode("Topics")} /> - setConnectionsMode("manuscripts")} /> - setConnectionsMode("Torah Readings")} /> + setConnectionsMode("Sheets")} /> + setConnectionsMode("WebPages")} /> + setConnectionsMode("Topics")} /> + setConnectionsMode("manuscripts")} /> + setConnectionsMode("Torah Readings")} />
); } @@ -774,9 +774,9 @@ const ToolsList = ({ setConnectionsMode, toggleSignUpModal, openComparePanel, co return (
!Sefaria._uid ? toggleSignUpModal() : setConnectionsMode("Add To Sheet", { "addSource": "mainPanel" })} /> - setConnectionsMode("Lexicon")} /> + setConnectionsMode("Lexicon")} /> {openComparePanel ? : null} - !Sefaria._uid ? toggleSignUpModal() : setConnectionsMode("Notes")} /> + !Sefaria._uid ? toggleSignUpModal() : setConnectionsMode("Notes")} /> !Sefaria._uid ? toggleSignUpModal() : setConnectionsMode("Chavruta")} /> {masterPanelMode !== "Sheet" ? setConnectionsMode("Share")} /> : null} setConnectionsMode("Feedback")} /> @@ -809,9 +809,9 @@ const AboutSheetButtons = ({ setConnectionsMode, masterPanelSheetId }) => { return (
{isOwner ? - setConnectionsMode("AboutSheet")} /> + setConnectionsMode("AboutSheet")} /> : - setConnectionsMode("AboutSheet")} /> + setConnectionsMode("AboutSheet")} /> } {showEditButton ? { @@ -969,7 +969,7 @@ class SheetNodeConnectionTools extends Component { {this.props.multiPanel ? : null} - this.props.setConnectionsMode("Sheets")} /> + this.props.setConnectionsMode("Sheets")} /> this.props.setConnectionsMode("Feedback")} />
); } @@ -1346,7 +1346,9 @@ AdvancedToolsList.propTypes = { }; -const ToolsButton = ({ en, he, icon, image, count = null, onClick, control = "interface", typeface = "system", alwaysShow = false, secondaryHe, secondaryEn, greyColor=false }) => { +const ToolsButton = ({ en, he, onClick, urlConnectionsMode = null, icon, image, + count = null, control = "interface", typeface = "system", alwaysShow = false, + secondaryHe, secondaryEn, greyColor=false }) => { const clickHandler = (e) => { e.preventDefault(); onClick(); @@ -1360,7 +1362,8 @@ const ToolsButton = ({ en, he, icon, image, count = null, onClick, control = "in } else if (image) { iconElem = (); } - const url = Sefaria.util.replaceUrlParam("with", en); + //We only want to generate reloadable urls for states where we actually respond to said url. See ReaderApp.makeHistoryState()- sidebarModes. + const url = urlConnectionsMode ? Sefaria.util.replaceUrlParam("with", urlConnectionsMode) : null; const nameClass = en.camelize(); const wrapperClasses = classNames({ toolsButton: 1, [nameClass]: 1, [control + "Control"]: 1, [typeface + "Typeface"]: 1, noselect: 1, greyColor: greyColor }) return ( diff --git a/static/js/sefaria/util.js b/static/js/sefaria/util.js index 0d3bb61f10..44f535ede3 100644 --- a/static/js/sefaria/util.js +++ b/static/js/sefaria/util.js @@ -695,6 +695,7 @@ class Util { return vars; } static replaceUrlParam(paramName, paramValue){ + //TODO: This does not create the correct urls for multipanel views. It ends up just tacking on an extra "with" param on the end var url = INBROWSER ? window.location.href : this._initialPath; if(paramValue == null) paramValue = '';