Skip to content

Conversation

@madsrasmussen
Copy link
Contributor

@madsrasmussen madsrasmussen commented Jun 27, 2025

This is a fix for the name field and save button to respond to late-coming readOnlyGuard rules. Eventually, we should consider supporting propertyGuards for these cases. This fix makes sure that the read-only guard we currently have also works as intended.

Before fixing:

Screen.Recording.2025-06-27.at.09.47.29.mov

Code that can be used for testing:

Manifest

{
  type: 'entityAction',
  kind: 'default',
  alias: 'Umb.EntityAction.Document.Lock',
  name: 'Lock Document Entity Action',
  forEntityTypes: [UMB_DOCUMENT_ENTITY_TYPE],
  api: () => import('./lock-action.js'),
  weight: 200,
  meta: {
    label: 'Lock it',
    icon: 'icon-lock',
  },
}

Entity Action

import { UMB_DOCUMENT_WORKSPACE_CONTEXT } from '../../constants.js';
import { UmbVariantId } from '@umbraco-cms/backoffice/variant';
import { UmbEntityActionBase } from '@umbraco-cms/backoffice/entity-action';

export class UmbDocumentLockEntityAction extends UmbEntityActionBase<never> {
  override async execute() {
    const context = await this.getContext(UMB_DOCUMENT_WORKSPACE_CONTEXT);
    const ruleUnique = 'lock';

    const myRule = {
      unique: ruleUnique,
      UmbVariantId: new UmbVariantId(),
    };

    const hasRule = context?.readOnlyGuard.getRules().find((rule) => rule.unique === ruleUnique);

    if (hasRule) {
      context?.readOnlyGuard.removeRule(ruleUnique);
    } else {
      context?.readOnlyGuard.addRule(myRule);
    }
  }
}

export { UmbDocumentLockEntityAction as api };

After fixing:

Screen.Recording.2025-06-27.at.11.20.20.mov

Added observation of read-only guard rules in the workspace split view variant selector to ensure read-only cultures are updated when rules change.
@madsrasmussen madsrasmussen marked this pull request as ready for review June 27, 2025 09:30
Copilot AI review requested due to automatic review settings June 27, 2025 09:30
Copy link
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

This PR ensures that the save button and variant selector respond to read-only guard rules added after initial render by observing guard rule changes and updating UI state accordingly.

  • Save action now observes both variants and readOnlyGuard.rules, running a check to enable/disable the save button based on variant permissions.
  • Split-view variant selector observes readOnlyGuard.rules to refresh read-only cultures dynamically.
  • Introduced private fields to store variants (and an unused read-only rules field).

Reviewed Changes

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

File Description
src/Umbraco.Web.UI.Client/src/packages/documents/documents/workspace/actions/save.action.ts Observe readOnlyGuard.rules and variants, add #checkReadOnlyGuardRules() to toggle save action.
src/Umbraco.Web.UI.Client/src/packages/core/workspace/components/workspace-split-view/workspace-split-view-variant-selector.element.ts Add observer on readOnlyGuard.rules to call #setReadOnlyCultures when rules change.
Comments suppressed due to low confidence (2)

src/Umbraco.Web.UI.Client/src/packages/documents/documents/workspace/actions/save.action.ts:10

  • This type import isn’t used in this file; consider removing it to keep imports clean.
	type UmbVariantDatasetWorkspaceContext,

src/Umbraco.Web.UI.Client/src/packages/core/workspace/components/workspace-split-view/workspace-split-view-variant-selector.element.ts:156

  • Ensure UmbVariantDatasetWorkspaceContext is imported at the top of this file; otherwise this will cause a compilation error.
	#observeReadOnlyGuardRules(workspaceContext?: UmbVariantDatasetWorkspaceContext) {

warrenbuckley added a commit to warrenbuckley/Umbraco.Community.ContentLock that referenced this pull request Jun 27, 2025
Once 16.1.0 out and this PR is in CMS - then remove this HACKY workaround
umbraco/Umbraco-CMS#19621

Still need to use readonlyGuard for the node name readonly and its not deprecated by core yet as they still use it
@nielslyngsoe nielslyngsoe merged commit 50327be into main Jun 30, 2025
27 checks passed
@nielslyngsoe nielslyngsoe deleted the v16/bugfix/react-on-late-read-only-rules branch June 30, 2025 13:22
warrenbuckley added a commit to warrenbuckley/Umbraco.Community.ContentLock that referenced this pull request Jul 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants