ywana-core8 0.0.831 → 0.0.833
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/db/db.json +3 -3
- package/dist/index.cjs +10 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.modern.js +10 -22
- package/dist/index.modern.js.map +1 -1
- package/dist/index.umd.js +10 -22
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/incubator/task-test.js +24 -12
- package/src/incubator/task.js +9 -15
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { useContext, useState } from "react"
|
2
2
|
import { Button } from "../html"
|
3
|
-
import { TaskContext, TaskContextProvider, TaskMonitor } from "./task"
|
3
|
+
import { TaskContext, TaskContextProvider, TaskMonitor, TASK_STATES } from "./task"
|
4
4
|
|
5
5
|
/**
|
6
6
|
* Task Example
|
@@ -35,11 +35,30 @@ const CreateTaskButton = (props) => {
|
|
35
35
|
const taskContext = useContext(TaskContext)
|
36
36
|
|
37
37
|
async function run() {
|
38
|
-
|
38
|
+
|
39
|
+
const listener = async (task, taskContext) => {
|
40
|
+
console.log("LISTENER FOR TASK: ", task)
|
41
|
+
|
42
|
+
if (task.percentage === 100) {
|
43
|
+
console.log("TASK COMPLETED: ", task)
|
44
|
+
taskContext.updateTask(Object.assign({}, task, { state: TASK_STATES.COMPLETED }))
|
45
|
+
taskContext.removeListener(task.id)
|
46
|
+
} else {
|
47
|
+
const percentage = task.percentage + 10 || 0
|
48
|
+
const nextTask = Object.assign({}, task, { percentage })
|
49
|
+
await taskContext.updateTask(nextTask)
|
50
|
+
}
|
51
|
+
|
52
|
+
}
|
53
|
+
|
54
|
+
await taskContext.createTask({
|
39
55
|
name: "TEST",
|
40
56
|
description: "Test Task " + Date.now(),
|
41
57
|
result: "OK",
|
42
|
-
|
58
|
+
percentage: 0
|
59
|
+
}, listener)
|
60
|
+
|
61
|
+
return
|
43
62
|
}
|
44
63
|
|
45
64
|
return (
|
@@ -50,20 +69,13 @@ const CreateTaskButton = (props) => {
|
|
50
69
|
|
51
70
|
const TaskTest = (props) => {
|
52
71
|
|
53
|
-
const taskListeners = {
|
54
|
-
"TEST": (task, taskContext) => {
|
55
|
-
console.log("LISTENER FOR TASK: ", task)
|
56
|
-
taskContext.updateTask(Object.assign({}, task, { percentage: task.percentage + 1 }))
|
57
|
-
}
|
58
|
-
}
|
59
|
-
|
60
72
|
const taskEditors = {
|
61
73
|
"TEST": (task) => <div>{task.description} {task.state}</div>,
|
62
74
|
}
|
63
75
|
|
64
76
|
return (
|
65
|
-
<TaskContextProvider host="http://localhost:
|
66
|
-
<TaskMonitor editors={taskEditors} from="2023-10-21"/>
|
77
|
+
<TaskContextProvider host="http://localhost:3000" frequency={1000}>
|
78
|
+
<TaskMonitor editors={taskEditors} from="2023-10-21" frequency={2000}/>
|
67
79
|
<CreateTaskButton />
|
68
80
|
</TaskContextProvider>
|
69
81
|
)
|
package/src/incubator/task.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import React, { useEffect, useContext, useState } from 'react'
|
2
2
|
import { CollectionAPI } from '../domain/CollectionAPI'
|
3
3
|
import { FORMATS, TYPES } from '../domain/ContentType'
|
4
|
-
import { LinearProgress, Header, DataTable, Icon,
|
4
|
+
import { LinearProgress, Header, DataTable, Icon, Chip } from '../html'
|
5
5
|
import "./task.css"
|
6
6
|
|
7
7
|
/**
|
@@ -78,10 +78,10 @@ export const TaskContextProvider = (props) => {
|
|
78
78
|
if (taskIDs.length === 0) return
|
79
79
|
for (let i = 0; i < taskIDs.length; i++) {
|
80
80
|
const taskID = taskIDs[i]
|
81
|
-
const
|
82
|
-
if (
|
81
|
+
const tsk = await task(taskID)
|
82
|
+
if (tsk) {
|
83
83
|
const listener = _listeners[taskID]
|
84
|
-
if (listener) listener(
|
84
|
+
if (listener) listener(tsk, value)
|
85
85
|
}
|
86
86
|
}
|
87
87
|
}, frequency)
|
@@ -94,6 +94,7 @@ export const TaskContextProvider = (props) => {
|
|
94
94
|
createTask,
|
95
95
|
updateTask,
|
96
96
|
removeTask,
|
97
|
+
listeners: _listeners,
|
97
98
|
addListener,
|
98
99
|
removeListener
|
99
100
|
};
|
@@ -148,22 +149,19 @@ export const TaskProgress = (props) => {
|
|
148
149
|
*/
|
149
150
|
export const TaskMonitor = (props) => {
|
150
151
|
|
151
|
-
const { title = "Task Monitor", filters = {}, editors } = props
|
152
|
+
const { title = "Task Monitor", filters = {}, editors, frequency = 5000 } = props
|
152
153
|
const context = useContext(TaskContext)
|
153
154
|
const [tasks = [], setTasks] = useState([])
|
154
|
-
const [from, setFrom ] = useState(props.from)
|
155
155
|
|
156
156
|
useEffect(() => {
|
157
157
|
refresh()
|
158
158
|
const interval = setInterval(() => {
|
159
159
|
refresh()
|
160
|
-
},
|
160
|
+
}, frequency)
|
161
161
|
return () => { clearInterval(interval) }
|
162
162
|
}, [])
|
163
163
|
|
164
164
|
async function refresh() {
|
165
|
-
if (from) filters["from"] = from
|
166
|
-
console.log("refresh", filters)
|
167
165
|
const tasks = await context.tasks(filters)
|
168
166
|
setTasks(tasks)
|
169
167
|
}
|
@@ -173,14 +171,10 @@ export const TaskMonitor = (props) => {
|
|
173
171
|
refresh()
|
174
172
|
}
|
175
173
|
|
176
|
-
function changeFrom(id, value) {
|
177
|
-
setFrom(value)
|
178
|
-
}
|
179
|
-
|
180
174
|
const table = {
|
181
175
|
columns: [
|
182
176
|
{ id: "state", label: "Estado" },
|
183
|
-
{ id: "init", label: "Inicio", type: TYPES.STRING, format: FORMATS.DATE},
|
177
|
+
{ id: "init", label: "Inicio", type: TYPES.STRING, format: FORMATS.DATE },
|
184
178
|
{ id: "end", label: "Fin", type: TYPES.STRING, format: FORMATS.DATE },
|
185
179
|
{ id: "description", label: "Descripcion" },
|
186
180
|
{ id: "progress", label: "%" },
|
@@ -218,7 +212,7 @@ export const TaskMonitor = (props) => {
|
|
218
212
|
return (
|
219
213
|
<div className="task-manager">
|
220
214
|
<Header icon="list" title={title} >
|
221
|
-
{
|
215
|
+
{ context.listeners ? <Chip label={Object.keys(context.listeners).length} /> : null }
|
222
216
|
</Header>
|
223
217
|
<main>
|
224
218
|
<DataTable {...table} />
|