Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix relative file links from index pages #746

Merged
merged 3 commits into from Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 18 additions & 1 deletion cypress/e2e/pages-links.spec.js
Expand Up @@ -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
})
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions src/components/Page.vue
Expand Up @@ -5,10 +5,10 @@
<div class="page-title-icon"
:class="{ 'mobile': isMobile }">
<!-- Landing page: collective emoji or CollectivesIcon -->
<div v-if="landingPage && currentCollective.emoji">
<div v-if="isLandingPage && currentCollective.emoji">
{{ currentCollective.emoji }}
</div>
<CollectivesIcon v-else-if="landingPage" :size="pageTitleIconSize" fill-color="var(--color-text-maxcontrast)" />
<CollectivesIcon v-else-if="isLandingPage" :size="pageTitleIconSize" fill-color="var(--color-text-maxcontrast)" />
<PageTemplateIcon v-else-if="isTemplatePage" :size="pageTitleIconSize" fill-color="var(--color-text-maxcontrast)" />

<!-- Emoji picker if editable -->
Expand Down Expand Up @@ -51,7 +51,7 @@

<!-- Page title -->
<form @submit.prevent="focusEditor()">
<input v-if="landingPage"
<input v-if="isLandingPage"
ref="landingPageTitle"
v-tooltip="titleIfTruncated(currentCollective.name)"
class="title"
Expand Down Expand Up @@ -89,7 +89,7 @@
:timestamp="currentPage.timestamp"
:last-user-id="currentPage.lastUserId"
:last-user-display-name="currentPage.lastUserDisplayName"
:is-landing-page="landingPage"
:is-landing-page="isLandingPage"
:is-template="isTemplatePage" />

<!-- Sidebar toggle -->
Expand Down Expand Up @@ -155,10 +155,10 @@ export default {
'currentPage',
'currentCollective',
'currentCollectiveCanEdit',
'indexPage',
'isIndexPage',
'isPublic',
'isTemplatePage',
'landingPage',
'isLandingPage',
'loading',
'showing',
]),
Expand All @@ -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)
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/components/Page/RichText.vue
Expand Up @@ -91,6 +91,7 @@ export default {
'currentCollective',
'currentPageDirectory',
'currentPageFilePath',
'isIndexPage',
'isPublic',
'loading',
'pageById',
Expand Down Expand Up @@ -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}/`
}

Expand Down
6 changes: 3 additions & 3 deletions src/store/store.js
Expand Up @@ -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,
Expand Down