@nocobase/plugin-workflow-manual 0.20.0-alpha.16 → 0.20.0-alpha.17

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.
@@ -1,87 +0,0 @@
1
- import { createForm } from '@formily/core';
2
- import { useField } from '@formily/react';
3
- import {
4
- BlockRequestContext_deprecated,
5
- CollectionProvider_deprecated,
6
- FormBlockContext,
7
- RecordProvider,
8
- useAPIClient,
9
- useAssociationNames,
10
- useBlockRequestContext,
11
- } from '@nocobase/client';
12
- import { useFlowContext } from '@nocobase/plugin-workflow/client';
13
- import { parse } from '@nocobase/utils/client';
14
- import React, { useMemo, useRef } from 'react';
15
-
16
- function useFlowContextData(dataSource) {
17
- const { execution, nodes } = useFlowContext();
18
-
19
- const nodesKeyMap = useMemo(() => {
20
- return nodes.reduce((map, node) => Object.assign(map, { [node.id]: node.key }), {});
21
- }, [nodes]);
22
-
23
- const data = useMemo(
24
- () => ({
25
- $context: execution?.context,
26
- $jobsMapByNodeKey: (execution?.jobs ?? []).reduce(
27
- (map, job) => Object.assign(map, { [nodesKeyMap[job.nodeId]]: job.result }),
28
- {},
29
- ),
30
- }),
31
- [execution?.context, execution?.jobs, nodesKeyMap],
32
- );
33
-
34
- const result = useMemo(() => parse(dataSource)(data), [data, dataSource]);
35
- return result;
36
- }
37
-
38
- export function DetailsBlockProvider(props) {
39
- const field = useField();
40
- const formBlockRef = useRef(null);
41
- const { getAssociationAppends } = useAssociationNames();
42
- const { appends, updateAssociationValues } = getAssociationAppends();
43
- const values = useFlowContextData(props.dataSource);
44
-
45
- const form = useMemo(
46
- () =>
47
- createForm({
48
- values,
49
- readPretty: true,
50
- }),
51
- [values],
52
- );
53
-
54
- const params = {
55
- appends,
56
- };
57
- const service = {
58
- loading: false,
59
- data: {
60
- data: values,
61
- },
62
- };
63
- const api = useAPIClient();
64
- const resource = api.resource(props.collection);
65
- const __parent = useBlockRequestContext();
66
-
67
- return (
68
- <CollectionProvider_deprecated collection={props.collection}>
69
- <RecordProvider record={values} parent={null}>
70
- <BlockRequestContext_deprecated.Provider value={{ block: 'form', field, service, resource, __parent }}>
71
- <FormBlockContext.Provider
72
- value={{
73
- params,
74
- form,
75
- field,
76
- service,
77
- updateAssociationValues,
78
- formBlockRef,
79
- }}
80
- >
81
- {props.children}
82
- </FormBlockContext.Provider>
83
- </BlockRequestContext_deprecated.Provider>
84
- </RecordProvider>
85
- </CollectionProvider_deprecated>
86
- );
87
- }