Skip to content

Commit

Permalink
Update DeviceManager UI if new device was added successfuly (#38)
Browse files Browse the repository at this point in the history
* started working on natural add/deletion flow via UI

* back to deletion

* update UI if new device successfuly connected
  • Loading branch information
foxriver76 authored Jul 16, 2024
1 parent 92ae532 commit c9fb631
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 27 deletions.
62 changes: 36 additions & 26 deletions src-admin/src/Tabs/Controller.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
LinearProgress,
Select,
MenuItem,
Backdrop, Typography,
Backdrop, Typography, Tooltip,
} from '@mui/material';
import {
Add,
Expand Down Expand Up @@ -146,7 +146,11 @@ interface ComponentState {
}

class Controller extends Component<ComponentProps, ComponentState> {
private readonly refQrScanner: React.RefObject<HTMLVideoElement>;
/** Reference object to call methods on QR Scanner */
private readonly refQrScanner: React.RefObject<HTMLVideoElement> = React.createRef();

/** Reference object to call methods on DM */
private readonly refDeviceManager: React.RefObject<DeviceManager> = React.createRef();

private qrScanner: QrScanner | null | true = null;

Expand Down Expand Up @@ -180,8 +184,6 @@ class Controller extends Component<ComponentProps, ComponentState> {
backendProcessingActive: false,
bleDialogOpen: false,
};

this.refQrScanner = React.createRef();
}

async readStructure() {
Expand Down Expand Up @@ -343,9 +345,7 @@ class Controller extends Component<ComponentProps, ComponentState> {
onMessage = (message: GUIMessage | null) => {
if (message?.command === 'discoveredDevice') {
if (message.device) {
const discovered: CommissionableDevice[] = JSON.parse(
JSON.stringify(this.state.discovered),
);
const discovered = clone(this.state.discovered);
discovered.push(message.device);
this.setState({ discovered });
} else {
Expand Down Expand Up @@ -638,7 +638,13 @@ class Controller extends Component<ComponentProps, ComponentState> {
`Cannot connect: ${result.error || 'Unknown error'}`,
);
} else {
window.alert('Connected');
window.alert(I18n.t('Connected'));
const deviceId = device.deviceIdentifier;
const discovered = this.state.discovered.filter(commDevice => commDevice.deviceIdentifier !== deviceId);

this.setState({ discovered }, () => {
this.refDeviceManager.current.loadData();
});
}
}}
startIcon={<Add />}
Expand Down Expand Up @@ -679,24 +685,26 @@ class Controller extends Component<ComponentProps, ComponentState> {
<TableCell>{device.DN}</TableCell>
<TableCell>{device.deviceIdentifier}</TableCell>
<TableCell>
<IconButton
onClick={() => {
this.setState({
showQrCodeDialog: device,
manualCode: '',
qrCode: '',
});
setTimeout(async () => {
try {
await this.initQrCode();
} catch (e) {
console.warn(`Cannot provide QR Code scanning: ${e}`);
}
}, 500);
}}
>
<LeakAdd />
</IconButton>
<Tooltip title={I18n.t('Connect')}>
<IconButton
onClick={() => {
this.setState({
showQrCodeDialog: device,
manualCode: '',
qrCode: '',
});
setTimeout(async () => {
try {
await this.initQrCode();
} catch (e) {
console.warn(`Cannot provide QR Code scanning: ${e}`);
}
}, 500);
}}
>
<LeakAdd />
</IconButton>
</Tooltip>
</TableCell>
</TableRow>
))}
Expand Down Expand Up @@ -967,8 +975,10 @@ class Controller extends Component<ComponentProps, ComponentState> {
if (!this.state.nodes) {
return null;
}

return <div style={{ width: '100%' }}>
<DeviceManager
ref={this.refDeviceManager}
title={I18n.t('Commitment devices')}
socket={this.props.socket}
selectedInstance={`${this.props.adapterName}.${this.props.instance}`}
Expand Down
3 changes: 2 additions & 1 deletion src-admin/src/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"Collapse all": "Alles einklappen",
"Commissioning information": "Informationen zur Inbetriebnahme",
"Configure custom device": "Benutzerdefiniertes Gerät konfigurieren",
"Connected": "In Verbindung gebracht",
"Connect": "Verbinden",
"Connected": "Verbunden",
"Controller": "Controller",
"Copied to clipboard": "In die Zwischenablage kopiert",
"Default bridge": "Standard-Bridge",
Expand Down
1 change: 1 addition & 0 deletions src-admin/src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"Collapse all": "Collapse all",
"Commissioning information": "Commissioning information",
"Configure custom device": "Configure custom device",
"Connect": "Connect",
"Connected": "Connected",
"Controller": "Controller",
"Copied to clipboard": "Copied to clipboard",
Expand Down
1 change: 1 addition & 0 deletions src-admin/src/i18n/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"Collapse all": "Desplegar todo",
"Commissioning information": "Información de puesta en servicio",
"Configure custom device": "Configurar dispositivo personalizado",
"Connect": "Conectar",
"Connected": "Conectado",
"Controller": "Controlador",
"Copied to clipboard": "Copiado al portapapeles",
Expand Down
1 change: 1 addition & 0 deletions src-admin/src/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"Collapse all": "Tout réduire",
"Commissioning information": "Informations de mise en service",
"Configure custom device": "Configurer un appareil personnalisé",
"Connect": "Connecter",
"Connected": "Connecté",
"Controller": "Manette",
"Copied to clipboard": "Copié dans le presse-papier",
Expand Down
1 change: 1 addition & 0 deletions src-admin/src/i18n/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"Collapse all": "Comprimi tutto",
"Commissioning information": "Informazioni sulla messa in servizio",
"Configure custom device": "Configura dispositivo personalizzato",
"Connect": "Collegare",
"Connected": "Collegato",
"Controller": "Controllore",
"Copied to clipboard": "Copiato negli appunti",
Expand Down
1 change: 1 addition & 0 deletions src-admin/src/i18n/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"Collapse all": "Alles inklappen",
"Commissioning information": "Inbedrijfstellingsinformatie",
"Configure custom device": "Configureer een aangepast apparaat",
"Connect": "Aansluiten",
"Connected": "Verbonden",
"Controller": "Controleur",
"Copied to clipboard": "Gekopieerd naar het klembord",
Expand Down
1 change: 1 addition & 0 deletions src-admin/src/i18n/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"Collapse all": "Zwinąć wszystkie",
"Commissioning information": "Informacje o uruchomieniu",
"Configure custom device": "Skonfiguruj urządzenie niestandardowe",
"Connect": "Łączyć",
"Connected": "Połączony",
"Controller": "Kontroler",
"Copied to clipboard": "Skopiowane do schowka",
Expand Down
1 change: 1 addition & 0 deletions src-admin/src/i18n/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"Collapse all": "Recolher todos",
"Commissioning information": "Informações de comissionamento",
"Configure custom device": "Configurar dispositivo personalizado",
"Connect": "Conectar",
"Connected": "Conectado",
"Controller": "Controlador",
"Copied to clipboard": "Copiado para a área de transferência",
Expand Down
1 change: 1 addition & 0 deletions src-admin/src/i18n/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"Collapse all": "Свернуть все",
"Commissioning information": "Информация о вводе в эксплуатацию",
"Configure custom device": "Настройка пользовательского устройства",
"Connect": "Соединять",
"Connected": "Связанный",
"Controller": "Контроллер",
"Copied to clipboard": "Скопировано в буфер обмена",
Expand Down
1 change: 1 addition & 0 deletions src-admin/src/i18n/uk.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"Collapse all": "Закрити все",
"Commissioning information": "Інформація про введення в експлуатацію",
"Configure custom device": "Налаштувати спеціальний пристрій",
"Connect": "Підключитися",
"Connected": "Підключено",
"Controller": "Контролер",
"Copied to clipboard": "Скопійовано в буфер обміну",
Expand Down
1 change: 1 addition & 0 deletions src-admin/src/i18n/zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"Collapse all": "全部收缩",
"Commissioning information": "调试信息",
"Configure custom device": "配置自定义设备",
"Connect": "连接",
"Connected": "连接的",
"Controller": "控制器",
"Copied to clipboard": "已复制到剪贴板",
Expand Down

0 comments on commit c9fb631

Please sign in to comment.