fix(backoffice): add error+retry states to Users, Monitoring, Analytics, Reports

Phase 8 (RC-01): these 4 list/dashboard pages had no error-state handling
on their primary data-load subscriptions — on a gateway error, `loading`
was either never reset (Users, Monitoring, Analytics: genuine infinite-
spinner risk, nested subscribe chain in Analytics never resolved on
failure) or there was no loading/empty/error handling at all (Reports
queue: raw table with zero skeleton or fallback).

- admin-users.facade.ts, admin-monitoring.facade.ts: add `error` signal,
  error callback on the primary load subscribe so `loading` always
  resolves.
- admin-analytics.facade.ts: add `error` signal; every level of the
  4-deep nested gateway subscribe chain (orders -> products ->
  categories -> reviews) now has an error handler that resolves loading
  instead of leaving it stuck true.
- admin-moderation.facade.ts: add `reportsLoading`/`reportsError` signals
  (reports list had none previously).
- Templates: reuse existing `app-skeleton`/`app-empty-state`/`app-button`
  primitives for the new error branch, `common.retry` label, two new
  generic `common.errorTitle`/`common.errorDescription` i18n keys added
  to en/ru/hy (reused across all 4 fixes instead of one-off per-page
  copy).

Verified: tsc --noEmit clean, `npm run build` green (pre-existing bundle-
budget warning only, unrelated). Live-checked Home (375px) and Backoffice
Products (1024px) — no console errors, tables/cards render without
overflow.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
sdarbinyan
2026-07-25 21:31:30 +04:00
parent b909a195f7
commit e153a67ec0
14 changed files with 113 additions and 38 deletions

View File

