Skip to content

Commit ce2f50c

Browse files
committed
update status logic
1 parent 49c4a60 commit ce2f50c

File tree

2 files changed

+38
-16
lines changed

2 files changed

+38
-16
lines changed

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

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

83-
this.observe(this.#itemManager.statuses, async (items) => {
84-
const status = items[0];
85-
if (status.state.type === 'success') {
83+
this.observe(this.#itemManager.statuses, async (statuses) => {
84+
const status = statuses[0];
85+
if (status?.state.type === 'success') {
8686
const item = await this.#itemManager.getItemByUnique(status.unique);
8787
this._fallbackIcon = item.icon;
8888
this._name = item.name ? this.localize.string(item.name) : this.localize.term('general_unknown');
8989
this._description = this.localize.string(item.description);
90-
} else if (status.state.type === 'error') {
90+
} else if (status?.state.type === 'error') {
9191
this._fallbackIcon = 'icon-alert';
92-
this._name = this.localize.string('general_error');
93-
this._description = this.localize.string(status.state.error);
92+
this._name = this.localize.term('blockEditor_elementTypeDoesNotExistHeadline');
93+
this._description = this.localize.term('blockEditor_elementTypeDoesNotExistDescription');
9494
}
9595
});
9696
}

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

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export class UmbRepositoryItemsManager<ItemType extends { unique: string }> exte
3838
#items = new UmbArrayState<ItemType>([], (x) => this.#getUnique(x));
3939
items = this.#items.asObservable();
4040

41-
#statuses = new UmbArrayState<UmbRepositoryItemsStatus>([], (x) => x);
41+
#statuses = new UmbArrayState<UmbRepositoryItemsStatus>([], (x) => x.unique);
4242
statuses = this.#statuses.asObservable();
4343

4444
/**
@@ -145,6 +145,15 @@ export class UmbRepositoryItemsManager<ItemType extends { unique: string }> exte
145145

146146
const requestedUniques = this.getUniques();
147147

148+
this.#statuses.setValue(
149+
requestedUniques.map((unique) => ({
150+
state: {
151+
type: 'loading',
152+
},
153+
unique,
154+
})),
155+
);
156+
148157
// TODO: Test if its just some items that is gone now, if so then just filter them out. (maybe use code from #removeItem)
149158
// 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.
150159
const request = this.repository.requestItems(requestedUniques);
@@ -175,17 +184,30 @@ export class UmbRepositoryItemsManager<ItemType extends { unique: string }> exte
175184
const rejectedUniques = requestedUniques.filter(
176185
(unique) => !data.find((item) => this.#getUnique(item) === unique),
177186
);
187+
const resolvedUniques = requestedUniques.filter((unique) => !rejectedUniques.includes(unique));
178188
this.#items.remove(rejectedUniques);
179189

180-
this.#statuses.append(
181-
rejectedUniques.map((unique) => ({
182-
state: {
183-
type: 'error',
184-
error: '#general_notFound',
185-
},
186-
unique,
187-
})),
188-
);
190+
this.#statuses.append([
191+
...rejectedUniques.map(
192+
(unique) =>
193+
({
194+
state: {
195+
type: 'error',
196+
error: '#general_notFound',
197+
},
198+
unique,
199+
}) as UmbRepositoryItemsStatus,
200+
),
201+
...resolvedUniques.map(
202+
(unique) =>
203+
({
204+
state: {
205+
type: 'success',
206+
},
207+
unique,
208+
}) as UmbRepositoryItemsStatus,
209+
),
210+
]);
189211
}
190212

191213
if (asObservable) {

0 commit comments

Comments
 (0)