-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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: Delete/Trash referenced by #18351
Changes from all commits
01516bb
9ccb58a
f99562a
e7348f5
edb6a7c
62f1bd7
fd06887
977b047
0731f66
5901d4a
5b0444f
d073ab5
964e86c
e1cbf73
b986ebd
a98e3db
3aba568
f4547b5
1adf436
db9b9d3
1088b04
d70fb95
914953b
726d07d
efe75be
33f3759
95c12ec
dea4393
c1276e4
93aa0ea
dbd27cc
e940f6e
0afe46c
e446c42
4394db3
4ffa3d6
fa49110
a76b30a
ed0deb6
0f72728
13d5fea
494fcbe
3c67f00
b521750
4988c80
80b144e
08d3add
2cb20c8
0c15b41
7fe30d7
e8ad351
cb4df75
212ae20
9be6d81
e47217e
f45ae29
2b0ae99
0ae2420
6f7cc8e
ef1638b
029cc3c
cdcbf31
f6ac0e4
ff164c7
fe1fbea
9b47824
d43c6cb
dbb744d
f218486
dc1b5ce
a1444b5
41a0c11
9b3f45d
c075deb
cf34d19
1b04ec7
6dea5f0
f1dc763
1c8432a
bafd96b
ec95d71
9f62268
870cd86
f43e32e
bb03968
fbf9f2f
75face7
63e03ac
575f3b2
81a0805
934e03b
54814c1
bbc5fee
193d93a
57b1145
5f9d9d4
a731160
ddbec2a
c401187
83cf3c2
23fd63d
6b1891e
b518e78
161c9d5
a8324b6
541753c
dcc9b3d
d3e2db5
e311867
1e084b4
9e273f9
c18e8e7
ece64d9
46b050a
11b3e04
2d3ca29
1c5aedf
edefa42
ac8955e
2cbe1ef
0a62426
8dd474d
5a38296
f83ee80
1443b9c
6815160
0e206b6
2823164
e0eca32
1f264f6
c37302e
cbd7ea4
7655089
a178424
aafc107
a63bdcd
3d6be7a
7559785
c17d198
6dcc897
8dd8293
608b103
3e06749
a92ea32
9b1534f
9b070c0
32c3d17
cc94607
2b0ceab
aa8bbea
6463334
d7410a0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './create/constants.js'; | ||
export * from './delete/constants.js'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { UMB_ENTITY_ACTION_DELETE_KIND_MANIFEST } from './delete.action.kind.js'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export type * from './delete/types.js'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './restore-from-recycle-bin/constants.js'; | ||
export * from './trash/constants.js'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { UMB_ENTITY_ACTION_TRASH_KIND_MANIFEST } from './trash.action.kind.js'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
export * from './collection/constants.js'; | ||
export { UMB_RELATION_ENTITY_TYPE } from './entity.js'; | ||
export * from './collection/constants.js'; | ||
export * from './entity-actions/delete/constants.js'; | ||
export * from './entity-actions/trash/constants.js'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './modal/constants.js'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import type { UmbExtensionManifestKind } from '@umbraco-cms/backoffice/extension-registry'; | ||
import { UMB_ENTITY_ACTION_DELETE_KIND_MANIFEST } from '@umbraco-cms/backoffice/entity-action'; | ||
|
||
export const manifest: UmbExtensionManifestKind = { | ||
type: 'kind', | ||
alias: 'Umb.Kind.EntityAction.DeleteWithRelation', | ||
matchKind: 'deleteWithRelation', | ||
matchType: 'entityAction', | ||
manifest: { | ||
...UMB_ENTITY_ACTION_DELETE_KIND_MANIFEST.manifest, | ||
type: 'entityAction', | ||
kind: 'deleteWithRelation', | ||
api: () => import('./delete-with-relation.action.js'), | ||
}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import type { MetaEntityActionDeleteWithRelationKind } from './types.js'; | ||
import { UMB_DELETE_WITH_RELATION_CONFIRM_MODAL } from './modal/constants.js'; | ||
import { UMB_MODAL_MANAGER_CONTEXT } from '@umbraco-cms/backoffice/modal'; | ||
import { UmbDeleteEntityAction } from '@umbraco-cms/backoffice/entity-action'; | ||
|
||
/** | ||
* Entity action for deleting an item with relations. | ||
* @class UmbDeleteWithRelationEntityAction | ||
* @augments {UmbEntityActionBase<MetaEntityActionDeleteWithRelationKind>} | ||
*/ | ||
export class UmbDeleteWithRelationEntityAction extends UmbDeleteEntityAction<MetaEntityActionDeleteWithRelationKind> { | ||
override async _confirmDelete() { | ||
if (!this.args.unique) throw new Error('Cannot delete an item without a unique identifier.'); | ||
|
||
const modalManager = await this.getContext(UMB_MODAL_MANAGER_CONTEXT); | ||
|
||
const modal = modalManager.open(this, UMB_DELETE_WITH_RELATION_CONFIRM_MODAL, { | ||
data: { | ||
unique: this.args.unique, | ||
entityType: this.args.entityType, | ||
itemRepositoryAlias: this.args.meta.itemRepositoryAlias, | ||
referenceRepositoryAlias: this.args.meta.referenceRepositoryAlias, | ||
}, | ||
}); | ||
|
||
await modal.onSubmit(); | ||
} | ||
} | ||
|
||
export { UmbDeleteWithRelationEntityAction as api }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './delete-with-relation.action.js'; | ||
export type * from './types.js'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { manifest as deleteKindManifest } from './delete-with-relation.action.kind.js'; | ||
import { manifests as modalManifests } from './modal/manifests.js'; | ||
|
||
import type { UmbExtensionManifestKind } from '@umbraco-cms/backoffice/extension-registry'; | ||
|
||
export const manifests: Array<UmbExtensionManifest | UmbExtensionManifestKind> = [ | ||
deleteKindManifest, | ||
...modalManifests, | ||
]; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './delete-with-relation-modal.token.js'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import type { | ||
UmbDeleteWithRelationConfirmModalData, | ||
UmbDeleteWithRelationConfirmModalValue, | ||
} from './delete-with-relation-modal.token.js'; | ||
import { | ||
html, | ||
customElement, | ||
css, | ||
state, | ||
type PropertyValues, | ||
nothing, | ||
unsafeHTML, | ||
} from '@umbraco-cms/backoffice/external/lit'; | ||
import { UmbTextStyles } from '@umbraco-cms/backoffice/style'; | ||
import { UmbModalBaseElement } from '@umbraco-cms/backoffice/modal'; | ||
import { umbFocus } from '@umbraco-cms/backoffice/lit-element'; | ||
import type { UmbItemRepository } from '@umbraco-cms/backoffice/repository'; | ||
import { createExtensionApiByAlias } from '@umbraco-cms/backoffice/extension-registry'; | ||
|
||
import '../../local-components/confirm-action-entity-references.element.js'; | ||
|
||
@customElement('umb-delete-with-relation-confirm-modal') | ||
export class UmbDeleteWithRelationConfirmModalElement extends UmbModalBaseElement< | ||
UmbDeleteWithRelationConfirmModalData, | ||
UmbDeleteWithRelationConfirmModalValue | ||
> { | ||
@state() | ||
_name?: string; | ||
|
||
@state() | ||
_referencesConfig?: any; | ||
|
||
#itemRepository?: UmbItemRepository<any>; | ||
|
||
protected override firstUpdated(_changedProperties: PropertyValues): void { | ||
super.firstUpdated(_changedProperties); | ||
this.#initData(); | ||
} | ||
|
||
async #initData() { | ||
if (!this.data) { | ||
this.#itemRepository?.destroy(); | ||
return; | ||
} | ||
|
||
this.#itemRepository = await createExtensionApiByAlias<UmbItemRepository<any>>(this, this.data.itemRepositoryAlias); | ||
|
||
const { data } = await this.#itemRepository.requestItems([this.data.unique]); | ||
const item = data?.[0]; | ||
if (!item) throw new Error('Item not found.'); | ||
|
||
this._name = item.name; | ||
|
||
this._referencesConfig = { | ||
unique: this.data.unique, | ||
itemRepositoryAlias: this.data.itemRepositoryAlias, | ||
referenceRepositoryAlias: this.data.referenceRepositoryAlias, | ||
}; | ||
} | ||
|
||
override render() { | ||
const headline = this.localize.string('#actions_delete'); | ||
const content = this.localize.string('#defaultdialogs_confirmdelete', this._name); | ||
|
||
return html` | ||
<uui-dialog-layout class="uui-text" headline=${headline}> | ||
<p>${unsafeHTML(content)}</p> | ||
${this._referencesConfig | ||
? html`<umb-confirm-action-modal-entity-references | ||
.config=${this._referencesConfig}></umb-confirm-action-modal-entity-references>` | ||
: nothing} | ||
<uui-button | ||
slot="actions" | ||
id="cancel" | ||
label=${this.localize.term('general_cancel')} | ||
@click=${this._rejectModal}></uui-button> | ||
<uui-button | ||
slot="actions" | ||
id="confirm" | ||
color="danger" | ||
look="primary" | ||
label=${this.localize.term('general_delete')} | ||
@click=${this._submitModal} | ||
${umbFocus()}></uui-button> | ||
</uui-dialog-layout> | ||
`; | ||
} | ||
|
||
static override styles = [ | ||
UmbTextStyles, | ||
css` | ||
uui-dialog-layout { | ||
max-inline-size: 60ch; | ||
} | ||
`, | ||
]; | ||
} | ||
|
||
export { UmbDeleteWithRelationConfirmModalElement as element }; | ||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
'umb-delete-with-relation-confirm-modal': UmbDeleteWithRelationConfirmModalElement; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { UmbModalToken } from '@umbraco-cms/backoffice/modal'; | ||
|
||
export interface UmbDeleteWithRelationConfirmModalData { | ||
unique: string; | ||
entityType: string; | ||
itemRepositoryAlias: string; | ||
referenceRepositoryAlias: string; | ||
} | ||
|
||
export type UmbDeleteWithRelationConfirmModalValue = undefined; | ||
|
||
export const UMB_DELETE_WITH_RELATION_CONFIRM_MODAL = new UmbModalToken< | ||
UmbDeleteWithRelationConfirmModalData, | ||
UmbDeleteWithRelationConfirmModalValue | ||
>('Umb.Modal.DeleteWithRelation', { | ||
modal: { | ||
type: 'dialog', | ||
}, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export const manifests: Array<UmbExtensionManifest> = [ | ||
{ | ||
type: 'modal', | ||
alias: 'Umb.Modal.DeleteWithRelation', | ||
name: 'Delete With Relation Modal', | ||
element: () => import('./delete-with-relation-modal.element.js'), | ||
}, | ||
]; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import type { ManifestEntityAction, MetaEntityActionDeleteKind } from '@umbraco-cms/backoffice/entity-action'; | ||
|
||
export interface ManifestEntityActionDeleteWithRelationKind | ||
extends ManifestEntityAction<MetaEntityActionDeleteWithRelationKind> { | ||
type: 'entityAction'; | ||
kind: 'deleteWithRelation'; | ||
} | ||
|
||
export interface MetaEntityActionDeleteWithRelationKind extends MetaEntityActionDeleteKind { | ||
referenceRepositoryAlias: string; | ||
} | ||
|
||
declare global { | ||
interface UmbExtensionManifestMap { | ||
umbManifestEntityActionDeleteWithRelationKind: ManifestEntityActionDeleteWithRelationKind; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
import type { UmbEntityReferenceRepository, UmbReferenceItemModel } from '../../reference/types.js'; | ||
import { | ||
html, | ||
customElement, | ||
css, | ||
state, | ||
nothing, | ||
type PropertyValues, | ||
property, | ||
} from '@umbraco-cms/backoffice/external/lit'; | ||
import { UmbTextStyles } from '@umbraco-cms/backoffice/style'; | ||
import type { UmbItemRepository } from '@umbraco-cms/backoffice/repository'; | ||
import { createExtensionApiByAlias } from '@umbraco-cms/backoffice/extension-registry'; | ||
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element'; | ||
|
||
@customElement('umb-confirm-action-modal-entity-references') | ||
export class UmbConfirmActionModalEntityReferencesElement extends UmbLitElement { | ||
@property({ type: Object, attribute: false }) | ||
config?: { | ||
itemRepositoryAlias: string; | ||
referenceRepositoryAlias: string; | ||
entityType: string; | ||
unique: string; | ||
}; | ||
|
||
@state() | ||
_referencedByItems: Array<UmbReferenceItemModel> = []; | ||
|
||
@state() | ||
_totalReferencedByItems: number = 0; | ||
|
||
@state() | ||
_totalDescendantsWithReferences: number = 0; | ||
|
||
@state() | ||
_descendantsWithReferences: Array<any> = []; | ||
|
||
#itemRepository?: UmbItemRepository<any>; | ||
#referenceRepository?: UmbEntityReferenceRepository; | ||
|
||
#limitItems = 3; | ||
|
||
protected override firstUpdated(_changedProperties: PropertyValues): void { | ||
super.firstUpdated(_changedProperties); | ||
this.#initData(); | ||
} | ||
|
||
async #initData() { | ||
if (!this.config) { | ||
this.#itemRepository?.destroy(); | ||
this.#referenceRepository?.destroy(); | ||
return; | ||
} | ||
|
||
if (!this.config?.referenceRepositoryAlias) { | ||
throw new Error('Missing referenceRepositoryAlias in config.'); | ||
} | ||
|
||
this.#referenceRepository = await createExtensionApiByAlias<UmbEntityReferenceRepository>( | ||
this, | ||
this.config?.referenceRepositoryAlias, | ||
); | ||
|
||
if (!this.config?.itemRepositoryAlias) { | ||
throw new Error('Missing itemRepositoryAlias in config.'); | ||
} | ||
|
||
this.#itemRepository = await createExtensionApiByAlias<UmbItemRepository<any>>( | ||
this, | ||
this.config.itemRepositoryAlias, | ||
); | ||
|
||
this.#loadReferencedBy(); | ||
this.#loadDescendantsWithReferences(); | ||
} | ||
Check warning on line 75 in src/Umbraco.Web.UI.Client/src/packages/relations/relations/entity-actions/local-components/confirm-action-entity-references.element.ts
|
||
|
||
async #loadReferencedBy() { | ||
if (!this.#referenceRepository) { | ||
throw new Error('Failed to create reference repository.'); | ||
} | ||
|
||
if (!this.config?.unique) { | ||
throw new Error('Missing unique in data.'); | ||
} | ||
|
||
const { data } = await this.#referenceRepository.requestReferencedBy(this.config.unique, 0, this.#limitItems); | ||
|
||
if (data) { | ||
this._referencedByItems = [...data.items]; | ||
this._totalReferencedByItems = data.total; | ||
} | ||
} | ||
|
||
async #loadDescendantsWithReferences() { | ||
if (!this.#referenceRepository) { | ||
throw new Error('Failed to create reference repository.'); | ||
} | ||
|
||
if (!this.#itemRepository) { | ||
throw new Error('Failed to create item repository.'); | ||
} | ||
|
||
// If the repository does not have the method, we don't need to load the referenced descendants. | ||
if (!this.#referenceRepository.requestDescendantsWithReferences) return; | ||
|
||
if (!this.config?.unique) { | ||
throw new Error('Missing unique in data.'); | ||
} | ||
|
||
const { data } = await this.#referenceRepository.requestDescendantsWithReferences( | ||
this.config.unique, | ||
0, | ||
this.#limitItems, | ||
); | ||
|
||
if (data) { | ||
this._totalDescendantsWithReferences = data.total; | ||
const uniques = data.items.map((item) => item.unique).filter((unique) => unique) as Array<string>; | ||
const { data: items } = await this.#itemRepository.requestItems(uniques); | ||
this._descendantsWithReferences = items ?? []; | ||
} | ||
} | ||
Check warning on line 122 in src/Umbraco.Web.UI.Client/src/packages/relations/relations/entity-actions/local-components/confirm-action-entity-references.element.ts
|
||
|
||
override render() { | ||
return html` | ||
${this.#renderItems('references_labelDependsOnThis', this._referencedByItems, this._totalReferencedByItems)} | ||
${this.#renderItems( | ||
'references_labelDependentDescendants', | ||
this._descendantsWithReferences, | ||
this._totalDescendantsWithReferences, | ||
)} | ||
`; | ||
} | ||
|
||
#renderItems(headline: string, items: Array<UmbReferenceItemModel>, total: number) { | ||
if (total === 0) return nothing; | ||
|
||
return html` | ||
<h5 id="reference-headline">${this.localize.term(headline)}</h5> | ||
<uui-ref-list> | ||
${items.map( | ||
(item) => | ||
html`<umb-entity-item-ref .item=${item} readonly ?standalone=${total === 1}></umb-entity-item-ref> `, | ||
)} | ||
</uui-ref-list> | ||
${total > this.#limitItems | ||
? html`<span>${this.localize.term('references_labelMoreReferences', total - this.#limitItems)}</span>` | ||
: nothing} | ||
`; | ||
} | ||
|
||
static override styles = [ | ||
UmbTextStyles, | ||
css` | ||
#reference-headline { | ||
margin-bottom: var(--uui-size-3); | ||
} | ||
uui-ref-list { | ||
margin-bottom: var(--uui-size-2); | ||
} | ||
`, | ||
]; | ||
} | ||
|
||
export { UmbConfirmActionModalEntityReferencesElement as element }; | ||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
'umb-confirm-action-modal-entity-references': UmbConfirmActionModalEntityReferencesElement; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './modal/constants.js'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './trash-with-relation.action.js'; | ||
export type * from './types.js'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { manifest as trashKindManifest } from './trash-with-relation.action.kind.js'; | ||
import { manifests as modalManifests } from './modal/manifests.js'; | ||
|
||
import type { UmbExtensionManifestKind } from '@umbraco-cms/backoffice/extension-registry'; | ||
|
||
export const manifests: Array<UmbExtensionManifest | UmbExtensionManifestKind> = [trashKindManifest, ...modalManifests]; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './trash-with-relation-modal.token.js'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export const manifests: Array<UmbExtensionManifest> = [ | ||
{ | ||
type: 'modal', | ||
alias: 'Umb.Modal.TrashWithRelation', | ||
name: 'Trash With Relation Modal', | ||
element: () => import('./trash-with-relation-modal.element.js'), | ||
}, | ||
]; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import type { | ||
UmbTrashWithRelationConfirmModalData, | ||
UmbTrashWithRelationConfirmModalValue, | ||
} from './trash-with-relation-modal.token.js'; | ||
import { | ||
html, | ||
customElement, | ||
css, | ||
state, | ||
type PropertyValues, | ||
nothing, | ||
unsafeHTML, | ||
} from '@umbraco-cms/backoffice/external/lit'; | ||
import { UmbTextStyles } from '@umbraco-cms/backoffice/style'; | ||
import { UmbModalBaseElement } from '@umbraco-cms/backoffice/modal'; | ||
import { umbFocus } from '@umbraco-cms/backoffice/lit-element'; | ||
import type { UmbItemRepository } from '@umbraco-cms/backoffice/repository'; | ||
import { createExtensionApiByAlias } from '@umbraco-cms/backoffice/extension-registry'; | ||
|
||
// import of local component | ||
import '../../local-components/confirm-action-entity-references.element.js'; | ||
|
||
@customElement('umb-trash-with-relation-confirm-modal') | ||
export class UmbTrashWithRelationConfirmModalElement extends UmbModalBaseElement< | ||
UmbTrashWithRelationConfirmModalData, | ||
UmbTrashWithRelationConfirmModalValue | ||
> { | ||
@state() | ||
_name?: string; | ||
|
||
@state() | ||
_referencesConfig?: any; | ||
|
||
#itemRepository?: UmbItemRepository<any>; | ||
|
||
protected override firstUpdated(_changedProperties: PropertyValues): void { | ||
super.firstUpdated(_changedProperties); | ||
this.#initData(); | ||
} | ||
|
||
async #initData() { | ||
if (!this.data) { | ||
this.#itemRepository?.destroy(); | ||
return; | ||
} | ||
|
||
this.#itemRepository = await createExtensionApiByAlias<UmbItemRepository<any>>(this, this.data.itemRepositoryAlias); | ||
|
||
const { data } = await this.#itemRepository.requestItems([this.data.unique]); | ||
const item = data?.[0]; | ||
if (!item) throw new Error('Item not found.'); | ||
|
||
this._name = item.name; | ||
|
||
this._referencesConfig = { | ||
unique: this.data.unique, | ||
itemRepositoryAlias: this.data.itemRepositoryAlias, | ||
referenceRepositoryAlias: this.data.referenceRepositoryAlias, | ||
}; | ||
} | ||
|
||
override render() { | ||
const headline = this.localize.string('#actions_trash'); | ||
const content = this.localize.string('#defaultdialogs_confirmTrash', this._name); | ||
|
||
return html` | ||
<uui-dialog-layout class="uui-text" headline=${headline}> | ||
<p>${unsafeHTML(content)}</p> | ||
${this._referencesConfig | ||
? html`<umb-confirm-action-modal-entity-references | ||
.config=${this._referencesConfig}></umb-confirm-action-modal-entity-references>` | ||
: nothing} | ||
<uui-button slot="actions" id="cancel" label="Cancel" @click=${this._rejectModal}></uui-button> | ||
<uui-button | ||
slot="actions" | ||
id="confirm" | ||
color="danger" | ||
look="primary" | ||
label=${this.localize.term('actions_trash')} | ||
@click=${this._submitModal} | ||
${umbFocus()}></uui-button> | ||
</uui-dialog-layout> | ||
`; | ||
} | ||
|
||
static override styles = [ | ||
UmbTextStyles, | ||
css` | ||
uui-dialog-layout { | ||
max-inline-size: 60ch; | ||
} | ||
`, | ||
]; | ||
} | ||
|
||
export { UmbTrashWithRelationConfirmModalElement as element }; | ||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
'umb-trash-with-relation-confirm-modal': UmbTrashWithRelationConfirmModalElement; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { UmbModalToken } from '@umbraco-cms/backoffice/modal'; | ||
|
||
export interface UmbTrashWithRelationConfirmModalData { | ||
unique: string; | ||
entityType: string; | ||
itemRepositoryAlias: string; | ||
referenceRepositoryAlias: string; | ||
} | ||
|
||
export type UmbTrashWithRelationConfirmModalValue = undefined; | ||
|
||
export const UMB_TRASH_WITH_RELATION_CONFIRM_MODAL = new UmbModalToken< | ||
UmbTrashWithRelationConfirmModalData, | ||
UmbTrashWithRelationConfirmModalValue | ||
>('Umb.Modal.TrashWithRelation', { | ||
modal: { | ||
type: 'dialog', | ||
}, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import type { UmbExtensionManifestKind } from '@umbraco-cms/backoffice/extension-registry'; | ||
import { UMB_ENTITY_ACTION_TRASH_KIND_MANIFEST } from '@umbraco-cms/backoffice/recycle-bin'; | ||
|
||
export const manifest: UmbExtensionManifestKind = { | ||
type: 'kind', | ||
alias: 'Umb.Kind.EntityAction.TrashWithRelation', | ||
matchKind: 'trashWithRelation', | ||
matchType: 'entityAction', | ||
manifest: { | ||
...UMB_ENTITY_ACTION_TRASH_KIND_MANIFEST.manifest, | ||
type: 'entityAction', | ||
kind: 'trashWithRelation', | ||
api: () => import('./trash-with-relation.action.js'), | ||
}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import type { MetaEntityActionTrashWithRelationKind } from './types.js'; | ||
import { UMB_TRASH_WITH_RELATION_CONFIRM_MODAL } from './modal/constants.js'; | ||
import { UMB_MODAL_MANAGER_CONTEXT } from '@umbraco-cms/backoffice/modal'; | ||
import { UmbTrashEntityAction } from '@umbraco-cms/backoffice/recycle-bin'; | ||
|
||
/** | ||
* Entity action for trashing an item with relations. | ||
* @class UmbTrashWithRelationEntityAction | ||
* @augments {UmbEntityActionBase<MetaEntityActionTrashWithRelationKind>} | ||
*/ | ||
export class UmbTrashWithRelationEntityAction extends UmbTrashEntityAction<MetaEntityActionTrashWithRelationKind> { | ||
override async _confirmTrash(item: any) { | ||
const modalManager = await this.getContext(UMB_MODAL_MANAGER_CONTEXT); | ||
|
||
const modal = modalManager.open(this, UMB_TRASH_WITH_RELATION_CONFIRM_MODAL, { | ||
data: { | ||
unique: item.unique, | ||
entityType: item.entityType, | ||
itemRepositoryAlias: this.args.meta.itemRepositoryAlias, | ||
referenceRepositoryAlias: this.args.meta.referenceRepositoryAlias, | ||
}, | ||
}); | ||
|
||
await modal.onSubmit(); | ||
} | ||
} | ||
|
||
export { UmbTrashWithRelationEntityAction as api }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import type { ManifestEntityAction } from '@umbraco-cms/backoffice/entity-action'; | ||
import type { MetaEntityActionTrashKind } from '@umbraco-cms/backoffice/recycle-bin'; | ||
|
||
export interface ManifestEntityActionTrashWithRelationKind | ||
extends ManifestEntityAction<MetaEntityActionTrashWithRelationKind> { | ||
type: 'entityAction'; | ||
kind: 'trashWithRelation'; | ||
} | ||
|
||
export interface MetaEntityActionTrashWithRelationKind extends MetaEntityActionTrashKind { | ||
referenceRepositoryAlias: string; | ||
} | ||
|
||
declare global { | ||
interface UmbExtensionManifestMap { | ||
umbManifestEntityActionTrashWithRelationKind: ManifestEntityActionTrashWithRelationKind; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,10 @@ | ||
import { manifests as collectionManifests } from './collection/manifests.js'; | ||
import { manifests as deleteManifests } from './entity-actions/delete/manifests.js'; | ||
import { manifests as trashManifests } from './entity-actions/trash/manifests.js'; | ||
import type { UmbExtensionManifestKind } from '@umbraco-cms/backoffice/extension-registry'; | ||
|
||
export const manifests: Array<UmbExtensionManifest> = [...collectionManifests]; | ||
export const manifests: Array<UmbExtensionManifest | UmbExtensionManifestKind> = [ | ||
...collectionManifests, | ||
...deleteManifests, | ||
...trashManifests, | ||
]; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import type { UmbEntityModel } from '@umbraco-cms/backoffice/entity'; | ||
import type { UmbApi } from '@umbraco-cms/backoffice/extension-api'; | ||
import type { | ||
DefaultReferenceResponseModel, | ||
DocumentReferenceResponseModel, | ||
MediaReferenceResponseModel, | ||
} from '@umbraco-cms/backoffice/external/backend-api'; | ||
import type { UmbDataSourceResponse, UmbPagedModel, UmbRepositoryResponse } from '@umbraco-cms/backoffice/repository'; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-empty-object-type | ||
export interface UmbReferenceItemModel extends UmbEntityModel {} | ||
|
||
export type UmbReferenceModel = | ||
| DefaultReferenceResponseModel | ||
| DocumentReferenceResponseModel | ||
| MediaReferenceResponseModel; | ||
|
||
export interface UmbEntityReferenceRepository extends UmbApi { | ||
requestReferencedBy( | ||
unique: string, | ||
skip?: number, | ||
take?: number, | ||
): Promise<UmbRepositoryResponse<UmbPagedModel<UmbReferenceItemModel>>>; | ||
requestDescendantsWithReferences?( | ||
unique: string, | ||
skip?: number, | ||
take?: number, | ||
): Promise<UmbRepositoryResponse<UmbPagedModel<UmbEntityModel>>>; | ||
} | ||
|
||
export interface UmbEntityReferenceDataSource { | ||
getReferencedBy( | ||
unique: string, | ||
skip?: number, | ||
take?: number, | ||
): Promise<UmbDataSourceResponse<UmbPagedModel<UmbReferenceItemModel>>>; | ||
getReferencedDescendants?( | ||
unique: string, | ||
skip?: number, | ||
take?: number, | ||
): Promise<UmbDataSourceResponse<UmbPagedModel<UmbEntityModel>>>; | ||
} |
Unchanged files with check annotations Beta
export class UmbDataMappingResolver extends UmbControllerBase { | ||
#apiCache = new Map<string, UmbDataMapping>(); | ||
async resolve(forDataSource: string, forDataModel: string): Promise<UmbDataMapping | undefined> { | ||
if (!forDataSource) { | ||
throw new Error('data source identifier is required'); | ||
} | ||
if (!forDataModel) { | ||
throw new Error('data identifier is required'); | ||
} | ||
const manifest = this.#getManifestWithBestFit(forDataSource, forDataModel); | ||
if (!manifest) { | ||
return undefined; | ||
} | ||
// Check the cache before creating a new instance | ||
if (this.#apiCache.has(manifest.alias)) { | ||
return this.#apiCache.get(manifest.alias)!; | ||
} | ||
const dataMapping = await createExtensionApi<UmbDataMapping>(this, manifest); | ||
if (!dataMapping) { | ||
return undefined; | ||
} | ||
if (!dataMapping.map) { | ||
throw new Error('Data Mapping does not have a map method.'); | ||
} | ||
// Cache the api instance for future use | ||
this.#apiCache.set(manifest.alias, dataMapping); | ||
return dataMapping; | ||
} | ||
Check warning on line 43 in src/Umbraco.Web.UI.Client/src/packages/core/repository/data-mapper/mapping/data-mapping-resolver.ts
|
||
#getManifestWithBestFit(forDataSource: string, forDataModel: string) { | ||
const supportedManifests = this.#getSupportedManifests(forDataSource, forDataModel); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we just already destroy the itemRepository if it exists at this point.
Aka. removing the condition around it. :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah well, I mean move it above the condition