Skip to content

Commit

Permalink
Made visRxWidget generic
Browse files Browse the repository at this point in the history
  • Loading branch information
GermanBluefox committed Jul 20, 2024
1 parent 1649769 commit 2bf21b7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ See here: https://github.com/ioBroker/ioBroker.vis-2-widgets-react-template
-->

## Changelog
### 3.0.2 (2024-07-20)
### **WORK IN PROGRESS**
* (bluefox) Rewritten with typescript

### 2.0.2 (2024-07-10)
Expand Down
13 changes: 6 additions & 7 deletions src/visRxWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { I18n } from '@iobroker/adapter-react-v5';

import {
AnyWidgetId,
WidgetData,
WidgetStyle,
RxRenderWidgetProps,
VisRxWidgetStateValues,
Expand All @@ -21,7 +20,7 @@ import {
RxWidgetInfo,
RxWidgetInfoAttributesFieldWithType,
VisViewProps,
VisBaseWidgetProps, VisContext, Project, ViewCommand, ViewCommandOptions, VisLegacy, VisTheme,
VisBaseWidgetProps,
} from '@iobroker/types-vis-2';

const POSSIBLE_MUI_STYLES = [
Expand Down Expand Up @@ -53,15 +52,15 @@ const POSSIBLE_MUI_STYLES = [
'word-spacing',
];

interface VisRxWidgetState {
interface VisRxWidgetState<T extends { widgetTitle?: string }> {
values: VisRxWidgetStateValues;
data: WidgetData;
data: T;
style: WidgetStyle;
rxData: WidgetData;
rxData: T;
rxStyle: WidgetStyle;
}

class visRxWidget extends Component<VisBaseWidgetProps, VisRxWidgetState> {
class visRxWidget<T extends { widgetTitle?: string }> extends Component<VisBaseWidgetProps, VisRxWidgetState<T>> {
static POSSIBLE_MUI_STYLES = POSSIBLE_MUI_STYLES;

// eslint-disable-next-line no-unused-vars
Expand Down Expand Up @@ -303,7 +302,7 @@ class visRxWidget extends Component<VisBaseWidgetProps, VisRxWidgetState> {
Object.keys(this.state.data).forEach(dataKey => {
// do not use here \d instead of [0-9] as it will be wrong compiled
if (dataKey.match(new RegExp(`^${field.name}[0-9]*$`))) {
const oid = this.state.data[dataKey];
const oid = (this.state.data as Record<string, string>)[dataKey];
if (!this.linkContext.IDs.includes(oid)) {
this.linkContext.IDs.push(oid);
}
Expand Down

0 comments on commit 2bf21b7

Please sign in to comment.