Skip to content

Commit

Permalink
further cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
foxriver76 committed Mar 12, 2024
1 parent 753bff7 commit 3b86b73
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 51 deletions.
5 changes: 3 additions & 2 deletions src/src/Toolbar/WidgetImportDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
import { useFocus } from '@/Utils';
import { store } from '@/Store';
import {
AnyWidgetId,
GroupWidget, GroupWidgetId, Project, Widget,
} from '@/types';
import CustomAceEditor from '../Components/CustomAceEditor';
Expand Down Expand Up @@ -59,7 +60,7 @@ const WidgetImportDialog = (props: WidgetImportDialogProps) => {
newWidgets[newKey] = widget;
if (widget.grouped && widget.groupid && newWidgets[widget.groupid]?.data?.members) {
// find group
const pos = (newWidgets[widget.groupid] as GroupWidget).data.members.indexOf(widget._id as string);
const pos = (newWidgets[widget.groupid] as GroupWidget).data.members.indexOf(widget._id as AnyWidgetId);
if (pos !== -1) {
(newWidgets[widget.groupid] as GroupWidget).data.members[pos] = newKey;
}
Expand All @@ -73,7 +74,7 @@ const WidgetImportDialog = (props: WidgetImportDialogProps) => {
if (!isGroup(newWidgets[wid]) && props.selectedGroup !== undefined) {
newWidgets[wid].grouped = true;
newWidgets[wid].groupid = props.selectedGroup;
(project[props.selectedView].widgets[props.selectedGroup] as GroupWidget).data.members.push(wid);
(project[props.selectedView].widgets[props.selectedGroup] as GroupWidget).data.members.push(wid as AnyWidgetId);
}
});

Expand Down
2 changes: 1 addition & 1 deletion src/src/Vis/Widgets/Basic/BasicBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default class BasicBar extends VisRxWidget<RxData> {
width: 200,
height: 130,
},
};
} as const;
}

