From 00bbaa4659a036efe7a5d906735227dc99ba2283 Mon Sep 17 00:00:00 2001 From: Jonas Date: Wed, 28 Jun 2023 13:02:54 +0200 Subject: [PATCH 1/3] refactor(frontend): Rename getters to `isIndexPage` and `isLandingPage` Signed-off-by: Jonas --- src/components/Page.vue | 16 ++++++++-------- src/store/store.js | 6 +++--- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/components/Page.vue b/src/components/Page.vue index 76abf35b0..6c41d5380 100644 --- a/src/components/Page.vue +++ b/src/components/Page.vue @@ -5,10 +5,10 @@
-
+
{{ currentCollective.emoji }}
- + @@ -51,7 +51,7 @@
- @@ -155,10 +155,10 @@ export default { 'currentPage', 'currentCollective', 'currentCollectiveCanEdit', - 'indexPage', + 'isIndexPage', 'isPublic', 'isTemplatePage', - 'landingPage', + 'isLandingPage', 'loading', 'showing', ]), @@ -174,10 +174,10 @@ export default { t('collectives', 'Collectives'), 'Nextcloud', ] - if (!this.landingPage) { + if (!this.isLandingPage) { // Add parent page names in reverse order filePath.split('/').forEach(part => part && parts.unshift(part)) - if (!this.indexPage) { + if (!this.isIndexPage) { parts.unshift(title) } } diff --git a/src/store/store.js b/src/store/store.js index 9fad20015..ceccb61e3 100644 --- a/src/store/store.js +++ b/src/store/store.js @@ -36,17 +36,17 @@ export default new Store({ pageParam: (state) => state.route.params.page, shareTokenParam: (state) => state.route.params.token, - indexPage: (_state, get) => + isIndexPage: (_state, get) => get.currentPage.fileName === 'Readme.md', - landingPage: (_state, get) => + isLandingPage: (_state, get) => !get.pageParam || get.pageParam === 'Readme', isTemplatePage: (_state, get) => get.currentPage.title === 'Template', title: (_state, get) => - get.landingPage ? get.currentCollective.name : get.currentPage.title, + get.isLandingPage ? get.currentCollective.name : get.currentPage.title, isPublic: (_state, get) => !!get.shareTokenParam, From 56f8d048180e47d61492f4011ccd2ac67afedd8d Mon Sep 17 00:00:00 2001 From: Jonas Date: Wed, 28 Jun 2023 13:05:41 +0200 Subject: [PATCH 2/3] fix(frontend): Fix relative file links from index pages Fixes: #726 Signed-off-by: Jonas --- src/components/Page/RichText.vue | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/Page/RichText.vue b/src/components/Page/RichText.vue index 57fcc54dc..e437b8b1b 100644 --- a/src/components/Page/RichText.vue +++ b/src/components/Page/RichText.vue @@ -91,6 +91,7 @@ export default { 'currentCollective', 'currentPageDirectory', 'currentPageFilePath', + 'isIndexPage', 'isPublic', 'loading', 'pageById', @@ -135,10 +136,9 @@ export default { handleCollectiveLink({ href }) { const collectiveParam = encodeURIComponent(this.collectiveParam) - // If we're on landing page, append `/` to location to make `URL()` append relative paths correctly + // If we're on index page, append `/` to location to make `URL()` append relative paths correctly let windowLocation = window.location.origin + window.location.pathname - if (windowLocation.endsWith(`/collectives/${collectiveParam}`) - || windowLocation.match(new RegExp(`/collectives/p/[^/]+/${collectiveParam}$`))) { + if (this.isIndexPage) { windowLocation = `${windowLocation}/` } From 9c8a4442b5a2fbf33bbe3fc92be7e76fdb6821db Mon Sep 17 00:00:00 2001 From: Jonas Date: Wed, 28 Jun 2023 14:19:00 +0200 Subject: [PATCH 3/3] test(cypress): Add test for relative file link handling from index page Signed-off-by: Jonas --- cypress/e2e/pages-links.spec.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/cypress/e2e/pages-links.spec.js b/cypress/e2e/pages-links.spec.js index 4a18983bf..f9e60d424 100644 --- a/cypress/e2e/pages-links.spec.js +++ b/cypress/e2e/pages-links.spec.js @@ -37,6 +37,8 @@ describe('Page Link Handling', function() { anotherCollectiveFirstPageId = id }) cy.deleteAndSeedCollective('Link Testing') + cy.seedPage('Parent', '', 'Readme.md') + cy.seedPage('Child', '', 'Parent.md') cy.seedPage('Link Target', '', 'Readme.md').then((id) => { linkTargetPageId = id }) @@ -53,10 +55,14 @@ describe('Page Link Handling', function() { }) }).then(() => { cy.seedPageContent('Link%20Testing/Readme.md', ` - ## Links supposed to open in same window * Relative path to page in this collective with fileId: [Link Target](./Link%20Target?fileId=${linkTargetPageId}) + `) + cy.seedPageContent('Link%20Testing/Parent/Readme.md', ` +## Links supposed to open in same window + +* Relative path to page in this collective with fileId: [../Link Target.md](../Link%20Target.md?fileId=${linkTargetPageId}) `) cy.seedPageContent('Link%20Testing/Link%20Source.md', ` ## Links supposed to open in viewer @@ -258,6 +264,17 @@ describe('Page Link Handling', function() { testLinkToNewTab(href, { edit: true }) } }) + it('Opens link with relative path from index page to page in this collective with fileId in same/new tab depending on view/edit mode', function() { + cy.visit('/apps/collectives/Link%20Testing/Parent') + // Link without origin and containing `fileId` param gets rewritten by editor rendering + // const href = `../Link%20Target.md?fileId=${linkTargetPageId}` + const href = `/index.php/apps/files/?dir=&openfile=${linkTargetPageId}#relPath=../Link%20Target.md` + testLinkToSameTab(href, { + expectedPathname: '/index.php/apps/collectives/Link%20Testing/Link%20Target', + expectedSearch: `?fileId=${linkTargetPageId}`, + }) + // testLinkToNewTab(href, { edit: true }) + }) it('Opens link with relative path from landing page to page in this collective with fileId in same/new tab depending on view/edit mode', function() { cy.visit('/apps/collectives/Link%20Testing') // Link without origin and containing `fileId` param gets rewritten by editor rendering