Skip to content

Commit

Permalink
Removed TS warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
GermanBluefox committed Mar 13, 2024
1 parent 702eded commit 0b91c2f
Show file tree
Hide file tree
Showing 10 changed files with 211 additions and 95 deletions.
6 changes: 3 additions & 3 deletions src/src/Components/WizardHelpers.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
Whatshot,
Water,
Lock,
Window,
Window as WindowIcon,
Palette,
PlayArrowRounded,
Power,
Expand Down Expand Up @@ -46,8 +46,8 @@ const deviceIcons = {
volume: <VolumeUp />,
volumeGroup: <VolumeUp />,
weatherForecast: <WbSunny />,
window: <Window />,
windowTilt: <Window />,
window: <WindowIcon />,
windowTilt: <WindowIcon />,
};

const allObjects = async socket => {
Expand Down
8 changes: 4 additions & 4 deletions src/src/Vis/visContextMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ interface VisContextMenuProps {
interface VisMarketplaceProps {
language: ioBroker.Languages;
addPage?: boolean;
widget: { name: string; date: string; widget_id: string; image_id: string; };
installWidget: (widget: { name: string; date: string; widget_id: string; image_id: string; }) => Promise<void>;
widget: { name: string; date: string; widget_id: string; image_id: string };
installWidget: (widget: { name: string; date: string; widget_id: string; image_id: string }) => Promise<void>;
installedWidgets?: {id: string}[];
themeName: string;
onAdded?: () => void;
Expand All @@ -70,8 +70,8 @@ declare global {
VisMarketplace?: {
api: {
apiGetWidgetRevision(widgetId: string, id: string): Promise<any>;
},
default: React.Component<VisMarketplaceProps>
};
default: React.Component<VisMarketplaceProps>;
};
}
}
Expand Down
22 changes: 11 additions & 11 deletions src/src/Vis/visFormatUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
* Licensees may copy, distribute, display, and perform the work and make derivative works based on it only for noncommercial purposes.
* (Free for non-commercial use).
*/
import { extractBinding } from './visUtils';
import { type Moment } from 'moment';
import { deepClone } from '@/Utils/utils';
import {
VisLegacy, AnyWidgetId, WidgetData,
SingleWidget, GroupWidget, VisRxWidgetStateValues,
} from '@/types';
import { type Moment } from 'moment';

import { extractBinding } from './visUtils';

interface VisFormatUtilsProps {
vis: VisLegacy;
Expand Down Expand Up @@ -236,7 +237,7 @@ class VisFormatUtils {
if (!dateObj) {
return '';
}
let realDateObj: Date | undefined = undefined
let realDateObj: Date | undefined;
const type = typeof dateObj;
if (type === 'string') {
realDateObj = new Date(dateObj);
Expand Down Expand Up @@ -298,18 +299,17 @@ class VisFormatUtils {
return result;
}


/**
* Format given binding
*/
formatBinding(options: {
format: string,
view: string,
wid: AnyWidgetId,
widget: SingleWidget | GroupWidget,
widgetData: WidgetData,
values?: VisRxWidgetStateValues,
moment: any,
format: string;
view: string;
wid: AnyWidgetId;
widget: SingleWidget | GroupWidget;
widgetData: WidgetData;
values?: VisRxWidgetStateValues;
moment: any;
}): string {
const {
view, wid, widget, widgetData, moment,
Expand Down
12 changes: 6 additions & 6 deletions src/src/Vis/visLoadWidgets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,10 @@ function registerWidgetsLoadIndicator(cb: (process: number, max: number) => void

interface VisLoadComponentContext {
visWidgetsCollection: ioBroker.VisWidget;
countRef: { count: number, max: number };
countRef: { count: number; max: number };
dynamicWidgetInstance: ioBroker.InstanceObject;
i18nPrefix: string
// List of custom react components
i18nPrefix: string;
// List of custom React components
result: VisRxWidget<any>[];
}

Expand All @@ -138,7 +138,7 @@ function _loadComponentHelper(context: VisLoadComponentContext): Promise<void[]>
// result
const promises: Promise<void>[] = [];

for (let i: number = 0; i < context.visWidgetsCollection.components.length; i++) {
for (let i = 0; i < context.visWidgetsCollection.components.length; i++) {
((index: number, _visWidgetsCollection) => {
context.countRef.max++;

Expand Down Expand Up @@ -206,8 +206,8 @@ function getRemoteWidgets(socket: Connection, onlyWidgetSets?: false | string[])
if (visWidgetsCollection.components) {
((collection, instance) => {
try {
let i18nPrefix: string = '';
let i18nPromiseWait: Promise<void | null> | undefined = undefined;
let i18nPrefix = '';
let i18nPromiseWait: Promise<void | null> | undefined;

// 1. Load language file ------------------
// instance.common.visWidgets.i18n is deprecated
Expand Down
2 changes: 1 addition & 1 deletion src/src/Vis/visNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
} from '@mui/icons-material';

import { Utils, Icon } from '@iobroker/adapter-react-v5';
import { ViewSettings } from "@/types";
import { ViewSettings } from '@/types';

const MENU_WIDTH_FULL = 200;
const MENU_WIDTH_NARROW = 56;
Expand Down
10 changes: 4 additions & 6 deletions src/src/Vis/visRxWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { Connection, I18n, Icon } from '@iobroker/adapter-react-v5';

import {
Project, AnyWidgetId, RxWidgetInfo,
WidgetData, VisRxWidgetStateValues, RxWidgetInfoAttributes,
WidgetData, VisRxWidgetStateValues, RxWidgetInfoGroup,
StateID, RxWidgetInfoAttributesFieldSelectSimple,
} from '@/types';
import { deepClone, calculateOverflow } from '@/Utils/utils';
Expand Down Expand Up @@ -120,8 +120,6 @@ export interface VisRxWidgetState extends VisBaseWidgetState {
class VisRxWidget<TRxData extends Record<string, any>, TState extends Partial<VisRxWidgetState> = VisRxWidgetState> extends VisBaseWidget<VisRxWidgetState & TState & { rxData: TRxData }> {
static POSSIBLE_MUI_STYLES = POSSIBLE_MUI_STYLES;

static i18nPrefix: string | undefined;

private linkContext: {
IDs: string[];
bindings: Record<string, any>;
Expand Down Expand Up @@ -162,7 +160,7 @@ class VisRxWidget<TRxData extends Record<string, any>, TState extends Partial<Vi
const widgetAttrInfo: Record<string, any> = {};
// collect all attributes (only types)
if (Array.isArray(options.visAttrs)) {
options.visAttrs.forEach((group: RxWidgetInfoAttributes) =>
options.visAttrs.forEach((group: RxWidgetInfoGroup) =>
group.fields && group.fields.forEach(item => {
widgetAttrInfo[item.name] = { type: (item as RxWidgetInfoAttributesFieldSelectSimple).type || '' };
}));
Expand Down Expand Up @@ -433,10 +431,10 @@ class VisRxWidget<TRxData extends Record<string, any>, TState extends Partial<Vi
}
}

async componentWillUnmount() {
componentWillUnmount() {
if (this.linkContext.IDs.length) {
for (let i = 0; i < this.linkContext.IDs.length; i++) {
await this.props.context.socket.unsubscribeState(this.linkContext.IDs[i], this.onIoBrokerStateChanged);
this.props.context.socket.unsubscribeState(this.linkContext.IDs[i], this.onIoBrokerStateChanged);
}
}
super.componentWillUnmount();
Expand Down
33 changes: 14 additions & 19 deletions src/src/Vis/visUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ declare global {
}
}

function replaceGroupAttr(inputStr: string, groupAttrList: WidgetData): { doesMatch: boolean, newString: string } {
function replaceGroupAttr(inputStr: string, groupAttrList: WidgetData): { doesMatch: boolean; newString: string } {
let newString = inputStr;
let match = false;
// old style: groupAttr0, groupAttr1, groupAttr2, ...
Expand Down Expand Up @@ -82,7 +82,7 @@ function getWidgetGroup(views: Project, view: string, widget: AnyWidgetId): Grou
*/
function isIdBinding(
/** the possible assignment to check */
assignment: string
assignment: string,
): boolean {
return !!assignment.match(/^[\d\w_]+:\s?[-.\d\w_#]+$/);
}
Expand Down Expand Up @@ -171,8 +171,7 @@ function extractBinding(format: string): VisBinding[] | null {
}
}

// @ts-ignore
operations[0].arg.push({
(operations[0].arg as VisBindingOperationArgument[])?.push({
name: argParts[0].trim(),
visOid: _visOid,
systemOid: _systemOid,
Expand Down Expand Up @@ -427,7 +426,7 @@ function getUsedObjectIDsInWidget(views: Project, view: string, wid: AnyWidgetId
if (widget.groupid) {
const parentWidgetData = views[view].widgets[widget.groupid]?.data;
if (parentWidgetData) {
let newGroupData: GroupData | undefined = undefined;
let newGroupData: GroupData | undefined;

Object.keys(data).forEach(attr => {
if (typeof data[attr] === 'string') {
Expand Down Expand Up @@ -653,22 +652,13 @@ function getUsedObjectIDsInWidget(views: Project, view: string, wid: AnyWidgetId
store.dispatch(updateWidget({ viewId: view, widgetId: wid, data: widget }));
}

interface UsedObjectsResult {
IDs: [],
visibility: {},
bindings: {},
lastChanges: {},
signals: {},
byViews?: Record<string, string[]>;
}

function getUsedObjectIDs(views: Project, isByViews?: boolean): UsedObjectsResult | null {
function getUsedObjectIDs(views: Project, isByViews?: boolean): VisStateUsage | null {
if (!views) {
console.log('Check why views are not yet loaded!');
return null;
}

const linkContext: UsedObjectsResult = {
const linkContext: VisStateUsage = {
IDs: [],
visibility: {},
bindings: {},
Expand Down Expand Up @@ -743,7 +733,7 @@ function getUrlParameter(attr: string): string | true {
async function readFile(socket: Connection, id: string, fileName: string, withType?: boolean): Promise<string | { file: string; mimeType: string }> {
const file = await socket.readFile(id, fileName);
let mimeType = '';
let data: string = '';
let data = '';
if (typeof file === 'object') {
if (withType) {
if (file.mimeType) {
Expand Down Expand Up @@ -812,7 +802,12 @@ function parseDimension(field: string | number | null | undefined): { value: num
return result;
}

function findWidgetUsages(views: Project, view: string, widgetId: AnyWidgetId, _result: { view: string, wid: AnyWidgetId, attr: string }[]): { view: string, wid: AnyWidgetId, attr: string }[] {
function findWidgetUsages(
views: Project,
view: string,
widgetId: AnyWidgetId,
_result: { view: string; wid: AnyWidgetId; attr: string }[],
): { view: string; wid: AnyWidgetId; attr: string }[] {
if (view) {
_result = _result || [];
// search in specific view
Expand All @@ -833,7 +828,7 @@ function findWidgetUsages(views: Project, view: string, widgetId: AnyWidgetId, _
}

// search in all views
const result: { view: string, wid: AnyWidgetId, attr: string }[] = [];
const result: { view: string; wid: AnyWidgetId; attr: string }[] = [];
Object.keys(views).forEach(_view => _view !== '___settings' && findWidgetUsages(views, _view, widgetId, _result));
return result;
}
Expand Down
10 changes: 5 additions & 5 deletions src/src/Vis/visView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,9 @@ class VisView extends React.Component<VisViewProps, VisViewState> {

// @ts-expect-error it is a trick
if (this.refView.current?._originalParent) {
// @ts-ignore it is a trick
// @ts-expect-error it is a trick
this.refView.current._originalParent.appendChild(this.refView.current);
// @ts-ignore it is a trick
// @ts-expect-error it is a trick
this.refView.current._originalParent = null;
}

Expand Down Expand Up @@ -413,7 +413,7 @@ class VisView extends React.Component<VisViewProps, VisViewState> {
};
};

doubleClickOnView = (_e: React.MouseEvent<HTMLDivElement, MouseEvent>) => {
doubleClickOnView = () => {
if (this.props.editMode &&
this.props.selectedWidgets &&
this.props.selectedWidgets.length === 1 &&
Expand Down Expand Up @@ -878,7 +878,7 @@ class VisView extends React.Component<VisViewProps, VisViewState> {
if (onCommand) {
onCommand('include', _wid);
}
})
});
}
}
}
Expand Down Expand Up @@ -1979,7 +1979,7 @@ class VisView extends React.Component<VisViewProps, VisViewState> {
ref={this.refView}
id={`visview_${this.props.view.replace(/\s/g, '_')}`}
onMouseDown={!this.props.context.runtime ? e => this.props.editMode && this.mouseDownLocal && this.mouseDownLocal(e) : undefined}
onDoubleClick={this.props.context.runtime ? e => this.props.editMode && this.doubleClickOnView && this.doubleClickOnView(e) : undefined}
onDoubleClick={this.props.context.runtime ? () => this.props.editMode && this.doubleClickOnView && this.doubleClickOnView() : undefined}
style={style}
>
<style>{this.state.themeCode}</style>
Expand Down
Loading

0 comments on commit 0b91c2f

Please sign in to comment.