@izara_frontend/shared-complex-filter 1.0.1

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.
@@ -0,0 +1,628 @@
1
+ import { useState, useEffect, useMemo } from "react";
2
+ import { useImmer } from "use-immer";
3
+ import {
4
+ IzaraDivStyle,
5
+ IzaraButtonStyle,
6
+ createStyleDefualtTags,
7
+ createStyleTags,
8
+ } from "@izaraFrontends/styles";
9
+
10
+ import { useDispatch } from "react-redux";
11
+ //test---------------------------------
12
+ // import { successTraversalConfig } from "./function/createActionLibCreateLinkStepAndComplexFilter";
13
+ // import { ConditionsAndMultipleIdentifersComponent } from "./conditionsAndMultipleIdentifersComponent";
14
+
15
+ function createObjTypeConcat(objType) {
16
+ console.log("objType:dfcvcbcxb ", objType);
17
+
18
+ return `${objType.serviceTag}_${objType.objectType}`;
19
+ }
20
+ function createRelTypeConcat(relType) {
21
+ console.log("objType:sdsadwsd ", relType);
22
+ return `${relType?.serviceTag}_${relType?.relationshipTag}`;
23
+ }
24
+ function objTypeFromObjTypeConcat(objTypeConcat) {
25
+ console.log("objTypeConcat:aeaeaeww ", objTypeConcat);
26
+ let result = objTypeConcat.split("_");
27
+
28
+ if (result.length !== 2) {
29
+ throw Error("objTypeConcat invalid");
30
+ }
31
+
32
+ return {
33
+ serviceTag: result[0],
34
+ objectType: result[1],
35
+ };
36
+ }
37
+
38
+ export const ModalLinkStepsComponent = ({
39
+ titleModal, //string
40
+ statusModalFunc, //func
41
+ objConfigUseCase, //store
42
+ objTypeMain,
43
+ nameReducer,
44
+ parentOutputId,
45
+ successFunc, //func
46
+ collectObjectLinksWithRequestProperties,
47
+ collectObjectSchemaWithHierarchy,
48
+
49
+ //useCase props
50
+ nameObjectLinkStepEdit,
51
+ userTag,
52
+ keyElement, //**** */
53
+ ComponentUseCase,
54
+ LastStepsComponentUseCase,
55
+ valueUserTags,
56
+ successFuncUseCase,
57
+ }) => {
58
+ // InitialSchemaLib.initSchemaFn(
59
+ // getObjSchemaS3WithHierarchyShared,
60
+ // getObjectLinksShared
61
+ // );
62
+
63
+ console.log("valueUserTags:ModalLinkStepsComponent ", valueUserTags);
64
+ let arrObjRequiredData = [{}];
65
+
66
+ arrObjRequiredData = [];
67
+ if (nameObjectLinkStepEdit) {
68
+ if (objConfigUseCase?.linkStepsObjects) {
69
+ for (const keyLinkStep of objConfigUseCase.linkStepsObjects[
70
+ nameObjectLinkStepEdit
71
+ ].linkSteps) {
72
+ arrObjRequiredData.push(objConfigUseCase.linkSteps[keyLinkStep]);
73
+ }
74
+ }
75
+ }
76
+
77
+ if (objConfigUseCase?.traversalSteps) {
78
+ for (const keyTraversalStep of objConfigUseCase.traversalSteps) {
79
+ arrObjRequiredData.push(
80
+ objConfigUseCase.traversalSteps[keyTraversalStep],
81
+ );
82
+ }
83
+ }
84
+
85
+ console.log("arrObjRequiredData: xxxxaaawwweee", arrObjRequiredData);
86
+ if (!objTypeMain) {
87
+ objTypeMain = objConfigUseCase.objType;
88
+ }
89
+
90
+ console.time("renderTimeInModalRequiredData");
91
+
92
+ //--------------------------------------------------------------
93
+
94
+ const [allObjTypesLinkConfigs, collectRequireLinksFn, collectLinksOpt] =
95
+ collectObjectLinksWithRequestProperties(); // allObjTypesLinkConfigs
96
+
97
+ const [resultFieldName, getObjSchemaHieFn, collectLinksOpt2] =
98
+ collectObjectSchemaWithHierarchy();
99
+
100
+ //--------------------------------------------------------------
101
+
102
+ const [linkSteps, setLinkSteps] = useImmer(arrObjRequiredData);
103
+
104
+ const [nameLinkSteps, setNameLinkSteps] = useState(nameObjectLinkStepEdit);
105
+ const [linkStepsOutput, setLinkStepsOutput] = useImmer({
106
+ status: null, //link or lastStep
107
+ active: 0,
108
+ });
109
+
110
+ const dispatch = useDispatch();
111
+
112
+ console.log("linkSteps:linkStepsLog ", linkSteps);
113
+ console.log("collectLinks: ", allObjTypesLinkConfigs, collectLinksOpt);
114
+ console.log("allObjTypesLinkConfigs: ", allObjTypesLinkConfigs);
115
+
116
+ useEffect(() => {
117
+ collectRequireLinksFn(objTypeMain, {
118
+ returnLinkTypeId: false,
119
+ returnPathLinkTypeId: true,
120
+ });
121
+ getObjSchemaHieFn(objTypeMain);
122
+
123
+ if (nameObjectLinkStepEdit) {
124
+ for (
125
+ let keyLinkStep = 0;
126
+ keyLinkStep < arrObjRequiredData.length;
127
+ keyLinkStep++
128
+ ) {
129
+ const linkStep = arrObjRequiredData[keyLinkStep];
130
+ if (linkStep.hasOwnProperty("pathLinkType")) {
131
+ collectRequireLinksFn(linkStep.pathLinkType.objType, {
132
+ returnLinkTypeId: false,
133
+ returnPathLinkTypeId: true,
134
+ });
135
+ getObjSchemaHieFn(linkStep.pathLinkType.objType);
136
+
137
+ // if (keyLinkStep === arrObjRequiredData.length - 1) {
138
+ // setLinkStepsOutput((linkStepsOutput) => {
139
+ // linkStepsOutput.status = true;
140
+ // });
141
+ // }
142
+ } else {
143
+ getObjSchemaHieFn(
144
+ keyLinkStep === 0
145
+ ? objTypeMain
146
+ : arrObjRequiredData[keyLinkStep - 1].pathLinkType.objType,
147
+ );
148
+ }
149
+ console.log("linkStep: sddfdfdfgcvb", linkStep);
150
+ }
151
+ }
152
+ }, []);
153
+ //-----------------------Shared function-----------------------------------
154
+
155
+ function checkObjTypeLinkStep(activeIndex) {
156
+ let objTypeConcat; // objTypeConcat
157
+ objTypeConcat = createObjTypeConcat(objTypeMain);
158
+ if (activeIndex !== 0) {
159
+ objTypeConcat = createObjTypeConcat(
160
+ linkSteps[activeIndex - 1].pathLinkType.objType,
161
+ );
162
+ }
163
+ return objTypeConcat;
164
+ }
165
+
166
+ //-----------------------End Shared function-----------------------------------
167
+
168
+ function hadelSelectType(e) {
169
+ let type = e.target.value;
170
+
171
+ setLinkStepsOutput((linkStepsOutput) => {
172
+ linkStepsOutput.status = type;
173
+ });
174
+
175
+ if (type === "link") {
176
+ setLinkSteps((linkSteps) => {
177
+ linkSteps[linkStepsOutput.active] = {
178
+ pathLinkType: {
179
+ relType: {},
180
+ objType: {},
181
+ direction: "",
182
+ },
183
+ };
184
+ });
185
+ } else {
186
+ setLinkSteps((linkSteps) => {
187
+ linkSteps[linkStepsOutput.active] = { lastStep: null };
188
+ });
189
+ }
190
+
191
+ setLinkSteps((linkSteps) => {
192
+ if (linkStepsOutput.active + 1 !== linkSteps.length) {
193
+ linkSteps = linkSteps.splice(
194
+ linkStepsOutput.active - linkSteps.length + 1,
195
+ );
196
+ }
197
+ });
198
+ }
199
+
200
+ function handelSelectRelTypeAndDirection(e) {
201
+ let relType = e.target.value;
202
+ let index = e.target.selectedIndex - 1;
203
+
204
+ console.log("index:handelSelectRelTypeAndDirection ", index, typeof index);
205
+ let objTypeConcat = checkObjTypeLinkStep(linkStepsOutput.active);
206
+
207
+ collectRequireLinksFn(
208
+ allObjTypesLinkConfigs[objTypeConcat][index].other.objType,
209
+ { returnLinkTypeId: false, returnPathLinkTypeId: true },
210
+ );
211
+
212
+ getObjSchemaHieFn(
213
+ allObjTypesLinkConfigs[objTypeConcat][index].other.objType,
214
+ );
215
+
216
+ setLinkSteps((linkSteps) => {
217
+ linkSteps[linkStepsOutput.active].pathLinkType = {
218
+ relType: JSON.parse(relType),
219
+ objType: allObjTypesLinkConfigs[objTypeConcat][index].other.objType,
220
+ direction: allObjTypesLinkConfigs[objTypeConcat][index].base.direction,
221
+ };
222
+
223
+ // linkSteps[
224
+ // linkStepsOutput.active
225
+ // ].allObjTypesLinkConfigIndex = index;
226
+
227
+ if (allObjTypesLinkConfigs[objTypeConcat][index]?.requestProperties) {
228
+ let requestProperties = {};
229
+ for (const key in allObjTypesLinkConfigs[objTypeConcat][index]
230
+ ?.requestProperties) {
231
+ requestProperties[key] = "";
232
+ }
233
+ linkSteps[linkStepsOutput.active].requestProperties = requestProperties;
234
+ } else {
235
+ delete linkSteps[linkStepsOutput.active].requestProperties;
236
+ }
237
+ if (linkStepsOutput.active + 1 !== linkSteps.length) {
238
+ linkSteps = linkSteps.splice(
239
+ linkStepsOutput.active - linkSteps.length + 1,
240
+ );
241
+ }
242
+ });
243
+ }
244
+
245
+ function handelActiveStep(index) {
246
+ setLinkStepsOutput((linkStepsOutput) => {
247
+ linkStepsOutput.active = index;
248
+ });
249
+ if (index !== 0) {
250
+ collectRequireLinksFn(linkSteps[index - 1].pathLinkType.objType, {
251
+ returnLinkTypeId: false,
252
+ returnPathLinkTypeId: true,
253
+ });
254
+
255
+ getObjSchemaHieFn(linkSteps[index - 1].pathLinkType.objType);
256
+ }
257
+ }
258
+
259
+ function handleNextStep() {
260
+ // funcUseCase.testA();
261
+ let validateResult = true;
262
+ // validateAggregateCompare() &&
263
+ // validateComparison() &&
264
+ // validateRequestProperties();
265
+
266
+ if (validateResult) {
267
+ setLinkStepsOutput((linkStepsOutput) => {
268
+ linkStepsOutput.active++;
269
+ }); //
270
+
271
+ if (linkSteps.length === linkStepsOutput.active + 1) {
272
+ setLinkSteps((linkSteps) => {
273
+ linkSteps[linkStepsOutput.active + 1] = {};
274
+ }); //
275
+ }
276
+ }
277
+ }
278
+
279
+ function handlePrevStep() {
280
+ setLinkStepsOutput((linkStepsOutput) => {
281
+ linkStepsOutput.active--;
282
+ });
283
+ }
284
+
285
+ function handleNameRequiredData(e) {
286
+ setNameLinkSteps(e.target.value);
287
+ }
288
+
289
+ function submitLinkSteps() {
290
+ console.log("nameObjectLinkStepEdit:xczxczxsd ", nameObjectLinkStepEdit);
291
+ console.log("nameLinkSteps:xczxczxsd ", nameLinkSteps);
292
+
293
+ if (nameObjectLinkStepEdit !== undefined) {
294
+ if (nameLinkSteps) {
295
+ console.log("xczxczxsd");
296
+ if (successFunc) {
297
+ dispatch(
298
+ successFunc({
299
+ parentOutputId: parentOutputId,
300
+ linkSteps: linkSteps,
301
+ initialObjType: objTypeMain,
302
+ nameLinkStepObject: nameLinkSteps,
303
+ dataType: "text",
304
+ }),
305
+ );
306
+ } else {
307
+ //sortFields in requiredData
308
+ successFuncUseCase(
309
+ parentOutputId,
310
+ linkSteps,
311
+ objTypeMain,
312
+ nameLinkSteps,
313
+ { dataType: "text" },
314
+ );
315
+ }
316
+ statusModalFunc(false);
317
+ } else {
318
+ alert("please fill name");
319
+ }
320
+ } else {
321
+ if (successFuncUseCase) {
322
+ console.log("dofigusoigdjigfdg");
323
+ const resultStaus = successFuncUseCase(parentOutputId, linkSteps);
324
+
325
+ statusModalFunc(resultStaus);
326
+ }
327
+
328
+ // dispatch(
329
+ // successTraversalConfig({
330
+ // parentOutputId: parentOutputId,
331
+ // traversalLinkStepsObj: linkSteps,
332
+ // }),
333
+ // );
334
+ // statusModalFunc(false);
335
+ }
336
+
337
+ // }
338
+ }
339
+
340
+ console.log("nameObjectLinkStepEdit: ", nameObjectLinkStepEdit);
341
+ console.timeEnd("renderTimeInModalRequiredData");
342
+ return (
343
+ <IzaraDivStyle
344
+ styletags={createStyleDefualtTags("modal", "", "mainBackgroundTemplate")}
345
+ >
346
+ <IzaraDivStyle
347
+ styletags={createStyleDefualtTags("modal", "", "mainBoxTemplate")}
348
+ >
349
+ <IzaraDivStyle
350
+ styletags={createStyleDefualtTags("modal", "", "gridTemplate")}
351
+ >
352
+ {/* --------------------------header-------------------- */}
353
+ <IzaraDivStyle
354
+ styletags={createStyleDefualtTags("modal", "", "headerTemplate")}
355
+ >
356
+ <IzaraDivStyle
357
+ styletags={createStyleDefualtTags("textAlign", "", "left")}
358
+ >
359
+ <h1>{titleModal}</h1>
360
+ </IzaraDivStyle>
361
+ {nameObjectLinkStepEdit !== undefined && (
362
+ <input
363
+ onChange={(e) => handleNameRequiredData(e)}
364
+ placeholder="name"
365
+ value={nameLinkSteps}
366
+ disabled={nameObjectLinkStepEdit}
367
+ />
368
+ )}
369
+
370
+ <button onClick={(e) => submitLinkSteps()}>save</button>
371
+ <button onClick={(e) => statusModalFunc(false)}>cancel</button>
372
+ </IzaraDivStyle>
373
+ {/* --------------------------data-------------------- */}
374
+ <div>
375
+ <IzaraDivStyle
376
+ styletags={createStyleDefualtTags("pagination", "", "template")}
377
+ >
378
+ <>
379
+ {linkStepsOutput.active === 0 ? (
380
+ <a style={{ color: "red", pointerEvents: "none" }}>
381
+ {createObjTypeConcat(objTypeMain)}
382
+ </a>
383
+ ) : (
384
+ <a onClick={(e) => handelActiveStep(0)}>
385
+ {createObjTypeConcat(objTypeMain)}
386
+ </a>
387
+ )}
388
+ {linkSteps.length > 1 && (
389
+ <>
390
+ {linkSteps.map((step, index) => (
391
+ <>
392
+ {linkSteps[index - 1]?.pathLinkType.objType && (
393
+ <>
394
+ /
395
+ {linkStepsOutput.active === index ? (
396
+ <a
397
+ style={{ color: "red", pointerEvents: "none" }}
398
+ >
399
+ {createObjTypeConcat(
400
+ linkSteps[index - 1].pathLinkType.objType,
401
+ )}
402
+ </a>
403
+ ) : (
404
+ <a onClick={(e) => handelActiveStep(index)}>
405
+ {createObjTypeConcat(
406
+ linkSteps[index - 1].pathLinkType.objType,
407
+ )}
408
+ </a>
409
+ )}
410
+ </>
411
+ )}
412
+ </>
413
+ ))}
414
+ </>
415
+ )}
416
+ </>
417
+ </IzaraDivStyle>
418
+ <IzaraDivStyle
419
+ // styletags={createStyleDefualtTags("background", "scroll", "div")}
420
+ >
421
+ <p>type:</p>
422
+
423
+ <select
424
+ value={
425
+ linkSteps.length === 0
426
+ ? ""
427
+ : linkSteps[linkStepsOutput.active].pathLinkType?.objType
428
+ ? "link"
429
+ : "lastStep"
430
+ }
431
+ value={
432
+ linkSteps.length === 0
433
+ ? ""
434
+ : linkSteps[linkStepsOutput.active].pathLinkType?.objType
435
+ }
436
+ onChange={(e) => {
437
+ hadelSelectType(e);
438
+ }}
439
+ >
440
+ <option
441
+ // value=""
442
+ // selected={
443
+ // Object.keys(linkSteps[linkStepsOutput.active]).length === 0
444
+ // }
445
+ // disabled={
446
+ // Object.keys(linkSteps[linkStepsOutput.active]).length !== 0
447
+ // }
448
+ >
449
+ -- choose type --
450
+ </option>
451
+ <option value="link">link</option>
452
+ <option value="lastStep">lastStep</option>
453
+ </select>
454
+ </IzaraDivStyle>
455
+ {allObjTypesLinkConfigs ? (
456
+ <IzaraDivStyle
457
+ styletags={createStyleDefualtTags("gridColumn", "", "1")}
458
+ >
459
+ {linkSteps.length === 0 ||
460
+ (linkSteps[linkStepsOutput.active].pathLinkType?.objType && (
461
+ <>
462
+ {!allObjTypesLinkConfigs[
463
+ linkStepsOutput.active === 0
464
+ ? createObjTypeConcat(objTypeMain)
465
+ : createObjTypeConcat(
466
+ linkSteps[linkStepsOutput.active - 1].pathLinkType
467
+ .objType,
468
+ )
469
+ ] ? (
470
+ <IzaraDivStyle
471
+ styletags={createStyleDefualtTags(
472
+ "loadingCircle",
473
+ "20px",
474
+ "template",
475
+ )}
476
+ ></IzaraDivStyle>
477
+ ) : (
478
+ <>
479
+ <IzaraDivStyle
480
+ // styletags={createStyleDefualtTags(
481
+ // "background",
482
+ // "scroll ",
483
+ // "div"
484
+ // )}
485
+ >
486
+ <p> relationship type:</p>
487
+ <select
488
+ value={JSON.stringify(
489
+ linkSteps[linkStepsOutput.active].pathLinkType
490
+ .relType,
491
+ )}
492
+ onChange={handelSelectRelTypeAndDirection}
493
+ >
494
+ <option
495
+ value=""
496
+ disabled={
497
+ Object.keys(
498
+ linkSteps[linkStepsOutput.active]
499
+ .pathLinkType.relType,
500
+ ).length !== 0
501
+ }
502
+ >
503
+ -- relType --
504
+ </option>
505
+ {allObjTypesLinkConfigs[
506
+ linkStepsOutput.active === 0
507
+ ? createObjTypeConcat(objTypeMain)
508
+ : createObjTypeConcat(
509
+ linkSteps[linkStepsOutput.active - 1]
510
+ .pathLinkType.objType,
511
+ )
512
+ ].map((dataLink, index) => (
513
+ <option
514
+ key={index}
515
+ value={JSON.stringify(dataLink.relType)}
516
+ >
517
+ {createRelTypeConcat(dataLink.relType)}
518
+ </option>
519
+ ))}
520
+ </select>
521
+
522
+ {Object.keys(
523
+ linkSteps[linkStepsOutput.active]?.pathLinkType
524
+ ?.relType,
525
+ ).length !== 0 && (
526
+ <>
527
+ <p> object type:</p>
528
+ <span>
529
+ {createObjTypeConcat(
530
+ linkSteps[linkStepsOutput.active]
531
+ ?.pathLinkType.objType,
532
+ )}
533
+ </span>
534
+ <p>direction</p>
535
+ <span>
536
+ {
537
+ linkSteps[linkStepsOutput.active]
538
+ ?.pathLinkType.direction
539
+ }
540
+ </span>
541
+ <br></br>
542
+ <hr></hr>
543
+ {ComponentUseCase && (
544
+ <ComponentUseCase
545
+ allObjTypesLinkConfigs={
546
+ allObjTypesLinkConfigs
547
+ }
548
+ resultFieldName={resultFieldName}
549
+ linkSteps={linkSteps}
550
+ setLinkSteps={setLinkSteps}
551
+ linkStepsOutput={linkStepsOutput}
552
+ objTypeMain={objTypeMain}
553
+ valueUserTags={valueUserTags}
554
+ objConfigUseCase={objConfigUseCase}
555
+ parentOutputId={parentOutputId}
556
+ collectObjectLinksWithRequestProperties={
557
+ collectObjectLinksWithRequestProperties
558
+ }
559
+ collectObjectSchemaWithHierarchy={
560
+ collectObjectSchemaWithHierarchy
561
+ }
562
+ LastStepsComponentUseCase={
563
+ LastStepsComponentUseCase
564
+ }
565
+ // funcUseCase={funcUseCase}
566
+ />
567
+ )}
568
+ </>
569
+ )}
570
+ </IzaraDivStyle>
571
+ </>
572
+ )}
573
+ </>
574
+ ))}
575
+
576
+ {LastStepsComponentUseCase && (
577
+ <LastStepsComponentUseCase
578
+ parentOutputId={parentOutputId}
579
+ linkSteps={linkSteps}
580
+ setLinkSteps={setLinkSteps}
581
+ linkStepsOutput={linkStepsOutput}
582
+ objTypeMain={objTypeMain}
583
+ resultFieldName={resultFieldName}
584
+ valueUserTags={valueUserTags}
585
+ />
586
+ )}
587
+ </IzaraDivStyle>
588
+ ) : (
589
+ <>
590
+ <IzaraDivStyle
591
+ styletags={createStyleDefualtTags(
592
+ "loadingCircle",
593
+ "20px",
594
+ "template",
595
+ )}
596
+ ></IzaraDivStyle>
597
+ </>
598
+ )}
599
+ </div>
600
+
601
+ {/* --------------------------footer-------------------- */}
602
+ <IzaraDivStyle
603
+ styletags={createStyleDefualtTags("gridColumn", "", "11")}
604
+ >
605
+ <button
606
+ onClick={handlePrevStep}
607
+ disabled={linkStepsOutput.active === 0}
608
+ >
609
+ prev
610
+ </button>
611
+ <button
612
+ onClick={handleNextStep}
613
+ disabled={
614
+ linkSteps[linkStepsOutput.active]?.pathLinkType?.direction ===
615
+ "" ||
616
+ !linkSteps[linkStepsOutput.active]?.pathLinkType?.objType
617
+ }
618
+ >
619
+ next
620
+ </button>
621
+ </IzaraDivStyle>
622
+ </IzaraDivStyle>
623
+ </IzaraDivStyle>
624
+ </IzaraDivStyle>
625
+ );
626
+ };
627
+
628
+ //----------------------------- use Lib -----------------------------------------------