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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Read-only documents #2156

Merged
merged 68 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
d0cba2b
expose more states on current user context
madsrasmussen Jul 29, 2024
7e9ccf8
wip readonly property ui
madsrasmussen Jul 29, 2024
74a61ae
add js docs
madsrasmussen Jul 29, 2024
66d9be8
add language access workspace context
madsrasmussen Jul 30, 2024
6e76d74
add state managers
madsrasmussen Jul 30, 2024
ecdee1a
add state manager to document workspace
madsrasmussen Jul 30, 2024
97e3a19
render readonly tag in variant dropdown
madsrasmussen Jul 30, 2024
431f60f
simplify variant display name
madsrasmussen Jul 30, 2024
0c3aa93
translate publish state
madsrasmussen Jul 30, 2024
d8c575e
update temp names
madsrasmussen Jul 30, 2024
6dca37c
adjust spacing
madsrasmussen Jul 30, 2024
d6c7acf
sort variants
madsrasmussen Jul 31, 2024
83ee669
render text for default language
madsrasmussen Jul 31, 2024
3c68c5b
use identifier in check
madsrasmussen Jul 31, 2024
385f439
add condition to check if a property is writable
madsrasmussen Jul 31, 2024
c59a6eb
check property context for readonly state
madsrasmussen Jul 31, 2024
5765113
implement readonly observable in property context
madsrasmussen Jul 31, 2024
5ec020a
add readonlyState manager to interface
madsrasmussen Jul 31, 2024
c6a693f
simplify identifier string
madsrasmussen Jul 31, 2024
bb932ea
check current variant
madsrasmussen Jul 31, 2024
bdcae2c
always allow editing invariant properties
madsrasmussen Jul 31, 2024
a1bcad6
remove temp debug label
madsrasmussen Jul 31, 2024
e3f1b7c
delete disabled state manager
madsrasmussen Jul 31, 2024
c4681f5
split classes into individual files
madsrasmussen Jul 31, 2024
94b0656
fix export
madsrasmussen Jul 31, 2024
a4fbf5c
use helper to check of variant is invariant
madsrasmussen Jul 31, 2024
eb4586e
set readonly attribute on element if its readonly
madsrasmussen Jul 31, 2024
4926ef8
only render overlay if the editor doesn't support readonly
madsrasmussen Jul 31, 2024
ca235af
add supportsReadOnly to supported manifests
madsrasmussen Jul 31, 2024
572e0fb
change 'Invariant' to 'Shared'
madsrasmussen Jul 31, 2024
d2cd01c
fine-tune tag styling
madsrasmussen Jul 31, 2024
84d528d
show variant info tag on hover
madsrasmussen Jul 31, 2024
1a38927
sort variants in context
madsrasmussen Jul 31, 2024
f0f9476
Merge branch 'main' into v14/feature/readonly-properties
madsrasmussen Aug 2, 2024
dccbcc8
Merge branch 'main' into v14/feature/readonly-properties
madsrasmussen Aug 5, 2024
568db64
fix imports
madsrasmussen Aug 5, 2024
244f67f
add readonly state manager
madsrasmussen Aug 5, 2024
200d1df
add readonly state manager
madsrasmussen Aug 5, 2024
ef4b52d
use content workspace context
madsrasmussen Aug 5, 2024
d33a24a
add readonly state manager
madsrasmussen Aug 5, 2024
4975de1
disable eslint for this example
madsrasmussen Aug 5, 2024
216490c
add null check
madsrasmussen Aug 5, 2024
cae130a
implement missing methods
madsrasmussen Aug 5, 2024
b59c89a
use context token
madsrasmussen Aug 5, 2024
78c0ed2
add missing methods
madsrasmussen Aug 5, 2024
8f807db
add missing methods
madsrasmussen Aug 5, 2024
44872ae
add missing methods
madsrasmussen Aug 5, 2024
33f8d9e
add fallback
madsrasmussen Aug 5, 2024
dc586b0
type fixing
madsrasmussen Aug 5, 2024
ed7de26
extend controller base
madsrasmussen Aug 5, 2024
7bedbc3
check state for unique field
madsrasmussen Aug 5, 2024
d876d20
check if unique is already in the array
madsrasmussen Aug 5, 2024
75deb6b
use optional chaining
madsrasmussen Aug 5, 2024
7495acc
add isOn and isOff observables
madsrasmussen Aug 6, 2024
d072723
remove unused
madsrasmussen Aug 6, 2024
3219e76
Merge branch 'main' into v14/feature/readonly-properties
madsrasmussen Aug 6, 2024
29521a6
Merge branch 'main' into v14/feature/readonly-properties
madsrasmussen Aug 6, 2024
b95fc78
Merge branch 'main' into v14/feature/readonly-properties
madsrasmussen Aug 7, 2024
78d137c
Merge branch 'main' into v14/feature/readonly-properties
madsrasmussen Aug 8, 2024
d0bbf9d
use constant
madsrasmussen Aug 8, 2024
5d8a2f4
Merge branch 'main' into v14/feature/readonly-properties
madsrasmussen Aug 9, 2024
fa4f5f7
Merge branch 'main' into v14/feature/readonly-properties
madsrasmussen Aug 12, 2024
d8d234a
Merge branch 'main' into v14/feature/readonly-properties
madsrasmussen Aug 13, 2024
eb6e35d
Update property.context.ts
madsrasmussen Aug 19, 2024
c3b0d7d
Merge branch 'main' into v14/feature/readonly-properties
madsrasmussen Aug 19, 2024
5d5fc1c
Merge branch 'main' into v14/feature/readonly-properties
madsrasmussen Aug 19, 2024
474aa28
remove unused
madsrasmussen Aug 19, 2024
b63c1c4
bump z-index
madsrasmussen Aug 19, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
import { UmbControllerBase } from '@umbraco-cms/backoffice/class-api';
import { UmbVariantId } from '@umbraco-cms/backoffice/variant';
import type { Observable } from '@umbraco-cms/backoffice/external/rxjs';
import { UmbBooleanState } from '@umbraco-cms/backoffice/observable-api';

