Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion apps/concierge/src/app/lockers/locker-bookings.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ import { LockerStateService } from './locker-state.service';
</ng-template>
<ng-template #locker_template let-row="row">
<div class="p-4">
{{ row.asset_name || row.asset_id }}
{{ lockerName(row) }}
</div>
</ng-template>
<ng-template #user_template let-row="row">
Expand Down Expand Up @@ -305,6 +305,24 @@ export class LockerBookingsComponent {
private _state = inject(LockerStateService);
public readonly load_error = this._state.load_error;
public readonly retryLoad = () => this._state.refresh();
/** Locker names by asset id, from the lockers loaded for the building. */
private readonly _locker_names = computed(() => {
const names: Record<string, string> = {};
for (const locker of this._state.lockers()) {
names[locker.id] = locker.name;
}
return names;
});

/**
* A booking stores only the locker's id, so the name comes from the
* lockers the state has loaded; the id is shown when it is not among them.
*/
public lockerName(row: Booking): string {
return (
this._locker_names()[row.asset_id] || row.asset_name || row.asset_id
);
}
public readonly rowKey = bookingRowKey;
public readonly canSelect = (
row: BookingRowKeyFields & Pick<Booking, 'status' | 'deleted'>,
Expand Down
12 changes: 12 additions & 0 deletions apps/concierge/src/tests/lockers/locker-bookings.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ describe('LockerBookingsComponent', () => {
search: signal(''),
has_more_pages: signal(false),
load_error: signal(false),
lockers: signal([{ id: 'locker-1', name: 'Locker 1' }]),
filtered_bookings: signal([
{ id: 'bk-1', date: 1_000, duration: 30 },
]),
Expand All @@ -49,6 +50,17 @@ describe('LockerBookingsComponent', () => {
]);
});

it('should name a locker from the loaded lockers, falling back to the id', () => {
const name = (row: any) => spectator.component.lockerName(row);
expect(name({ asset_id: 'locker-1', asset_name: 'locker-1' })).toBe(
'Locker 1',
);
expect(name({ asset_id: 'locker-9', asset_name: 'Named' })).toBe(
'Named',
);
expect(name({ asset_id: 'locker-9', asset_name: '' })).toBe('locker-9');
});

it('should request the next page when loading more', () => {
spectator.component.loadMore();
expect(state.nextPage).toHaveBeenCalledTimes(1);
Expand Down
Loading