option.storage.key === storageKey && option.folder.key === folderKey
- )[0]
+ )
+
+ // currentOption may be undefined
+ const storageName = _.get(currentOption, 'storage.name') || ''
+ const folderName = _.get(currentOption, 'folder.name') || ''
const trashTopBar = (
@@ -901,8 +907,8 @@ class SnippetNoteDetail extends React.Component {
/>
this.handleInfoButtonClick(e)} />
this.handleInfoButtonClick(e)} />
key === note.folder
- )
+ const storage = this.getNoteStorage(note)
+ return storage
+ ? _.find(storage.folders, ({ key }) => key === note.folder)
+ : []
}
getViewType() {
@@ -1145,9 +1145,14 @@ class NoteList extends React.Component {
? this.getNotes().sort(sortFunc)
: this.sortByPin(this.getNotes().sort(sortFunc))
this.notes = notes = sortedNotes.filter(note => {
- // this is for the trash box
- if (note.isTrashed !== true || location.pathname === '/trashed')
+ if (
+ // has matching storage
+ !!this.getNoteStorage(note) &&
+ // this is for the trash box
+ (note.isTrashed !== true || location.pathname === '/trashed')
+ ) {
return true
+ }
})
if (sortDir === 'DESCENDING') this.notes.reverse()
@@ -1193,6 +1198,8 @@ class NoteList extends React.Component {
sortBy === 'CREATED_AT' ? note.createdAt : note.updatedAt
).fromNow('D')
+ const storage = this.getNoteStorage(note)
+
if (isDefault) {
return (
)
diff --git a/browser/main/lib/dataApi/attachmentManagement.js b/browser/main/lib/dataApi/attachmentManagement.js
index f3b11997..f59a7ef3 100644
--- a/browser/main/lib/dataApi/attachmentManagement.js
+++ b/browser/main/lib/dataApi/attachmentManagement.js
@@ -835,7 +835,15 @@ function getAttachmentsPathAndStatus(markdownContent, storageKey, noteKey) {
if (storageKey == null || noteKey == null || markdownContent == null) {
return null
}
- const targetStorage = findStorage.findStorage(storageKey)
+ let targetStorage = null
+ try {
+ targetStorage = findStorage.findStorage(storageKey)
+ } catch (error) {
+ console.warn(`No stroage found for: ${storageKey}`)
+ }
+ if (!targetStorage) {
+ return null
+ }
const attachmentFolder = path.join(
targetStorage.path,
DESTINATION_FOLDER,
diff --git a/tests/dataApi/attachmentManagement.test.js b/tests/dataApi/attachmentManagement.test.js
index e49556ca..2759445c 100644
--- a/tests/dataApi/attachmentManagement.test.js
+++ b/tests/dataApi/attachmentManagement.test.js
@@ -912,6 +912,19 @@ it('should test that getAttachmentsPathAndStatus return null if noteKey, storage
expect(result).toBeNull()
})
+it('should test that getAttachmentsPathAndStatus return null if no storage found', function() {
+ const noteKey = 'test'
+ const storageKey = 'not_exist'
+ const markdownContent = ''
+
+ const result = systemUnderTest.getAttachmentsPathAndStatus(
+ markdownContent,
+ storageKey,
+ noteKey
+ )
+ expect(result).toBeNull()
+})
+
it('should test that getAttachmentsPathAndStatus return the correct path and status for attachments', async function() {
const dummyStorage = { path: 'dummyStoragePath' }
const noteKey = 'noteKey'