Skip to content

Commit

Permalink
Fixed errors with Widget in Widget
Browse files Browse the repository at this point in the history
  • Loading branch information
GermanBluefox committed Apr 19, 2024
1 parent 787c39e commit 8251c32
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 35 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@devbookhq/splitter": "^1.4.2",
"@emotion/react": "^11.11.4",
"@emotion/styled": "^11.11.5",
"@iobroker/adapter-react-v5": "^4.13.4",
"@iobroker/adapter-react-v5": "^4.13.7",
"@iobroker/type-detector": "^3.0.5",
"@iobroker/types": "^5.0.19",
"@iobroker/vis-2-widgets-react-dev": "^1.0.5",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ import {

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

import { store, recalculateFields } from '@/Store';

import VisFormatUtils from '../../Vis/visFormatUtils';
import { store, recalculateFields } from '../../Store';

const styles = () => ({
dialog: {
Expand Down Expand Up @@ -117,10 +118,8 @@ class WidgetBindingField extends Component {
if (!oids) {
return false;
}
if (oids.find(it => it.token?.includes(':'))) {
return false;
}
return true;

return !oids.find(it => it.token?.includes(':'));
}

async calculateValue(value) {
Expand Down
37 changes: 12 additions & 25 deletions packages/iobroker.vis-2/src/src/Attributes/Widget/WidgetField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ declare global {
interface Window {
collectClassesValue: Record<string, ClassesValue>;
_: (word: string, ...args: any[]) => string;
jQuery: any;
}
}

Expand Down Expand Up @@ -170,8 +171,7 @@ function getStylesOptions(options: {
isFound = !attrs;
if (!isFound) {
isFound = !!attrs.find((attr: string) => {
// @ts-expect-error fixed later
const t: string | number = _internalList[style].attrs[attr] as string | number;
const t: string | number = (_internalList[style].attrs as Record<string, string | number>)[attr] as string | number;
return t || t === 0;
});
}
Expand Down Expand Up @@ -486,7 +486,7 @@ const WidgetField = (props: WidgetFieldProps) => {
if (Array.isArray(changeValue) || field.immediateChange) {
// apply immediately
applyValue(changeValue);
} else {
} else if (changeValue !== cachedValue) {
setCachedValue(changeValue);
cacheTimer.current && clearTimeout(cacheTimer.current);
cacheTimer.current = setTimeout(() => {
Expand Down Expand Up @@ -643,7 +643,6 @@ const WidgetField = (props: WidgetFieldProps) => {
if (typeof customLegacyComponent.button.code === 'function') {
customLegacyComponent.button.code(customLegacyComponent.button);
}
// @ts-expect-error fix later
const $button = window.jQuery(e.target);
$button.data('wdata', {
attr: field.name,
Expand Down Expand Up @@ -692,10 +691,8 @@ const WidgetField = (props: WidgetFieldProps) => {
customFilter = { common: { custom: '_dataSources' } };
} else if (
typeof field.filter === 'string' &&
// @ts-expect-error fix later
field.filter !== 'chart' &&
field.filter !== 'channel' &&
// @ts-expect-error fix later
field.filter !== 'device'
) {
// detect role
Expand Down Expand Up @@ -741,10 +738,8 @@ const WidgetField = (props: WidgetFieldProps) => {
onOk={selected => change(selected)}
onClose={() => setIdDialog(false)}
socket={props.socket}
// @ts-expect-error fix later
types={field.filter === 'chart' || field.filter === 'channel' || field.filter === 'device' ? [field.filter] as ObjectBrowserType[] : null}
filters={filters}
// @ts-expect-error fix later
expertMode={field.filter === 'chart' ? true : undefined}
customFilter={customFilter}
/> : null}
Expand Down Expand Up @@ -1218,28 +1213,27 @@ const WidgetField = (props: WidgetFieldProps) => {
options = window.vis ? window.vis.updateFilter() : [];
options.unshift('');
}
if (options[0] && typeof options === 'string') {
options = (options as PaletteFieldOptions[]).map(item => item.value);
}

return <Autocomplete
freeSolo
fullWidth
disabled={disabled}
placeholder={isDifferent ? t('different') : null}
// @ts-expect-error fix later
options={options || []}
options={options as string[] || []}
inputValue={value as string || ''}
value={value || ''}
onInputChange={(e, inputValue) => change(inputValue)}
onChange={(e, inputValue) => change(inputValue)}
classes={{ input: Utils.clsx(props.classes.clearPadding, props.classes.fieldContent) }}
// @ts-expect-error fix later
renderOption={field.name === 'font-family' || field.type === 'lc-font-family' ?
// @ts-expect-error fix later
(optionProps, option) => <div
renderOption={field.name === 'font-family' || field.name === 'lc-font-family' ?
(optionProps, option) => <li
style={{ fontFamily: option as string }}
{...optionProps}
>
{option}
</div> : null}
</li> : null}
renderInput={params => <TextField
variant="standard"
error={!!error}
Expand All @@ -1257,18 +1251,11 @@ const WidgetField = (props: WidgetFieldProps) => {
freeSolo
fullWidth
disabled={disabled}
// @ts-expect-error fix later
placeholder={isDifferent ? t('different') : null}
// placeholder={isDifferent ? t('different') : null}
options={options || []}
inputValue={value as string || ''}
value={value as string || ''}
onInputChange={(e, inputValue) => {
if (typeof inputValue === 'object' && inputValue) {
// @ts-expect-error fix later
inputValue = inputValue.type === 'view' ? inputValue.view : inputValue.folder.name;
}
change(inputValue);
}}
onInputChange={(e, inputValue) => change(inputValue)}
onChange={(e, inputValue) => {
if (typeof inputValue === 'object' && inputValue !== null) {
inputValue = inputValue.type === 'view' ? inputValue.view : inputValue.folder.name;
Expand Down
4 changes: 3 additions & 1 deletion packages/iobroker.vis-2/src/src/Editor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1204,7 +1204,9 @@ class Editor extends Runtime {
}, 200);
};

onFontsUpdate = fonts => this.setState({ fonts });
onFontsUpdate(fonts) {
this.setState({ fonts });
}

cssClone = (attr, cb) => {
if (this.visEngineHandlers[this.state.selectedView] && this.visEngineHandlers[this.state.selectedView].onStealStyle) {
Expand Down
3 changes: 1 addition & 2 deletions packages/iobroker.vis-2/src/src/Runtime.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,6 @@ class Runtime extends GenericApp {
await this.setStateAsync(newState);
};

onFontsUpdate = fonts => this.setState({ fonts });

showAlert(message, type) {
if (type !== 'error' && type !== 'warning' && type !== 'info' && type !== 'success') {
Expand Down Expand Up @@ -1035,7 +1034,7 @@ class Runtime extends GenericApp {
lockDragging={this.state.lockDragging}
disableInteraction={this.state.disableInteraction}
widgetHint={this.state.widgetHint}
onFontsUpdate={this.state.runtime ? null : this.onFontsUpdate}
onFontsUpdate={this.state.runtime ? null : fonts => this.onFontsUpdate(fonts)}
registerEditorCallback={this.state.runtime ? null : this.registerCallback}
themeType={this.state.themeType}
themeName={this.state.themeName}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import VisView from '@/Vis/visView';
import VisRxWidget, { VisRxWidgetState } from '../../visRxWidget';

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

interface BasicGroupState extends VisRxWidgetState {
mounted: boolean;
Expand Down
3 changes: 3 additions & 0 deletions packages/iobroker.vis-2/src/src/Vis/visEngine.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ class VisEngine extends React.Component {
this.props.setLoadingText && this.props.setLoadingText(null);
this.setState({ ready: true });
});

// update one time the fonts
this.props.onFontsUpdate && this.props.onFontsUpdate(this.fontNames);
}

static getCurrentPath() {
Expand Down

0 comments on commit 8251c32

Please sign in to comment.