Skip to content

Commit

Permalink
Disable Input when switch is active
Browse files Browse the repository at this point in the history
  • Loading branch information
MiRo1310 committed Sep 15, 2024
1 parent c65a517 commit 3fd7bd5
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 37 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"alexa",
"azul",
"csstype",
"dropbox",
"echart",
"Echart",
"echarts",
Expand Down
57 changes: 41 additions & 16 deletions admin/app.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { GenericAppProps, GenericAppState } from "@iobroker/adapter-react-v5";
import { Tab } from '@mui/material';

export interface AdditionalPropInfo extends GenericAppProps {
themeName: string;
Expand Down Expand Up @@ -57,7 +58,7 @@ export interface StateTabNavigation {
editedValueFromHelperText: string | null;
isOK: boolean;
helperText: boolean;
newRow: Nav;
newRow: RowsNav;
call: string;
nav: string;
text: string;
Expand Down Expand Up @@ -101,7 +102,7 @@ export interface SetState {

export interface PropsTableDndNav {
entries: NavEntries[];
tableData: Nav | undefined;
tableData: TableData | undefined;
card: string;
activeMenu?: string;
openAddRowCard: (value: any) => void;
Expand All @@ -111,13 +112,23 @@ export interface PropsTableDndNav {
callback: CallbackFunctions;
}

interface TableData {
[key: string]: RowsNav[];
}

export interface StateTableDndNav {
rows: Rows[];
rows: RowsNav[];
dropStart: number;
dropOver: number;
dropEnd: number;
mouseOverNoneDraggable: boolean;
}
export interface RowsNav {
call: string;
parse_mode: BooleanString;
text: string;
value: string;
}

export interface PropsTabAction {
callback: Callback;
Expand Down Expand Up @@ -195,7 +206,7 @@ type BooleanString = "true" | "false";

export interface PropsRowNavCard {
entries: NavEntries[];
newRow: Nav;
newRow: RowsNav;
callback: { onchange: (data: ChangeInputNav) => void };
inUse: boolean;
openHelperText: (value: string) => void;
Expand Down Expand Up @@ -242,6 +253,7 @@ export interface InputProps {
children?: ReactNode;
function?: string;
index?: number;
disabled?: boolean;
onMouseOver?: (e: any, setState: any) => void;
onMouseLeave?: (e: any, setState: any) => void;
setState?: SetStateFunction;
Expand Down Expand Up @@ -404,7 +416,7 @@ export interface StatePopupContainer {
}
export interface PropsRowEditPopupCard {
entries: any;
newRow: any;
newRow: ActionNewRowProps;
data: any;
openHelperText: any;
subCard: any;
Expand All @@ -413,8 +425,22 @@ export interface PropsRowEditPopupCard {
newUnUsedTrigger: any;
callback?: { setState: SetStateFunction };
}

export type BooleanString = "true" | "false";

export interface ActionNewRowProps {
IDs: string[];
ack: BooleanString[];
confirm: BooleanString[];
parse_mode: BooleanString[];
returnText: string[];
values: string[];
trigger: string[];
switch_checkbox: BooleanString[];

}
export interface StateRowEditPopupCard {
rows: Rows[];
rows: RowsSetState[];
trigger: string;
data: any;
showSelectId: boolean;
Expand All @@ -426,9 +452,15 @@ export interface StateRowEditPopupCard {
mouseOverNoneDraggable: boolean;
itemForID: string;
}
export interface Rows {
export interface RowsSetState {
IDs: string;
call?: string;
ack: ActionNewRowProps;
confirm: BooleanString;
parse_mode: BooleanString;
returnText: string;
values: string;
trigger: string;
switch_checkbox: BooleanString;
}

export interface AppState {
Expand Down Expand Up @@ -590,7 +622,7 @@ export interface Native {
}
export interface NativeData {
action: { [key: string]: Actions };
nav: { [key: string]: Nav };
nav: { [key: string]: RowsNav };
}
export interface Actions {
get: Get[];
Expand All @@ -608,13 +640,6 @@ export interface HttpRequest {
trigger: string[];
delay: string[];
}
export interface Nav {
// nav: string
call: string;
value: string;
text: string;
parse_mode: BooleanString;
}
export interface Set {
ack: BooleanString[];
confirm: BooleanString[];
Expand Down
14 changes: 7 additions & 7 deletions admin/build/index.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions admin/build/index.js.map

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion admin/src/components/btn-Input/input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class Input extends Component<InputProps> {
this.props.callback({ val: event.target.value, index: this.props.index, id: this.props.id });
}
};

getClassName = () => {};
render() {
const container = {
width: this.props.width ? this.props.width : "auto",
Expand All @@ -26,7 +28,7 @@ class Input extends Component<InputProps> {
fontSize: "16px",
border: "none",
borderColor: "transparent",
borderBottom: "1px solid #ccc",
borderBottom: "1px solid #ccc ",
};
const styleChildren = {
display: "inline",
Expand All @@ -42,6 +44,7 @@ class Input extends Component<InputProps> {
className="InputField noneDraggable"
placeholder={I18n.t(this.props.placeholder || "")}
value={this.props.value}
disabled={this.props.disabled}
onChange={this.onChangeHandler}
spellCheck={this.props.spellCheck ? this.props.spellCheck : false}
onMouseOver={this.props.onMouseOver ? (e) => this.props.onMouseOver?.(e, this.props.setState) : undefined}
Expand Down
8 changes: 8 additions & 0 deletions admin/src/pages/AppContentTabActionContentRowEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ class RowEditPopupCard extends Component<PropsRowEditPopupCard, StateRowEditPopu
}
};

disableInput = (name: string, index: number): boolean => {
if (this.state?.rows?.[index]?.switch_checkbox === "true" && name === "values") {
return true;
}
return false;
};

render() {
return (
<div className="Edit-Container">
Expand Down Expand Up @@ -157,6 +164,7 @@ class RowEditPopupCard extends Component<PropsRowEditPopupCard, StateRowEditPopu
callback={this.updateData}
callbackValue="event.target.value"
function="manual"
disabled={this.disableInput(entry.name, indexRow)}
type={entry.type}
inputWidth={
!entry.search || entry.name === "returnText" || entry.name === "text"
Expand Down
8 changes: 4 additions & 4 deletions admin/src/pages/AppContentTabNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import TableNavEditRow from "@/pages/AppContentTabNavigationTableRowEditor";
import TableNavHelper from "@/pages/AppContentTabNavigationTableHelper";

import { deepCopy } from "@/lib/Utils.js";
import { Nav, PropsTabNavigation, StateTabNavigation } from "admin/app";
import { RowsNav, PropsTabNavigation, StateTabNavigation } from "admin/app";

class TabNavigation extends Component<PropsTabNavigation, StateTabNavigation> {
constructor(props) {
Expand All @@ -21,7 +21,7 @@ class TabNavigation extends Component<PropsTabNavigation, StateTabNavigation> {
editedValueFromHelperText: null,
isOK: false,
helperText: false,
newRow: {} as Nav,
newRow: {} as RowsNav,
nav: "",
call: "",
text: "",
Expand Down Expand Up @@ -109,7 +109,7 @@ class TabNavigation extends Component<PropsTabNavigation, StateTabNavigation> {
if (value) {
this.setState({ rowIndex: value });
}
const obj = {} as Nav;
const obj = {} as RowsNav;
this.props.entries.forEach((entry) => {
obj[entry.name] = entry.val;
});
Expand Down Expand Up @@ -143,7 +143,7 @@ class TabNavigation extends Component<PropsTabNavigation, StateTabNavigation> {
setState={this.setState.bind(this)}
activeMenu={this.props.data.state.activeMenu}
entries={this.props.entries}
></TableNavBody>
/>
</Table>
</TableContainer>
{this.state.rowPopup ? (
Expand Down
14 changes: 8 additions & 6 deletions admin/src/pages/AppContentTabNavigationTableBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ import {
} from "@/lib/dragNDrop.js";
import { getElementIcon } from "@/lib/actionUtils.js";
import { I18n } from "@iobroker/adapter-react-v5";
import { PropsTableDndNav, Rows, StateTableDndNav } from "admin/app";
import { PropsTableDndNav, RowsSetState, StateTableDndNav, TableData } from "admin/app";

Check failure on line 18 in admin/src/pages/AppContentTabNavigationTableBody.tsx

View workflow job for this annotation

GitHub Actions / check-and-lint

'RowsSetState' is defined but never used
import { RowsNav } from "../../app";

function createData(entriesOfParentComponent, element) {
const obj: Rows = {} as Rows;
const obj: RowsNav = {} as RowsNav;
entriesOfParentComponent.forEach((entry) => {
obj[entry.name] = element[entry.name];
});
Expand All @@ -37,13 +38,14 @@ class TableDndNav extends Component<PropsTableDndNav, StateTableDndNav> {
};
}

getRows(nav, activeMenu) {
if (!nav) {
getRows(nav: TableData | undefined, activeMenu: string | undefined): void {
if (!nav || !activeMenu) {
return;
}

const elements = nav[activeMenu];
const rows: Rows[] = [];
if (elements === undefined) {
const rows: RowsNav[] = [];
if (!elements) {
return;
}
for (const entry of elements) {
Expand Down
6 changes: 6 additions & 0 deletions admin/src/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -743,13 +743,19 @@ input:focus {
outline: none;
}

input:disabled {
opacity: 0.3;
}

/* checkbox */
input[type="checkbox"] {
width: 20px;
height: 20px;
margin-bottom: 0;
vertical-align: text-bottom;
cursor: pointer !important;
}

input[type="checkbox"]:checked {
accent-color: rgb(33, 150, 243);
}
Expand Down

0 comments on commit 3fd7bd5

Please sign in to comment.