moved cleanupundefined
moved tags
This commit is contained in:
1 parent
27314be9a8
commit
5d9c04072b
6 files changed
+51
-35
No files matched your search
@@ -0,0 +1,36 @@
|
||||
import { FC } from "react";
|
||||
|
||||
import DeleteIcon from "@mui/icons-material/ClearTwoTone";
|
||||
|
||||
import { cleanUpUndefined } from "utils/helpers";
|
||||
|
||||
export type TagsProps = {
|
||||
tags: Record<string, string>;
|
||||
onUpdate: (t: Record<string, string>) => void;
|
||||
};
|
||||
|
||||
export const Tags: FC<TagsProps> = ({ tags, onUpdate }) => {
|
||||
return (
|
||||
<div className="metadatabox--tags">
|
||||
{Object.entries(tags).map(([tagName, tagValue]) => (
|
||||
<span key={tagName} className="tag">
|
||||
<DeleteIcon
|
||||
onClick={() =>
|
||||
onUpdate(
|
||||
cleanUpUndefined({
|
||||
...tags,
|
||||
[tagName]: undefined,
|
||||
})
|
||||
)
|
||||
}
|
||||
className="delete-tag"
|
||||
/>
|
||||
<b>{tagName}</b>: {tagValue}
|
||||
</span>
|
||||
))}
|
||||
<span className="tag-add" onClick={() => {}}>
|
||||
+
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -4,14 +4,14 @@ import { FC } from "react";
|
||||
import Switch from "@mui/material/Switch";
|
||||
import Alert from "@mui/material/Alert";
|
||||
|
||||
import DeleteIcon from "@mui/icons-material/ClearTwoTone";
|
||||
import DeleteForeverIcon from "@mui/icons-material/DeleteForever";
|
||||
import SelectIcon from "@mui/icons-material/HighlightAltSharp";
|
||||
|
||||
import { InputTextView } from "components/Inputs/InputTextView";
|
||||
import { ButtonIcon } from "components/Icons/ButtonIcons";
|
||||
import { cleanUpUndefined } from "components/NodeEditor/OptionManager/OptionManager";
|
||||
import { cleanUpUndefined } from "utils/helpers";
|
||||
import { AutomationListAuto } from "../types";
|
||||
import { Tags } from "./Tags";
|
||||
|
||||
export type MetadataBoxProps = AutomationListAuto & {
|
||||
onDelete: () => void;
|
||||
@@ -57,27 +57,7 @@ export const MetadataBox: FC<MetadataBoxProps> = (props) => {
|
||||
value={props.description}
|
||||
onChange={props.onDescriptionUpdate}
|
||||
/>
|
||||
<div className="metadatabox--tags">
|
||||
{Object.entries(props.tags).map(([tagName, tagValue]) => (
|
||||
<span key={tagName} className="tag">
|
||||
<DeleteIcon
|
||||
onClick={() =>
|
||||
props.onTagUpdate(
|
||||
cleanUpUndefined({
|
||||
...props.tags,
|
||||
[tagName]: undefined,
|
||||
})
|
||||
)
|
||||
}
|
||||
className="delete-tag"
|
||||
/>
|
||||
<b>{tagName}</b>: {tagValue}
|
||||
</span>
|
||||
))}
|
||||
<span className="tag-add" onClick={() => {}}>
|
||||
+
|
||||
</span>
|
||||
</div>
|
||||
<Tags tags={props.tags} onUpdate={props.onTagUpdate} />
|
||||
{props.issue ? (
|
||||
<Alert severity="warning" className="issue">
|
||||
{props.issue}
|
||||
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
import { InputDevice } from "components/Inputs/InputDevice";
|
||||
import { InputDeviceCapabilties } from "components/Inputs/InputDeviceCapabilties";
|
||||
import { InputEntity } from "components/Inputs/InputEntities";
|
||||
import { cleanUpUndefined } from "components/NodeEditor/OptionManager/OptionManager";
|
||||
import { cleanUpUndefined } from "utils/helpers";
|
||||
import { DeviceBaseType, DeviceTypeCapability } from "haService/types";
|
||||
import { AutomationDeviceState } from "types/automations/common";
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import { HAEntitiesState } from "haService/HAEntities";
|
||||
import { FC } from "react";
|
||||
import { AutomationAction } from "types/automations/actions";
|
||||
import { AutomationCondition } from "types/automations/conditions";
|
||||
import { cleanUpUndefined } from "utils/helpers";
|
||||
export type OptionManager<T> = {
|
||||
defaultState(): T;
|
||||
isReady(s: T): boolean;
|
||||
@@ -24,16 +25,6 @@ export type OptionManager<T> = {
|
||||
}
|
||||
);
|
||||
|
||||
export const cleanUpUndefined = (data: Record<string, any>): any => {
|
||||
const clean: any = {};
|
||||
Object.keys(data).forEach((k) => {
|
||||
if (data[k] !== undefined && data[k] !== null) {
|
||||
clean[k] = data[k];
|
||||
}
|
||||
});
|
||||
return clean;
|
||||
};
|
||||
|
||||
export const updateConditionData =
|
||||
<T extends AutomationCondition>(setState: (s: T) => void) =>
|
||||
(state: T, data: Partial<T>) =>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import "./index.css";
|
||||
|
||||
import { cleanUpUndefined } from "components/NodeEditor/OptionManager/OptionManager";
|
||||
import { cleanUpUndefined } from "utils/helpers";
|
||||
import { TypedHassService } from "haService/fieldTypes";
|
||||
import { FC, useState } from "react";
|
||||
import {
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
export const cleanUpUndefined = (data: Record<string, any>): any => {
|
||||
const clean: any = {};
|
||||
Object.keys(data).forEach((k) => {
|
||||
if (data[k] !== undefined && data[k] !== null) {
|
||||
clean[k] = data[k];
|
||||
}
|
||||
});
|
||||
return clean;
|
||||
};
|
||||
Reference in new issue
Block a user