Skip to content

Commit d830790

Browse files
committed
Remove data source; move error handling to repository and correct functionalities.
1 parent a771b99 commit d830790

File tree

5 files changed

+129
-248
lines changed

5 files changed

+129
-248
lines changed

src/Umbraco.Cms.Integrations.Search.Algolia/Client/src/dashboard/search-management-dashboard/views/algolia-dashboard-overview.ts

Lines changed: 24 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,9 @@
88
} from "@umbraco-cms/backoffice/external/lit";
99
import { UmbElementMixin } from "@umbraco-cms/backoffice/element-api";
1010
import { UMB_MODAL_MANAGER_CONTEXT, UMB_CONFIRM_MODAL } from "@umbraco-cms/backoffice/modal";
11-
import {
12-
UMB_NOTIFICATION_CONTEXT,
13-
} from "@umbraco-cms/backoffice/notification";
1411
import { type AlgoliaIndexContext, ALGOLIA_CONTEXT_TOKEN } from '@umbraco-integrations/algolia/context';
1512
import type {
16-
IndexConfigurationModel,
17-
ResultModel
13+
IndexConfigurationModel
1814
} from "@umbraco-integrations/algolia/generated";
1915

2016
const elementName = "algolia-dashboard-overview";
@@ -45,17 +41,15 @@ export class AlgoliaDashboardOverviewElement extends UmbElementMixin(LitElement)
4541
async #getIndices() {
4642
this._loading = true;
4743

48-
await this.#algoliaIndexContext?.getIndices()
49-
.then(response => {
50-
this._indices = response as Array<IndexConfigurationModel>;
51-
this._loading = false;
52-
})
53-
.catch(error => this.#showError(error.message));
44+
var response = await this.#algoliaIndexContext?.getIndices();
45+
this._indices = response?.data as IndexConfigurationModel[];
46+
47+
this._loading = false;
5448
}
5549

