1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-21 22:32:41 +01:00

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
This commit is contained in:
epriestley 2021-03-23 12:02:32 -07:00
parent b964731b6a
commit cb00cb99e2
3 changed files with 74 additions and 28 deletions

View file

@ -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',

View file

@ -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)

View file

@ -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;
}
}
}
});