Skip to content

Commit 49c4a60

Browse files
committed
block-type element type not found
1 parent 9c5768e commit 49c4a60

File tree

4 files changed

+58
-7
lines changed

4 files changed

+58
-7
lines changed

src/Umbraco.Web.UI.Client/src/assets/lang/en-us.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,7 @@ export default {
866866
next: 'Next',
867867
no: 'No',
868868
nodeName: 'Node Name',
869+
notFound: 'Not found',
869870
of: 'of',
870871
off: 'Off',
871872
ok: 'OK',

src/Umbraco.Web.UI.Client/src/assets/lang/en.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,7 @@ export default {
862862
next: 'Next',
863863
no: 'No',
864864
nodeName: 'Node Name',
865+
notFound: 'Not found',
865866
of: 'of',
866867
off: 'Off',
867868
ok: 'OK',

src/Umbraco.Web.UI.Client/src/packages/block/block-type/components/block-type-card/block-type-card.element.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,17 @@ export class UmbBlockTypeCardElement extends UmbLitElement {
8080
this.#serverUrl = appContext.getServerUrl();
8181
});
8282

83-
this.observe(this.#itemManager.items, (items) => {
84-
const item = items[0];
85-
if (item) {
83+
this.observe(this.#itemManager.statuses, async (items) => {
84+
const status = items[0];
85+
if (status.state.type === 'success') {
86+
const item = await this.#itemManager.getItemByUnique(status.unique);
8687
this._fallbackIcon = item.icon;
8788
this._name = item.name ? this.localize.string(item.name) : this.localize.term('general_unknown');
8889
this._description = this.localize.string(item.description);
90+
} else if (status.state.type === 'error') {
91+
this._fallbackIcon = 'icon-alert';
92+
this._name = this.localize.string('general_error');
93+
this._description = this.localize.string(status.state.error);
8994
}
9095
});
9196
}

src/Umbraco.Web.UI.Client/src/packages/core/repository/repository-items.manager.ts

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,14 @@ import { UmbEntityUpdatedEvent } from '@umbraco-cms/backoffice/entity-action';
1010

1111
const ObserveRepositoryAlias = Symbol();
1212

13-
// TODO: v16 - add entityType to the type
13+
interface UmbRepositoryItemsStatus {
14+
state: {
15+
type: 'success' | 'error' | 'loading';
16+
error?: string;
17+
};
18+
unique: string;
19+
}
20+
1421
export class UmbRepositoryItemsManager<ItemType extends { unique: string }> extends UmbControllerBase {
1522
//
1623
repository?: UmbItemRepository<ItemType>;
@@ -31,6 +38,9 @@ export class UmbRepositoryItemsManager<ItemType extends { unique: string }> exte
3138
#items = new UmbArrayState<ItemType>([], (x) => this.#getUnique(x));
3239
items = this.#items.asObservable();
3340

41+
#statuses = new UmbArrayState<UmbRepositoryItemsStatus>([], (x) => x);
42+
statuses = this.#statuses.asObservable();
43+
3444
/**
3545
* Creates an instance of UmbRepositoryItemsManager.
3646
* @param {UmbControllerHost} host - The host for the controller.
@@ -133,22 +143,56 @@ export class UmbRepositoryItemsManager<ItemType extends { unique: string }> exte
133143
await this.#init;
134144
if (!this.repository) throw new Error('Repository is not initialized');
135145

146+
const requestedUniques = this.getUniques();
147+
136148
// TODO: Test if its just some items that is gone now, if so then just filter them out. (maybe use code from #removeItem)
137149
// This is where this.#getUnique comes in play. Unless that can come from the repository, but that collides with the idea of having a multi-type repository. If that happens.
138-
const request = this.repository.requestItems(this.getUniques());
150+
const request = this.repository.requestItems(requestedUniques);
139151
this.#currentRequest = request;
140-
const { asObservable } = await request;
152+
const { asObservable, data, error } = await request;
141153

142154
if (this.#currentRequest !== request) {
143155
// You are not the newest request, so please back out.
144156
return;
145157
}
146158

159+
if (error) {
160+
this.#statuses.append(
161+
requestedUniques.map((unique) => ({
162+
state: {
163+
type: 'error',
164+
error: '#general_error',
165+
},
166+
unique,
167+
})),
168+
);
169+
return;
170+
}
171+
172+
// find uniques not resolved:
173+
if (data) {
174+
// find rejected uniques:
175+
const rejectedUniques = requestedUniques.filter(
176+
(unique) => !data.find((item) => this.#getUnique(item) === unique),
177+
);
178+
this.#items.remove(rejectedUniques);
179+
180+
this.#statuses.append(
181+
rejectedUniques.map((unique) => ({
182+
state: {
183+
type: 'error',
184+
error: '#general_notFound',
185+
},
186+
unique,
187+
})),
188+
);
189+
}
190+
147191
if (asObservable) {
148192
this.observe(
149193
asObservable(),
150194
(data) => {
151-
this.#items.setValue(this.#sortByUniques(data));
195+
this.#items.append(this.#sortByUniques(data));
152196
},
153197
ObserveRepositoryAlias,
154198
);

0 commit comments

Comments
 (0)