Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
89d8985
Documents: Use single-transaction create/update-and-publish endpoints…
iOvergaard Jun 1, 2026
c25740b
Merge remote-tracking branch 'origin/v17/improvement/save-and-publish…
iOvergaard Jun 1, 2026
3fb8ac4
Documents: Address review feedback on save-and-publish FE
iOvergaard Jun 1, 2026
149d77f
Documents: Drop redundant document re-read on save-and-publish
iOvergaard Jun 1, 2026
2eeb9d4
Documents: Fix spurious discard dialog after create-and-publish
iOvergaard Jun 3, 2026
368da35
Documents: Move create/update-and-publish into the publishing domain
iOvergaard Jun 3, 2026
3fa459b
Documents: Drop redundant context guard in save-and-publish orchestrator
iOvergaard Jun 3, 2026
9cbd92b
Documents: Reconcile current as well as persisted in finalizeCreate
iOvergaard Jun 3, 2026
ad059a0
Documents: Align finalizeUpdate with finalizeCreate and tighten metho…
iOvergaard Jun 5, 2026
95f7f16
Merge branch 'v17/improvement/save-and-publish-take-three' into v17/f…
iOvergaard Jun 5, 2026
1defc81
initial correction
nielslyngsoe Jun 17, 2026
ce26103
second round of refactor
nielslyngsoe Jun 18, 2026
119fe09
url-pattern-to-string tests
nielslyngsoe Jun 18, 2026
bfc51e7
url-pattern-to-string jsdocs
nielslyngsoe Jun 18, 2026
96c34ab
avoid discard changes dialog when navigating between create and edit
nielslyngsoe Jun 18, 2026
2f5ab7f
keep track of the absolute route as well
nielslyngsoe Jun 18, 2026
0342d33
check absolute path as part of dirty check
nielslyngsoe Jun 18, 2026
20b313e
check navigation util
nielslyngsoe Jun 18, 2026
0e82e21
added TODOs
nielslyngsoe Jun 18, 2026
f21b71b
clean up
nielslyngsoe Jun 19, 2026
60d7350
error handling
nielslyngsoe Jun 19, 2026
6fd51e5
error handling for schedule
nielslyngsoe Jun 19, 2026
10d6127
remove unused import
nielslyngsoe Jun 19, 2026
f3a5dac
rename to performDefault...
nielslyngsoe Jun 19, 2026
9a9b55a
rename
nielslyngsoe Jun 19, 2026
f2dbcde
rename and export interface
nielslyngsoe Jun 19, 2026
21f09df
simplify #applyPersistedData
nielslyngsoe Jun 19, 2026
0a86e25
fix(documents): avoid double notification on publish/schedule validat…
iOvergaard Jun 19, 2026
bba87c7
fix(documents): don't report publish failure when only the read-back …
iOvergaard Jun 19, 2026
0951f36
simplify comment
nielslyngsoe Jun 22, 2026
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
35 changes: 31 additions & 4 deletions src/Umbraco.Web.UI.Client/mocks/db/document-publishing.manager.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import type { UmbMockDocumentModel } from '../data/mock-data-set.types.js';

Check warning on line 1 in src/Umbraco.Web.UI.Client/mocks/db/document-publishing.manager.ts

View check run for this annotation

CodeScene Delta Analysis / CodeScene Code Health Review (v17/improvement/save-and-publish-take-three)

❌ New issue: String Heavy Function Arguments

In this module, 46.7% of all arguments to its 9 functions are strings. The threshold for string arguments is 39.0%. The functions in this file have a high ratio of strings as arguments. Avoid adding more.
import type { UmbDocumentMockDB } from './document.db.js';
import type {
CreateAndPublishDocumentRequestModel,
PublishDocumentRequestModel,
PublishDocumentWithDescendantsRequestModel,
UnpublishDocumentRequestModel,
UpdateAndPublishDocumentRequestModel,
} from '@umbraco-cms/backoffice/external/backend-api';
import { UmbId } from '@umbraco-cms/backoffice/id';
import type { DocumentVariantResponseModel } from '@umbraco-cms/backoffice/external/backend-api';
Expand Down Expand Up @@ -55,6 +57,34 @@
this.#documentDb.detail.update(id, document);
}

createAndPublish(data: CreateAndPublishDocumentRequestModel) {
const id = this.#documentDb.detail.create(data);
this.#publishCultures(id, data.culturesToPublish);
return id;
}

updateAndPublish(id: string, data: UpdateAndPublishDocumentRequestModel) {
this.#documentDb.detail.update(id, data);
this.#publishCultures(id, data.culturesToPublish);
}

