Skip to content

fix(browser): pass folderPath when creating file asset from Site Browser#35507

Open
adrianjm-dotCMS wants to merge 1 commit intomainfrom
issue-34588-fix-file-asset-folder-prefill-site-browser
Open

fix(browser): pass folderPath when creating file asset from Site Browser#35507
adrianjm-dotCMS wants to merge 1 commit intomainfrom
issue-34588-fix-file-asset-folder-prefill-site-browser

Conversation

@adrianjm-dotCMS
Copy link
Copy Markdown
Member

Summary

  • Fixes TC-004 QA failure from PR feat(dot-custom-event-handler): enhance contentlet creation with folder #35322: when a user navigated into a nested folder in Site Browser and opened Add Asset → File, the folderPath was not passed to createContentlet(), so the new Angular edit-content form always defaulted the Host/Folder field to site root instead of the current folder
  • Stores the active folderMap in currentFileAssetFolderMap inside showFileAssetPopUp — mirroring the existing currentPageAssetFolderMap pattern already in place for HTML pages
  • Passes the resolved folderPath to createContentlet() in the single-file branch of getSelectedfileAsset
  • Adds E2E coverage for FileAssetContentType folderPath pre-fill (field variable hostFolder), complementing the SimpleContentType specs added in PR feat(dot-custom-event-handler): enhance contentlet creation with folder #35322

Related

Closes #34588

Test plan

  • Navigate into a nested folder in Site Browser (e.g. folder-1/folder-2)
  • Click +Add AssetFile, select a file-asset content type with the new editor enabled
  • Verify the Angular form opens with ?folderPath=<site>/folder-1/folder-2/ in the URL and Host/Folder field pre-filled correctly
  • Upload a file, save, return to Site Browser → confirm file is inside folder-2, not at site root
  • Verify HTML page creation (TC-003) still works as before — no regression

🤖 Generated with Claude Code

When opening the Add File Asset dialog from a nested folder in Site
Browser, folderPath was not passed to createContentlet(), causing the
new Angular edit-content form to always default Host/Folder to site root.

Stores the active folderMap in currentFileAssetFolderMap (mirroring the
existing currentPageAssetFolderMap pattern used for HTML pages) and
passes the resolved folderPath to createContentlet() in the single-file
branch of getSelectedfileAsset.

Adds E2E coverage for FileAsset content type folderPath pre-fill,
complementing the SimpleContentType specs added in PR #35322.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@claude
Copy link
Copy Markdown
Contributor

claude Bot commented Apr 29, 2026

Claude finished @adrianjm-dotCMS's task in 2m 44s —— View job


PR Review

  • Read changed files
  • Review JSP fix for correctness and edge cases
  • Review E2E test spec
  • Post findings

view_browser_js_inc.jsp — Clean fix

The JSP change is correct and minimal. currentFileAssetFolderMap was already declared at line 1567 but never assigned; the fix stores the folderMap in showFileAssetPopUp (line 1534) and adds the identical folderPath extraction already used in getSelectedpageAsset (lines 1661–1666). The symmetry is exact.

One thing worth making explicit in the PR description: the isMultiple branch at line 1669 (addMultipleFile(...)) intentionally does not receive folderPath. That path is legacy multi-file upload and doesn't invoke the Angular form, so this is correct — but a reader unfamiliar with the codebase might wonder why only the single-file branch was updated.


host-folder-field-file-asset.spec.ts — Three issues

1. Missing afterEach cleanup — the beforeEach creates a content type and two folders, but there is no afterEach calling apiHelpers.deleteContentType(contentType.id). Test data accumulates on every run. The sibling host-folder-field-prefill.spec.ts has the same problem, but that doesn't make it correct here.

2. navigateToNewFileAsset duplicates NewEditContentFormPage.goToNewWithFolderPath() — the local helper navigates to the same URL pattern as the existing page-object method, but waits on field-hostFolder instead of title. This is understandable for file asset types (no title testid), but the helper should either live in NewEditContentFormPage as an overload or at least import and extend it. As written, two places now contain goto('/dotAdmin/#/content/new/${contentType}?folderPath=${folderPath}') with slightly different waits.

// current local helper — duplicates NewEditContentFormPage internals
async function navigateToNewFileAsset(adminPage, contentType, folderPath) {
    await adminPage.goto(`/dotAdmin/#/content/new/${contentType}?folderPath=${folderPath}`);
    await adminPage.waitForLoadState('domcontentloaded');
    await adminPage.getByTestId('field-hostFolder').waitFor({ state: 'visible', timeout: 15000 });
}

Fix this →

3. expect not imported from the fixture — the existing sibling spec imports { expect, test } from the fixture. This spec only imports test. The tests still pass because HostFolderField methods call Playwright's expect internally, but the pattern is inconsistent and expect is available in the fixture's re-export for a reason.


Not an issue (verified)

  • CONTENT_EDITOR2_ENABLED: truecreateFakeContentType sets this in defaults and the spread { ...defaults, ...data } preserves it when the caller doesn't override metadata. The content type will use the new Angular editor. ✓
  • fullPath.split(':')[0] hostname extraction — identical to the page asset path. ✓
  • Trailing-slash handling in folderPathexpectLabelContains uses substring match, so trailing slash doesn't break assertions. ✓

@github-actions github-actions Bot added Area : Backend PR changes Java/Maven backend code Area : Frontend PR changes Angular/TypeScript frontend code labels Apr 29, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes Site Browser “Add Asset → File” creation so the Angular edit-content form receives the correct folderPath for nested folders (regression noted in TC-004 / issue #34588), and adds E2E coverage to prevent recurrence.

Changes:

  • Persist the active folder context for file assets (currentFileAssetFolderMap) when opening the “Add File Asset” popup.
  • Pass the resolved folderPath into createContentlet() for the single-file asset creation path (mirrors existing HTML page behavior).
  • Add Playwright E2E specs validating folderPath pre-fill for File Asset content types (hostFolder field variable).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
dotCMS/src/main/webapp/html/portlet/ext/browser/view_browser_js_inc.jsp Captures the current folder context for file assets and forwards folderPath into the Angular create-contentlet event payload.
core-web/apps/dotcms-ui-e2e/src/tests/edit-content/fields/host-folder-field/host-folder-field-file-asset.spec.ts Adds E2E coverage ensuring folderPath query param pre-fills Host/Folder for File Asset types (nested, shallow, empty fallback).

Comment on lines +28 to +38
async function navigateToNewFileAsset(
adminPage: import('@playwright/test').Page,
contentType: string,
folderPath: string
) {
await adminPage.goto(`/dotAdmin/#/content/new/${contentType}?folderPath=${folderPath}`);
await adminPage.waitForLoadState('domcontentloaded');
await adminPage
.getByTestId('field-hostFolder')
.waitFor({ state: 'visible', timeout: 15000 });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI: Safe To Rollback Area : Backend PR changes Java/Maven backend code Area : Frontend PR changes Angular/TypeScript frontend code

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

[DEFECT] Host or Folder field not picking up current location in Site Browser

2 participants