Skip to content

Commit

Permalink
Showed latest/stable labels by updating/downgrading of adapters: #2833
Browse files Browse the repository at this point in the history
  • Loading branch information
GermanBluefox committed Dec 21, 2024
1 parent aa9159a commit f6788af
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 14 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ The icons may not be reused in other projects without the proper flaticon licens
<!--
### **WORK IN PROGRESS**
-->
### **WORK IN PROGRESS**

- (@GermanBluefox) Show latest/stable labels by updating/downgrading of adapters
- (@GermanBluefox) Corrected selection of chinese language

### 7.4.7 (2024-12-12)

- (@GermanBluefox) Corrected the rendering of custom JSON config components
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ import AdapterInstallDialog, {
import AutoUpgradeConfigDialog, { ICONS } from '@/dialogs/AutoUpgradeConfigDialog';

import IsVisible from '../IsVisible';
import { extractUrlLink } from './Utils';
import { extractUrlLink, type RepoInfo } from './Utils';
import sentryIcon from '../../assets/sentry.svg';

export const genericStyles: Record<string, any> = {
Expand Down Expand Up @@ -136,7 +136,12 @@ export const genericStyles: Record<string, any> = {
fontWeight: 'bold',
marginLeft: '4px',
}),
repoVersionText: (theme: IobTheme) => ({
repoStableVersionText: (theme: IobTheme) => ({
color: theme.palette.mode === 'dark' ? '#8dff7a' : '#2b9800',
fontWeight: 'bold',
marginLeft: '4px',
}),
repoLatestVersionText: (theme: IobTheme) => ({
color: theme.palette.mode === 'dark' ? '#a3fcff' : '#005498',
fontWeight: 'bold',
marginLeft: '4px',
Expand Down Expand Up @@ -676,6 +681,7 @@ export default abstract class AdapterGeneric<
onUpdate={version =>
this.setState({ showUpdateDialog: false, showDialog: false }, () => this.update(version))
}
isStable={(this.props.context.repository._repoInfo as unknown as RepoInfo).stable}
onIgnore={ignoreVersion =>
this.setState({ showUpdateDialog: false, showDialog: false }, () =>
this.props.context.socket
Expand Down Expand Up @@ -724,8 +730,16 @@ export default abstract class AdapterGeneric<
if (!this.state.showInstallVersion) {
return null;
}

const repoVersion = this.props.context.repository[this.props.adapterName]?.version;
let stableVersion: string;
let latestVersion: string;
const repoInfo: RepoInfo = this.props.context.repository._repoInfo as unknown as RepoInfo;
if (repoInfo?.stable) {
stableVersion = this.props.context.repository[this.props.adapterName]?.version;
latestVersion = this.props.context.repository[this.props.adapterName]?.latestVersion;
} else {
stableVersion = this.props.context.repository[this.props.adapterName]?.stable;
latestVersion = this.props.context.repository[this.props.adapterName]?.version;
}

return (
<CustomModal
Expand Down Expand Up @@ -838,11 +852,19 @@ export default abstract class AdapterGeneric<
sx={this.styles.currentVersionText}
>{`(${this.props.context.t('current')})`}</Box>
) : null}
{repoVersion === version ? (
{latestVersion === version ? (
<Box
component="span"
sx={this.styles.repoLatestVersionText}
>
(latest)
</Box>
) : null}
{stableVersion === version ? (
<Box
component="span"
sx={this.styles.repoVersionText}
>{`(${this.props.context.t('repository')})`}</Box>
sx={this.styles.repoStableVersionText}
>{`(${this.props.context.t('stable')})`}</Box>
) : null}
</Typography>
<Typography
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { I18n, type IobTheme, Utils } from '@iobroker/adapter-react-v5';

import type { AdapterRatingInfo, InstalledInfo } from '@/components/Adapters/AdapterInstallDialog';
import { checkCondition } from '@/dialogs/AdapterUpdateDialog';
import type { RepoAdapterObject } from '@/components/Adapters/Utils';
import type { RepoAdapterObject, RepoInfo } from '@/components/Adapters/Utils';

interface GetNewsResultEntry {
version: string;
Expand Down Expand Up @@ -88,6 +88,16 @@ const styles: Record<string, any> = {
fontWeight: 'bold',
color: theme.palette.mode === 'dark' ? 'black' : 'white',
}),
repoStableVersionText: (theme: IobTheme) => ({
color: theme.palette.mode === 'dark' ? '#8dff7a' : '#2b9800',
fontWeight: 'bold',
marginLeft: '4px',
}),
repoLatestVersionText: (theme: IobTheme) => ({
color: theme.palette.mode === 'dark' ? '#a3fcff' : '#005498',
fontWeight: 'bold',
marginLeft: '4px',
}),
};

interface AdaptersUpdaterProps {
Expand Down Expand Up @@ -333,6 +343,17 @@ class AdaptersUpdater extends Component<AdaptersUpdaterProps, AdaptersUpdaterSta
fromVersion = fromVersion || installed.version;
const result: JSX.Element[] = [];

let stableVersion: string;
let latestVersion: string;
const repoInfo: RepoInfo = this.props.repository._repoInfo as unknown as RepoInfo;
if (repoInfo?.stable) {
stableVersion = this.props.repository[adapter]?.version;
latestVersion = this.props.repository[adapter]?.latestVersion;
} else {
stableVersion = this.props.repository[adapter]?.stable;
latestVersion = this.props.repository[adapter]?.version;
}

if (installed && adapterObj?.news) {
Object.keys(adapterObj.news).forEach(version => {
try {
Expand All @@ -355,7 +376,23 @@ class AdaptersUpdater extends Component<AdaptersUpdaterProps, AdaptersUpdaterSta

result.push(
<Grid2 key={version}>
<Typography sx={styles.versionHeader}>{version}</Typography>
<Typography sx={styles.versionHeader}>
{version}
{latestVersion === version ? (
<Box
component="span"
sx={styles.repoLatestVersionText}
>
(latest)
</Box>
) : null}
{stableVersion === version ? (
<Box
component="span"
sx={styles.repoStableVersionText}
>{`(${I18n.t('stable')})`}</Box>
) : null}
</Typography>
{news.map((value, index) => (
<Typography
key={`${version}-${index}`}
Expand Down
13 changes: 13 additions & 0 deletions packages/admin/src-admin/src/components/Adapters/Utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
export interface RepoInfo {
stable?: boolean;
name?: ioBroker.Translated;
repoTime: string;
recommendedVersions?: {
nodeJsAccepted: number[];
nodeJsRecommended: number;
npmRecommended: number;
};
}

export interface RepoAdapterObject extends ioBroker.AdapterCommon {
versionDate: string;
controller?: boolean;
Expand All @@ -8,6 +19,8 @@ export interface RepoAdapterObject extends ioBroker.AdapterCommon {
allowAdapterDelete?: boolean;
allowAdapterReadme?: boolean;
allowAdapterRating?: boolean;
stable?: string;
latestVersion?: string;
}

export function extractUrlLink(adapterRepo: RepoAdapterObject): string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
} from '@iobroker/adapter-react-v5';

import type HostsWorker from '@/Workers/HostsWorker';
// eslint-disable-next-line no-duplicate-imports
import { type NotificationAnswer } from '@/Workers/HostsWorker';
import AdapterUpdateDialog, { type News } from '@/dialogs/AdapterUpdateDialog';
import JsControllerUpdater from '@/dialogs/JsControllerUpdater';
Expand Down
42 changes: 39 additions & 3 deletions packages/admin/src-admin/src/dialogs/AdapterUpdateDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import semver from 'semver';
import moment from 'moment';

import {
Box,
Button,
Dialog,
DialogActions,
Expand Down Expand Up @@ -127,6 +128,16 @@ const styles: Record<string, any> = {
dialogPaper: {
maxWidth: 880,
},
repoStableVersionText: (theme: IobTheme) => ({
color: theme.palette.mode === 'dark' ? '#8dff7a' : '#2b9800',
fontWeight: 'bold',
marginLeft: '4px',
}),
repoLatestVersionText: (theme: IobTheme) => ({
color: theme.palette.mode === 'dark' ? '#a3fcff' : '#005498',
fontWeight: 'bold',
marginLeft: '4px',
}),
};

export interface Message {
Expand Down Expand Up @@ -348,6 +359,7 @@ interface AdapterUpdateDialogProps {
textInstruction?: string;
instances?: Record<string, CompactInstanceInfo>;
theme: IobTheme;
isStable?: boolean;
}

interface AdapterUpdateDialogState {
Expand Down Expand Up @@ -457,6 +469,18 @@ class AdapterUpdateDialog extends Component<AdapterUpdateDialogProps, AdapterUpd
getNews(): JSX.Element[] {
const result: JSX.Element[] = [];

let stableVersion: string | undefined;
let latestVersion: string | undefined;
if (this.props.isStable !== undefined) {
if (this.props.isStable) {
stableVersion = this.props.adapterObject.version;
latestVersion = this.props.adapterObject.latestVersion;
} else {
stableVersion = this.props.adapterObject.stable;
latestVersion = this.props.adapterObject.version;
}
}

this.props.news?.forEach(entry => {
const news: string[] = (entry.news ? entry.news.split('\n') : [])
.map((line: string) =>
Expand All @@ -482,13 +506,25 @@ class AdapterUpdateDialog extends Component<AdapterUpdateDialogProps, AdapterUpd
<Grid2 key={entry.version}>
<Typography sx={styles.version}>
{entry.version}
{latestVersion && latestVersion === entry.version ? (
<Box
component="span"
sx={styles.repoLatestVersionText}
>
(latest)
</Box>
) : null}
{stableVersion && stableVersion === entry.version ? (
<Box
component="span"
sx={styles.repoStableVersionText}
>{`(${I18n.t('stable')})`}</Box>
) : null}
{this.props.adapterObject?.version === entry.version ? (
<span style={styles.versionTime}>
({moment(this.props.adapterObject.versionDate).fromNow()})
</span>
) : (
''
)}
) : null}
</Typography>
{news.map((value, index) => (
<Typography
Expand Down
2 changes: 1 addition & 1 deletion packages/admin/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -951,8 +951,8 @@ class Admin extends Adapter {
async updateNews(): Promise<void> {
if (this.timerNews) {
clearTimeout(this.timerNews);
this.timerNews = null;
}
this.timerNews = null;

this.checkNodeJsVersion().catch(e => this.log.warn(`Cannot check node.js versions: ${e}`));

Expand Down

0 comments on commit f6788af

Please sign in to comment.