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

Persist remarkup metadata in "VersionedDrafts" and record explicit file uploads

Summary:
Ref T13603. Allow "VersionedDraft" to persist remarkup comment area metadata from stacked actions controls.

When files are dragged and dropped, record them as explicit uploads in comment metadata.

Test Plan: Dragged and dropped files into Remarkup stacked action text areas (e.g., in Maniphest), reloaded page, saw metadata persist across reloads.

Maniphest Tasks: T13603

Differential Revision: https://secure.phabricator.com/D21828
This commit is contained in:
epriestley 2022-05-19 11:22:56 -07:00
parent 33a0731619
commit 7693a711a7
4 changed files with 54 additions and 27 deletions

View file

@ -13,7 +13,7 @@ return array(
'core.pkg.js' => 'd2de90d9',
'dark-console.pkg.js' => '187792c2',
'differential.pkg.css' => 'ffb69e3d',
'differential.pkg.js' => 'e31329dc',
'differential.pkg.js' => 'c60bec1b',
'diffusion.pkg.css' => '42c75c37',
'diffusion.pkg.js' => '78c9885d',
'maniphest.pkg.css' => '35995d6d',
@ -473,7 +473,7 @@ return array(
'rsrc/js/core/behavior-copy.js' => 'cf32921f',
'rsrc/js/core/behavior-detect-timezone.js' => '78bc5d94',
'rsrc/js/core/behavior-device.js' => 'ac2b1e01',
'rsrc/js/core/behavior-drag-and-drop-textarea.js' => '7df68a45',
'rsrc/js/core/behavior-drag-and-drop-textarea.js' => '3277c62d',
'rsrc/js/core/behavior-fancy-datepicker.js' => '36821f8d',
'rsrc/js/core/behavior-form.js' => '55d7b788',
'rsrc/js/core/behavior-gesture.js' => 'b58d1a2a',
@ -589,7 +589,7 @@ return array(
'javelin-behavior-aphlict-listen' => '4e61fa88',
'javelin-behavior-aphlict-status' => 'c3703a16',
'javelin-behavior-aphront-basic-tokenizer' => '3b4899b0',
'javelin-behavior-aphront-drag-and-drop-textarea' => '7df68a45',
'javelin-behavior-aphront-drag-and-drop-textarea' => '3277c62d',
'javelin-behavior-aphront-form-disable-on-submit' => '55d7b788',
'javelin-behavior-aphront-more' => '506aa3f4',
'javelin-behavior-audio-source' => '3dc5ad43',
@ -1195,6 +1195,13 @@ return array(
'javelin-install',
'javelin-util',
),
'3277c62d' => array(
'javelin-behavior',
'javelin-dom',
'javelin-json',
'phabricator-drag-and-drop-file-upload',
'phabricator-textareautils',
),
'32db8374' => array(
'javelin-behavior',
'javelin-stratcom',
@ -1614,13 +1621,6 @@ return array(
'javelin-install',
'javelin-dom',
),
'7df68a45' => array(
'javelin-behavior',
'javelin-dom',
'javelin-json',
'phabricator-drag-and-drop-file-upload',
'phabricator-textareautils',
),
'80bff3af' => array(
'javelin-install',
'javelin-typeahead-source',

View file

@ -1908,6 +1908,11 @@ abstract class PhabricatorEditEngine
$comment_text = $request->getStr('comment');
$comment_metadata = $request->getStr('comment_metadata');
if (strlen($comment_metadata)) {
$comment_metadata = phutil_json_decode($comment_metadata);
}
$actions = $request->getStr('editengine.actions');
if ($actions) {
$actions = phutil_json_decode($actions);
@ -1923,10 +1928,9 @@ abstract class PhabricatorEditEngine
$viewer->getPHID(),
$current_version);
$is_empty = (!strlen($comment_text) && !$actions);
$draft
->setProperty('comment', $comment_text)
->setProperty('metadata', $comment_metadata)
->setProperty('actions', $actions)
->save();

View file

@ -294,18 +294,39 @@ final class PhabricatorApplicationTransactionCommentView
}
private function renderCommentPanel() {
$viewer = $this->getViewer();
$remarkup_control = id(new PhabricatorRemarkupControl())
->setViewer($viewer)
->setID($this->getCommentID())
->addClass('phui-comment-fullwidth-control')
->addClass('phui-comment-textarea-control')
->setCanPin(true)
->setName('comment');
$draft_comment = '';
$draft_metadata = array();
$draft_key = null;
if ($this->getDraft()) {
$draft_comment = $this->getDraft()->getDraft();
$draft_key = $this->getDraft()->getDraftKey();
$legacy_draft = $this->getDraft();
if ($legacy_draft) {
$draft_comment = $legacy_draft->getDraft();
$draft_key = $legacy_draft->getDraftKey();
}
$versioned_draft = $this->getVersionedDraft();
if ($versioned_draft) {
$draft_comment = $versioned_draft->getProperty('comment', '');
$draft_comment = $versioned_draft->getProperty(
'comment',
$draft_comment);
$draft_metadata = $versioned_draft->getProperty(
'metadata',
$draft_metadata);
}
$remarkup_control->setValue($draft_comment);
$remarkup_control->setRemarkupMetadata($draft_metadata);
if (!$this->getObjectPHID()) {
throw new PhutilInvalidStateException('setObjectPHID', 'render');
}
@ -314,7 +335,7 @@ final class PhabricatorApplicationTransactionCommentView
$version_value = $this->getCurrentVersion();
$form = id(new AphrontFormView())
->setUser($this->getUser())
->setUser($viewer)
->addSigil('transaction-append')
->setWorkflow(true)
->setFullWidth($this->fullWidth)
@ -465,15 +486,7 @@ final class PhabricatorApplicationTransactionCommentView
->setValue($this->getSubmitButtonName());
$form
->appendChild(
id(new PhabricatorRemarkupControl())
->setID($this->getCommentID())
->addClass('phui-comment-fullwidth-control')
->addClass('phui-comment-textarea-control')
->setCanPin(true)
->setName('comment')
->setUser($this->getUser())
->setValue($draft_comment))
->appendChild($remarkup_control)
->appendChild(
id(new AphrontFormSubmitControl())
->addClass('phui-comment-fullwidth-control')

View file

@ -16,7 +16,7 @@ JX.behavior('aphront-drag-and-drop-textarea', function(config) {
function set_metadata(key, value) {
metadata_value[key] = value;
metadata_node.value = JX.JSON.stringify(metadata_value);
write_metadata();
}
function get_metadata(key, default_value) {
@ -26,6 +26,12 @@ JX.behavior('aphront-drag-and-drop-textarea', function(config) {
return default_value;
}
function write_metadata() {
metadata_node.value = JX.JSON.stringify(metadata_value);
}
write_metadata();
if (JX.PhabricatorDragAndDropFileUpload.isSupported()) {
var drop = new JX.PhabricatorDragAndDropFileUpload(target)
.setURI(config.uri)
@ -41,6 +47,10 @@ JX.behavior('aphront-drag-and-drop-textarea', function(config) {
drop.listen('didUpload', function(file) {
JX.TextAreaUtils.insertFileReference(target, file);
var phids = get_metadata('attachedFilePHIDs', []);
phids.push(file.getPHID());
set_metadata('attachedFilePHIDs', phids);
});
drop.start();