@kingteza/crud-component 1.22.2 → 1.22.3
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,2 +1,2 @@
|
|
|
1
|
-
"use strict";const s=require("react/jsx-runtime"),T=require("@ant-design/icons"),O=require("papaparse"),f=require("antd"),L=require("file-saver"),
|
|
2
|
-
`,t=new Blob([e],{type:"text/csv;charset=utf-8;"});L.saveAs(t,(
|
|
1
|
+
"use strict";const s=require("react/jsx-runtime"),T=require("@ant-design/icons"),O=require("papaparse"),f=require("antd"),L=require("file-saver"),r=require("react"),R=require("../../locale/index.cjs.js"),z=require("../view/CrudViewer.cjs.js"),$=require("../../util/DateUtil.cjs.js"),H=require("../../common/button/Button.cjs.js"),U=require("../../common/button/ImportButton.cjs.js");function Y({onCloseMethod:w,open:y,fields:q,importProps:o}){const[c,C]=r.useState([]),[g,k]=r.useState(!1),[D,S]=r.useState(0);r.useEffect(()=>{y||(C([]),k(!1))},[y]);const p=r.useMemo(()=>new Map(q.filter(e=>{var t;return!e.hidden&&!((t=e.importProps)!=null&&t.hidden)&&!e.readonly}).map(e=>[e.name,e])),[q]),A=r.useMemo(()=>Array.from(p.values()).flatMap(e=>{var t;return[e.name,...((t=e.importProps)==null?void 0:t.extraFields)??[]]}),[p]),E=r.useCallback(async function(){const e=`${A.join(",")}
|
|
2
|
+
`,t=new Blob([e],{type:"text/csv;charset=utf-8;"});L.saveAs(t,(o==null?void 0:o.name)+" - "+$.formatDateTimeWithSecond(new Date).replaceAll(":","-")+".csv")},[A,o==null?void 0:o.name]),{t:i}=R.useTranslationLib(),M=r.useCallback(async e=>{const t=new FileReader;t.onerror=console.error,t.onload=async n=>{var a;const u=(a=n==null?void 0:n.target)==null?void 0:a.result,l=O.parse(u,{header:!0});C(l.data.map((d,m)=>({...d,id_private_private:"crud-import-"+m})))},t.readAsText(e)},[]),B=r.useCallback(async e=>{console.log("Deleting item from import component",e,c),C(t=>t.filter(n=>n.id_private_private!==(e==null?void 0:e.id_private_private)))},[c]),v=r.useMemo(()=>{var t,n,u;let e=!1;for(const l of c)for(const[a,d]of p.entries()){const m=l[a],h=m||!isNaN(m);if(d.required&&!h)if((n=(t=d.importProps)==null?void 0:t.extraFields)!=null&&n.length)for(const j of((u=d.importProps)==null?void 0:u.extraFields)??[])if(l[j]||!isNaN(l[j])){e=!1;break}else return!0;else return!0}return e},[c,p]),x=r.useCallback(e=>(t,n)=>{var l,a,d;const u=t||!isNaN(t);if(e.required&&!u){let m=i("err.validation.required");if((a=(l=e.importProps)==null?void 0:l.extraFields)!=null&&a.length){const h=(d=e.importProps)==null?void 0:d.extraFields;(h==null?void 0:h.find(_=>!n[_]))&&(m="Either one of these fields is required: "+[e.name,...h].join(", "))}return s.jsxs(f.Tooltip,{className:"d-flex",title:m,children:[s.jsx(T.WarningTwoTone,{twoToneColor:"#ee9702"}),t]})}return t},[i]),I=r.useCallback(async e=>{S(e)},[]),b=r.useCallback(async()=>{try{k(!0),await o.onClickImport(c,I),w(!1)}finally{k(!1),S(0)}},[c,o,w,I]),{modal:F}=f.App.useApp(),V=r.useCallback(async()=>{v?F.warning?F.warning({title:i("str.warning"),content:i("qus.importWithIssues"),okText:i("str.import"),onOk:b,okCancel:!0,closable:!0}):(console.error("You must wrap your react app with App component. https://ant.design/components/app"),window.confirm(i("qus.importWithIssues"))&&b()):b()},[v,b,i]),N=r.useMemo(()=>Array.from(p.values()).flatMap(e=>{var t,n,u,l;return e.type==="text"?[{...e,label:e.name,render:x(e)},...((n=(t=e.importProps)==null?void 0:t.extraFields)==null?void 0:n.map((a,d)=>({...e,name:a,label:a,render:x(e)})))??[]]:e.type==="select"?[{...e,label:e.name,type:"text",render:x(e)},...((l=(u=e.importProps)==null?void 0:u.extraFields)==null?void 0:l.map(a=>({...e,name:a,label:a,type:"text",render:x(e)})))??[]]:[{...e,label:e.name,render:x(e)}]}),[p,x]),W=r.useMemo(()=>N.map(e=>({...e,hideInTable:!1})),[N]);return s.jsxs(f.Modal,{title:[i("str.import"),o==null?void 0:o.name].filter(Boolean).join(" "),width:"100%",open:y,onOk:V,destroyOnHidden:!0,onCancel:()=>w(!1),okText:i("str.import"),confirmLoading:g,okButtonProps:{disabled:!(c!=null&&c.length)},footer:(e,{OkBtn:t,CancelBtn:n})=>s.jsxs(f.Space,{children:[s.jsx(n,{}),s.jsx(t,{}),v&&s.jsx(f.Tooltip,{className:"d-flex",title:"Some fields have issue. Please review before submit.",children:s.jsx(T.WarningTwoTone,{twoToneColor:"#ee9702"})})]}),children:[s.jsxs(f.Space,{children:[s.jsx(H,{onClick:E,icon:s.jsx(T.DownloadOutlined,{}),children:i("str.downloadCsvTemplate")}),s.jsx(U.ImportButton,{disabled:g,type:"default",onClick:M,accept:".csv",children:i("str.importCsvFile")})]}),s.jsx(f.Spin,{spinning:g,indicator:D?s.jsx(f.Progress,{type:"circle",percent:D*100,size:50,format:e=>`${parseInt(e)}%`}):void 0,children:s.jsx(z,{data:c,bordered:!0,size:"small",idField:"id_private_private",onDelete:B,fields:W})})]})}module.exports=Y;
|
|
@@ -11,14 +11,14 @@ import ee from "../../common/button/Button.es.js";
|
|
|
11
11
|
import { ImportButton as te } from "../../common/button/ImportButton.es.js";
|
|
12
12
|
function pe({
|
|
13
13
|
onCloseMethod: g,
|
|
14
|
-
open:
|
|
14
|
+
open: v,
|
|
15
15
|
fields: F,
|
|
16
16
|
importProps: o
|
|
17
17
|
}) {
|
|
18
|
-
const [l,
|
|
18
|
+
const [l, x] = A([]), [C, k] = A(!1), [I, N] = A(0);
|
|
19
19
|
Q(() => {
|
|
20
|
-
|
|
21
|
-
}, [
|
|
20
|
+
v || (x([]), k(!1));
|
|
21
|
+
}, [v]);
|
|
22
22
|
const p = w(
|
|
23
23
|
() => new Map(
|
|
24
24
|
F.filter((e) => {
|
|
@@ -27,7 +27,7 @@ function pe({
|
|
|
27
27
|
}).map((e) => [e.name, e])
|
|
28
28
|
),
|
|
29
29
|
[F]
|
|
30
|
-
),
|
|
30
|
+
), _ = w(
|
|
31
31
|
() => Array.from(p.values()).flatMap((e) => {
|
|
32
32
|
var t;
|
|
33
33
|
return [
|
|
@@ -38,20 +38,20 @@ function pe({
|
|
|
38
38
|
[p]
|
|
39
39
|
), W = f(
|
|
40
40
|
async function() {
|
|
41
|
-
const e = `${
|
|
41
|
+
const e = `${_.join(",")}
|
|
42
42
|
`, t = new Blob([e], { type: "text/csv;charset=utf-8;" });
|
|
43
43
|
K(
|
|
44
44
|
t,
|
|
45
45
|
(o == null ? void 0 : o.name) + " - " + P.formatDateTimeWithSecond(/* @__PURE__ */ new Date()).replaceAll(":", "-") + ".csv"
|
|
46
46
|
);
|
|
47
47
|
},
|
|
48
|
-
[
|
|
48
|
+
[_, o == null ? void 0 : o.name]
|
|
49
49
|
), { t: a } = X(), L = f(async (e) => {
|
|
50
50
|
const t = new FileReader();
|
|
51
51
|
t.onerror = console.error, t.onload = async (r) => {
|
|
52
52
|
var n;
|
|
53
53
|
const c = (n = r == null ? void 0 : r.target) == null ? void 0 : n.result, s = R.parse(c, { header: !0 });
|
|
54
|
-
|
|
54
|
+
x(
|
|
55
55
|
s.data.map((d, m) => ({
|
|
56
56
|
...d,
|
|
57
57
|
id_private_private: "crud-import-" + m
|
|
@@ -60,7 +60,7 @@ function pe({
|
|
|
60
60
|
}, t.readAsText(e);
|
|
61
61
|
}, []), M = f(
|
|
62
62
|
async (e) => {
|
|
63
|
-
console.log("Deleting item from import component", e, l),
|
|
63
|
+
console.log("Deleting item from import component", e, l), x((t) => t.filter((r) => r.id_private_private !== (e == null ? void 0 : e.id_private_private)));
|
|
64
64
|
},
|
|
65
65
|
[l]
|
|
66
66
|
), T = w(() => {
|
|
@@ -97,16 +97,16 @@ function pe({
|
|
|
97
97
|
return t;
|
|
98
98
|
},
|
|
99
99
|
[a]
|
|
100
|
-
),
|
|
100
|
+
), S = f(async (e) => {
|
|
101
101
|
N(e);
|
|
102
102
|
}, []), y = f(async () => {
|
|
103
103
|
try {
|
|
104
|
-
k(!0), await o.onClickImport(l,
|
|
104
|
+
k(!0), await o.onClickImport(l, S), g(!1);
|
|
105
105
|
} finally {
|
|
106
106
|
k(!1), N(0);
|
|
107
107
|
}
|
|
108
|
-
}, [l, o, g,
|
|
109
|
-
T ?
|
|
108
|
+
}, [l, o, g, S]), { modal: E } = U.useApp(), z = f(async () => {
|
|
109
|
+
T ? E.warning ? E.warning({
|
|
110
110
|
title: a("str.warning"),
|
|
111
111
|
content: a("qus.importWithIssues"),
|
|
112
112
|
okText: a("str.import"),
|
|
@@ -160,7 +160,7 @@ function pe({
|
|
|
160
160
|
{
|
|
161
161
|
title: [a("str.import"), o == null ? void 0 : o.name].filter(Boolean).join(" "),
|
|
162
162
|
width: "100%",
|
|
163
|
-
open:
|
|
163
|
+
open: v,
|
|
164
164
|
onOk: z,
|
|
165
165
|
destroyOnHidden: !0,
|
|
166
166
|
onCancel: () => g(!1),
|
|
@@ -223,7 +223,6 @@ function pe({
|
|
|
223
223
|
size: "small",
|
|
224
224
|
idField: "id_private_private",
|
|
225
225
|
onDelete: M,
|
|
226
|
-
confirmDeleting: !1,
|
|
227
226
|
fields: $
|
|
228
227
|
}
|
|
229
228
|
)
|