Skip to content

Commit

Permalink
show important notifications above changelog, so user reads them on u… (
Browse files Browse the repository at this point in the history
#2374)

…pdate dialog

- closes #2331
  • Loading branch information
foxriver76 authored Feb 19, 2024
1 parent fc5002e commit 50cba00
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ The icons may not be reused in other projects without the proper flaticon licens
## Changelog
### **WORK IN PROGRESS**
* (foxriver76) adapters tab is now showing information from `licenseInformation`
* (foxriver76) show important notifications above changelog, so user reads them on update dialog

### 6.13.21 (2024-02-15)
* (foxriver76) do not crash when using the dropdown on multi edit custom settings
Expand Down
25 changes: 22 additions & 3 deletions packages/admin/src/src/components/Adapters/AdaptersUpdater.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,15 @@ interface AdaptersUpdaterState {
showNews: null | Record<string, any>;
}

interface UpdateAvailableCheckOptions {
/** The installed version */
oldVersion: string;
/** The repo version or new version */
newVersion: string;
/** Adapter name */
name: string;
}

class AdaptersUpdater extends Component<AdaptersUpdaterProps, AdaptersUpdaterState> {
private readonly updateAvailable: string[];

Expand Down Expand Up @@ -146,15 +155,22 @@ class AdaptersUpdater extends Component<AdaptersUpdaterProps, AdaptersUpdaterSta
}
}

static isUpdateAvailable(oldVersion: string, newVersion: string) {
static isUpdateAvailable(options: UpdateAvailableCheckOptions) {
const { oldVersion, newVersion, name } = options;

try {
return semver.gt(newVersion, oldVersion);
} catch (e) {
console.warn(`Cannot compare "${newVersion}" and "${oldVersion}"`);
console.warn(`Cannot compare "${newVersion}" and "${oldVersion}" of adapter ${name}`);
return false;
}
}

/**
* Get list of available adapter updates
* Admin and controller is filtered out
* and all adapters which have messages for this update are filtered out too
*/
detectUpdates(): string[] {
const updateAvailable: string[] = [];

Expand All @@ -165,12 +181,15 @@ class AdaptersUpdater extends Component<AdaptersUpdaterProps, AdaptersUpdaterSta
return;
}
if (_installed &&
this.props.repository[adapter].version &&
_installed.ignoreVersion !== this.props.repository[adapter].version &&
AdaptersUpdater.isUpdateAvailable(_installed.version, this.props.repository[adapter].version)
AdaptersUpdater.isUpdateAvailable({ oldVersion: _installed.version, newVersion: this.props.repository[adapter].version, name: adapter })
) {
// @ts-expect-error should be ok wait for ts port
if (!AdapterUpdateDialog.checkCondition(this.props.repository[adapter].messages, _installed.version, this.props.repository[adapter].version)) {
updateAvailable.push(adapter);
} else {
console.log(`Adapter ${adapter} is filtered out from update all functionality, because it has messages which need to be read before update`);
}
}
});
Expand Down
3 changes: 2 additions & 1 deletion packages/admin/src/src/dialogs/AdapterUpdateDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ class AdapterUpdateDialog extends Component {
spacing={2}
direction="column"
wrap="nowrap"
sx={{ marginBottom: 1 }}
>
{this.messages.map((message, i) => this.renderOneMessage(message, i))}
</Grid>;
Expand Down Expand Up @@ -490,6 +491,7 @@ class AdapterUpdateDialog extends Component {
</Typography>
</DialogTitle>
<DialogContent dividers>
{this.renderMessages()}
<Grid
container
direction="column"
Expand All @@ -514,7 +516,6 @@ class AdapterUpdateDialog extends Component {
</Grid>
</Grid> : this.t('No change log available')}
</Grid>
{this.renderMessages()}
</DialogContent>
<DialogActions className={classes.wrapperButton}>
{!!this.props.rightDependencies && this.props.onIgnore && version && <Button
Expand Down
8 changes: 5 additions & 3 deletions packages/admin/src/src/tabs/Adapters.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1450,7 +1450,7 @@ class Adapters extends Component {
installedVersion={installed?.version}
keywords={adapter.keywords}
name={cached.title}
license={adapter.licenseInformation.license || adapter.license}
license={adapter.licenseInformation?.license || adapter.license}
licenseInformation={adapter.licenseInformation}
updateAvailable={cached.updateAvailable}
version={adapter.version}
Expand Down Expand Up @@ -1767,7 +1767,7 @@ class Adapters extends Component {
installedFrom={installed?.installedFrom}
installedVersion={installed?.version}
keywords={adapter.keywords}
license={adapter.licenseInformation.license || adapter.license}
license={adapter.licenseInformation?.license || adapter.license}
licenseInformation={adapter.licenseInformation}
updateAvailable={cached.updateAvailable}
version={adapter.version}
Expand All @@ -1792,7 +1792,9 @@ class Adapters extends Component {
url = `${url.split('/master')[0]}/master/LICENSE`;
}

if (adapter.license === 'MIT') {
const license = adapter.licenseInformation?.license || adapter.license;

if (license === 'MIT') {
this.addInstance(value);
} else {
this.setState({ showLicenseDialog: { url, instance: value } });
Expand Down

0 comments on commit 50cba00

Please sign in to comment.