Skip to content

Commit c1f889d

Browse files
authored
feat: tweak user config history with serial number and set active tab of the currently connected device (#2351)
1 parent 338aa4b commit c1f889d

File tree

8 files changed

+64
-12
lines changed

8 files changed

+64
-12
lines changed

packages/uhk-web/src/app/components/device/configuration/device-configuration.component.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ <h1>
6262
<div class="row">
6363
<div class="col-md-6 ps-0">
6464
<user-configuration-history [state]="userConfigHistoryState$ | async"
65-
(getUserConfigFromHistory)="getUserConfigFromHistory($event)"></user-configuration-history>
65+
(getUserConfigFromHistory)="getUserConfigFromHistory($event)"
66+
(changeTab)="changeConfigHistoryTab($event)"
67+
></user-configuration-history>
6668
</div>
6769
</div>
6870
</div>

packages/uhk-web/src/app/components/device/configuration/device-configuration.component.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
} from '../../../store/actions/user-config';
2121
import { UhkProgressBarState, UserConfigHistoryComponentState } from '../../../models';
2222
import {
23+
ChangeUserConfigurationHistoryTabAction,
2324
GetUserConfigurationFromHistoryAction,
2425
LoadUserConfigurationHistoryAction
2526
} from '../../../store/actions/user-configuration-history.actions';
@@ -56,6 +57,7 @@ export class DeviceConfigurationComponent implements OnInit, OnDestroy {
5657

5758
ngOnDestroy(): void {
5859
this.subscription.unsubscribe();
60+
this.changeConfigHistoryTab(null);
5961
}
6062

6163
resetUserConfiguration() {
@@ -78,6 +80,10 @@ export class DeviceConfigurationComponent implements OnInit, OnDestroy {
7880
}
7981
}
8082

83+
changeConfigHistoryTab(index: number | null) {
84+
this.store.dispatch(new ChangeUserConfigurationHistoryTabAction(index));
85+
}
86+
8187
changeFile(data: UploadFileData): void {
8288
this.store.dispatch(new LoadUserConfigurationFromFileAction({
8389
uploadFileData: {

packages/uhk-web/src/app/components/user-configuration-history/user-configuration-history.component.html

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,19 @@ <h4 class="panel-title">
2020
[class.disabled]="tab.disabled"
2121
(click)="onSelectTab(index)">
2222
<a class="nav-link"
23-
[class.active]="selectedTabIndex === index"
24-
[class.disabled]="tab.disabled">
23+
[class.active]="state.selectedTabIndex === index"
24+
[class.fw-bold]="tab.isCurrentDevice"
25+
[class.disabled]="tab.disabled"
26+
[attr.title]="tab.tooltip"
27+
>
2528
<span>{{ tab.displayText }}</span>
2629
</a>
2730
</li>
2831
</ul>
2932

3033
<ul class="list-unstyled mb-0 mt-2"
31-
*ngIf="!state.loading">
32-
<li *ngFor="let fileInfo of state.tabs[selectedTabIndex].files; trackBy:trackByFn">
34+
*ngIf="!state.loading && state.selectedTabIndex !== null">
35+
<li *ngFor="let fileInfo of state.tabs[state.selectedTabIndex].files; trackBy:trackByFn">
3336
<span class="btn btn-link btn-padding-0 current">
3437
{{ fileInfo.timestamp }}
3538
</span>

packages/uhk-web/src/app/components/user-configuration-history/user-configuration-history.component.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@ export class UserConfigurationHistoryComponent {
1212
@Input() state: UserConfigHistoryComponentState;
1313

1414
@Output() getUserConfigFromHistory = new EventEmitter<string>();
15-
16-
selectedTabIndex = 0;
15+
@Output() changeTab = new EventEmitter<number>();
1716

1817
trackByFn(index: number, key: HistoryFileInfo): string {
1918
return key.file;
2019
}
2120

2221
onSelectTab(index: number): void {
23-
this.selectedTabIndex = index;
22+
this.changeTab.emit(index);
2423
}
2524
}

packages/uhk-web/src/app/models/user-config-history-component-state.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,12 @@ export interface HistoryFileInfo {
2020
export interface Tab {
2121
displayText: string;
2222
files: HistoryFileInfo[];
23+
isCurrentDevice: boolean;
24+
tooltip: string;
2325
}
2426

2527
export interface UserConfigHistoryComponentState {
28+
selectedTabIndex: number | null;
2629
commonFiles: HistoryFileInfo[];
2730
tabs: Tab[];
2831
loading: boolean;

packages/uhk-web/src/app/store/actions/user-configuration-history.actions.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@ import { Action } from '@ngrx/store';
22
import { UserConfigHistory } from 'uhk-common';
33

44
export enum ActionTypes {
5+
ChangeUserConfigurationHistoryTab = '[user-config] Change user configuration history tab',
56
LoadUserConfigurationHistory = '[user-config] Load user configuration history',
67
LoadUserConfigurationHistorySuccess = '[user-config] Load user configuration history success',
78
GetUserConfigurationFromHistory = '[user-config] Get user configuration from history'
89
}
910

11+
export class ChangeUserConfigurationHistoryTabAction implements Action {
12+
type = ActionTypes.ChangeUserConfigurationHistoryTab;
13+
constructor(public payload: number | null) {}
14+
}
15+
1016
export class LoadUserConfigurationHistoryAction implements Action {
1117
type = ActionTypes.LoadUserConfigurationHistory;
1218
}
@@ -26,6 +32,7 @@ export class GetUserConfigurationFromHistoryAction implements Action {
2632
}
2733

2834
export type Actions =
35+
| ChangeUserConfigurationHistoryTabAction
2936
| LoadUserConfigurationHistoryAction
3037
| LoadUserConfigurationHistorySuccessAction
3138
| GetUserConfigurationFromHistoryAction

packages/uhk-web/src/app/store/index.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -579,30 +579,49 @@ export const getUserConfigHistoryComponentState = createSelector(
579579
};
580580
}
581581

582+
let selectedTabIndex = state.activeTabIndex || 0;
583+
const currentDeviceHasHistory = state.userConfigHistory.devices.find((device, index) => {
584+
if (device.uniqueId === hardwareConfig?.uniqueId) {
585+
if (state.activeTabIndex === null) {
586+
selectedTabIndex = index;
587+
}
588+
589+
return true;
590+
}
591+
592+
return false;
593+
});
594+
582595
const result: UserConfigHistoryComponentState = {
596+
selectedTabIndex,
583597
commonFiles: state.userConfigHistory.commonFiles.map(fileMapper),
584598
loading: inElectron && state.loading,
585599
tabs: state.userConfigHistory.devices.map(device => {
586600
return {
587601
displayText: `${device.deviceName} (${device.device.name})`,
588602
files: device.files.map(fileMapper),
603+
isCurrentDevice: device.uniqueId === hardwareConfig?.uniqueId,
604+
tooltip: `serial number: ${device.uniqueId}`,
589605
};
590606
}),
591607
disabled: saving
592608
};
593609

594-
const currentDeviceHasHistory = state.userConfigHistory.devices.find(device => device.uniqueId === hardwareConfig?.uniqueId);
595-
596610
if (result.tabs.length === 0 || !currentDeviceHasHistory) {
597611
let deviceName = UHK_60_V2_DEVICE.name;
612+
let tooltip = '';
598613
if (hardwareConfig) {
614+
tooltip = `serial number: ${hardwareConfig.uniqueId}`;
615+
599616
const uhkDevice = UHK_DEVICES.find(device => device.id === hardwareConfig.deviceId);
600617
deviceName = uhkDevice ? uhkDevice.name : deviceName;
601618
}
602619

603620
result.tabs.push({
604621
displayText: `${userConfig.deviceName} (${deviceName})`,
605-
files: []
622+
files: [],
623+
isCurrentDevice: true,
624+
tooltip,
606625
});
607626
}
608627

packages/uhk-web/src/app/store/reducers/user-configuration-history.reducer.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@ import {
22
UserConfigHistory,
33
} from 'uhk-common';
44

5-
import { Actions, ActionTypes, LoadUserConfigurationHistorySuccessAction } from '../actions/user-configuration-history.actions';
5+
import {
6+
Actions,
7+
ActionTypes,
8+
ChangeUserConfigurationHistoryTabAction,
9+
LoadUserConfigurationHistorySuccessAction,
10+
} from '../actions/user-configuration-history.actions';
611

712
export interface State {
13+
activeTabIndex: number | null;
814
userConfigHistory: UserConfigHistory;
915
loading: boolean;
1016
}
@@ -17,13 +23,20 @@ function defaultUserConfigHistory(): UserConfigHistory {
1723
}
1824

1925
export const initialState: State = {
26+
activeTabIndex: null,
2027
userConfigHistory: defaultUserConfigHistory(),
2128
loading: false
2229
};
2330

2431
export function reducer(state = initialState, action: Actions) {
2532
switch (action.type) {
2633

34+
case ActionTypes.ChangeUserConfigurationHistoryTab:
35+
return {
36+
...state,
37+
activeTabIndex: (action as ChangeUserConfigurationHistoryTabAction).payload,
38+
};
39+
2740
case ActionTypes.LoadUserConfigurationHistory:
2841
return {
2942
...state,

0 commit comments

Comments
 (0)