Skip to content

Commit

Permalink
add more types
Browse files Browse the repository at this point in the history
  • Loading branch information
MiRo1310 committed Sep 28, 2024
1 parent 982f6e0 commit f7c84c1
Show file tree
Hide file tree
Showing 70 changed files with 387 additions and 363 deletions.
84 changes: 27 additions & 57 deletions admin/app.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { GenericAppProps, GenericAppState } from "@iobroker/adapter-react-v5";
import { Tab } from '@mui/material';
import { AdminConnection } from '@iobroker/socket-client';
import { LegacyRef, ReactNode } from "react";

export type Nullable<T> = T | null | undefined;

Expand Down Expand Up @@ -32,22 +33,7 @@ export interface AdditionalStateInfo extends GenericAppState {
}

export interface PropsSettings {
data: {
state: {
native: {
instance: string;
textNoEntry: string;
tokenGrafana: string;
directory: string;
checkbox: {
[key: string]: boolean;
};
};
};

instances: string[];
checkbox: Object;
};
data: DataMainContent;
callback: CallbackFunctionsApp;
}

Expand Down Expand Up @@ -79,10 +65,10 @@ export interface TabValues {
searchRoot?: SearchRoot | null;
}

interface PopupCard {
export interface PopupCard {
buttons: PopupCardButtons, width: string, height: string
}
interface PopupCardButtons {
export interface PopupCardButtons {
add?: boolean;
remove?: boolean;
copy?: boolean;
Expand All @@ -92,6 +78,7 @@ export interface SearchRoot {
root: string;
type: ObjectBrowserType | ObjectBrowserType[] | undefined;
}
export type ObjectBrowserType = any
export interface TabValueEntries {
name: string;
width?: string;
Expand All @@ -108,7 +95,7 @@ export interface TabValueEntries {
password?: boolean;
type?: string;
}
type UpdateNative = {
export type UpdateNative = {
updateNative: UpdateNativeFunction;
};
export interface SetState {
Expand All @@ -124,10 +111,8 @@ export interface PropsTableDndNav {
callback: CallbackFunctionsApp;
}

interface ActionData {
[key: string]: Actions
}
interface NavData {

export interface NavData {
[key: string]: RowsNav[];
}

Expand Down Expand Up @@ -166,7 +151,7 @@ export interface Data {
}

export type UsersInGroup = { [key: string]: string[] };
type socket = AdminConnection;
export type socket = AdminConnection;

export interface StateTabAction {
value: string;
Expand Down Expand Up @@ -203,7 +188,7 @@ export interface ButtonProps {
className?: string;
children?: ReactNode;
}
type CallbackValue = boolean | string | number | undefined;
export type CallbackValue = boolean | string | number | undefined;

export interface PropsCheckbox {
id: string;
Expand All @@ -220,7 +205,6 @@ export interface PropsCheckbox {
marginTop?: string;
class?: string;
}
type BooleanString = "true" | "false";

export interface PropsRowNavCard {
entries: TabValueEntries[];
Expand Down Expand Up @@ -254,7 +238,7 @@ export interface SelectProps {
width?: string;
callbackValue?: CallbackValue;
}
type UpdateNativeFunction = (key: string, value?: any, cb?: () => void) => void;
export type UpdateNativeFunction = (key: string, value?: any, cb?: () => void) => void;
export interface InputProps {
id: string;
type?: string;
Expand Down Expand Up @@ -304,7 +288,7 @@ export interface StateHelperCard {
showSelectId: boolean;
selectedId: string;
}
type SetStateFunction = React.Component["setState"];
export type SetStateFunction = React.Component["setState"];
export interface PropsTextarea {
id: string;
value: string;
Expand All @@ -331,25 +315,18 @@ export interface StateTextarea {
value: string;
}
export interface PropsActionCard {
data: DataMainContent & { tab: TabValues }
card: string;
showButtons: ShowButtons;
data: DataMainContent & TabActionContentTableProps
callback: CallbackFunctionsApp;
}
interface ShowButtons {
add: boolean;
remove: boolean;
edit: boolean;
moveUp: boolean;
moveDown: boolean;
}
export interface TabActionContentTableProps { tab: TabValues; card: string; showButtons: ShowButtons; }

export interface StateActionCard {
rowPopup: boolean;
rowIndex: number;
editRow: boolean;
newRow: any;
rowsLength: number;
newUnUsedTrigger: any;
newUnUsedTrigger: string[] | null;
helperText: boolean;
helperTextFor: string;
editedValueFromHelperText: any;
Expand All @@ -362,12 +339,10 @@ export interface StateActionCard {
helperTextForInput: string;
}
export interface PropsTableDndAction {
data: DataMainContent & { tab: TabValues }
showButtons: ShowButtons;
data: DataMainContent & TabActionContentTableProps
callback: CallbackFunctionsApp & CallbackTabActionContent & TabActionContentCallback;
card: string;
}
interface TabActionContentCallback {
export interface TabActionContentCallback {
addEditedTrigger: (trigger: string | null) => void;
openAddRowCard: (index: number) => void;
}
Expand Down Expand Up @@ -438,16 +413,10 @@ export interface StatePopupContainer {
inUse: boolean;
}
export interface PropsRowEditPopupCard {
entries: TabValueEntries[];
newRow: ActionNewRowProps;
data: Data;
openHelperText: (value: any) => void;
subCard: string;
searchRoot: SearchRoot | null | undefined;
buttons: PopupCardButtons;
newUnUsedTrigger: string[];
callback: CallbackFunctionsApp & CallbackTabActionContent;
data: DataMainContent & TabActionContentTableProps & DataTabActionContent
callback: CallbackFunctionsApp & CallbackTabActionContent & { openHelperText: (value: any) => void }
}
export interface DataTabActionContent { newRow: ActionNewRowProps; newUnUsedTrigger: string[]; }

export interface CallbackTabActionContent {
setStateTabActionContent: SetStateFunction;
Expand Down Expand Up @@ -582,7 +551,6 @@ export interface StateSquare {
export interface PropsHeaderTelegramUsers {
callback: CallbackFunctionsApp;
data: { state: AdditionalStateInfo, activeMenu: string, usersInGroup: UsersInGroup, userActiveCheckbox: UserActiveCheckbox };
menuPopupOpen: boolean;
}
export interface StateHeaderTelegramUsers {
menuOpen: boolean;
Expand Down Expand Up @@ -735,7 +703,8 @@ export interface PropsMainDropBox {
data: DataDropBox;
}
export interface DataDropBox {
dropBoxRef: React.RefObject<unknown>, state: AdditionalStateInfo
dropBoxRef: LegacyRef<HTMLDivElement> | undefined,
state: AdditionalStateInfo
}
export interface PropsTableNavHeader {
entries: TabValueEntries[];
Expand All @@ -747,10 +716,11 @@ export interface PropsTableNavHelper {
data: Data;
popupHelperCard: (isOkay: boolean) => void;
}

export interface PropsActionEditHeader {
entries: TabValueEntries[];
buttons: PopupCardButtons
tab: TabValues
}

export interface PropsButtonCard {
showButtons: ShowButtons;
openAddRowCard: (index: number) => void;
Expand All @@ -774,7 +744,7 @@ export interface TabListingType {
value: string;
}

interface RowForButton {
export interface RowForButton {
trigger: string;
parse_mode: string[];
[key: string]: any;
Expand Down
172 changes: 86 additions & 86 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.

3 changes: 2 additions & 1 deletion admin/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ import { AdditionalPropInfo, AdditionalStateInfo, Native, Nullable, TriggerObjec
import React from "react";
import { getDefaultDropBoxCoordinates } from "./lib/dragNDrop";
import { getDoubleEntries, getFirstItem as getFirstObjectKey } from "./lib/object";
import { LegacyRef } from "react";

class App extends GenericApp<AdditionalPropInfo, AdditionalStateInfo> {
dropBoxRef: React.RefObject<unknown>;
dropBoxRef: LegacyRef<HTMLDivElement> | undefined;
constructor(props) {
const extendedProps = {
...props,
Expand Down
4 changes: 2 additions & 2 deletions admin/src/lib/actionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,15 @@ export const deleteRow = (index, props, array, setState, rowElements): void => {
saveRows(props, setState, rowElements, newRow);
};

export const moveItem = (index, props, array, setState, rowElements, val): void => {
export const moveItem = (index, props, array, setState, val): void => {
const newRow = deepCopy(props.newRow);
array.forEach((element) => {
if (element.name !== "trigger") {
newRow[element.name].splice(index + val, 0, newRow[element.name].splice(index, 1)[0]);
}
});
props.callback.setState({ newRow: newRow });
saveRows(props, setState, rowElements, newRow);
saveRows(props, setState, array, newRow);
};

export const updateId = (selected, props, indexID, setState, rowElements, ID): void => {
Expand Down
4 changes: 4 additions & 0 deletions admin/src/lib/string.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
export function replaceSpaceWithUnderscore(menu: string): string {
return menu.replace(/ /g, "_");
}

export function isTruthy(value: string | number | boolean): boolean {
return !!value;
}
1 change: 0 additions & 1 deletion admin/src/pages/AppContentHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class MainActions extends Component<PropsMainActions> {
activeMenu: this.props.data.state.activeMenu,
}}
callback={this.props.callback}
menuPopupOpen={this.props.data.state.popupMenuOpen}
/>
) : null}
</Grid>
Expand Down
4 changes: 1 addition & 3 deletions admin/src/pages/AppContentHeaderTelegramUsers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,10 @@ class HeaderTelegramUsers extends Component<PropsHeaderTelegramUsers, StateHeade
const usersInGroup = this.props.data.usersInGroup;
if (this.state.menuChecked || val) {
if (usersInGroup && usersInGroup[this.props.data.activeMenu] && usersInGroup[this.props.data.activeMenu].length <= 0) {
// TelegramUserCard.jsx setzt zurück
this.setState({ errorUserChecked: true });
return false;
} else {
return true;
}
return true;
}
};

Expand Down
9 changes: 1 addition & 8 deletions admin/src/pages/AppContentTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,7 @@ class Tabs extends Component<PropsMainTabs> {
<TabAction data={this.props.data} callback={this.props.callback} />
</TabPanel>
<TabPanel value="settings">
<Settings
data={{
instances: this.props.data.state.instances,
state: this.props.data.state,
checkbox: this.props.data.state.native.checkbox,
}}
callback={this.props.callback}
/>
<Settings data={this.props.data} callback={this.props.callback} />
</TabPanel>
</>
);
Expand Down
4 changes: 1 addition & 3 deletions admin/src/pages/AppContentTabAction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ class TabAction extends Component<PropsTabAction, StateTabAction> {
<TabPanel key={index} value={tab.value} className="TabPanel-Action">
<AppContentTabActionContent
callback={this.props.callback}
data={{ ...this.props.data, tab }}
card="action"
showButtons={{ add: true, remove: true, edit: true }}
data={{ ...this.props.data, tab, card: "action", showButtons: { add: true, remove: true, edit: true } }}
/>
</TabPanel>
))}
Expand Down
Loading

0 comments on commit f7c84c1

Please sign in to comment.