From 95dc56d8508109a76c232cfbcd858889d32916a9 Mon Sep 17 00:00:00 2001 From: btheado Date: Sat, 11 Feb 2023 03:15:44 -0600 Subject: [PATCH] Fix importTitle and autoOpenOnImport in the tm-import-tiddler message (#7243) * Add initial tm-import-tiddler test * Add failing test for tm-import-tiddlers importTitle #7234 * Add failing test for tm-import-tiddlers autoOpenOnImport #7234 * Use event.paramObject instead of event to access tm-import-tiddlers options. Fixes #7234. * Added a clarifying comment * Allow mixing tm-import-tiddler params in both event and event.paramObject * Added import test using tv-auto-open-on-import variable * Removed stray punctuation --- core/modules/widgets/navigator.js | 5 +-- .../tm-import-tiddler/CustomTitle.tid | 35 ++++++++++++++++++ .../messages/tm-import-tiddler/NoAutoOpen.tid | 35 ++++++++++++++++++ .../tm-import-tiddler/NoAutoOpenViaVar.tid | 36 +++++++++++++++++++ .../messages/tm-import-tiddler/default.tid | 34 ++++++++++++++++++ 5 files changed, 143 insertions(+), 2 deletions(-) create mode 100644 editions/test/tiddlers/tests/data/messages/tm-import-tiddler/CustomTitle.tid create mode 100644 editions/test/tiddlers/tests/data/messages/tm-import-tiddler/NoAutoOpen.tid create mode 100644 editions/test/tiddlers/tests/data/messages/tm-import-tiddler/NoAutoOpenViaVar.tid create mode 100644 editions/test/tiddlers/tests/data/messages/tm-import-tiddler/default.tid diff --git a/core/modules/widgets/navigator.js b/core/modules/widgets/navigator.js index 2e39fdd20..efdbba83f 100755 --- a/core/modules/widgets/navigator.js +++ b/core/modules/widgets/navigator.js @@ -499,7 +499,8 @@ NavigatorWidget.prototype.handleImportTiddlersEvent = function(event) { // Get the tiddlers var tiddlers = $tw.utils.parseJSONSafe(event.param,[]); // Get the current $:/Import tiddler - var importTitle = event.importTitle ? event.importTitle : IMPORT_TITLE, + var paramObject = event.paramObject || {}, + importTitle = event.importTitle || paramObject.importTitle || IMPORT_TITLE, importTiddler = this.wiki.getTiddler(importTitle), importData = this.wiki.getTiddlerData(importTitle,{}), newFields = new Object({ @@ -540,7 +541,7 @@ NavigatorWidget.prototype.handleImportTiddlersEvent = function(event) { newFields.text = JSON.stringify(importData,null,$tw.config.preferences.jsonSpaces); this.wiki.addTiddler(new $tw.Tiddler(importTiddler,newFields)); // Update the story and history details - var autoOpenOnImport = event.autoOpenOnImport ? event.autoOpenOnImport : this.getVariable("tv-auto-open-on-import"); + var autoOpenOnImport = event.autoOpenOnImport || paramObject.autoOpenOnImport || this.getVariable("tv-auto-open-on-import"); if(autoOpenOnImport !== "no") { var storyList = this.getStoryList(), history = []; diff --git a/editions/test/tiddlers/tests/data/messages/tm-import-tiddler/CustomTitle.tid b/editions/test/tiddlers/tests/data/messages/tm-import-tiddler/CustomTitle.tid new file mode 100644 index 000000000..2c7b8ba05 --- /dev/null +++ b/editions/test/tiddlers/tests/data/messages/tm-import-tiddler/CustomTitle.tid @@ -0,0 +1,35 @@ +title: Message/tm-import-tiddlers/CustomTitle +description: tm-import-tiddlers message can import to a tiddler with a custom title +type: text/vnd.tiddlywiki-multiple +tags: [[$:/tags/wiki-test-spec]] + +title: Output + +text: <$text text={{MyCustomTitle}}/> +plugin-type: <$text text={{MyCustomTitle!!plugin-type}}/> +~$:/StoryList: <$text text={{$:/StoryList!!list}}/> ++ +title: Actions + +<$navigator story="$:/StoryList"> +<$action-sendmessage + $message="tm-import-tiddlers" + $param='[{"title": "Elephants"}, {"title": "Eagles"}]' + importTitle=MyCustomTitle/> + + ++ +title: ExpectedResult + +

text: { + "tiddlers": { + "Elephants": { + "title": "Elephants" + }, + "Eagles": { + "title": "Eagles" + } + } +} +plugin-type: import +$:/StoryList: MyCustomTitle

\ No newline at end of file diff --git a/editions/test/tiddlers/tests/data/messages/tm-import-tiddler/NoAutoOpen.tid b/editions/test/tiddlers/tests/data/messages/tm-import-tiddler/NoAutoOpen.tid new file mode 100644 index 000000000..cc2c3673a --- /dev/null +++ b/editions/test/tiddlers/tests/data/messages/tm-import-tiddler/NoAutoOpen.tid @@ -0,0 +1,35 @@ +title: Message/tm-import-tiddlers/NoAutoOpen +description: tm-import-tiddlers can import without automatically opening the import tiddler +type: text/vnd.tiddlywiki-multiple +tags: [[$:/tags/wiki-test-spec]] + +title: Output + +text: <$text text={{$:/Import}}/> +plugin-type: <$text text={{$:/Import!!plugin-type}}/> +~$:/StoryList: <$text text={{$:/StoryList!!list}}/> ++ +title: Actions + +<$navigator story="$:/StoryList"> +<$action-sendmessage + $message="tm-import-tiddlers" + $param='[{"title": "Elephants"}, {"title": "Eagles"}]' + autoOpenOnImport=no/> + + ++ +title: ExpectedResult + +

text: { + "tiddlers": { + "Elephants": { + "title": "Elephants" + }, + "Eagles": { + "title": "Eagles" + } + } +} +plugin-type: import +$:/StoryList:

\ No newline at end of file diff --git a/editions/test/tiddlers/tests/data/messages/tm-import-tiddler/NoAutoOpenViaVar.tid b/editions/test/tiddlers/tests/data/messages/tm-import-tiddler/NoAutoOpenViaVar.tid new file mode 100644 index 000000000..6970131f1 --- /dev/null +++ b/editions/test/tiddlers/tests/data/messages/tm-import-tiddler/NoAutoOpenViaVar.tid @@ -0,0 +1,36 @@ +title: Message/tm-import-tiddlers/NoAutoOpenViaVar +description: tm-import-tiddlers can import and open based on tv-auto-open-on-import +type: text/vnd.tiddlywiki-multiple +tags: [[$:/tags/wiki-test-spec]] + +title: Output + +text: <$text text={{$:/Import}}/> +plugin-type: <$text text={{$:/Import!!plugin-type}}/> +~$:/StoryList: <$text text={{$:/StoryList!!list}}/> ++ +title: Actions + +<$let tv-auto-open-on-import="no"> +<$navigator story="$:/StoryList"> +<$action-sendmessage + $message="tm-import-tiddlers" + $param='[{"title": "Elephants"}, {"title": "Eagles"}]'/> + + + ++ +title: ExpectedResult + +

text: { + "tiddlers": { + "Elephants": { + "title": "Elephants" + }, + "Eagles": { + "title": "Eagles" + } + } +} +plugin-type: import +$:/StoryList:

\ No newline at end of file diff --git a/editions/test/tiddlers/tests/data/messages/tm-import-tiddler/default.tid b/editions/test/tiddlers/tests/data/messages/tm-import-tiddler/default.tid new file mode 100644 index 000000000..715a763f4 --- /dev/null +++ b/editions/test/tiddlers/tests/data/messages/tm-import-tiddler/default.tid @@ -0,0 +1,34 @@ +title: Message/tm-import-tiddlers/default +description: tm-import-tiddlers message by default should import to $:/Import and open the tiddler +type: text/vnd.tiddlywiki-multiple +tags: [[$:/tags/wiki-test-spec]] + +title: Output + +text: <$text text={{$:/Import}}/> +plugin-type: <$text text={{$:/Import!!plugin-type}}/> +~$:/StoryList: <$text text={{$:/StoryList!!list}}/> ++ +title: Actions + +<$navigator story="$:/StoryList"> +<$action-sendmessage + $message="tm-import-tiddlers" + $param='[{"title": "Elephants"}, {"title": "Eagles"}]'/> + + ++ +title: ExpectedResult + +

text: { + "tiddlers": { + "Elephants": { + "title": "Elephants" + }, + "Eagles": { + "title": "Eagles" + } + } +} +plugin-type: import +$:/StoryList: $:/Import

\ No newline at end of file