@kingteza/crud-component 1.40.0 → 1.41.0
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/dist/crud/CrudSearchComponent.cjs.js +1 -1
- package/dist/crud/CrudSearchComponent.d.ts +2 -1
- package/dist/crud/CrudSearchComponent.es.js +83 -56
- package/dist/locale/translations/en.cjs.js +1 -1
- package/dist/locale/translations/en.d.ts +1 -0
- package/dist/locale/translations/en.es.js +1 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const
|
|
1
|
+
"use strict";const o=require("react/jsx-runtime"),e=require("react"),p=require("@ant-design/icons"),i=require("antd"),N=require("./CrudField.cjs.js"),E=require("../util/CrudUtil.cjs.js"),C=require("../context/CrudSearchContext.cjs.js"),_=require("../common/button/Button.cjs.js");function k({searchFields:t=[],fields:g,searchOnChange:c,onSearch:b,searchDefaultValues:a,searchFieldsCustomColumnProps:d}){const j=e.useMemo(()=>t.map(n=>{if(e.isValidElement(n))return n;if(typeof n=="string"){const l=g.find(m=>n===m.name);return l?{...l,required:!1}:null}const u=g.find(l=>(n==null?void 0:n.name)===l.name);return u?{...u,...n}:null}).filter(n=>e.isValidElement(n)||n&&!(n!=null&&n.hidden)),[t,g]),x=e.useMemo(()=>t.length===1?{field:22,button:2}:t.length===2?{field:11,button:2}:t.length===3?{field:6,button:6}:t.length===4?{field:5,button:4}:t.length===5?{field:4,button:4}:{field:4,button:4},[t.length]),s=e.useMemo(()=>t.length===1?{field:22,button:2}:t.length===2?{field:11,button:2}:t.length===3?{field:6,button:6}:t.length===4?{field:5,button:4}:t.length===5?{field:4,button:4}:{field:4,button:4},[t.length]),y=e.useMemo(()=>t.length===1?{field:21,button:3}:t.length===2?{field:11,button:2}:t.length===3?{field:24,button:24}:t.length===4?{field:5,button:4}:t.length===5?{field:4,button:4}:{field:4,button:4},[t.length]),[r]=i.Form.useForm(),f=e.useCallback(async n=>{if((n||c)&&b){const u=await r.validateFields();b(u)}},[r,b,c]);return e.useEffect(()=>{a&&(r.setFieldsValue(a),f(!0))},[r,a]),t!=null&&t.length?o.jsx(i.Form,{form:r,onFinish:()=>f(!0),layout:"vertical",className:"mb-2",onChange:()=>f(!1),children:o.jsx(C.CrudSearchContextProvider,{search:()=>f(!1),children:o.jsxs(i.Row,{gutter:[4,8],className:"w-100",children:[j.map((n,u)=>{const l=(d==null?void 0:d[u])??{md:x.field,sm:s.field,xs:y.field};if(e.isValidElement(n))return e.createElement(i.Col,{...l,key:`search_field_element_${u}`,className:"align-self-end"},n);const m=n,q=E.getRealName(m.name);return e.createElement(i.Col,{...l,key:`search_field_${String(q)}`,className:"align-self-end"},o.jsx(N.default,{...m,readonly:!1,fieldClassName:"mb-0"}))}),o.jsx(i.Col,{md:x.button,sm:s.button,xs:y.button,style:{alignSelf:"end"},children:o.jsx(_,{type:"primary",htmlType:"submit",block:!0,icon:o.jsx(p.SearchOutlined,{})})})]})})}):o.jsx(o.Fragment,{})}module.exports=k;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ColProps } from 'antd/lib';
|
|
2
|
+
import { ReactElement } from 'react';
|
|
2
3
|
import { ReadonlyCrudFields } from './CrudComponent';
|
|
3
4
|
export type CrudSearchOption<T> = {
|
|
4
5
|
required?: boolean;
|
|
@@ -28,7 +29,7 @@ export type CrudSearchOption<T> = {
|
|
|
28
29
|
disableToday?: boolean;
|
|
29
30
|
});
|
|
30
31
|
export interface CrudSearchComponentProps<T, FormType> {
|
|
31
|
-
searchFields?: Array<keyof T | CrudSearchOption<T
|
|
32
|
+
searchFields?: Array<keyof T | CrudSearchOption<T> | ReactElement>;
|
|
32
33
|
fields: ReadonlyCrudFields<T>;
|
|
33
34
|
searchOnChange?: boolean;
|
|
34
35
|
searchDefaultValues?: FormType;
|
|
@@ -1,97 +1,124 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { useMemo as
|
|
1
|
+
import { jsx as f, Fragment as S, jsxs as c } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo as r, isValidElement as d, useCallback as j, useEffect as C, createElement as k } from "react";
|
|
3
3
|
import { SearchOutlined as R } from "@ant-design/icons";
|
|
4
|
-
import { Form as
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import { CrudSearchContextProvider as
|
|
8
|
-
import
|
|
9
|
-
function
|
|
4
|
+
import { Form as w, Row as $, Col as a } from "antd";
|
|
5
|
+
import h from "./CrudField.es.js";
|
|
6
|
+
import q from "../util/CrudUtil.es.js";
|
|
7
|
+
import { CrudSearchContextProvider as B } from "../context/CrudSearchContext.es.js";
|
|
8
|
+
import M from "../common/button/Button.es.js";
|
|
9
|
+
function K({
|
|
10
10
|
searchFields: t = [],
|
|
11
11
|
fields: i,
|
|
12
|
-
searchOnChange:
|
|
12
|
+
searchOnChange: y,
|
|
13
13
|
onSearch: g,
|
|
14
14
|
searchDefaultValues: b,
|
|
15
|
-
searchFieldsCustomColumnProps:
|
|
15
|
+
searchFieldsCustomColumnProps: p
|
|
16
16
|
}) {
|
|
17
|
-
const
|
|
18
|
-
() => t.map((n) =>
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
17
|
+
const v = r(
|
|
18
|
+
() => t.map((n) => {
|
|
19
|
+
if (d(n))
|
|
20
|
+
return n;
|
|
21
|
+
if (typeof n == "string") {
|
|
22
|
+
const e = i.find((u) => n === u.name);
|
|
23
|
+
return e ? {
|
|
24
|
+
...e,
|
|
25
|
+
required: !1
|
|
26
|
+
} : null;
|
|
27
|
+
}
|
|
28
|
+
const o = i.find(
|
|
29
|
+
(e) => (n == null ? void 0 : n.name) === e.name
|
|
30
|
+
);
|
|
31
|
+
return o ? {
|
|
32
|
+
...o,
|
|
33
|
+
...n
|
|
34
|
+
} : null;
|
|
35
|
+
}).filter((n) => d(n) || n && !(n != null && n.hidden)),
|
|
27
36
|
[t, i]
|
|
28
|
-
),
|
|
37
|
+
), x = r(
|
|
29
38
|
() => t.length === 1 ? { field: 22, button: 2 } : t.length === 2 ? { field: 11, button: 2 } : t.length === 3 ? { field: 6, button: 6 } : t.length === 4 ? { field: 5, button: 4 } : t.length === 5 ? { field: 4, button: 4 } : { field: 4, button: 4 },
|
|
30
39
|
[t.length]
|
|
31
|
-
),
|
|
40
|
+
), N = r(
|
|
32
41
|
() => t.length === 1 ? { field: 22, button: 2 } : t.length === 2 ? { field: 11, button: 2 } : t.length === 3 ? { field: 6, button: 6 } : t.length === 4 ? { field: 5, button: 4 } : t.length === 5 ? { field: 4, button: 4 } : { field: 4, button: 4 },
|
|
33
42
|
[t.length]
|
|
34
|
-
),
|
|
43
|
+
), _ = r(
|
|
35
44
|
() => t.length === 1 ? { field: 21, button: 3 } : t.length === 2 ? { field: 11, button: 2 } : t.length === 3 ? { field: 24, button: 24 } : t.length === 4 ? { field: 5, button: 4 } : t.length === 5 ? { field: 4, button: 4 } : { field: 4, button: 4 },
|
|
36
45
|
[t.length]
|
|
37
|
-
), [
|
|
46
|
+
), [l] = w.useForm(), m = j(
|
|
38
47
|
async (n) => {
|
|
39
|
-
if ((n ||
|
|
40
|
-
const
|
|
41
|
-
g(
|
|
48
|
+
if ((n || y) && g) {
|
|
49
|
+
const o = await l.validateFields();
|
|
50
|
+
g(o);
|
|
42
51
|
}
|
|
43
52
|
},
|
|
44
|
-
[
|
|
53
|
+
[l, g, y]
|
|
45
54
|
);
|
|
46
55
|
return C(() => {
|
|
47
|
-
b && (
|
|
48
|
-
}, [
|
|
49
|
-
|
|
56
|
+
b && (l.setFieldsValue(b), m(!0));
|
|
57
|
+
}, [l, b]), t != null && t.length ? /* @__PURE__ */ f(
|
|
58
|
+
w,
|
|
50
59
|
{
|
|
51
|
-
form:
|
|
52
|
-
onFinish: () =>
|
|
60
|
+
form: l,
|
|
61
|
+
onFinish: () => m(!0),
|
|
53
62
|
layout: "vertical",
|
|
54
63
|
className: "mb-2",
|
|
55
|
-
onChange: () =>
|
|
56
|
-
children: /* @__PURE__ */
|
|
57
|
-
|
|
58
|
-
const
|
|
59
|
-
md:
|
|
60
|
-
sm:
|
|
61
|
-
xs:
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
64
|
+
onChange: () => m(!1),
|
|
65
|
+
children: /* @__PURE__ */ f(B, { search: () => m(!1), children: /* @__PURE__ */ c($, { gutter: [4, 8], className: "w-100", children: [
|
|
66
|
+
v.map((n, o) => {
|
|
67
|
+
const e = (p == null ? void 0 : p[o]) ?? {
|
|
68
|
+
md: x.field,
|
|
69
|
+
sm: N.field,
|
|
70
|
+
xs: _.field
|
|
71
|
+
};
|
|
72
|
+
if (d(n))
|
|
73
|
+
return /* @__PURE__ */ k(
|
|
74
|
+
a,
|
|
75
|
+
{
|
|
76
|
+
...e,
|
|
77
|
+
key: `search_field_element_${o}`,
|
|
78
|
+
className: "align-self-end"
|
|
79
|
+
},
|
|
80
|
+
n
|
|
81
|
+
);
|
|
82
|
+
const u = n, E = q.getRealName(u.name);
|
|
83
|
+
return /* @__PURE__ */ k(
|
|
84
|
+
a,
|
|
65
85
|
{
|
|
66
|
-
...
|
|
67
|
-
key: `search_field_${String(
|
|
86
|
+
...e,
|
|
87
|
+
key: `search_field_${String(E)}`,
|
|
68
88
|
className: "align-self-end"
|
|
69
89
|
},
|
|
70
|
-
/* @__PURE__ */
|
|
90
|
+
/* @__PURE__ */ f(
|
|
91
|
+
h,
|
|
92
|
+
{
|
|
93
|
+
...u,
|
|
94
|
+
readonly: !1,
|
|
95
|
+
fieldClassName: "mb-0"
|
|
96
|
+
}
|
|
97
|
+
)
|
|
71
98
|
);
|
|
72
99
|
}),
|
|
73
|
-
/* @__PURE__ */
|
|
74
|
-
|
|
100
|
+
/* @__PURE__ */ f(
|
|
101
|
+
a,
|
|
75
102
|
{
|
|
76
|
-
md:
|
|
77
|
-
sm:
|
|
78
|
-
xs:
|
|
103
|
+
md: x.button,
|
|
104
|
+
sm: N.button,
|
|
105
|
+
xs: _.button,
|
|
79
106
|
style: { alignSelf: "end" },
|
|
80
|
-
children: /* @__PURE__ */
|
|
81
|
-
|
|
107
|
+
children: /* @__PURE__ */ f(
|
|
108
|
+
M,
|
|
82
109
|
{
|
|
83
110
|
type: "primary",
|
|
84
111
|
htmlType: "submit",
|
|
85
112
|
block: !0,
|
|
86
|
-
icon: /* @__PURE__ */
|
|
113
|
+
icon: /* @__PURE__ */ f(R, {})
|
|
87
114
|
}
|
|
88
115
|
)
|
|
89
116
|
}
|
|
90
117
|
)
|
|
91
118
|
] }) })
|
|
92
119
|
}
|
|
93
|
-
) : /* @__PURE__ */
|
|
120
|
+
) : /* @__PURE__ */ f(S, {});
|
|
94
121
|
}
|
|
95
122
|
export {
|
|
96
|
-
|
|
123
|
+
K as default
|
|
97
124
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const e={str:{delete:"Delete",clone:"Clone",update:"Update",new:"New",back:"Back",next:"Next",save:"Save",import:"Import",cancel:"Cancel",print:"Print",hide:"Hide",no:"No",action:"Action",remove:"Remove",view:"View",ok:"Ok",yes:"Yes",warning:"Warning",success:"Success",error:"Error",retry:"Retry",previous:"Previous",unhide:"Unhide",downloadCsvTemplate:"Download CSV Template",importCsvFile:"Import CSV File",export:"Export",goBack:"Go Back",refresh:"Refresh",fileUploadMessage1:"Drag file here or ",fileUploadMessage2:"Click to Upload",rotateLeft:"Rotate Left",rotateRight:"Rotate Right",flipHorizontal:"Flip Horizontal",flipVertical:"Flip Vertical",skipCrop:"Skip Crop",showFields:"Show Fields"},err:{save:"An error occurred while saving",validation:{required:"is required",minLength8:"must be at least 8 characters",percentage:"must be a percentage",maximumValueExceeded:"must be less than %maxValue%",invalidNic:"must be a valid NIC",invalid:"must be a valid",integer:"must be an integer"},notFound:"Not Found"},message:{loading:{saving:"Saving"},uploadButtonText:"Click to Upload"},qus:{importWithIssues:"Some fields have issues. Do you want to proceed with the import?",doYouWantToDelete:"Do you want to delete?",doYouWantToHide:"Do you want to hide?",doYouWantToUnhide:"Do you want to unhide?"}};module.exports=e;
|
|
1
|
+
"use strict";const e={str:{delete:"Delete",clone:"Clone",update:"Update",new:"New",back:"Back",next:"Next",save:"Save",import:"Import",cancel:"Cancel",print:"Print",hide:"Hide",no:"No",action:"Action",remove:"Remove",view:"View",ok:"Ok",yes:"Yes",warning:"Warning",success:"Success",error:"Error",retry:"Retry",previous:"Previous",unhide:"Unhide",downloadCsvTemplate:"Download CSV Template",importCsvFile:"Import CSV File",export:"Export",goBack:"Go Back",refresh:"Refresh",fileUploadMessage1:"Drag file here or ",fileUploadMessage2:"Click to Upload",rotateLeft:"Rotate Left",rotateRight:"Rotate Right",flipHorizontal:"Flip Horizontal",flipVertical:"Flip Vertical",skipCrop:"Skip Crop",showFields:"Show Fields"},err:{save:"An error occurred while saving",validation:{required:"is required",minLength8:"must be at least 8 characters",percentage:"must be a percentage",maximumValueExceeded:"must be less than %maxValue%",invalidNic:"must be a valid NIC",invalid:"must be a valid",invalidEmail:"Invalid email address",integer:"must be an integer"},notFound:"Not Found"},message:{loading:{saving:"Saving"},uploadButtonText:"Click to Upload"},qus:{importWithIssues:"Some fields have issues. Do you want to proceed with the import?",doYouWantToDelete:"Do you want to delete?",doYouWantToHide:"Do you want to hide?",doYouWantToUnhide:"Do you want to unhide?"}};module.exports=e;
|