#publishCultures(id: string, culturesToPublish: Array<string>) {
const document: UmbMockDocumentModel = this.#documentDb.detail.read(id);

// Invariant content types publish with an empty cultures array; publish the invariant variant in that case.
const cultures: Array<string | null> = culturesToPublish.length > 0 ? culturesToPublish : [null];

cultures.forEach((culture) => {
const variant = document.variants.find((x) => x.culture === culture);
if (variant) {
variant.state = 'Published' as UmbDocumentVariantState;
variant.updateDate = new Date().toISOString();
}
});

this.#documentDb.detail.update(id, document);
}

publishWithDescendants(id: string, data: PublishDocumentWithDescendantsRequestModel) {
const document: UmbMockDocumentModel = this.#documentDb.detail.read(id);
const documents = this.getDescendants(id, []);
Expand All @@ -64,10 +94,7 @@
for (const culture of data.cultures) {
for (const d of documents) {
const variant = document.variants.find((x) => x.culture === culture);
if (
variant &&
(data.includeUnpublishedDescendants || variant.state !== 'Published')
) {
if (variant && (data.includeUnpublishedDescendants || variant.state !== 'Published')) {
variant.state = 'Published' as UmbDocumentVariantState;
variant.updateDate = new Date().toISOString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import { umbMockManager } from '../../mock-manager.js';
import { umbDocumentMockDb } from '../../db/document.db.js';
import { UMB_SLUG } from './slug.js';
import type {
CreateAndPublishDocumentRequestModel,
CreateDocumentRequestModel,
DefaultReferenceResponseModel,
GetDocumentByIdAvailableSegmentOptionsResponse,
GetDocumentByIdReferencedDescendantsResponse,
PagedIReferenceResponseModel,
UpdateAndPublishDocumentRequestModel,
UpdateDocumentRequestModel,
} from '@umbraco-cms/backoffice/external/backend-api';
import { umbracoPath } from '@umbraco-cms/backoffice/utils';
Expand Down Expand Up @@ -38,6 +40,21 @@ export const detailHandlers = [
});
}),

http.post(umbracoPath(`${UMB_SLUG}/create-and-publish`), async ({ request }) => {
const requestBody = (await request.json()) as CreateAndPublishDocumentRequestModel;
if (!requestBody) return new HttpResponse(null, { status: 400, statusText: 'no body found' });

const id = umbDocumentMockDb.publishing.createAndPublish(requestBody);

return HttpResponse.json(null, {
status: 201,
headers: {
Location: request.url + '/' + id,
'Umb-Generated-Resource': id,
},
});
}),

http.get(umbracoPath(`${UMB_SLUG}/configuration`), () => {
return HttpResponse.json(umbDocumentMockDb.getConfiguration());
}),
Expand Down Expand Up @@ -155,6 +172,19 @@ export const detailHandlers = [
}
}),

http.put(umbracoPath(`${UMB_SLUG}/:id/update-and-publish`), async ({ request, params }) => {
const id = params.id as string;
if (!id) return new HttpResponse(null, { status: 400 });
if (id === 'forbidden') {
// Simulate a forbidden response
return new HttpResponse(null, { status: 403 });
}
const requestBody = (await request.json()) as UpdateAndPublishDocumentRequestModel;
if (!requestBody) return new HttpResponse(null, { status: 400, statusText: 'no body found' });
umbDocumentMockDb.publishing.updateAndPublish(id, requestBody);
return new HttpResponse(null, { status: 200 });
}),

http.put(umbracoPath(`${UMB_SLUG}/:id`), async ({ request, params }) => {
const id = params.id as string;
if (!id) return new HttpResponse(null, { status: 400 });
Expand Down

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Comment thread
nielslyngsoe marked this conversation as resolved.
Resolved
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { UMB_DOCUMENT_WORKSPACE_CONTEXT } from '../../workspace/context/document-workspace.context-token.js';

Check notice on line 1 in src/Umbraco.Web.UI.Client/src/packages/documents/documents/publishing/workspace-context/document-publishing.workspace-context.ts

View check run for this annotation

CodeScene Delta Analysis / CodeScene Code Health Review (v17/improvement/save-and-publish-take-three)

✅ Getting better: Overall Code Complexity

The mean cyclomatic complexity decreases from 6.78 to 6.72, threshold = 4. This file has many conditional statements (e.g. if, for, while) across its implementation, leading to lower code health. Avoid adding more conditionals.
import type {
UmbDocumentDetailModel,
UmbDocumentVariantOptionModel,
Expand Down Expand Up @@ -399,33 +399,36 @@
const entityType = this.#documentWorkspaceContext.getEntityType();
if (!entityType) throw new Error('Entity type is missing');

await this.#documentWorkspaceContext.performCreateOrUpdate(variantIds, saveData);
// Capture the current (draft) data before the operation, so variants that are not being published
// but still hold unsaved edits can be kept dirty after the reload below.
const dirtyData = this.#documentWorkspaceContext.getData();

const { error } = await this.#publishingRepository.publish(
unique,
variantIds.map((variantId) => ({ variantId })),
);
// Save and publish in a single server transaction (replaces the separate save + publish calls).
await this.#documentWorkspaceContext.performCreateOrUpdateAndPublish(variantIds, saveData);

if (!error) {
this.#notificationContext?.peek('positive', {
data: {
message: this.#localize.term('speechBubbles_editContentPublishedHeader'),
},
});
this.#notificationContext?.peek('positive', {
data: {
message: this.#localize.term('speechBubbles_editContentPublishedHeader'),
},
});

