Skip to content

Commit

Permalink
Fixed license link (#2558)
Browse files Browse the repository at this point in the history
Better typing in discovery dialog
  • Loading branch information
GermanBluefox authored Jul 22, 2024
1 parent 2e2ea8f commit 454fcd0
Show file tree
Hide file tree
Showing 37 changed files with 870 additions and 514 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ The icons may not be reused in other projects without the proper flaticon licens
### **WORK IN PROGRESS**
* (bluefox) Corrected export from JSON table
* (foxriver76) added `qrCode` component to JSON config
* (bluefox) Corrected adding of adapters with licenses (other than MIT)
* (bluefox) Improved license dialog

### 7.0.17 (2024-07-15)
* (bluefox) Corrected the CRON description
Expand Down
459 changes: 290 additions & 169 deletions package-lock.json

Large diffs are not rendered by default.

34 changes: 17 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,22 @@
"@esbuild-plugins/node-globals-polyfill": "^0.2.3",
"@fnando/sparkline": "^0.3.10",
"@honkhonk/vite-plugin-svgr": "^1.1.0",
"@iobroker/adapter-react-v5": "^6.1.1",
"@iobroker/adapter-react-v5": "^6.1.5",
"@iobroker/admin-component-easy-access": "^1.0.1",
"@iobroker/dm-utils": "^0.3.0",
"@iobroker/js-controller-common-db": "^6.0.8",
"@iobroker/dm-utils": "^0.3.1",
"@iobroker/js-controller-common-db": "^6.0.9",
"@iobroker/legacy-testing": "^1.0.12",
"@iobroker/socket-client": "^2.4.18",
"@iobroker/testing": "^4.1.3",
"@iobroker/types": "6.0.8",
"@iobroker/types": "6.0.9",
"@mui/icons-material": "^5.16.4",
"@mui/lab": "5.0.0-alpha.172",
"@mui/material": "^5.16.4",
"@mui/x-data-grid": "^7.10.0",
"@mui/x-date-pickers": "^7.10.0",
"@mui/x-data-grid": "^7.11.0",
"@mui/x-date-pickers": "^7.11.0",
"@originjs/vite-plugin-commonjs": "^1.0.3",
"@react-leaflet/core": "^2.1.0",
"@sentry/browser": "^8.18.0",
"@sentry/browser": "^8.19.0",
"@sentry/integrations": "^7.114.0",
"@testing-library/jest-dom": "^6.4.6",
"@testing-library/react": "^16.0.0",
Expand Down Expand Up @@ -90,7 +90,7 @@
"eslint-plugin-jsx-a11y": "^6.9.0",
"eslint-plugin-only-warn": "^1.1.0",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-react": "^7.34.4",
"eslint-plugin-react": "^7.35.0",
"eslint-plugin-react-hooks": "^4.6.2",
"gulp": "^4.0.2",
"gulp-clean-css": "^4.3.0",
Expand All @@ -105,7 +105,7 @@
"leaflet-geosearch": "^4.0.0",
"lerna": "^8.1.6",
"lodash": "^4.17.21",
"mocha": "^10.6.0",
"mocha": "^10.7.0",
"moment": "^2.30.1",
"ol": "^9.2.4",
"prettier": "^3.3.3",
Expand Down Expand Up @@ -139,10 +139,10 @@
"typescript": "^5.5.3"
},
"optionalDependencies": {
"@nx/nx-darwin-arm64": "19.5.0",
"@nx/nx-darwin-x64": "19.5.0",
"@nx/nx-linux-x64-gnu": "19.5.0",
"@nx/nx-win32-x64-msvc": "19.5.0"
"@nx/nx-darwin-arm64": "19.5.1",
"@nx/nx-darwin-x64": "19.5.1",
"@nx/nx-linux-x64-gnu": "19.5.1",
"@nx/nx-win32-x64-msvc": "19.5.1"
},
"overrides": {
"react-sortable-hoc": {
Expand All @@ -153,10 +153,10 @@
"string-width": "4.2.3",
"strip-ansi": "6.0.1",
"wrap-ansi": "7.0.0",
"@nx/nx-darwin-arm64": "19.5.0",
"@nx/nx-darwin-x64": "19.5.0",
"@nx/nx-linux-x64-gnu": "19.5.0",
"@nx/nx-win32-x64-msvc": "19.5.0"
"@nx/nx-darwin-arm64": "19.5.1",
"@nx/nx-darwin-x64": "19.5.1",
"@nx/nx-linux-x64-gnu": "19.5.1",
"@nx/nx-win32-x64-msvc": "19.5.1"
}
},
"scripts": {
Expand Down
5 changes: 3 additions & 2 deletions packages/admin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@
"devDependencies": {
"@iobroker/dm-gui-components": "file:../dm-gui-components",
"@iobroker/json-config": "file:../jsonConfig",
"@iobroker/types": "^6.0.8",
"@types/ace": "^0.0.52"
"@iobroker/types": "^6.0.9",
"@types/ace": "^0.0.52",
"mocha": "^10.7.0"
},
"bugs": {
"url": "https://github.com/ioBroker/ioBroker.admin/issues"
Expand Down
2 changes: 1 addition & 1 deletion packages/admin/src-admin/public/css/adapter.css.map

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

32 changes: 18 additions & 14 deletions packages/admin/src-admin/src/components/Adapters/AdapterGeneric.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ import AdapterInstallDialog, {
type AdaptersContext,
} from '@/components/Adapters/AdapterInstallDialog';
import AutoUpgradeConfigDialog from '@/dialogs/AutoUpgradeConfigDialog';
import sentryIcon from '../../assets/sentry.svg';

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

export const genericStyles: Record<string, any> = {
hidden: {
Expand Down Expand Up @@ -344,9 +346,10 @@ export default abstract class AdapterGeneric<TProps extends AdapterGenericProps,
// eslint-disable-next-line react/no-unused-class-component-methods
renderLicenseInfo() {
const adapter = this.props.context.repository[this.props.adapterName];
const link = extractUrlLink(adapter);

return <Link
href={adapter.licenseInformation?.link}
href={link}
target="_blank"
rel="noopener"
sx={{ color: 'black', '&:hover': { color: 'black' } }}
Expand Down Expand Up @@ -770,18 +773,19 @@ export default abstract class AdapterGeneric<TProps extends AdapterGenericProps,

onUpload() {
const adapter = this.props.context.repository[this.props.adapterName];
// @ts-expect-error licenseUrl is deprecated
let url = adapter.licenseUrl || adapter.licenseInformation?.link || adapter.extIcon || '';
if (url.includes('/main')) {
url = `${url.split('/main')[0]}/main/LICENSE`;
} else {
url = `${url.split('/master')[0]}/master/LICENSE`;
}

const license = adapter.licenseInformation?.license || adapter.license;

if (license !== 'MIT') {
this.setState({ showLicenseDialog: { url, upload: true, adapterName: this.props.adapterName }, showDialog: true });
const url = extractUrlLink(adapter);
const licenseType = adapter.licenseInformation?.license || adapter.license;

if (licenseType !== 'MIT') {
this.setState({
showLicenseDialog: {
url,
upload: true,
adapterName: this.props.adapterName,
licenseType,
},
showDialog: true,
});
} else {
this.upload(this.props.adapterName, this.props.context);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ import {
import {
checkCondition,
type CompactInstanceInfo,
type RepoAdapterObject,
} from '@/dialogs/AdapterUpdateDialog';

import AddInstanceDialog, { type AdapterDependencies } from '@/dialogs/AddInstanceDialog';
import LicenseDialog from '@/dialogs/LicenseDialog';
import type { AdapterInformation } from '@iobroker/js-controller-common-db/build/esm/lib/common/tools';
import type InstancesWorker from '@/Workers/InstancesWorker';
import type HostsWorker from '@/Workers/HostsWorker';
import type { RatingDialogRepository } from '@/dialogs/RatingDialog';
import { extractUrlLink, type RepoAdapterObject } from './Utils';

export type AdapterRating = {
rating?: { r: number; c: number };
Expand Down Expand Up @@ -83,6 +84,7 @@ export interface AdapterInstallDialogProps {
export interface AdapterInstallDialogState {
showLicenseDialog: {
url: string;
licenseType: string;
upload?: boolean;
adapterName: string;
} | null;
Expand Down Expand Up @@ -111,6 +113,7 @@ export default abstract class AdapterInstallDialog<TProps extends AdapterInstall
}

return <LicenseDialog
licenseType={this.state.showLicenseDialog.licenseType}
url={this.state.showLicenseDialog.url}
onClose={result => {
if (result) {
Expand Down Expand Up @@ -321,22 +324,14 @@ export default abstract class AdapterInstallDialog<TProps extends AdapterInstall
// eslint-disable-next-line react/no-unused-class-component-methods
onAddInstance(adapterName: string, context: AdaptersContext) {
const adapter = context.repository[adapterName];
// @ts-expect-error licenseUrl is deprecated
let url = adapter.licenseUrl ||
adapter.licenseInformation?.link || adapter.extIcon || '';
if (url.includes('/main')) {
url = `${url.split('/main')[0]}/main/LICENSE`;
} else {
url = `${url.split('/master')[0]}/master/LICENSE`;
}

const license = adapter.licenseInformation?.license || adapter.license;
const url = extractUrlLink(adapter);
const licenseType = adapter.licenseInformation?.license || adapter.license;

if (license === 'MIT') {
if (licenseType === 'MIT') {
this.addInstance({ adapterName, context })
.catch(e => window.alert(`Cannot add instance: ${e}`));
} else {
this.setState({ showLicenseDialog: { url, adapterName }, showDialog: true });
this.setState({ showLicenseDialog: { url, adapterName, licenseType }, showDialog: true });
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class AdapterRow extends AdapterGeneric<AdapterGenericProps, AdapterGenericState
{this.renderVersion()}
</Grid>
</TableCell>
<TableCell>{adapter?.licenseInformation?.license || adapter?.license}</TableCell>
<TableCell style={{ fontSize: 'smaller' }}>{adapter?.licenseInformation?.license || adapter?.license}</TableCell>
<TableCell>
{this.renderAddInstanceButton()}
{this.renderAutoUpgradeButton()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import {
import { I18n, type IobTheme, Utils } from '@iobroker/adapter-react-v5';

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

interface GetNewsResultEntry {
version: string;
Expand Down
47 changes: 47 additions & 0 deletions packages/admin/src-admin/src/components/Adapters/Utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
export interface RepoAdapterObject extends ioBroker.AdapterCommon {
versionDate: string;
controller?: boolean;
stat?: number;
node?: string;
allowAdapterInstall?: boolean;
allowAdapterUpdate?: boolean;
allowAdapterDelete?: boolean;
allowAdapterReadme?: boolean;
allowAdapterRating?: boolean;
}

export function extractUrlLink(adapterRepo: RepoAdapterObject): string {
if (!adapterRepo) {
return '';
}
let url = adapterRepo.licenseInformation?.link ||
// @ts-expect-error licenseUrl is deprecated
adapterRepo.licenseUrl;

if (!url || !url.includes('/LICENSE') || !url.includes('raw.githubusercontent.com')) {
url = adapterRepo.extIcon;
if (!url) {
// @ts-expect-error fixed in types of js-controller
url = adapterRepo.readme;
if (!url) {
console.error(`No extIcon for ${adapterRepo.name}`);
return '';
}
url = url.replace('github.com', 'raw.githubusercontent.com').replace('/blob/', '/');
if (url.includes('/main')) {
url = `${url.split('/main')[0]}/main/LICENSE`;
} else if (url.includes('/master')) {
url = `${url.split('/master')[0]}/master/LICENSE`;
}
}
if (url.includes('/main')) {
url = `${url.split('/main')[0]}/main/LICENSE`;
} else if (url.includes('/master')) {
url = `${url.split('/master')[0]}/master/LICENSE`;
} else {
return '';
}
}

return url;
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ import {

import type HostsWorker from '@/Workers/HostsWorker';
import { type NotificationAnswer } from '@/Workers/HostsWorker';
import AdapterUpdateDialog, { type RepoAdapterObject } from '@/dialogs/AdapterUpdateDialog';
import AdapterUpdateDialog from '@/dialogs/AdapterUpdateDialog';
import JsControllerUpdater from '@/dialogs/JsControllerUpdater';
import JsControllerDialog from '@/dialogs/JsControllerDialog';
import BaseSettingsDialog from '@/dialogs/BaseSettingsDialog';
import { CONTROLLER_CHANGELOG_URL } from '@/helpers/utils';
import type { RepoAdapterObject } from '@/components/Adapters/Utils';
import AdminUtils from '../../AdminUtils';
import HostEdit from './HostEdit';
import CustomModal from '../CustomModal';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import {

import {
Utils, withWidth, TableResize, type AdminConnection,
type IobTheme,
type IobTheme, type Translate,
} from '@iobroker/adapter-react-v5';

import { localeMap } from './utils';
Expand Down Expand Up @@ -209,7 +209,7 @@ const styles: Record<string, any> = {
type SupportedFeatures = ('insert' | 'update' | 'delete')[];

interface ObjectHistoryDataProps {
t: (...text: string[]) => string;
t: Translate;
lang: ioBroker.Languages;
expertMode: boolean;
socket: AdminConnection;
Expand Down
13 changes: 1 addition & 12 deletions packages/admin/src-admin/src/dialogs/AdapterUpdateDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
} from '@iobroker/adapter-react-v5';

import { MOBILE_WIDTH } from '@/helpers/MobileDialog';
import type { RepoAdapterObject } from '@/components/Adapters/Utils';

import State from '../components/State';

Expand Down Expand Up @@ -147,18 +148,6 @@ interface News {
news: string;
}

export interface RepoAdapterObject extends ioBroker.AdapterCommon {
versionDate: string;
controller?: boolean;
stat?: number;
node?: string;
allowAdapterInstall?: boolean;
allowAdapterUpdate?: boolean;
allowAdapterDelete?: boolean;
allowAdapterReadme?: boolean;
allowAdapterRating?: boolean;
}

export interface CompactInstanceInfo {
adminTab: ioBroker.AdapterCommon['adminTab'];
name: ioBroker.InstanceCommon['name'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ import {
type Translate,
} from '@iobroker/adapter-react-v5';

import type { RepoAdapterObject } from '@/dialogs/AdapterUpdateDialog';
import type { AdapterRatingInfo, InstalledInfo } from '@/components/Adapters/AdapterInstallDialog';
import type { RepoAdapterObject } from '@/components/Adapters/Utils';
import AdaptersUpdater from '../components/Adapters/AdaptersUpdater';
import Command from '../components/Command';

Expand Down
Loading

0 comments on commit 454fcd0

Please sign in to comment.