From b8fb9e6b21319e790e9aa7453ca265b0ed4898db Mon Sep 17 00:00:00 2001
From: Jeremy Ruston
Date: Wed, 21 Aug 2024 18:40:49 +0100
Subject: [PATCH] Fix DataWidget to allow titles to be overwritten
See https://talk.tiddlywiki.org/t/can-innerwiki-only-show-exactly-current-wiki/10452/5
---
core/modules/widgets/data.js | 1 -
.../data/data-widget/ImportCustomTitle.tid | 23 +++++++++++++++
.../DataWidget/ImportCustomTitle.tid | 29 +++++++++++++++++++
3 files changed, 52 insertions(+), 1 deletion(-)
create mode 100644 editions/test/tiddlers/tests/data/data-widget/ImportCustomTitle.tid
create mode 100644 editions/tw5.com/tiddlers/testcases/DataWidget/ImportCustomTitle.tid
diff --git a/core/modules/widgets/data.js b/core/modules/widgets/data.js
index c3da00919..5d76f5abd 100644
--- a/core/modules/widgets/data.js
+++ b/core/modules/widgets/data.js
@@ -123,7 +123,6 @@ DataWidget.prototype.computeDataTiddlerValues = function() {
}
} else {
// Apply the item fields to each of the tiddlers
- delete item.title; // Do not overwrite the title
if(Object.keys(item).length > 0) {
$tw.utils.each(tiddlers,function(tiddler,index) {
tiddlers[index] = new $tw.Tiddler(tiddler,item);
diff --git a/editions/test/tiddlers/tests/data/data-widget/ImportCustomTitle.tid b/editions/test/tiddlers/tests/data/data-widget/ImportCustomTitle.tid
new file mode 100644
index 000000000..34029ae32
--- /dev/null
+++ b/editions/test/tiddlers/tests/data/data-widget/ImportCustomTitle.tid
@@ -0,0 +1,23 @@
+title: Data/ImportCustomTitle
+type: text/vnd.tiddlywiki-multiple
+tags: [[$:/tags/wiki-test-spec]]
+description: Importing a payload tiddler and overwriting the title
+
+title: Description
+text: Importing a payload tiddler and overwriting the title
++
+title: Output
+
+\whitespace trim
+<$testcase template="$:/core/ui/testcases/RawJSONTemplate">
+<$data $tiddler="HelloThere" title="RealTitle"/>
+$testcase>
++
+title: HelloThere
+tags: Definitions
+
+This is the tiddler HelloThere
++
+title: ExpectedResult
+
+[{"title":"RealTitle","tags":"Definitions","text":"This is the tiddler HelloThere"}]
\ No newline at end of file
diff --git a/editions/tw5.com/tiddlers/testcases/DataWidget/ImportCustomTitle.tid b/editions/tw5.com/tiddlers/testcases/DataWidget/ImportCustomTitle.tid
new file mode 100644
index 000000000..5eb48cde4
--- /dev/null
+++ b/editions/tw5.com/tiddlers/testcases/DataWidget/ImportCustomTitle.tid
@@ -0,0 +1,29 @@
+title: TestCases/DataWidget/ImportCustomTitle
+type: text/vnd.tiddlywiki-multiple
+tags: [[$:/tags/wiki-test-spec]]
+description: Importing a payload tiddler and overwriting the title
+display-format: plaintext
+
+title: Narrative
+
+Importing a payload tiddler and overwriting the title
++
+title: Output
+
+\whitespace trim
+<$data $tiddler="HelloThere" title="RealTitle"/>
++
+title: HelloThere
+tags: Definitions
+
+This is the tiddler HelloThere
++
+title: ExpectedResult
+
+[
+ {
+ "title": "RealTitle",
+ "tags": "Definitions",
+ "text": "This is the tiddler HelloThere"
+ }
+]
\ No newline at end of file