feat: feature/mvp-sprint-1 Added delete functionality
This commit is contained in:
parent
e8ec2b156b
commit
c3804ef93f
@ -126,6 +126,13 @@ export const ThingtimeProvider = (props: any): JSX.Element => {
|
|||||||
|
|
||||||
const setThingtime = React.useCallback(
|
const setThingtime = React.useCallback(
|
||||||
(path, value) => {
|
(path, value) => {
|
||||||
|
if (["thingtime", "tt"]?.includes(path)) {
|
||||||
|
if (value) {
|
||||||
|
set(value)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const newThingtime = thingtime
|
const newThingtime = thingtime
|
||||||
|
|
||||||
const paths = smarts.parsePropertyPath(path)
|
const paths = smarts.parsePropertyPath(path)
|
||||||
@ -163,6 +170,8 @@ export const ThingtimeProvider = (props: any): JSX.Element => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// TODO: make thingtime settable
|
||||||
|
|
||||||
newThingtime.thingtime = newThingtime
|
newThingtime.thingtime = newThingtime
|
||||||
newThingtime.tt = newThingtime
|
newThingtime.tt = newThingtime
|
||||||
|
|
||||||
@ -175,6 +184,8 @@ export const ThingtimeProvider = (props: any): JSX.Element => {
|
|||||||
|
|
||||||
smarts.setsmart(newThingtime, path, value)
|
smarts.setsmart(newThingtime, path, value)
|
||||||
|
|
||||||
|
console.log("nik set(newThingtime)", newThingtime)
|
||||||
|
|
||||||
set(newThingtime)
|
set(newThingtime)
|
||||||
},
|
},
|
||||||
[thingtime, set]
|
[thingtime, set]
|
||||||
|
@ -23,6 +23,8 @@ import { MagicInput } from "../MagicInput/MagicInput"
|
|||||||
import { Safe } from "../Safety/Safe"
|
import { Safe } from "../Safety/Safe"
|
||||||
import { useThingtime } from "./useThingtime"
|
import { useThingtime } from "./useThingtime"
|
||||||
|
|
||||||
|
import { getThing } from "~/smarts"
|
||||||
|
|
||||||
export const Thingtime = (props) => {
|
export const Thingtime = (props) => {
|
||||||
// TODO: Add a circular reference seen prop check
|
// TODO: Add a circular reference seen prop check
|
||||||
// and add button to expand circular reference
|
// and add button to expand circular reference
|
||||||
@ -123,6 +125,20 @@ export const Thingtime = (props) => {
|
|||||||
return ret
|
return ret
|
||||||
}, [props?.fullPath, props?.path, props?.thing])
|
}, [props?.fullPath, props?.path, props?.thing])
|
||||||
|
|
||||||
|
const parentPath = React.useMemo(() => {
|
||||||
|
const parentPath = fullPath.split(".").slice(0, -1).join(".")
|
||||||
|
|
||||||
|
if (!parentPath) {
|
||||||
|
return "thingtime"
|
||||||
|
}
|
||||||
|
|
||||||
|
return parentPath
|
||||||
|
}, [fullPath])
|
||||||
|
|
||||||
|
const parent = React.useMemo(() => {
|
||||||
|
return getThingtime(parentPath)
|
||||||
|
}, [parentPath, getThingtime])
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
console.log("thingtime changed in path", props?.fullPath)
|
console.log("thingtime changed in path", props?.fullPath)
|
||||||
createDependancies()
|
createDependancies()
|
||||||
@ -356,14 +372,15 @@ export const Thingtime = (props) => {
|
|||||||
|
|
||||||
const deleteValue = React.useCallback(() => {
|
const deleteValue = React.useCallback(() => {
|
||||||
// use parent path to clone parent object but without this key
|
// use parent path to clone parent object but without this key
|
||||||
const parentPath = fullPath.split(".").slice(0, -1).join(".")
|
|
||||||
const parent = getThingtime(parentPath)
|
|
||||||
const clone = { ...parent }
|
const clone = { ...parent }
|
||||||
|
|
||||||
delete clone[path]
|
delete clone[path]
|
||||||
|
|
||||||
|
console.log("nik parentPath", parentPath)
|
||||||
|
console.log("nik clone", clone)
|
||||||
|
|
||||||
setThingtime(parentPath, clone)
|
setThingtime(parentPath, clone)
|
||||||
}, [fullPath, path, getThingtime, setThingtime])
|
}, [path, parent, parentPath, setThingtime])
|
||||||
|
|
||||||
const atomicValue = React.useMemo(() => {
|
const atomicValue = React.useMemo(() => {
|
||||||
if (props?.edit) {
|
if (props?.edit) {
|
||||||
|
Loading…
Reference in New Issue
Block a user