Skip to content

Commit

Permalink
Correcting close&save button: ioBroker/ioBroker.matter#310
Browse files Browse the repository at this point in the history
  • Loading branch information
GermanBluefox committed Jan 15, 2025
1 parent c3a1add commit 92060dc
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 18 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ The icons may not be reused in other projects without the proper flaticon licens
### **WORK IN PROGRESS**

- (@GermanBluefox) Extended DM with device type
- (@GermanBluefox) Corrected Save&Close button for the instance configs

### 7.4.12 (2025-01-11)

Expand Down
5 changes: 3 additions & 2 deletions packages/adapter-react-v5/src/GenericApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -803,8 +803,9 @@ export class GenericApp<
// ignore
}

this.setState({ changed: false });
isClose && GenericApp.onClose();
this.setState({ changed: false }, () => {
isClose && GenericApp.onClose();
});
})
.catch(e => console.error(`Cannot save configuration: ${e}`));
}
Expand Down
35 changes: 20 additions & 15 deletions packages/admin/src-admin/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,6 @@ interface AppState {
drawerState: 0 | 1 | 2;
editMenuList: boolean;
tab: any;
allStored: boolean;
dataNotStoredDialog: boolean;
dataNotStoredTab: {
tab: string;
Expand Down Expand Up @@ -488,6 +487,8 @@ interface AppState {
class App extends Router<AppProps, AppState> {
private readonly translations: Record<ioBroker.Languages, Record<string, string>>;

private _tempAllStored = true;

/** Seconds before logout to show warning */
private readonly EXPIRE_WARNING_THRESHOLD: number = 120;

Expand Down Expand Up @@ -610,8 +611,9 @@ class App extends Router<AppProps, AppState> {
get: () => this.state.configNotSaved,
set: configNotSaved => {
const allStored = !configNotSaved;
if (allStored !== this.state.allStored) {
this.setState({ allStored });
if (allStored !== this._tempAllStored) {
this._tempAllStored = allStored;
this.forceUpdate();
}
},
configurable: true,
Expand Down Expand Up @@ -655,7 +657,6 @@ class App extends Router<AppProps, AppState> {
editMenuList: false,

tab: null,
allStored: true,
dataNotStoredDialog: false,
dataNotStoredTab: null,

Expand Down Expand Up @@ -2202,7 +2203,7 @@ class App extends Router<AppProps, AppState> {

handleNavigation = (tab: string, subTab?: string, param?: string): void => {
if (tab) {
if (this.state.allStored) {
if (this._tempAllStored) {
Router.doNavigate(tab, subTab, param);

this.setState({ currentTab: Router.getLocation() });
Expand All @@ -2224,20 +2225,21 @@ class App extends Router<AppProps, AppState> {
};

allStored(value: boolean): void {
this.setState({
allStored: value,
});
if (this._tempAllStored !== value) {
this._tempAllStored = value;
this.forceUpdate();
}
}

closeDataNotStoredDialog(): void {
this.setState({ dataNotStoredDialog: false });
}

confirmDataNotStored(): void {
this._tempAllStored = true;
this.setState(
{
dataNotStoredDialog: false,
allStored: true,
},
() =>
this.handleNavigation(
Expand Down Expand Up @@ -2475,6 +2477,9 @@ class App extends Router<AppProps, AppState> {
}

renderDialogConfirm(): JSX.Element | null {
if (!this.state.dataNotStoredDialog) {
return null;
}
/* return <DialogConfirm
onClose={() => this.closeDataNotStoredDialog()}
open={this.state.dataNotStoredDialog}
Expand All @@ -2484,15 +2489,15 @@ class App extends Router<AppProps, AppState> {
>
{I18n.t('Some data are not stored. Discard?')}
</DialogConfirm>; */
return this.state.dataNotStoredDialog ? (
return (
<DialogConfirm
title={I18n.t('Please confirm')}
text={I18n.t('Some data are not stored. Discard?')}
ok={I18n.t('Ok')}
cancel={I18n.t('Cancel')}
title={I18n.t('ra_Please confirm')}
text={I18n.t('ra_Some data are not stored. Discard?')}
ok={I18n.t('ra_Discard')}
cancel={I18n.t('ra_Cancel')}
onClose={(isYes: boolean) => (isYes ? this.confirmDataNotStored() : this.closeDataNotStoredDialog())}
/>
) : null;
);
}

renderExpertDialog(): JSX.Element | null {
Expand Down
2 changes: 1 addition & 1 deletion packages/admin/src-admin/src/tabs/Intro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1500,7 +1500,7 @@ class Intro extends React.Component<IntroProps, IntroState> {
hostData && typeof hostData === 'object'
? Object.keys(hostData).reduce(
(acom: string, item: string) =>
`${acom}${this.t(item)}:${formatInfo[item] ? formatInfo[item](hostData[item] as number, this.t) : (typeof hostData[item] === 'object' ? JSON.stringify(hostData[item]) : hostData[item] as string) || '--'}\n`,
`${acom}${this.t(item)}:${formatInfo[item] ? formatInfo[item](hostData[item] as number, this.t) : (typeof hostData[item] === 'object' ? JSON.stringify(hostData[item]) : (hostData[item] as string)) || '--'}\n`,
)
: '',
};
Expand Down

0 comments on commit 92060dc

Please sign in to comment.