From cb00cb99e2445b12345c7a9adc2107ceb08652f4 Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 23 Mar 2021 12:02:32 -0700 Subject: [PATCH] Make client inlines track an "active" state Summary: Ref T13559. Rather than reading from the document, make client inlines actively track their current "active" state. The "active" state is what the user currently sees in the client UI. Test Plan: Created inlines, etc. See followups. Maniphest Tasks: T13559 Differential Revision: https://secure.phabricator.com/D21646 --- resources/celerity/map.php | 24 ++++----- .../rsrc/js/application/diff/DiffInline.js | 29 +++++------ .../diff/DiffInlineContentState.js | 49 +++++++++++++++++++ 3 files changed, 74 insertions(+), 28 deletions(-) diff --git a/resources/celerity/map.php b/resources/celerity/map.php index a55a0986a6..c95b0e350c 100644 --- a/resources/celerity/map.php +++ b/resources/celerity/map.php @@ -13,7 +13,7 @@ return array( 'core.pkg.js' => 'ab3502fe', 'dark-console.pkg.js' => '187792c2', 'differential.pkg.css' => 'ffb69e3d', - 'differential.pkg.js' => '5e0c7197', + 'differential.pkg.js' => '68a2e7be', 'diffusion.pkg.css' => '42c75c37', 'diffusion.pkg.js' => '78c9885d', 'maniphest.pkg.css' => '35995d6d', @@ -385,8 +385,8 @@ return array( 'rsrc/js/application/dashboard/behavior-dashboard-tab-panel.js' => '0116d3e8', 'rsrc/js/application/diff/DiffChangeset.js' => 'd7d3ba75', 'rsrc/js/application/diff/DiffChangesetList.js' => 'cc2c5de5', - 'rsrc/js/application/diff/DiffInline.js' => '09e0c6e5', - 'rsrc/js/application/diff/DiffInlineContentState.js' => 'cb9e5396', + 'rsrc/js/application/diff/DiffInline.js' => 'a5f196da', + 'rsrc/js/application/diff/DiffInlineContentState.js' => '68e6339d', 'rsrc/js/application/diff/DiffPathView.js' => '8207abf9', 'rsrc/js/application/diff/DiffTreeView.js' => '5d83623b', 'rsrc/js/application/differential/behavior-diff-radios.js' => '925fe8cd', @@ -788,8 +788,8 @@ return array( 'phabricator-dashboard-css' => '5a205b9d', 'phabricator-diff-changeset' => 'd7d3ba75', 'phabricator-diff-changeset-list' => 'cc2c5de5', - 'phabricator-diff-inline' => '09e0c6e5', - 'phabricator-diff-inline-content-state' => 'cb9e5396', + 'phabricator-diff-inline' => 'a5f196da', + 'phabricator-diff-inline-content-state' => '68e6339d', 'phabricator-diff-path-view' => '8207abf9', 'phabricator-diff-tree-view' => '5d83623b', 'phabricator-drag-and-drop-file-upload' => '4370900d', @@ -1000,10 +1000,6 @@ return array( 'herald-rule-editor', 'javelin-behavior', ), - '09e0c6e5' => array( - 'javelin-dom', - 'phabricator-diff-inline-content-state', - ), '0ad8d31f' => array( 'javelin-behavior', 'javelin-stratcom', @@ -1544,6 +1540,9 @@ return array( 'javelin-install', 'javelin-dom', ), + '68e6339d' => array( + 'javelin-dom', + ), '6a1583a8' => array( 'javelin-behavior', 'javelin-history', @@ -1872,6 +1871,10 @@ return array( 'javelin-install', 'javelin-dom', ), + 'a5f196da' => array( + 'javelin-dom', + 'phabricator-diff-inline-content-state', + ), 'a77e2cbd' => array( 'javelin-behavior', 'javelin-stratcom', @@ -2089,9 +2092,6 @@ return array( 'javelin-workflow', 'javelin-json', ), - 'cb9e5396' => array( - 'javelin-dom', - ), 'cc2c5de5' => array( 'javelin-install', 'phuix-button-view', diff --git a/webroot/rsrc/js/application/diff/DiffInline.js b/webroot/rsrc/js/application/diff/DiffInline.js index 4701919eef..d5e87ed431 100644 --- a/webroot/rsrc/js/application/diff/DiffInline.js +++ b/webroot/rsrc/js/application/diff/DiffInline.js @@ -416,25 +416,12 @@ JX.install('DiffInline', { .send(); }, - _getContentState: function() { - var state; - - if (this._editRow) { - state = this._readFormState(this._editRow); - } else { - state = this._originalState; - } - - return state; - }, - reply: function(with_quote) { this._closeMenu(); var content_state = this._newContentState(); if (with_quote) { - var text = this._getContentState().text; - text = '> ' + text.replace(/\n/g, '\n> ') + '\n\n'; + var text = this._getActiveContentState().getTextForQuote(); content_state.text = text; } @@ -607,6 +594,9 @@ JX.install('DiffInline', { _readInlineState: function(state) { this._id = state.id; this._originalState = state.contentState; + + this._getActiveContentState().readWireFormat(state.contentState); + this._canSuggestEdit = state.canSuggestEdit; }, @@ -790,7 +780,13 @@ JX.install('DiffInline', { }, _getActiveContentState: function() { - return this._activeContentState; + var state = this._activeContentState; + + if (this._editRow) { + state.readForm(this._editRow); + } + + return state; }, setHasSuggestion: function(has_suggestion) { @@ -819,12 +815,13 @@ JX.install('DiffInline', { }, save: function() { + var state = this._getActiveContentState(); var handler = JX.bind(this, this._onsubmitresponse); this.setLoading(true); var uri = this._getInlineURI(); - var data = this._newRequestData('save', this._getContentState()); + var data = this._newRequestData('save', state.getWireFormat()); new JX.Request(uri, handler) .setData(data) diff --git a/webroot/rsrc/js/application/diff/DiffInlineContentState.js b/webroot/rsrc/js/application/diff/DiffInlineContentState.js index 2641b10bb4..b1668f962c 100644 --- a/webroot/rsrc/js/application/diff/DiffInlineContentState.js +++ b/webroot/rsrc/js/application/diff/DiffInlineContentState.js @@ -17,6 +17,55 @@ JX.install('DiffInlineContentState', { }, members: { + readForm: function(row) { + var node; + + try { + node = JX.DOM.find(row, 'textarea', 'inline-content-text'); + this.setText(node.value); + } catch (ex) { + this.setText(null); + } + + node = this._getSuggestionNode(row); + if (node) { + this.setSuggestionText(node.value); + } else { + this.setSuggestionText(null); + } + + return this; + }, + + getWireFormat: function() { + return { + text: this.getText(), + suggestionText: this.getSuggestionText(), + hasSuggestion: this.getHasSuggestion() + }; + }, + + readWireFormat: function(map) { + this.setText(map.text || null); + this.setSuggestionText(map.suggestionText || null); + this.setHasSuggestion(!!map.hasSuggestion); + + return this; + }, + + getTextForQuote: function() { + var text = this.getText(); + text = '> ' + text.replace(/\n/g, '\n> ') + '\n\n'; + return text; + }, + + _getSuggestionNode: function(row) { + try { + return JX.DOM.find(row, 'textarea', 'inline-content-suggestion'); + } catch (ex) { + return null; + } + } } });