@coding-flow/flow-approval-presenter 0.0.44 → 0.0.45

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,6 +1,7 @@
1
1
  import React from "react";
2
2
  import { ApprovalLayoutProps, ApprovalState } from "../typings";
3
3
  import { ApprovalPresenter } from "../presenters";
4
+ import { FieldPermission, FlowForm } from "@coding-flow/flow-types";
4
5
  export declare class ApprovalContextScope {
5
6
  private readonly presenter;
6
7
  private readonly props;
@@ -8,6 +9,7 @@ export declare class ApprovalContextScope {
8
9
  syncState(state: ApprovalState): void;
9
10
  getPresenter(): ApprovalPresenter;
10
11
  getInitData(): any;
12
+ convertMeta(form: FlowForm | undefined, permissions: FieldPermission[]): FlowForm | undefined;
11
13
  close(): void;
12
14
  initialState(): void;
13
15
  }
@@ -1,4 +1,5 @@
1
1
  import react from "react";
2
+ import { MetaService } from "../service/meta-service.js";
2
3
  class ApprovalContextScope {
3
4
  presenter;
4
5
  props;
@@ -15,6 +16,11 @@ class ApprovalContextScope {
15
16
  getInitData() {
16
17
  return this.props.initData;
17
18
  }
19
+ convertMeta(form, permissions) {
20
+ const metaService = new MetaService(form, permissions);
21
+ const data = metaService.getFormMeta();
22
+ return data;
23
+ }
18
24
  close() {
19
25
  this.props.onClose?.();
20
26
  }
@@ -0,0 +1,9 @@
1
+ import { FieldPermission, FlowForm } from "@coding-flow/flow-types";
2
+ export declare class MetaService {
3
+ private readonly flowForm;
4
+ private readonly fieldPermissions;
5
+ constructor(flowForm: FlowForm | undefined, fieldPermissions: FieldPermission[]);
6
+ getFormMeta(): FlowForm | undefined;
7
+ private convertForm;
8
+ private mapFormField;
9
+ }
@@ -0,0 +1,40 @@
1
+ class MetaService {
2
+ flowForm;
3
+ fieldPermissions;
4
+ constructor(flowForm, fieldPermissions){
5
+ this.flowForm = flowForm;
6
+ this.fieldPermissions = fieldPermissions;
7
+ }
8
+ getFormMeta() {
9
+ if (!this.flowForm) return;
10
+ return this.convertForm(this.flowForm);
11
+ }
12
+ convertForm(form) {
13
+ const formCode = form.code;
14
+ const subForms = form.subForms || [];
15
+ const list = [];
16
+ if (subForms.length > 0) for (const subForm of subForms)list.push(this.convertForm(subForm));
17
+ return {
18
+ ...form,
19
+ fields: form.fields.map((field)=>this.mapFormField(formCode, field)),
20
+ subForms: list
21
+ };
22
+ }
23
+ mapFormField(formCode, field) {
24
+ const permission = this.fieldPermissions.find((p)=>p.formCode === formCode && p.fieldCode === field.code);
25
+ if (permission) {
26
+ if ('HIDDEN' === permission.type) return {
27
+ ...field,
28
+ hidden: true,
29
+ required: false
30
+ };
31
+ if ('READ' === permission.type) return {
32
+ ...field,
33
+ readonly: true,
34
+ required: false
35
+ };
36
+ }
37
+ return field;
38
+ }
39
+ }
40
+ export { MetaService };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coding-flow/flow-approval-presenter",
3
- "version": "0.0.44",
3
+ "version": "0.0.45",
4
4
  "description": "flow-engine approval presenter framework ",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -36,11 +36,11 @@
36
36
  "dayjs": "^1.11.19",
37
37
  "immer": "^11.1.3",
38
38
  "react-redux": "^9.2.0",
39
- "@coding-flow/flow-core": "0.0.44",
40
- "@coding-flow/flow-types": "0.0.44"
39
+ "@coding-flow/flow-core": "0.0.45",
40
+ "@coding-flow/flow-types": "0.0.45"
41
41
  },
42
42
  "devDependencies": {
43
- "@coding-flow/flow-types": "0.0.44"
43
+ "@coding-flow/flow-types": "0.0.45"
44
44
  },
45
45
  "scripts": {
46
46
  "build": "rslib build",