5650
async #onBuildIndex(index: IndexConfigurationModel) {
57-
const modalManager = await this.getContext(UMB_MODAL_MANAGER_CONTEXT);
58-
const modalContext = modalManager.open(
51+
const modalManagerContext = await this.getContext(UMB_MODAL_MANAGER_CONTEXT);
52+
const modalContext = modalManagerContext.open(
5953
this, UMB_CONFIRM_MODAL,
6054
{
6155
data: {
@@ -72,28 +66,19 @@ export class AlgoliaDashboardOverviewElement extends UmbElementMixin(LitElement)
7266
}
7367
}
7468
);
75-
await modalContext.onSubmit().catch(() => undefined);
76-
77-
this._loading = true;
78-
79-
await this.#algoliaIndexContext?.buildIndex(index)
80-
.then(response => {
81-
const result = response as ResultModel;
82-
if (result.success) {
83-
this.#showSuccess("Index built.");
84-
}
85-
else {
86-
this.#showError(result.error);
87-
}
69+
await modalContext
70+
?.onSubmit()
71+
.then(async () => {
72+
this._loading = true;
73+
await this.#algoliaIndexContext?.buildIndex(index);
74+
this._loading = false;
8875
})
89-
.catch(error => this.#showError(error));
90-
91-
this._loading = false;
76+
.catch(() => undefined);
9277
}
9378

9479
async #onDeleteIndex(index: IndexConfigurationModel) {
95-
const modalManager = await this.getContext(UMB_MODAL_MANAGER_CONTEXT);
96-
const modalContext = modalManager.open(
80+
const modalManagerContext = await this.getContext(UMB_MODAL_MANAGER_CONTEXT);
81+
const modalContext = modalManagerContext.open(
9782
this, UMB_CONFIRM_MODAL,
9883
{
9984
data: {
@@ -107,44 +92,15 @@ export class AlgoliaDashboardOverviewElement extends UmbElementMixin(LitElement)
10792
}
10893
}
10994
);
110-
modalContext?.onSubmit().catch((error) => this.#showError(error.message));
111-
112-
if (index == undefined || index.id == undefined) return;
113-
114-
this._loading = true;
115-
116-
await this.#algoliaIndexContext?.deleteIndex(index.id)
117-
.then(response => {
118-
const result = response as ResultModel;
119-
120-
if (result.success) {
121-
this.#getIndices();
122-
this.#showSuccess("Index deleted");
123-
}
124-
else {
125-
this.#showError(result.error);
126-
}
127-
95+
modalContext
96+
?.onSubmit()
97+
.then(async () => {
98+
this._loading = true;
99+
await this.#algoliaIndexContext?.deleteIndex(index.id);
100+
this.#getIndices();
101+
this._loading = false;
128102
})
129-
.catch(error => this.#showError(error));
130-
131-
this._loading = false;
132-
133-
}
134-
135-
// notifications
136-
async #showSuccess(message: string) {
137-
const notificationContext = await this.getContext(UMB_NOTIFICATION_CONTEXT);
138-
notificationContext?.peek("positive", {
139-
data: { message: message },
140-
});
141-
}
142-
143-
async #showError(message: string) {
144-
const notificationContext = await this.getContext(UMB_NOTIFICATION_CONTEXT);
145-
notificationContext?.peek("danger", {
146-
data: { message: message },
147-
});
103+
.catch(() => undefined);
148104
}
149105

150106
#renderIndicesList() {

src/Umbraco.Cms.Integrations.Search.Algolia/Client/src/dashboard/search-management-dashboard/views/algolia-index.ts

Lines changed: 8 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ import { type AlgoliaIndexContext, ALGOLIA_CONTEXT_TOKEN } from '@umbraco-integr
1616

1717
import type {
1818
IndexConfigurationModel,
19-
ContentTypeDtoModel,
20-
ResultModel
19+
ContentTypeDtoModel
2120
} from "@umbraco-integrations/algolia/generated";
2221

2322
const elementName = "algolia-index";
@@ -65,27 +64,18 @@ export class AlgoliaIndexElement extends UmbElementMixin(LitElement) {
6564
}
6665

6766
async #getContentTypes() {
68-
await this.#algoliaIndexContext?.getContentTypes()
69-
.then(response => {
70-
this._contentTypes = response as Array<ContentTypeDtoModel>;
71-
})
72-
.catch(error => this.#showError(error.message));
67+
var response = await this.#algoliaIndexContext?.getContentTypes();
68+
this._contentTypes = response?.data as Array<ContentTypeDtoModel>;
7369
}
7470

7571
async #getContentTypesWithIndex() {
76-
await this.#algoliaIndexContext?.getContentTypesWithIndex(Number(this.indexId))
77-
.then(response => {
78-
this._contentTypes = response as Array<ContentTypeDtoModel>;
79-
})
80-
.catch((error) => this.#showError(error.message));
72+
var response = await this.#algoliaIndexContext?.getContentTypesWithIndex(Number(this.indexId));
73+
this._contentTypes = response?.data as Array<ContentTypeDtoModel>;
8174
}
8275

8376
async #getIndex() {
84-
await this.#algoliaIndexContext?.getIndexById(Number(this.indexId))
85-
.then(response => {
86-
this._model = response as IndexConfigurationModel;
87-
})
88-
.catch(error => this.#showError(error.message));
77+
var response = await this.#algoliaIndexContext?.getIndexById(Number(this.indexId));
78+
this._model = response?.data as IndexConfigurationModel;
8979
}
9080

9181
async #contentTypeSelected(id: number) {
@@ -167,32 +157,10 @@ export class AlgoliaIndexElement extends UmbElementMixin(LitElement) {
167157
}
168158
indexConfiguration.contentData = this._contentTypes;
169159

170-
await this.#algoliaIndexContext?.saveIndex(indexConfiguration)
171-
.then(response => {
172-
const resultModel = response as ResultModel;
173-
if (resultModel.success) {
174-
this.#showSuccess("Index saved.");
175-
176-
const redirectPath = this.indexId.length > 0
177-
? window.location.href.replace(`/index/${this.indexId}`, '')
178-
: window.location.href.replace('/index', '');
179-
180-
window.history.pushState({}, '', redirectPath);
181-
} else {
182-
this.#showError(resultModel.error);
183-
}
184-
})
185-
.catch((error) => this.#showError(error.message));
160+
await this.#algoliaIndexContext?.saveIndex(indexConfiguration);
186161
}
187162

188163
// notifications
189-
async #showSuccess(message: string) {
190-
const notificationContext = await this.getContext(UMB_NOTIFICATION_CONTEXT);
191-
notificationContext?.peek("positive", {
192-
data: { message: message },
193-
});
194-
}
195-
196164
async #showError(message: string) {
197165
const notificationContext = await this.getContext(UMB_NOTIFICATION_CONTEXT);
198166
notificationContext?.peek("danger", {

src/Umbraco.Cms.Integrations.Search.Algolia/Client/src/dashboard/search-management-dashboard/views/algolia-search.ts

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
query
99
} from "@umbraco-cms/backoffice/external/lit";
1010
import { UmbElementMixin } from "@umbraco-cms/backoffice/element-api";
11-
import { UMB_NOTIFICATION_CONTEXT } from "@umbraco-cms/backoffice/notification";
1211
import { type AlgoliaIndexContext, ALGOLIA_CONTEXT_TOKEN } from '@umbraco-integrations/algolia/context';
1312
import type { IndexConfigurationModel, ResponseModel } from "@umbraco-integrations/algolia/generated";
1413

@@ -53,9 +52,8 @@ export class AlgoliaSearchElement extends UmbElementMixin(LitElement) {
5352
}
5453

5554
async #getIndex() {
56-
await this.#algoliaIndexContext?.getIndexById(Number(this.indexId))
57-
.then(response => this.index = response as IndexConfigurationModel)
58-
.catch(error => this.#showError(error.message));
55+
var response = await this.#algoliaIndexContext?.getIndexById(Number(this.indexId));
56+
this.index = response?.data as IndexConfigurationModel;
5957
}
6058

6159
#onKeyPress(e: KeyboardEvent) {
@@ -65,19 +63,8 @@ export class AlgoliaSearchElement extends UmbElementMixin(LitElement) {
6563
async #onSearch() {
6664
if (!this._searchInput.value.length) return;
6765

68-
await this.#algoliaIndexContext?.searchIndex(Number(this.indexId), this._searchInput.value)
69-
.then(response => {
70-
this.indexSearchResult = response as ResponseModel;
71-
})
72-
.catch((error) => this.#showError(error));
73-
}
74-
75-
// notifications
76-
async #showError(message: string) {
77-
const notificationContext = await this.getContext(UMB_NOTIFICATION_CONTEXT);
78-
notificationContext?.peek("danger", {
79-
data: { message: message },
80-
});
66+
var response = await this.#algoliaIndexContext?.searchIndex(Number(this.indexId), this._searchInput.value);
67+
this.indexSearchResult = response?.data as ResponseModel;
8168
}
8269

8370
render() {

src/Umbraco.Cms.Integrations.Search.Algolia/Client/src/repository/algolia-index.data-source.ts

Lines changed: 0 additions & 109 deletions
This file was deleted.

0 commit comments

Comments
 (0)