/**
Expand Down
10 changes: 6 additions & 4 deletions src/src/Vis/Widgets/Basic/BasicFilterDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ import { Edit } from '@mui/icons-material';

import { I18n, Icon } from '@iobroker/adapter-react-v5';

import { GetRxDataFromWidget, RxRenderWidgetProps, RxWidgetInfo } from '@/types';
import {
GetRxDataFromWidget, RxRenderWidgetProps, RxWidgetInfo, WidgetData,
} from '@/types';
import VisRxWidget from '@/Vis/visRxWidget';
import { WidgetData } from '@/types';
import { RxWidgetInfoAttributesField, RxWidgetInfoCustomComponentProperties, RxWidgetInfoCustomComponentContext } from '@/allInOneTypes';
import { VisWidgetCommand } from '@/Vis/visBaseWidget';
import FiltersEditorDialog from './FiltersEditorDialog';
import { RxWidgetInfoAttributesField, RxWidgetInfoCustomComponentProperties, RxWidgetInfoCustomComponentContext } from "@/allInOneTypes";

// eslint-disable-next-line no-use-before-define
type RxData = GetRxDataFromWidget<typeof BasicFilterDropdown>
Expand Down Expand Up @@ -281,7 +283,7 @@ class BasicFilterDropdown extends VisRxWidget<RxData> {
}
}

onCommand(command: string): void {
onCommand(command: VisWidgetCommand): void {
if (command === 'changeFilter') {
// analyse filter
this.forceUpdate();
Expand Down
18 changes: 3 additions & 15 deletions src/src/Vis/Widgets/Basic/BasicIFrame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,9 @@ import { GetRxDataFromWidget, RxRenderWidgetProps } from '@/types';
import VisRxWidget from '@/Vis/visRxWidget';

// eslint-disable-next-line no-use-before-define
// type RxData = GetRxDataFromWidget<typeof BasicIFrame>

interface BasicIFrameData {
src: string;
refreshInterval: number;
refreshWithNoQuery: boolean;
noSandbox: boolean;
refreshOnViewChange: boolean;
refreshOnWakeUp: boolean;
scrollX: boolean;
scrollY: boolean;
seamless: boolean;
}
type RxData = GetRxDataFromWidget<typeof BasicIFrame>

export default class BasicIFrame extends VisRxWidget<BasicIFrameData> {
export default class BasicIFrame extends VisRxWidget<RxData> {
private refreshInterval: ReturnType<typeof setInterval> | null = null;

private readonly frameRef: React.RefObject<HTMLIFrameElement>;
Expand Down Expand Up @@ -96,7 +84,7 @@ export default class BasicIFrame extends VisRxWidget<BasicIFrameData> {
width: 600,
height: 320,
},
};
} as const;
}

async componentDidMount(): Promise<void> {
Expand Down
16 changes: 3 additions & 13 deletions src/src/Vis/Widgets/Basic/BasicImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,9 @@ import { GetRxDataFromWidget, RxRenderWidgetProps } from '@/types';
import VisRxWidget from '@/Vis/visRxWidget';

// eslint-disable-next-line no-use-before-define
// type RxData = GetRxDataFromWidget<typeof BasicImage>

interface BasicImageData {
src: string;
stretch: boolean;
refreshInterval: number;
refreshOnWakeUp: boolean;
refreshOnViewChange: boolean;
refreshWithNoQuery: boolean;
allowUserInteractions: boolean;
}
type RxData = GetRxDataFromWidget<typeof BasicImage>

export default class BasicImage extends VisRxWidget<BasicImageData> {
export default class BasicImage extends VisRxWidget<RxData> {
private refreshInterval: ReturnType<typeof setInterval> | null = null;

private readonly imageRef: React.RefObject<HTMLImageElement>;
Expand Down Expand Up @@ -85,7 +75,7 @@ export default class BasicImage extends VisRxWidget<BasicImageData> {
width: 200,
height: 130,
},
};
} as const;
}

async componentDidMount(): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion src/src/Vis/Widgets/Basic/BasicImage8.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export default class BasicImage8 extends VisRxWidget<RxData> {
},
],
}],
};
} as const;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/src/Vis/Widgets/Basic/BasicRedNumber.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export default class BasicRedNumber extends VisRxWidget<RxData> {
width: 52,
height: 30,
},
};
} as const;
}

/**
Expand Down Expand Up @@ -123,7 +123,7 @@ export default class BasicRedNumber extends VisRxWidget<RxData> {
top: 0,
left: 0,
zIndex: 0,
color: this.state.rxData.backgroundColor || 'red',
color: this.state.rxData.background || 'red',
}}
/>
<div
Expand Down Expand Up @@ -154,7 +154,7 @@ export default class BasicRedNumber extends VisRxWidget<RxData> {
borderColor: this.state.rxData.borderColor || 'white',
borderWidth: 3,
borderStyle: 'solid',
backgroundColor: this.state.rxData.backgroundColor || 'red',
backgroundColor: this.state.rxData.background || 'red',
minWidth: 21,
textAlign: 'center',
color: props.style.color || 'white',
Expand Down
18 changes: 9 additions & 9 deletions src/src/Vis/Widgets/Basic/BasicScreenResolution.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@ import React from 'react';
import { I18n } from '@iobroker/adapter-react-v5';

import {
RxRenderWidgetProps, VisLegacy,
RxWidgetState, RxWidgetProps, GetRxDataFromWidget,
RxRenderWidgetProps, VisLegacy, RxWidgetProps, GetRxDataFromWidget,
} from '@/types';
import VisRxWidget from '@/Vis/visRxWidget';
import VisRxWidget, { VisRxWidgetState } from '@/Vis/visRxWidget';

declare global {
interface Window {
vis: VisLegacy;
}
}

interface BasicScreenResolutionState extends RxWidgetState {
interface BasicScreenResolutionState extends VisRxWidgetState {
width: number;
height: number;
defaultView: string;
Expand All @@ -30,9 +29,11 @@ export default class BasicScreenResolution extends VisRxWidget<RxData, BasicScre
constructor(props: RxWidgetProps) {
// @ts-expect-error refactor types to extend from parent types
super(props);
const state = this.state;
state.width = document.documentElement.clientWidth;
state.height = document.documentElement.clientHeight;
this.state = {
...this.state,
width: document.documentElement.clientWidth,
height: document.documentElement.clientHeight,
};
this.essentialData = JSON.stringify(this.buildEssentialProjectData());
}

Expand Down Expand Up @@ -63,7 +64,7 @@ export default class BasicScreenResolution extends VisRxWidget<RxData, BasicScre
width: 170,
height: 75,
},
};
} as const;
}

async componentDidMount(): Promise<void> {
Expand Down Expand Up @@ -122,7 +123,6 @@ export default class BasicScreenResolution extends VisRxWidget<RxData, BasicScre
defaultView = window.vis.findNearestResolution();
}
this.setState({
// @ts-expect-error unknown error
width,
height,
defaultView,
Expand Down
2 changes: 1 addition & 1 deletion src/src/Vis/Widgets/Basic/BasicSvgShape.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export default class BasicSvgShape extends VisRxWidget<RxData> {
width: 100,
height: 100,
},
};
} as const;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/src/Vis/visRxWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export interface CustomWidgetProperties {
selectedWidget: AnyWidgetId;
}

interface VisRxWidgetState extends VisBaseWidgetState {
export interface VisRxWidgetState extends VisBaseWidgetState {
rxData: RxData;
values: VisRxWidgetStateValues;
visible?: boolean;
Expand Down
2 changes: 1 addition & 1 deletion src/src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -613,4 +613,4 @@ type GetRxDataFromVisAttrs<T extends Record<string, any>> = {
}

/** Infers the RxData from a given Widget */
type GetRxDataFromWidget<T extends { getWidgetInfo: () => Record<string, any> }> = GetRxDataFromVisAttrs<ReturnType<(T['getWidgetInfo'])>>
type GetRxDataFromWidget<T extends { getWidgetInfo: () => Record<string, any> }> = GetRxDataFromVisAttrs<ReturnType<(T['getWidgetInfo'])>>

0 comments on commit 3b86b73

Please sign in to comment.