@sustaina/shared-ui 1.13.1 → 1.13.2

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/index.d.mts CHANGED
@@ -38,6 +38,7 @@ interface FieldSchemaBase<T extends FieldType> {
38
38
  type: T;
39
39
  label?: string;
40
40
  multiTableSearch?: boolean;
41
+ lookupFieldName?: string;
41
42
  }
42
43
  interface DropdownFieldSchema extends FieldSchemaBase<"dropdown"> {
43
44
  options: Option[];
@@ -77,6 +78,7 @@ type RowState = {
77
78
  value2?: undefined;
78
79
  multiTableSearch?: boolean;
79
80
  jsonPath?: string[];
81
+ lookupFieldName?: string;
80
82
  } | {
81
83
  id: string;
82
84
  fieldName: string;
@@ -86,6 +88,7 @@ type RowState = {
86
88
  value2: string;
87
89
  multiTableSearch?: boolean;
88
90
  jsonPath?: string[];
91
+ lookupFieldName?: string;
89
92
  };
90
93
  interface Params {
91
94
  AND: Record<string, unknown>[];
package/dist/index.d.ts CHANGED
@@ -38,6 +38,7 @@ interface FieldSchemaBase<T extends FieldType> {
38
38
  type: T;
39
39
  label?: string;
40
40
  multiTableSearch?: boolean;
41
+ lookupFieldName?: string;
41
42
  }
42
43
  interface DropdownFieldSchema extends FieldSchemaBase<"dropdown"> {
43
44
  options: Option[];
@@ -77,6 +78,7 @@ type RowState = {
77
78
  value2?: undefined;
78
79
  multiTableSearch?: boolean;
79
80
  jsonPath?: string[];
81
+ lookupFieldName?: string;
80
82
  } | {
81
83
  id: string;
82
84
  fieldName: string;
@@ -86,6 +88,7 @@ type RowState = {
86
88
  value2: string;
87
89
  multiTableSearch?: boolean;
88
90
  jsonPath?: string[];
91
+ lookupFieldName?: string;
89
92
  };
90
93
  interface Params {
91
94
  AND: Record<string, unknown>[];
package/dist/index.js CHANGED
@@ -666,7 +666,19 @@ function makeNewRow(field) {
666
666
  value: "",
667
667
  value2: "",
668
668
  multiTableSearch: field.multiTableSearch,
669
- jsonPath: field.jsonPath
669
+ lookupFieldName: field.lookupFieldName
670
+ };
671
+ }
672
+ if (field.type === "json") {
673
+ return {
674
+ id: crypto.randomUUID(),
675
+ fieldName: field.name,
676
+ fieldType: field.type,
677
+ operator: op,
678
+ value: "",
679
+ multiTableSearch: field.multiTableSearch,
680
+ jsonPath: field.jsonPath,
681
+ lookupFieldName: field.lookupFieldName
670
682
  };
671
683
  }
672
684
  return {
@@ -676,7 +688,7 @@ function makeNewRow(field) {
676
688
  operator: op,
677
689
  value: "",
678
690
  multiTableSearch: field.multiTableSearch,
679
- jsonPath: field.jsonPath
691
+ lookupFieldName: field.lookupFieldName
680
692
  };
681
693
  }
682
694
  function useAdvanceSearch({ fields, limitRows }) {
@@ -718,7 +730,8 @@ function useAdvanceSearch({ fields, limitRows }) {
718
730
  value: "",
719
731
  value2: "",
720
732
  multiTableSearch: r.multiTableSearch,
721
- jsonPath: r.jsonPath
733
+ jsonPath: r.jsonPath,
734
+ lookupFieldName: r.lookupFieldName
722
735
  } : {
723
736
  id: r.id,
724
737
  fieldName: r.fieldName,
@@ -726,7 +739,8 @@ function useAdvanceSearch({ fields, limitRows }) {
726
739
  operator: nextOp,
727
740
  value: "",
728
741
  multiTableSearch: r.multiTableSearch,
729
- jsonPath: r.jsonPath
742
+ jsonPath: r.jsonPath,
743
+ lookupFieldName: r.lookupFieldName
730
744
  };
731
745
  })
732
746
  );
@@ -759,6 +773,7 @@ function useAdvanceSearch({ fields, limitRows }) {
759
773
  fieldName: r.fieldName,
760
774
  fieldType: r.fieldType,
761
775
  multiTableSearch: r.multiTableSearch,
776
+ lookupFieldName: r.lookupFieldName,
762
777
  jsonPath: r.jsonPath,
763
778
  operator,
764
779
  value: "",
@@ -770,6 +785,7 @@ function useAdvanceSearch({ fields, limitRows }) {
770
785
  fieldName: r.fieldName,
771
786
  fieldType: r.fieldType,
772
787
  multiTableSearch: r.multiTableSearch,
788
+ lookupFieldName: r.lookupFieldName,
773
789
  jsonPath: r.jsonPath,
774
790
  operator,
775
791
  value: ""
@@ -3118,40 +3134,29 @@ var JSONBuilder = class {
3118
3134
  // src/components/advanceSearch/builder/lookup.ts
3119
3135
  var LookupBuilder = class {
3120
3136
  build(row) {
3137
+ if (!Array.isArray(row.value)) {
3138
+ return {};
3139
+ }
3140
+ const lookupField = row.lookupFieldName ?? "id";
3121
3141
  switch (row.operator) {
3122
3142
  case "containsAny":
3123
3143
  return {
3124
- [row.fieldName]: helper(
3125
- { hasSome: String(row.value).split(",") },
3126
- { multiTableSearch: row.multiTableSearch }
3127
- )
3144
+ OR: row.value.map((v) => ({ [row.fieldName]: { some: { [lookupField]: v } } }))
3128
3145
  };
3129
- case "containsAll":
3146
+ case "containsOnly":
3130
3147
  return {
3131
- [row.fieldName]: helper(
3132
- { hasEvery: String(row.value).split(",") },
3133
- { multiTableSearch: row.multiTableSearch }
3134
- )
3148
+ AND: row.value.map((v) => ({ [row.fieldName]: { some: { [lookupField]: v } } }))
3135
3149
  };
3136
- case "containsOnly":
3150
+ case "containsAll": {
3151
+ const includes = row.value.map((v) => ({ [row.fieldName]: { some: { [lookupField]: v } } }));
3152
+ const excludes = { [row.fieldName]: { none: { [lookupField]: { notIn: row.value } } } };
3137
3153
  return {
3138
- [row.fieldName]: helper(
3139
- { equals: String(row.value).split(",") },
3140
- {
3141
- multiTableSearch: row.multiTableSearch,
3142
- insensitive: true
3143
- }
3144
- )
3154
+ AND: [...includes, excludes]
3145
3155
  };
3156
+ }
3146
3157
  case "notContains":
3147
3158
  return {
3148
- [row.fieldName]: helper(
3149
- { not: { contains: row.value } },
3150
- {
3151
- multiTableSearch: row.multiTableSearch,
3152
- insensitive: true
3153
- }
3154
- )
3159
+ NOT: { OR: row.value.map((v) => ({ [row.fieldName]: { some: { [lookupField]: v } } })) }
3155
3160
  };
3156
3161
  default:
3157
3162
  return {};