// Clear stale published data and pending changes state so the
// persistedData observer does not run a comparison against outdated
// data during reload, which would briefly show a false-positive
// "pending changes" state.
this.#clear();
// Clear stale published data and pending changes state so the
// persistedData observer does not run a comparison against outdated
// data during reload, which would briefly show a false-positive
// "pending changes" state.
this.#clear();

// reload the document so all states are updated after the publish operation
await this.#documentWorkspaceContext.reload();
await this.#loadAndProcessLastPublished();
// reload the document so all states are updated after the publish operation
await this.#documentWorkspaceContext.reload();

const event = new UmbRequestReloadStructureForEntityEvent({ unique, entityType });
this.#eventContext?.dispatchEvent(event);
}
// The reload resets the current data state to the full server document. Re-apply the edits of the
// variants that were not published, so they remain dirty (and the Discard-Changes guard fires).
await this.#documentWorkspaceContext.transferPublishedVariantsToCurrent(dirtyData, variantIds);

await this.#loadAndProcessLastPublished();

const event = new UmbRequestReloadStructureForEntityEvent({ unique, entityType });
this.#eventContext?.dispatchEvent(event);

Check notice on line 431 in src/Umbraco.Web.UI.Client/src/packages/documents/documents/publishing/workspace-context/document-publishing.workspace-context.ts

View check run for this annotation

CodeScene Delta Analysis / CodeScene Code Health Review (v17/improvement/save-and-publish-take-three)

✅ Getting better: Complex Method

UmbDocumentPublishingWorkspaceContext.performSaveAndPublish decreases in cyclomatic complexity from 10 to 9, threshold = 9. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.
}

#publishableVariantsFilter = (option: UmbDocumentVariantOptionModel) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,41 @@ import { UmbDocumentServerDataSource } from './document-detail.server.data-sourc
import { UMB_DOCUMENT_DETAIL_STORE_CONTEXT } from './document-detail.store.context-token.js';
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
import { UmbDetailRepositoryBase } from '@umbraco-cms/backoffice/repository';
export class UmbDocumentDetailRepository extends UmbDetailRepositoryBase<UmbDocumentDetailModel> {
import type { UmbVariantId } from '@umbraco-cms/backoffice/variant';
export class UmbDocumentDetailRepository extends UmbDetailRepositoryBase<
UmbDocumentDetailModel,
UmbDocumentServerDataSource
> {
constructor(host: UmbControllerHost) {
super(host, UmbDocumentServerDataSource, UMB_DOCUMENT_DETAIL_STORE_CONTEXT);
}

/**
* Creates and publishes a new Document in a single operation
* @param {UmbDocumentDetailModel} model - The Document to create
* @param {Array<UmbVariantId>} variantIds - The variants to publish after creating
* @param {string | null} parentUnique - The unique of the parent to create under
* @returns {*}
* @memberof UmbDocumentDetailRepository
*/
async createAndPublish(
model: UmbDocumentDetailModel,
variantIds: Array<UmbVariantId>,
parentUnique: string | null = null,
Comment thread
iOvergaard marked this conversation as resolved.
Resolved
) {
return this.detailDataSource.createAndPublish(model, variantIds, parentUnique);
}

/**
* Updates and publishes an existing Document in a single operation
* @param {UmbDocumentDetailModel} model - The Document to update
* @param {Array<UmbVariantId>} variantIds - The variants to publish after updating
* @returns {*}
* @memberof UmbDocumentDetailRepository
*/
async updateAndPublish(model: UmbDocumentDetailModel, variantIds: Array<UmbVariantId>) {
return this.detailDataSource.updateAndPublish(model, variantIds);
}
}

export { UmbDocumentDetailRepository as api };
Loading