export class UmbBlockGridInlinePropertyDatasetContext extends UmbControllerBase implements UmbPropertyDatasetContext {
#entryContext: UmbBlockGridEntryContext;

#currentVariantCultureIsReadOnly = new UmbBooleanState(false);
public currentVariantCultureIsReadOnly = this.#currentVariantCultureIsReadOnly.asObservable();

// default data:

getVariantId() {
Expand Down Expand Up @@ -57,4 +61,13 @@ export class UmbBlockGridInlinePropertyDatasetContext extends UmbControllerBase
// TODO: Investigate how I do that with the workspaces..
return this.#entryContext.setContentPropertyValue(propertyAlias, value);
}

/**
* Gets the read-only state of the current variant culture.
* @returns {*} {boolean}
* @memberof UmbBlockGridInlinePropertyDatasetContext
*/
getCurrentVariantCultureIsReadOnly(): boolean {
return this.#currentVariantCultureIsReadOnly.getValue();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
import { UmbControllerBase } from '@umbraco-cms/backoffice/class-api';
import { UmbVariantId } from '@umbraco-cms/backoffice/variant';
import type { Observable } from '@umbraco-cms/backoffice/external/rxjs';
import { UmbBooleanState } from '@umbraco-cms/backoffice/observable-api';

export class UmbBlockElementPropertyDatasetContext extends UmbControllerBase implements UmbPropertyDatasetContext {
#elementManager: UmbBlockElementManager;

#currentVariantCultureIsReadOnly = new UmbBooleanState(false);
public currentVariantCultureIsReadOnly = this.#currentVariantCultureIsReadOnly.asObservable();

// default data:

getVariantId() {
Expand Down Expand Up @@ -59,4 +63,13 @@ export class UmbBlockElementPropertyDatasetContext extends UmbControllerBase imp
async setPropertyValue(alias: string, value: unknown) {
return this.#elementManager.setPropertyValue(alias, value);
}

/**
* Gets the read-only state of the current variant culture.
* @returns {*} {boolean}
* @memberof UmbBlockGridInlinePropertyDatasetContext
*/
getCurrentVariantCultureIsReadOnly(): boolean {
return this.#currentVariantCultureIsReadOnly.getValue();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { UMB_PROPERTY_DATASET_CONTEXT } from '@umbraco-cms/backoffice/property';
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
import { UmbContextBase } from '@umbraco-cms/backoffice/class-api';
import { type Observable, map } from '@umbraco-cms/backoffice/external/rxjs';
import { UmbObjectState } from '@umbraco-cms/backoffice/observable-api';
import { UmbBooleanState, UmbObjectState } from '@umbraco-cms/backoffice/observable-api';
import type { UmbVariantModel } from '@umbraco-cms/backoffice/variant';
import { UmbVariantId } from '@umbraco-cms/backoffice/variant';
import type { UmbContentTypeModel, UmbPropertyTypeModel } from '@umbraco-cms/backoffice/content-type';
Expand All @@ -30,6 +30,9 @@ export class UmbContentPropertyDatasetContext<
culture = this.#currentVariant.asObservablePart((x) => x?.culture);
segment = this.#currentVariant.asObservablePart((x) => x?.segment);

#currentVariantCultureIsReadOnly = new UmbBooleanState(false);
public currentVariantCultureIsReadOnly = this.#currentVariantCultureIsReadOnly.asObservable();

getEntityType(): string {
return this.#workspace.getEntityType();
}
Expand All @@ -46,6 +49,10 @@ export class UmbContentPropertyDatasetContext<
return this.#workspace.getVariant(this.#variantId);
}

getCurrentVariantCultureIsReadOnly() {
return this.#currentVariantCultureIsReadOnly.getValue();
}

constructor(
host: UmbControllerHost,
workspace: UmbContentWorkspaceContext<ContentTypeModel, VariantModelType>,
Expand All @@ -64,6 +71,18 @@ export class UmbContentPropertyDatasetContext<
},
'_observeActiveVariant',
);

this.observe(
this.#workspace.readOnlyState.states,
(states) => {
const isReadOnly = states.some(
(state) => state.unique.startsWith('UMB_CULTURE_') && state.variantId.equal(this.#variantId),
);

this.#currentVariantCultureIsReadOnly.setValue(isReadOnly);
},
'umbObserveReadOnlyStates',
);
}

#createPropertyVariantId(property: UmbPropertyTypeModel) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { UmbContentTypeModel } from '@umbraco-cms/backoffice/content-type';
import type { Observable } from '@umbraco-cms/backoffice/external/rxjs';
import type { UmbReadOnlyVariantStateManager } from '@umbraco-cms/backoffice/utils';
import type { UmbVariantId, UmbVariantModel } from '@umbraco-cms/backoffice/variant';
import type {
UmbPropertyStructureWorkspaceContext,
Expand All @@ -14,6 +15,7 @@ export interface UmbContentWorkspaceContext<
UmbVariantDatasetWorkspaceContext<VariantModelType>,
UmbPropertyStructureWorkspaceContext<ContentTypeModel> {
readonly IS_CONTENT_WORKSPACE_CONTEXT: true;
readonly readOnlyState: UmbReadOnlyVariantStateManager;

isLoaded(): Promise<unknown> | undefined;
variantById(variantId: UmbVariantId): Observable<VariantModelType | undefined>;
Expand Down
2 changes: 2 additions & 0 deletions src/packages/core/manifests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { manifests as localizationManifests } from './localization/manifests.js'
import { manifests as modalManifests } from './modal/common/manifests.js';
import { manifests as pickerManifests } from './picker/manifests.js';
import { manifests as propertyActionManifests } from './property-action/manifests.js';
import { manifests as propertyManifests } from './property/manifests.js';
import { manifests as propertyTypeManifests } from './property-type/manifests.js';
import { manifests as recycleBinManifests } from './recycle-bin/manifests.js';
import { manifests as sectionManifests } from './section/manifests.js';
Expand All @@ -38,6 +39,7 @@ export const manifests: Array<ManifestTypes | UmbBackofficeManifestKind> = [
...modalManifests,
...pickerManifests,
...propertyActionManifests,
...propertyManifests,
...propertyTypeManifests,
...recycleBinManifests,
...sectionManifests,
Expand Down
12 changes: 12 additions & 0 deletions src/packages/core/property-action/manifests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import type {
UmbBackofficeManifestKind,
} from '@umbraco-cms/backoffice/extension-registry';

import { UMB_WRITABLE_PROPERTY_CONDITION_ALIAS } from '@umbraco-cms/backoffice/property';

export const propertyActionManifests: Array<ManifestPropertyActions> = [
{
type: 'propertyAction',
Expand All @@ -17,6 +19,11 @@ export const propertyActionManifests: Array<ManifestPropertyActions> = [
icon: 'icon-paste-in',
label: 'Copy',
},
conditions: [
{
alias: UMB_WRITABLE_PROPERTY_CONDITION_ALIAS,
},
],
},
{
type: 'propertyAction',
Expand All @@ -29,6 +36,11 @@ export const propertyActionManifests: Array<ManifestPropertyActions> = [
icon: 'icon-trash',
label: 'Clear',
},
conditions: [
{
alias: UMB_WRITABLE_PROPERTY_CONDITION_ALIAS,
},
],
},
];

Expand Down
1 change: 1 addition & 0 deletions src/packages/core/property/conditions/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const UMB_WRITABLE_PROPERTY_CONDITION_ALIAS = 'Umb.Condition.Property.Writable';
1 change: 1 addition & 0 deletions src/packages/core/property/conditions/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './constants.js';
11 changes: 11 additions & 0 deletions src/packages/core/property/conditions/manifests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { UMB_WRITABLE_PROPERTY_CONDITION_ALIAS } from './constants.js';
import type { ManifestTypes } from '@umbraco-cms/backoffice/extension-registry';

export const manifests: Array<ManifestTypes> = [
{
type: 'condition',
name: 'Writable Property Condition',
alias: UMB_WRITABLE_PROPERTY_CONDITION_ALIAS,
api: () => import('./writable-property.condition.js'),
},
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { UMB_PROPERTY_CONTEXT } from '../property/property.context.js';
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
import type {
UmbConditionConfigBase,
UmbConditionControllerArguments,
UmbExtensionCondition,
} from '@umbraco-cms/backoffice/extension-api';
import { UmbConditionBase } from '@umbraco-cms/backoffice/extension-registry';

export class UmbWritablePropertyCondition
extends UmbConditionBase<UmbConditionConfigBase>
implements UmbExtensionCondition
{
constructor(host: UmbControllerHost, args: UmbConditionControllerArguments<UmbConditionConfigBase>) {
super(host, args);

this.consumeContext(UMB_PROPERTY_CONTEXT, (context) => {
this.observe(context.isReadOnly, (value) => {
this.permitted = value !== true;
});
});
}
}

export { UmbWritablePropertyCondition as api };
3 changes: 2 additions & 1 deletion src/packages/core/property/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './property/index.js';
export * from './conditions/index.js';
export * from './property-dataset/index.js';
export * from './property-layout/index.js';
export * from './property/index.js';
export * from './types/index.js';
3 changes: 3 additions & 0 deletions src/packages/core/property/manifests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { manifests as conditionManifests } from './conditions/manifests.js';

export const manifests = [...conditionManifests];
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { UmbPropertyDatasetContext } from './property-dataset-context.inter
import type { UmbNameablePropertyDatasetContext } from './nameable-property-dataset-context.interface.js';
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
import { UmbContextBase } from '@umbraco-cms/backoffice/class-api';
import { UmbArrayState, UmbStringState } from '@umbraco-cms/backoffice/observable-api';
import { UmbArrayState, UmbBooleanState, UmbStringState } from '@umbraco-cms/backoffice/observable-api';
import { UmbVariantId } from '@umbraco-cms/backoffice/variant';

/**
Expand All @@ -24,6 +24,9 @@ export class UmbPropertyDatasetContextBase
private _entityType!: string;
private _unique!: string;

#currentVariantCultureIsReadOnly = new UmbBooleanState(false);
public currentVariantCultureIsReadOnly = this.#currentVariantCultureIsReadOnly.asObservable();

getEntityType() {
return this._entityType;
}
Expand Down Expand Up @@ -76,4 +79,13 @@ export class UmbPropertyDatasetContextBase
setValues(map: Array<UmbPropertyValueData>) {
this.#values.setValue(map);
}

/**
* Gets the read-only state of the current variant culture.
* @return {*} {boolean}
* @memberof UmbBlockGridInlinePropertyDatasetContext
*/
getCurrentVariantCultureIsReadOnly(): boolean {
return this.#currentVariantCultureIsReadOnly.getValue();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ export interface UmbPropertyDatasetContext extends UmbContext {
getName(): string | undefined;
readonly name: Observable<string | undefined>;

getCurrentVariantCultureIsReadOnly(): boolean;
readonly currentVariantCultureIsReadOnly: Observable<boolean>;

// Should it be possible to get the properties as a list of property aliases?
//readonly properties: Observable<Array<string>>;

Expand Down
Loading
Loading