@@ -38,6 +38,7 @@ export class AdminAnalyticsFacade {
readonly dateRange = signal<AdminAnalyticsDateRange>(30); readonly dateRange = signal<AdminAnalyticsDateRange>(30);
readonly loading = signal(false); readonly loading = signal(false);
readonly error = signal(false);
readonly summary = signal<AdminAnalyticsSummary | null>(null); readonly summary = signal<AdminAnalyticsSummary | null>(null);
readonly salesSeries = signal<AdminAnalyticsSeriesPoint[]>([]); readonly salesSeries = signal<AdminAnalyticsSeriesPoint[]>([]);
readonly topProducts = signal<AdminAnalyticsTopProduct[]>([]); readonly topProducts = signal<AdminAnalyticsTopProduct[]>([]);
@@ -63,6 +64,7 @@ export class AdminAnalyticsFacade {
load(): void { load(): void {
this.loading.set(true); this.loading.set(true);
this.error.set(false);
this.dashboardFacade.ensureLoaded(); this.dashboardFacade.ensureLoaded();
this.recentActivity.set( this.recentActivity.set(
this.dashboardFacade.activityEntries().map(entry => ({ this.dashboardFacade.activityEntries().map(entry => ({
@@ -72,44 +74,58 @@ export class AdminAnalyticsFacade {
})), })),
); );
this.ordersGateway.loadOrders({ search: '', status: 'all', page: 1, pageSize: 100000 }).pipe(take(1)).subscribe(orderResult => { const fail = (): void => { this.loading.set(false); this.error.set(true); };
const cutoff = Date.now() - this.dateRange() * 24 * 60 * 60 * 1000;
const inRange = orderResult.items.filter(order => new Date(order.createdAt).getTime() >= cutoff);
this.salesSeries.set(this.buildSeries(inRange, this.dateRange())); this.ordersGateway.loadOrders({ search: '', status: 'all', page: 1, pageSize: 100000 }).pipe(take(1)).subscribe({
this.topProducts.set(this.buildTopProducts(inRange)); next: orderResult => {
this.customerAnalytics.set(this.buildCustomerAnalytics(orderResult.items, inRange, this.dateRange())); const cutoff = Date.now() - this.dateRange() * 24 * 60 * 60 * 1000;
const inRange = orderResult.items.filter(order => new Date(order.createdAt).getTime() >= cutoff);
const revenueTotal = inRange.reduce((sum, order) => sum + order.total, 0); this.salesSeries.set(this.buildSeries(inRange, this.dateRange()));
const ordersCount = inRange.length; this.topProducts.set(this.buildTopProducts(inRange));
const uniqueCustomers = new Set(inRange.map(order => order.customer.email)).size; this.customerAnalytics.set(this.buildCustomerAnalytics(orderResult.items, inRange, this.dateRange()));
this.productsGateway.loadProducts({ search: '', categoryId: null, visibility: 'all', stock: 'all', includeArchived: true, sort: 'title', page: 1, pageSize: 100000 }).pipe(take(1)).subscribe(productResult => { const revenueTotal = inRange.reduce((sum, order) => sum + order.total, 0);
this.categoriesGateway.loadCategories({ search: '', visibility: 'all', includeDeleted: true }).pipe(take(1)).subscribe(categories => { const ordersCount = inRange.length;
this.moderationGateway.loadReviews({ search: '', status: 'all', rating: 'all', page: 1, pageSize: 100000 }).pipe(take(1)).subscribe(reviewResult => { const uniqueCustomers = new Set(inRange.map(order => order.customer.email)).size;
const products = productResult.items;
const reviews = reviewResult.items;
this.summary.set({ this.productsGateway.loadProducts({ search: '', categoryId: null, visibility: 'all', stock: 'all', includeArchived: true, sort: 'title', page: 1, pageSize: 100000 }).pipe(take(1)).subscribe({
revenueTotal, next: productResult => {
currency: inRange[0]?.currency ?? 'RUB', this.categoriesGateway.loadCategories({ search: '', visibility: 'all', includeDeleted: true }).pipe(take(1)).subscribe({
ordersCount, next: categories => {
avgOrderValue: ordersCount > 0 ? Math.round(revenueTotal / ordersCount) : 0, this.moderationGateway.loadReviews({ search: '', status: 'all', rating: 'all', page: 1, pageSize: 100000 }).pipe(take(1)).subscribe({
productsCount: products.length, next: reviewResult => {
categoriesCount: categories.length, const products = productResult.items;
customersCount: uniqueCustomers, const reviews = reviewResult.items;
conversionRate: null,
this.summary.set({
revenueTotal,
currency: inRange[0]?.currency ?? 'RUB',
ordersCount,
avgOrderValue: ordersCount > 0 ? Math.round(revenueTotal / ordersCount) : 0,
productsCount: products.length,
categoriesCount: categories.length,
customersCount: uniqueCustomers,
conversionRate: null,
});
this.lowStockProducts.set(this.buildLowStock(products));
this.productAnalytics.set(this.buildProductAnalytics(products));
this.marketplaceHealth.set(this.buildMarketplaceHealth(products, categories, reviews, orderResult.items));
this.recommendations.set(this.buildRecommendations(products, categories));
this.loading.set(false);
},
error: fail
});
},
error: fail
}); });
},
this.lowStockProducts.set(this.buildLowStock(products)); error: fail
this.productAnalytics.set(this.buildProductAnalytics(products));
this.marketplaceHealth.set(this.buildMarketplaceHealth(products, categories, reviews, orderResult.items));
this.recommendations.set(this.buildRecommendations(products, categories));
this.loading.set(false);
});
}); });
}); },
error: fail
}); });
} }

View File

@@ -11,6 +11,14 @@
</div> </div>
</div> </div>
@if (facade.error()) {
<app-empty-state [title]="'common.errorTitle' | translate" [description]="'common.errorDescription' | translate">
<span slot="actions">
<app-button variant="primary" (click)="facade.load()">{{ 'common.retry' | translate }}</app-button>
</span>
</app-empty-state>
} @else {
<div class="tabs" role="tablist" [attr.aria-label]="'adminAnalytics.tabsLabel' | translate"> <div class="tabs" role="tablist" [attr.aria-label]="'adminAnalytics.tabsLabel' | translate">
@for (tab of tabs; track tab) { @for (tab of tabs; track tab) {
<button <button
@@ -245,4 +253,5 @@
</div> </div>
</div> </div>
} }
}
</section> </section>

View File

@@ -47,6 +47,8 @@ export class AdminModerationFacade {
readonly loading = signal(false); readonly loading = signal(false);
readonly selected = signal<AdminReview | null>(null); readonly selected = signal<AdminReview | null>(null);
readonly reports = signal<AdminReport[]>([]); readonly reports = signal<AdminReport[]>([]);
readonly reportsLoading = signal(false);
readonly reportsError = signal(false);
readonly viewMode = signal<AdminModerationViewMode>((this.localStorage.getItem(VIEW_MODE_KEY) as AdminModerationViewMode) || 'table'); readonly viewMode = signal<AdminModerationViewMode>((this.localStorage.getItem(VIEW_MODE_KEY) as AdminModerationViewMode) || 'table');
readonly density = signal<AdminModerationDensity>((this.localStorage.getItem(DENSITY_KEY) as AdminModerationDensity) || 'comfortable'); readonly density = signal<AdminModerationDensity>((this.localStorage.getItem(DENSITY_KEY) as AdminModerationDensity) || 'comfortable');
@@ -167,7 +169,12 @@ export class AdminModerationFacade {
} }
loadReports(): void { loadReports(): void {
this.gateway.loadReports().pipe(take(1)).subscribe({ next: reports => this.reports.set(reports) }); this.reportsLoading.set(true);
this.reportsError.set(false);
this.gateway.loadReports().pipe(take(1)).subscribe({
next: reports => { this.reports.set(reports); this.reportsLoading.set(false); },
error: () => { this.reports.set([]); this.reportsLoading.set(false); this.reportsError.set(true); }
});
} }
setReportStatus(id: string, status: AdminReportStatus): void { setReportStatus(id: string, status: AdminReportStatus): void {

View File

@@ -4,7 +4,18 @@
<h1>{{ 'adminModeration.reportsQueue' | translate }}</h1> <h1>{{ 'adminModeration.reportsQueue' | translate }}</h1>
</header> </header>
@if (facade.reports().length === 0) { @if (facade.reportsLoading()) {
<div class="skeleton-rows" role="status" aria-live="polite" aria-busy="true">
@for (i of [1,2,3,4]; track i) { <app-skeleton shape="rect" height="40px" /> }
<span class="sr-only">{{ 'common.loading' | translate }}</span>
</div>
} @else if (facade.reportsError()) {
<app-empty-state [title]="'common.errorTitle' | translate" [description]="'common.errorDescription' | translate">
<span slot="actions">
<app-button variant="primary" (click)="facade.loadReports()">{{ 'common.retry' | translate }}</app-button>
</span>
</app-empty-state>
} @else if (facade.reports().length === 0) {
<app-empty-state [title]="'adminModeration.reportsEmptyTitle' | translate" [description]="'adminModeration.reportsEmptyDescription' | translate" /> <app-empty-state [title]="'adminModeration.reportsEmptyTitle' | translate" [description]="'adminModeration.reportsEmptyDescription' | translate" />
} @else { } @else {
<app-table> <app-table>

View File

@@ -9,11 +9,12 @@ import { ButtonComponent } from '../../../../shared/ui/button/button.component';
import { BadgeComponent } from '../../../../shared/ui/badge/badge.component'; import { BadgeComponent } from '../../../../shared/ui/badge/badge.component';
import { TableComponent } from '../../../../shared/ui/table/table.component'; import { TableComponent } from '../../../../shared/ui/table/table.component';
import { EmptyStateComponent } from '../../../../shared/ui/empty-state/empty-state.component'; import { EmptyStateComponent } from '../../../../shared/ui/empty-state/empty-state.component';
import { SkeletonComponent } from '../../../../shared/ui/skeleton/skeleton.component';
@Component({ @Component({
selector: 'app-admin-reports-list-page', selector: 'app-admin-reports-list-page',
standalone: true, standalone: true,
imports: [CommonModule, TranslatePipe, ButtonComponent, BadgeComponent, TableComponent, EmptyStateComponent], imports: [CommonModule, TranslatePipe, ButtonComponent, BadgeComponent, TableComponent, EmptyStateComponent, SkeletonComponent],
templateUrl: './admin-reports-list-page.component.html', templateUrl: './admin-reports-list-page.component.html',
styleUrls: ['./admin-reports-list-page.component.scss'], styleUrls: ['./admin-reports-list-page.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush changeDetection: ChangeDetectionStrategy.OnPush

View File

@@ -12,10 +12,15 @@ export class AdminMonitoringFacade {
readonly queues = signal<AdminQueue[]>([]); readonly queues = signal<AdminQueue[]>([]);
readonly webhooks = signal<AdminWebhookDelivery[]>([]); readonly webhooks = signal<AdminWebhookDelivery[]>([]);
readonly loading = signal(false); readonly loading = signal(false);
readonly error = signal(false);
loadAll(): void { loadAll(): void {
this.loading.set(true); this.loading.set(true);
this.gateway.loadEvents(this.filters()).pipe(take(1)).subscribe(events => { this.events.set(events); this.loading.set(false); }); this.error.set(false);
this.gateway.loadEvents(this.filters()).pipe(take(1)).subscribe({
next: events => { this.events.set(events); this.loading.set(false); },
error: () => { this.events.set([]); this.loading.set(false); this.error.set(true); }
});
this.gateway.loadQueues().pipe(take(1)).subscribe(queues => this.queues.set(queues)); this.gateway.loadQueues().pipe(take(1)).subscribe(queues => this.queues.set(queues));
this.gateway.loadWebhooks().pipe(take(1)).subscribe(webhooks => this.webhooks.set(webhooks)); this.gateway.loadWebhooks().pipe(take(1)).subscribe(webhooks => this.webhooks.set(webhooks));
} }

View File

@@ -73,6 +73,12 @@
} }
<span class="sr-only">{{ 'common.loading' | translate }}</span> <span class="sr-only">{{ 'common.loading' | translate }}</span>
</div> </div>
} @else if (facade.error()) {
<app-empty-state [title]="'common.errorTitle' | translate" [description]="'common.errorDescription' | translate">
<span slot="actions">
<app-button variant="primary" (click)="facade.loadAll()">{{ 'common.retry' | translate }}</app-button>
</span>
</app-empty-state>
} @else if (facade.events().length === 0) { } @else if (facade.events().length === 0) {
<app-empty-state [title]="'adminMonitoring.eventsEmptyTitle' | translate" [description]="'adminMonitoring.eventsEmptyDescription' | translate" /> <app-empty-state [title]="'adminMonitoring.eventsEmptyTitle' | translate" [description]="'adminMonitoring.eventsEmptyDescription' | translate" />
} @else { } @else {

View File

@@ -9,11 +9,12 @@ import { BadgeComponent } from '../../../../shared/ui/badge/badge.component';
import { TableComponent } from '../../../../shared/ui/table/table.component'; import { TableComponent } from '../../../../shared/ui/table/table.component';
import { SkeletonComponent } from '../../../../shared/ui/skeleton/skeleton.component'; import { SkeletonComponent } from '../../../../shared/ui/skeleton/skeleton.component';
import { EmptyStateComponent } from '../../../../shared/ui/empty-state/empty-state.component'; import { EmptyStateComponent } from '../../../../shared/ui/empty-state/empty-state.component';
import { ButtonComponent } from '../../../../shared/ui/button/button.component';
@Component({ @Component({
selector: 'app-admin-monitoring-page', selector: 'app-admin-monitoring-page',
standalone: true, standalone: true,
imports: [CommonModule, FormsModule, TranslatePipe, InputComponent, BadgeComponent, TableComponent, SkeletonComponent, EmptyStateComponent], imports: [CommonModule, FormsModule, TranslatePipe, InputComponent, BadgeComponent, TableComponent, SkeletonComponent, EmptyStateComponent, ButtonComponent],
templateUrl: './admin-monitoring-page.component.html', templateUrl: './admin-monitoring-page.component.html',
styleUrls: ['./admin-monitoring-page.component.scss'], styleUrls: ['./admin-monitoring-page.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush changeDetection: ChangeDetectionStrategy.OnPush

View File

@@ -11,6 +11,7 @@ export class AdminUsersFacade {
readonly roles = signal<AdminRole[]>([]); readonly roles = signal<AdminRole[]>([]);
readonly invitations = signal<AdminInvitation[]>([]); readonly invitations = signal<AdminInvitation[]>([]);
readonly loading = signal(false); readonly loading = signal(false);
readonly error = signal(false);
readonly sessionsTarget = signal<AdminUser | null>(null); readonly sessionsTarget = signal<AdminUser | null>(null);
readonly sessions = signal<AdminSession[]>([]); readonly sessions = signal<AdminSession[]>([]);
readonly auditTarget = signal<AdminUser | null>(null); readonly auditTarget = signal<AdminUser | null>(null);
@@ -18,7 +19,11 @@ export class AdminUsersFacade {
loadAll(): void { loadAll(): void {
this.loading.set(true); this.loading.set(true);
this.gateway.loadUsers().pipe(take(1)).subscribe(users => { this.users.set(users); this.loading.set(false); }); this.error.set(false);
this.gateway.loadUsers().pipe(take(1)).subscribe({
next: users => { this.users.set(users); this.loading.set(false); },
error: () => { this.users.set([]); this.loading.set(false); this.error.set(true); }
});
this.gateway.loadRoles().pipe(take(1)).subscribe(roles => this.roles.set(roles)); this.gateway.loadRoles().pipe(take(1)).subscribe(roles => this.roles.set(roles));
this.gateway.loadInvitations().pipe(take(1)).subscribe(invitations => this.invitations.set(invitations)); this.gateway.loadInvitations().pipe(take(1)).subscribe(invitations => this.invitations.set(invitations));
} }

View File

@@ -6,6 +6,12 @@
@for (i of [1,2,3]; track i) { <app-skeleton shape="rect" height="40px" /> } @for (i of [1,2,3]; track i) { <app-skeleton shape="rect" height="40px" /> }
<span class="sr-only">{{ 'common.loading' | translate }}</span> <span class="sr-only">{{ 'common.loading' | translate }}</span>
</div> </div>
} @else if (facade.error()) {
<app-empty-state [title]="'common.errorTitle' | translate" [description]="'common.errorDescription' | translate">
<span slot="actions">
<app-button variant="primary" (click)="facade.loadAll()">{{ 'common.retry' | translate }}</app-button>
</span>
</app-empty-state>
} @else if (facade.users().length === 0) { } @else if (facade.users().length === 0) {
<app-empty-state [title]="'adminUsers.emptyTitle' | translate" [description]="'adminUsers.emptyDescription' | translate" /> <app-empty-state [title]="'adminUsers.emptyTitle' | translate" [description]="'adminUsers.emptyDescription' | translate" />
} @else { } @else {

View File

@@ -1084,6 +1084,8 @@ export const en: Translations = {
retry: 'Try again', retry: 'Try again',
loading: 'Loading...', loading: 'Loading...',
remove: 'Remove', remove: 'Remove',
errorTitle: 'Something went wrong',
errorDescription: 'We could not load this data. Please try again.',
}, },
location: { location: {
allRegions: 'All regions', allRegions: 'All regions',

View File

@@ -1084,6 +1084,8 @@ export const hy: Translations = {
retry: 'Փորձել կրկին', retry: 'Փորձել կրկին',
loading: 'Բեռնում...', loading: 'Բեռնում...',
remove: 'Հեռացնել', remove: 'Հեռացնել',
errorTitle: 'Ինչ-որ բան այն չէ',
errorDescription: 'Չհաջողվեց բեռնել տվյալները։ Փորձեք կրկին։',
}, },
location: { location: {
allRegions: 'Բոլոր տարածաշրջանները', allRegions: 'Բոլոր տարածաշրջանները',

View File

@@ -1084,6 +1084,8 @@ export const ru: Translations = {
retry: 'Попробовать снова', retry: 'Попробовать снова',
loading: 'Загрузка...', loading: 'Загрузка...',
remove: 'Удалить', remove: 'Удалить',
errorTitle: 'Что-то пошло не так',
errorDescription: 'Не удалось загрузить данные. Попробуйте ещё раз.',
}, },
location: { location: {
allRegions: 'Все регионы', allRegions: 'Все регионы',

View File

@@ -1083,6 +1083,8 @@ export interface Translations {
retry: string; retry: string;
loading: string; loading: string;
remove: string; remove: string;
errorTitle: string;
errorDescription: string;
}; };
location: { location: {
allRegions: string; allRegions: string;