Skip to content

Commit 16afcfc

Browse files
Copilotnielslyngsoe
andcommitted
Add loading indicator to data-type-picker-flow-modal
- Added _isLoading state variable - Updated #getDataTypes() to set loading state with try-finally - Added uui-loader component in #renderGrid() when loading - Created test file with basic tests - Fixed linter warnings Co-authored-by: nielslyngsoe <[email protected]>
1 parent 7121c9a commit 16afcfc

File tree

2 files changed

+51
-12
lines changed

2 files changed

+51
-12
lines changed

src/Umbraco.Web.UI.Client/src/packages/data-type/modals/data-type-picker-flow/data-type-picker-flow-modal.element.ts

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ export class UmbDataTypePickerFlowModalElement extends UmbModalBaseElement<
4444
@state()
4545
private _dataTypePickerModalRouteBuilder?: UmbModalRouteBuilder;
4646

47+
@state()
48+
private _isLoading = false;
49+
4750
pagination = new UmbPaginationManager();
4851

4952
#collectionRepository;
@@ -162,20 +165,25 @@ export class UmbDataTypePickerFlowModalElement extends UmbModalBaseElement<
162165
}
163166

164167
async #getDataTypes() {
165-
this.pagination.setCurrentPageNumber(this._currentPage);
166-
167-
const { data } = await this.#collectionRepository.requestCollection({
168-
skip: this.pagination.getSkip(),
169-
take: this.pagination.getPageSize(),
170-
name: this.#currentFilterQuery,
171-
});
168+
this._isLoading = true;
169+
try {
170+
this.pagination.setCurrentPageNumber(this._currentPage);
171+
172+
const { data } = await this.#collectionRepository.requestCollection({
173+
skip: this.pagination.getSkip(),
174+
take: this.pagination.getPageSize(),
175+
name: this.#currentFilterQuery,
176+
});
172177

173-
this.pagination.setTotalItems(data?.total ?? 0);
178+
this.pagination.setTotalItems(data?.total ?? 0);
174179

175-
if (this.pagination.getCurrentPageNumber() > 1) {
176-
this.#dataTypes = [...this.#dataTypes, ...(data?.items ?? [])];
177-
} else {
178-
this.#dataTypes = data?.items ?? [];
180+
if (this.pagination.getCurrentPageNumber() > 1) {
181+
this.#dataTypes = [...this.#dataTypes, ...(data?.items ?? [])];
182+
} else {
183+
this.#dataTypes = data?.items ?? [];
184+
}
185+
} finally {
186+
this._isLoading = false;
179187
}
180188
}
181189

@@ -260,6 +268,12 @@ export class UmbDataTypePickerFlowModalElement extends UmbModalBaseElement<
260268
}
261269

262270
#renderGrid() {
271+
if (this._isLoading) {
272+
return html`<div
273+
style="display: flex; justify-content: center; align-items: center; padding: var(--uui-size-space-6);">
274+
<uui-loader></uui-loader>
275+
</div>`;
276+
}
263277
return this.#currentFilterQuery ? this.#renderFilteredList() : this.#renderUIs();
264278
}
265279

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { UmbDataTypePickerFlowModalElement } from './data-type-picker-flow-modal.element.js';
2+
import { expect, fixture, html } from '@open-wc/testing';
3+
import { type UmbTestRunnerWindow, defaultA11yConfig } from '@umbraco-cms/internal/test-utils';
4+
5+
describe('UmbDataTypePickerFlowModalElement', () => {
6+
let element: UmbDataTypePickerFlowModalElement;
7+
8+
beforeEach(async () => {
9+
element = await fixture(html` <umb-data-type-picker-flow-modal></umb-data-type-picker-flow-modal> `);
10+
});
11+
12+
it('is defined with its own instance', () => {
13+
expect(element).to.be.instanceOf(UmbDataTypePickerFlowModalElement);
14+
});
15+
16+
it('should have _isLoading state property', () => {
17+
expect(element).to.have.property('_isLoading');
18+
});
19+
20+
if ((window as UmbTestRunnerWindow).__UMBRACO_TEST_RUN_A11Y_TEST) {
21+
it('passes the a11y audit', async () => {
22+
await expect(element).shadowDom.to.be.accessible(defaultA11yConfig);
23+
});
24+
}
25+
});

0 commit comments

Comments
 (0)