Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions lib/Service/RecentPagesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ public function forUserAsPageInfo(string $userId, ?string $query, int $limit = 1
if ($query) {
// Extract title based on page type
$filename = $row['name'];
$path = $row['path'];

// Determine title
$splitPath = explode('/', $row['path'], 4);
Expand All @@ -165,8 +164,11 @@ public function forUserAsPageInfo(string $userId, ?string $query, int $limit = 1
// Regular page - title is filename without extension
$title = basename($filename, PageInfo::SUFFIX);
} elseif ($internalPath === '' || $internalPath === '.') {
// Landing page - title is "Landing page" (localized)
$title = $this->getLandingPageTranslation();
// Landing page - set title to "Landing page" (localized) + collective name
// in order to find searches for "Landing page" as well as searches for collective name
$title = $this->getLandingPageTranslation()
. ' '
. $collectivesMap[$collectiveId]->getName();
} else {
// Index page - title is folder name
$title = basename($internalPath);
Expand Down Expand Up @@ -245,9 +247,10 @@ private function getRecentPagesQuery(string $userId, int $limit, array $selectFi
$qb->expr()->like($qb->func()->lower('f.path'), $qb->createNamedParameter($pathSearchPattern)),
];

if (stripos($this->getLandingPageTranslation(), strtolower($query)) !== false) {
// Searching for landing page, also match root Readme.md files
foreach ($collectives as $collective) {
$queryMatchesLandingPageTitle = stripos($this->getLandingPageTranslation(), $query) !== false;
// Searching for landing page, also match root Readme.md files
foreach ($collectives as $collective) {
if ($queryMatchesLandingPageTitle || stripos($collective->getName(), $query) !== false) {
$landingPagePath = sprintf($appData . '/collectives/%d/%s', $collective->getId(), PageInfo::INDEX_PAGE_TITLE . PageInfo::SUFFIX);
$searchConditions[] = $qb->expr()->eq('f.path', $qb->createNamedParameter($landingPagePath));
}
Expand Down
38 changes: 38 additions & 0 deletions playwright/e2e/page-picker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,20 @@ test.describe('Custom page picker - local search', () => {
const origin = new URL(page.url()).origin
await expect(pageWidget).toHaveAttribute('href', origin + targetPage.getPageUrl())
})

test('searching "landing page" lists landing pages', async ({ editor }) => {
await editor.pagePickerSearch.pressSequentially('landing page')

const landingPageItem = editor.pagePicker.locator('.page-preview-item').filter({ hasText: 'Landing page' })
await expect(landingPageItem).toBeVisible()
})

test('searching collective title lists landing page', async ({ collective, editor }) => {
await editor.pagePickerSearch.pressSequentially(collective.data.name)

const landingPageItem = editor.pagePicker.locator('.page-preview-item').filter({ hasText: 'Landing page' })
await expect(landingPageItem).toBeVisible()
})
})

test.describe('Custom page picker - cross-collective search', () => {
Expand Down Expand Up @@ -88,4 +102,28 @@ test.describe('Custom page picker - cross-collective search', () => {
const origin = new URL(page.url()).origin
await expect(pageWidget).toHaveAttribute('href', origin + otherTargetPage.getPageUrl())
})

test('searching "Landing page" lists landing page', async ({ page, editor }) => {
await editor.pagePicker.locator('.searchbar [aria-haspopup="menu"]').click()
await page.getByText('Limit to current collective').click()

await editor.pagePickerSearch.fill('Landing page')
await expect(editor.pagePicker.locator('.page-preview-item').filter({ hasText: 'Source page' })).not.toBeVisible()

const landingPageItem = editor.pagePicker.locator('.page-preview-item').filter({ hasText: 'Landing page' })
await expect(landingPageItem).toHaveCount(2)
})

test('searching collective title lists landing page', async ({ page, collectives, editor }) => {
await editor.pagePicker.locator('.searchbar [aria-haspopup="menu"]').click()
await page.getByText('Limit to current collective').click()

await editor.pagePickerSearch.fill(collectives[1].data.name)
await expect(editor.pagePicker.locator('.page-preview-item').filter({ hasText: 'Source page' })).not.toBeVisible()

const landingPageItem = editor.pagePicker.locator('.page-preview-item')
.filter({ hasText: 'Landing page' })
.filter({ hasText: collectives[1].data.name })
await expect(landingPageItem).toBeVisible()
})
})
27 changes: 21 additions & 6 deletions src/views/PagePicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,19 @@ export default defineComponent({
const recentPages = this.currentPages
.slice()
.sort(byTimeAsc)
return this.query
? recentPages.filter((p) => p.title.toLocaleLowerCase().includes(this.query.toLowerCase()))
: recentPages
if (!this.query) {
return recentPages
}
const lowerQuery = this.query.toLowerCase()
const collectiveName = window.OCA.Collectives?.currentCollective?.nameWithEmoji ?? ''
const collectiveNameMatches = collectiveName.toLocaleLowerCase().includes(lowerQuery)
return recentPages.filter((p) => {
if (p.title.toLocaleLowerCase().includes(lowerQuery)) {
return true
}
// Also show landing page when the collective name matches
return collectiveNameMatches && p.parentId === 0
})
},

pages() {
Expand Down Expand Up @@ -236,12 +246,17 @@ export default defineComponent({
},

async getSearchedPages() {
const currentQuery = this.query
this.searchedPagesLoading = true
try {
const response = await searchRecentPages(this.query)
this.searchedPages = response.data.ocs.data.pages
const response = await searchRecentPages(currentQuery)
if (this.query === currentQuery) {
this.searchedPages = response.data.ocs.data.pages
}
} finally {
this.searchedPagesLoading = false
if (this.query === currentQuery) {
this.searchedPagesLoading = false
}
}
},
},
Expand Down
Loading