-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Collection: Introduce Collection Item Card extension type #20954
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
Merged
+639
−143
Merged
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
cc1c99b
Add entity collection item card extension type + default elements
madsrasmussen 852a9d7
implement user collection item card
madsrasmussen 0dc90ad
fix selection events
madsrasmussen 8c047e0
map to prop
madsrasmussen f06d594
add prop/attr for href
madsrasmussen df1219a
add support for which detail properties to show
madsrasmussen 0f59c3e
update type import
madsrasmussen 2aefe5e
Update src/Umbraco.Web.UI.Client/src/packages/core/collection/item/en…
madsrasmussen 37b9df4
import card in correct file
madsrasmussen 3dbe65a
Fix event listener binding for selection events
madsrasmussen 8865403
implement disabled property for collection item cards
madsrasmussen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
src/Umbraco.Web.UI.Client/src/packages/core/collection/global-components.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| import './menu/collection-menu.element.js'; | ||
|
|
||
| import './item/global-components.js'; | ||
| export * from './menu/collection-menu.element.js'; |
64 changes: 64 additions & 0 deletions
64
.../core/collection/item/entity-collection-item-card/default-collection-item-card.element.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| import type { UmbCollectionItemModel } from '../types.js'; | ||
| import { getItemFallbackName, getItemFallbackIcon } from '@umbraco-cms/backoffice/entity-item'; | ||
| import { UmbDeselectedEvent, UmbSelectedEvent } from '@umbraco-cms/backoffice/event'; | ||
| import { customElement, html, nothing, property } from '@umbraco-cms/backoffice/external/lit'; | ||
| import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element'; | ||
|
|
||
| @customElement('umb-default-collection-item-card') | ||
| export class UmbDefaultCollectionItemCardElement extends UmbLitElement { | ||
| @property({ type: Object }) | ||
| item?: UmbCollectionItemModel; | ||
|
|
||
| @property({ type: Boolean }) | ||
| selectable = false; | ||
|
|
||
| @property({ type: Boolean }) | ||
| selected = false; | ||
|
|
||
| @property({ type: Boolean }) | ||
| selectOnly = false; | ||
|
|
||
| @property({ type: String }) | ||
| href?: string; | ||
|
|
||
| #onSelected(event: CustomEvent) { | ||
| if (!this.item) return; | ||
| event.stopPropagation(); | ||
| this.dispatchEvent(new UmbSelectedEvent(this.item.unique)); | ||
| } | ||
|
|
||
| #onDeselected(event: CustomEvent) { | ||
| if (!this.item) return; | ||
| event.stopPropagation(); | ||
| this.dispatchEvent(new UmbDeselectedEvent(this.item.unique)); | ||
| } | ||
|
|
||
| override render() { | ||
| if (!this.item) return nothing; | ||
|
|
||
| return html` | ||
| <uui-card-content-node | ||
| name=${this.item.name ?? `${getItemFallbackName(this.item)}`} | ||
| href=${this.href} | ||
| ?selectable=${this.selectable} | ||
| ?select-only=${this.selectOnly} | ||
| ?selected=${this.selected} | ||
| @selected=${this.#onSelected} | ||
| @deselected=${this.#onDeselected}> | ||
| <slot name="actions" slot="actions"></slot> | ||
| ${this.#renderIcon(this.item)} | ||
| </uui-card-content-node> | ||
| `; | ||
| } | ||
|
|
||
| #renderIcon(item: UmbCollectionItemModel) { | ||
| const icon = item.icon || getItemFallbackIcon(); | ||
| return html`<umb-icon slot="icon" name=${icon}></umb-icon>`; | ||
| } | ||
| } | ||
|
|
||
| declare global { | ||
| interface HTMLElementTagNameMap { | ||
| 'umb-default-collection-item-card': UmbDefaultCollectionItemCardElement; | ||
| } | ||
| } | ||
210 changes: 210 additions & 0 deletions
210
...s/core/collection/item/entity-collection-item-card/entity-collection-item-card.element.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,210 @@ | ||
| import type { UmbCollectionItemDetailPropertyConfig, UmbCollectionItemModel } from '../types.js'; | ||
| import type { ManifestEntityCollectionItemCard } from './entity-collection-item-card.extension.js'; | ||
| import { css, customElement, html, property, state } from '@umbraco-cms/backoffice/external/lit'; | ||
| import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element'; | ||
| import { UmbExtensionsElementInitializer } from '@umbraco-cms/backoffice/extension-api'; | ||
| import { umbExtensionsRegistry } from '@umbraco-cms/backoffice/extension-registry'; | ||
| import { UmbDeselectedEvent, UmbSelectedEvent } from '@umbraco-cms/backoffice/event'; | ||
| import { UmbRoutePathAddendumContext } from '@umbraco-cms/backoffice/router'; | ||
| import { UMB_MARK_ATTRIBUTE_NAME } from '@umbraco-cms/backoffice/const'; | ||
| import type { PropertyValueMap } from '@umbraco-cms/backoffice/external/lit'; | ||
|
|
||
| import './default-collection-item-card.element.js'; | ||
|
|
||
| @customElement('umb-entity-collection-item-card') | ||
| export class UmbEntityCollectionItemCardElement extends UmbLitElement { | ||
| #extensionsController?: UmbExtensionsElementInitializer<any>; | ||
| #item?: UmbCollectionItemModel; | ||
|
|
||
| @state() | ||
| private _component?: any; // TODO: Add type | ||
|
|
||
| @property({ type: Object, attribute: false }) | ||
| public set item(value: UmbCollectionItemModel | undefined) { | ||
| const oldValue = this.#item; | ||
| this.#item = value; | ||
|
|
||
| if (value === oldValue) return; | ||
| if (!value) return; | ||
|
|
||
| // If the component is already created and the entity type is the same, we can just update the item. | ||
| if (this._component && value.entityType === oldValue?.entityType) { | ||
| this._component.item = value; | ||
| return; | ||
| } | ||
|
|
||
| this.#pathAddendum.setAddendum('collection-item-card/' + value.entityType + '/' + value.unique); | ||
|
|
||
| // If the component is already created, but the entity type is different, we need to destroy the component. | ||
| this.#createController(value.entityType); | ||
| } | ||
| public get item(): UmbCollectionItemModel | undefined { | ||
| return this.#item; | ||
| } | ||
|
|
||
| #selectable = false; | ||
| @property({ type: Boolean, reflect: true }) | ||
| public get selectable() { | ||
| return this.#selectable; | ||
| } | ||
| public set selectable(value) { | ||
| this.#selectable = value; | ||
|
|
||
| if (this._component) { | ||
| this._component.selectable = this.#selectable; | ||
| } | ||
| } | ||
|
|
||
| #selectOnly = false; | ||
| @property({ type: Boolean, attribute: 'select-only', reflect: true }) | ||
| public get selectOnly() { | ||
| return this.#selectOnly; | ||
| } | ||
| public set selectOnly(value) { | ||
| this.#selectOnly = value; | ||
|
|
||
| if (this._component) { | ||
| this._component.selectOnly = this.#selectOnly; | ||
| } | ||
| } | ||
|
|
||
| #selected = false; | ||
| @property({ type: Boolean, reflect: true }) | ||
| public get selected() { | ||
| return this.#selected; | ||
| } | ||
| public set selected(value) { | ||
| this.#selected = value; | ||
|
|
||
| if (this._component) { | ||
| this._component.selected = this.#selected; | ||
| } | ||
| } | ||
|
|
||
| #disabled = false; | ||
| @property({ type: Boolean, reflect: true }) | ||
| public get disabled() { | ||
| return this.#disabled; | ||
| } | ||
| public set disabled(value) { | ||
| this.#disabled = value; | ||
|
|
||
| if (this._component) { | ||
| this._component.disabled = this.#disabled; | ||
| } | ||
| } | ||
|
|
||
| #href?: string; | ||
| @property({ type: String, reflect: true }) | ||
| public get href() { | ||
| return this.#href; | ||
| } | ||
| public set href(value) { | ||
| this.#href = value; | ||
|
|
||
| if (this._component) { | ||
| this._component.href = this.#href; | ||
| } | ||
| } | ||
|
|
||
| #detailProperties?: Array<UmbCollectionItemDetailPropertyConfig>; | ||
| @property({ type: Array, attribute: false }) | ||
| public get detailProperties() { | ||
| return this.#detailProperties; | ||
| } | ||
| public set detailProperties(value) { | ||
| this.#detailProperties = value; | ||
|
|
||
| if (this._component) { | ||
| this._component.detailProperties = this.#detailProperties; | ||
| } | ||
| } | ||
|
|
||
| #pathAddendum = new UmbRoutePathAddendumContext(this); | ||
|
|
||
| #onSelected(event: UmbSelectedEvent) { | ||
| event.stopPropagation(); | ||
| const unique = this.item?.unique; | ||
| if (!unique) throw new Error('No unique id found for item'); | ||
| this.dispatchEvent(new UmbSelectedEvent(unique)); | ||
| } | ||
|
|
||
| #onDeselected(event: UmbDeselectedEvent) { | ||
| event.stopPropagation(); | ||
| const unique = this.item?.unique; | ||
| if (!unique) throw new Error('No unique id found for item'); | ||
| this.dispatchEvent(new UmbDeselectedEvent(unique)); | ||
| } | ||
|
|
||
| protected override firstUpdated(_changedProperties: PropertyValueMap<any> | Map<PropertyKey, unknown>): void { | ||
| super.firstUpdated(_changedProperties); | ||
| this.setAttribute(UMB_MARK_ATTRIBUTE_NAME, 'entity-collection-item-card'); | ||
| } | ||
|
|
||
| #createController(entityType: string) { | ||
| if (this.#extensionsController) { | ||
| this.#extensionsController.destroy(); | ||
| } | ||
|
|
||
| this.#extensionsController = new UmbExtensionsElementInitializer( | ||
| this, | ||
| umbExtensionsRegistry, | ||
| 'entityCollectionItemCard', | ||
| (manifest: ManifestEntityCollectionItemCard) => manifest.forEntityTypes.includes(entityType), | ||
| (extensionControllers) => { | ||
| this._component?.remove(); | ||
| const component = | ||
| extensionControllers[0]?.component || document.createElement('umb-default-collection-item-card'); | ||
|
|
||
| // TODO: I would say this code can use feature of the UmbExtensionsElementInitializer, to set properties and get a fallback element. [NL] | ||
| // assign the properties to the component | ||
| component.item = this.item; | ||
| component.selectable = this.selectable; | ||
| component.selectOnly = this.selectOnly; | ||
| component.selected = this.selected; | ||
| component.disabled = this.disabled; | ||
| component.href = this.href; | ||
| component.detailProperties = this.detailProperties; | ||
|
|
||
| component.addEventListener(UmbSelectedEvent.TYPE, this.#onSelected.bind(this)); | ||
| component.addEventListener(UmbDeselectedEvent.TYPE, this.#onDeselected.bind(this)); | ||
|
|
||
| // Proxy the actions slot to the component | ||
| const slotElement = document.createElement('slot'); | ||
| slotElement.name = 'actions'; | ||
| slotElement.setAttribute('slot', 'actions'); | ||
| component.appendChild(slotElement); | ||
|
|
||
| this._component = component; | ||
| }, | ||
| undefined, // We can leave the alias to undefined, as we destroy this our selfs. | ||
madsrasmussen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| undefined, | ||
| { single: true }, | ||
| ); | ||
| } | ||
|
|
||
| override render() { | ||
| return html`${this._component}`; | ||
| } | ||
|
|
||
| override destroy(): void { | ||
| this._component?.removeEventListener(UmbSelectedEvent.TYPE, this.#onSelected.bind(this)); | ||
| this._component?.removeEventListener(UmbDeselectedEvent.TYPE, this.#onDeselected.bind(this)); | ||
madsrasmussen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| super.destroy(); | ||
| } | ||
|
|
||
| static override styles = [ | ||
| css` | ||
| :host { | ||
| display: block; | ||
| position: relative; | ||
| } | ||
| `, | ||
| ]; | ||
| } | ||
|
|
||
| declare global { | ||
| interface HTMLElementTagNameMap { | ||
| 'umb-entity-collection-item-card': UmbEntityCollectionItemCardElement; | ||
| } | ||
| } | ||
19 changes: 19 additions & 0 deletions
19
...core/collection/item/entity-collection-item-card/entity-collection-item-card.extension.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import type { ManifestElement, ManifestWithDynamicConditions } from '@umbraco-cms/backoffice/extension-api'; | ||
|
|
||
| export interface ManifestEntityCollectionItemCard< | ||
| MetaType extends MetaEntityCollectionItemCard = MetaEntityCollectionItemCard, | ||
| > extends ManifestElement<any>, | ||
| ManifestWithDynamicConditions<UmbExtensionConditionConfig> { | ||
| type: 'entityCollectionItemCard'; | ||
| meta: MetaType; | ||
| forEntityTypes: Array<string>; | ||
| } | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/no-empty-object-type | ||
| export interface MetaEntityCollectionItemCard {} | ||
|
|
||
| declare global { | ||
| interface UmbExtensionManifestMap { | ||
| umbManifestEntityCollectionItemCard: ManifestEntityCollectionItemCard; | ||
| } | ||
| } |
1 change: 1 addition & 0 deletions
1
...Client/src/packages/core/collection/item/entity-collection-item-card/global-components.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| import './entity-collection-item-card.element.js'; |
1 change: 1 addition & 0 deletions
1
...raco.Web.UI.Client/src/packages/core/collection/item/entity-collection-item-card/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export * from './entity-collection-item-card.element.js'; |
1 change: 1 addition & 0 deletions
1
...raco.Web.UI.Client/src/packages/core/collection/item/entity-collection-item-card/types.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export type * from './entity-collection-item-card.extension.js'; |
1 change: 1 addition & 0 deletions
1
src/Umbraco.Web.UI.Client/src/packages/core/collection/item/global-components.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| import './entity-collection-item-card/global-components.js'; |
7 changes: 7 additions & 0 deletions
7
src/Umbraco.Web.UI.Client/src/packages/core/collection/item/types.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,14 @@ | ||
| import type { UmbEntityModel } from '@umbraco-cms/backoffice/entity'; | ||
| export type * from './entity-collection-item-card/types.js'; | ||
|
|
||
| export interface UmbCollectionItemModel extends UmbEntityModel { | ||
| unique: string; | ||
| name?: string; | ||
| icon?: string; | ||
| } | ||
|
|
||
| export interface UmbCollectionItemDetailPropertyConfig { | ||
| alias: string; | ||
| name: string; | ||
| isSystem: boolean; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.