datastake-daf 0.6.510 → 0.6.511

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.
@@ -36742,21 +36742,20 @@ function AjaxSelectMain(_ref) {
36742
36742
  };
36743
36743
  const endpoint = meta !== null && meta !== void 0 && meta.endpoint ? "".concat(url).concat(meta === null || meta === void 0 ? void 0 : meta.endpoint) : meta.application && !queryOptionsApps.includes(app) ? "".concat(url, "/query/").concat(app, "/options") : "".concat(url, "/").concat(queryOptionsAppEndpoints[app] || "query/options");
36744
36744
  React.useEffect(() => {
36745
- if (value === "new") {
36746
- if (!model.find(m => m.value === "new")) {
36747
- setModel(model.concat({
36748
- label: searchValue || t("New"),
36749
- value: "new"
36750
- }));
36745
+ // Check if this is a new item (not in the fetched model from server)
36746
+ const isNewItem = value && typeof value === 'string' && !model.find(m => m.value === value);
36747
+ if (isNewItem && value) {
36748
+ // Add the new item to the model with its actual value
36749
+ if (!model.find(m => m.value === value)) {
36750
+ const newOption = {
36751
+ label: value,
36752
+ value: value
36753
+ };
36754
+ setModel(model.concat(newOption));
36751
36755
  if (updateOptions) {
36752
- onOptions(model.concat({
36753
- label: searchValue || t("New"),
36754
- value: "new"
36755
- }));
36756
+ onOptions(model.concat(newOption));
36756
36757
  }
36757
36758
  }
36758
- } else {
36759
- setModel(model.filter(v => v.value !== "new"));
36760
36759
  }
36761
36760
  setModelValue(value ? value : multiple ? [] : null);
36762
36761
  setSearchValue(value);
@@ -36855,16 +36854,18 @@ function AjaxSelectMain(_ref) {
36855
36854
  let {
36856
36855
  data
36857
36856
  } = _ref2;
36858
- //? FUTURE ILVI KEEP THIS IN MIND
36859
36857
  if (meta.saveAjaxOptions) {
36860
36858
  changeAjaxOptions(name, data);
36861
36859
  }
36862
- if (modelValue === "new") {
36863
- const newData = model.find(m => m.value === "new");
36864
- data = data.concat([newData || {
36865
- label: (inputMeta === null || inputMeta === void 0 ? void 0 : inputMeta.name) || searchValue || t("New"),
36866
- value: "new"
36867
- }]);
36860
+
36861
+ // Check if current value is a new item (not in fetched data)
36862
+ const isNewItem = modelValue && !data.find(d => d.value === modelValue);
36863
+ if (isNewItem) {
36864
+ // Preserve the new item in the options
36865
+ const newItem = model.find(m => m.value === modelValue);
36866
+ if (newItem) {
36867
+ data = data.concat([newItem]);
36868
+ }
36868
36869
  } else {
36869
36870
  updateLabel(data, undefined, true);
36870
36871
  setTimeout(() => {
@@ -37068,7 +37069,7 @@ function AjaxSelectMain(_ref) {
37068
37069
  marginTop: 4
37069
37070
  }
37070
37071
  }),
37071
- disabled: !searchValue || typeof searchValue === "string" && searchValue.trim() === "" || (typeof modelValue === "string" && modelValue !== "new" || modelValue === "new" && model.filter(m => m.value === "new" && m.label === searchValue)) && asOption,
37072
+ disabled: !searchValue || typeof searchValue === "string" && searchValue.trim() === "" || model.find(m => m.value === searchValue) && asOption,
37072
37073
  type: "link primary",
37073
37074
  onClick: () => {
37074
37075
  const oldValue = searchValue;
@@ -37175,14 +37176,11 @@ function AjaxSelectMain(_ref) {
37175
37176
  setModelValue(value);
37176
37177
  }
37177
37178
  }
37178
- if (!value) {
37179
- setModel([...(model || []).filter(m => m.value !== "new")]);
37180
- }
37181
37179
  };
37182
37180
  const addNewData = oldValue => {
37183
37181
  if (onNewSetValue) {
37184
37182
  if (repeatIndex !== null && repeatValues) {
37185
- repeatValues[inputName] = "new";
37183
+ repeatValues[inputName] = oldValue;
37186
37184
  repeatValues[onNewSetValue] = oldValue;
37187
37185
  if (!formsValue[name]) {
37188
37186
  formsValue[name] = [];
@@ -37192,10 +37190,12 @@ function AjaxSelectMain(_ref) {
37192
37190
  // mainForm.scrollToField([name, repeatIndex, onNewSetValue]);
37193
37191
  }
37194
37192
  }
37195
- const newModelInd = model.findIndex(m => m.value === "new");
37193
+
37194
+ // Use the actual value instead of "new"
37195
+ const newModelInd = model.findIndex(m => m.value === oldValue);
37196
37196
  let newModel = {
37197
37197
  label: oldValue,
37198
- value: "new"
37198
+ value: oldValue
37199
37199
  };
37200
37200
  if (newModelInd >= 0) {
37201
37201
  model[newModelInd] = newModel;
@@ -37206,17 +37206,17 @@ function AjaxSelectMain(_ref) {
37206
37206
  if (updateOptions) {
37207
37207
  onOptions(model.concat({
37208
37208
  label: oldValue || t("New"),
37209
- value: "new"
37209
+ value: oldValue
37210
37210
  }));
37211
37211
  }
37212
- setModelValue("new");
37212
+ setModelValue(oldValue);
37213
37213
  inst.current.blur();
37214
37214
  if (!onNewSetValue) {
37215
37215
  const otherValues = onNewSetValue ? {
37216
37216
  [onNewSetValue]: searchValue,
37217
- [name]: "new"
37217
+ [name]: oldValue
37218
37218
  } : {
37219
- [name]: "new"
37219
+ [name]: oldValue
37220
37220
  };
37221
37221
 
37222
37222
  // remove keys, because can be from prev selection
@@ -37257,7 +37257,7 @@ function AjaxSelectMain(_ref) {
37257
37257
  return;
37258
37258
  }
37259
37259
  setTimeout(() => {
37260
- onChange("new", model || []);
37260
+ onChange(oldValue, model || []);
37261
37261
  addNewValueKey(searchValue);
37262
37262
  }, 200);
37263
37263
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "datastake-daf",
3
- "version": "0.6.510",
3
+ "version": "0.6.511",
4
4
  "dependencies": {
5
5
  "@ant-design/icons": "^5.2.5",
6
6
  "@antv/g2": "^5.1.1",
@@ -88,15 +88,18 @@ export function AjaxSelectMain({
88
88
  : `${url}/${queryOptionsAppEndpoints[app] || "query/options"}`;
89
89
 
90
90
  useEffect(() => {
91
- if (value === "new") {
92
- if (!model.find((m) => m.value === "new")) {
93
- setModel(model.concat({ label: searchValue || t("New"), value: "new" }));
91
+ // Check if this is a new item (not in the fetched model from server)
92
+ const isNewItem = value && typeof value === 'string' && !model.find((m) => m.value === value);
93
+
94
+ if (isNewItem && value) {
95
+ // Add the new item to the model with its actual value
96
+ if (!model.find((m) => m.value === value)) {
97
+ const newOption = { label: value, value: value };
98
+ setModel(model.concat(newOption));
94
99
  if (updateOptions) {
95
- onOptions(model.concat({ label: searchValue || t("New"), value: "new" }));
100
+ onOptions(model.concat(newOption));
96
101
  }
97
102
  }
98
- } else {
99
- setModel(model.filter((v) => v.value !== "new"));
100
103
  }
101
104
  setModelValue(value ? value : multiple ? [] : null);
102
105
  setSearchValue(value);
@@ -214,19 +217,18 @@ export function AjaxSelectMain({
214
217
  },
215
218
  )
216
219
  .then(({ data }) => {
217
- //? FUTURE ILVI KEEP THIS IN MIND
218
220
  if (meta.saveAjaxOptions) {
219
221
  changeAjaxOptions(name, data);
220
222
  }
221
223
 
222
- if (modelValue === "new") {
223
- const newData = model.find((m) => m.value === "new");
224
- data = data.concat([
225
- newData || {
226
- label: inputMeta?.name || searchValue || t("New"),
227
- value: "new",
228
- },
229
- ]);
224
+ // Check if current value is a new item (not in fetched data)
225
+ const isNewItem = modelValue && !data.find((d) => d.value === modelValue);
226
+ if (isNewItem) {
227
+ // Preserve the new item in the options
228
+ const newItem = model.find((m) => m.value === modelValue);
229
+ if (newItem) {
230
+ data = data.concat([newItem]);
231
+ }
230
232
  } else {
231
233
  updateLabel(data, undefined, true);
232
234
  setTimeout(() => {
@@ -445,10 +447,7 @@ export function AjaxSelectMain({
445
447
  disabled={
446
448
  !searchValue ||
447
449
  (typeof searchValue === "string" && searchValue.trim() === "") ||
448
- (((typeof modelValue === "string" && modelValue !== "new") ||
449
- (modelValue === "new" &&
450
- model.filter((m) => m.value === "new" && m.label === searchValue))) &&
451
- asOption)
450
+ (model.find((m) => m.value === searchValue) && asOption)
452
451
  }
453
452
  type="link primary"
454
453
  onClick={() => {
@@ -575,15 +574,12 @@ export function AjaxSelectMain({
575
574
  setModelValue(value);
576
575
  }
577
576
  }
578
- if (!value) {
579
- setModel([...(model || []).filter((m) => m.value !== "new")]);
580
- }
581
577
  };
582
578
 
583
579
  const addNewData = (oldValue) => {
584
580
  if (onNewSetValue) {
585
581
  if (repeatIndex !== null && repeatValues) {
586
- repeatValues[inputName] = "new";
582
+ repeatValues[inputName] = oldValue;
587
583
  repeatValues[onNewSetValue] = oldValue;
588
584
  if (!formsValue[name]) {
589
585
  formsValue[name] = [];
@@ -596,8 +592,10 @@ export function AjaxSelectMain({
596
592
  // mainForm.scrollToField(onNewSetValue);
597
593
  }
598
594
  }
599
- const newModelInd = model.findIndex((m) => m.value === "new");
600
- let newModel = { label: oldValue, value: "new" };
595
+
596
+ // Use the actual value instead of "new"
597
+ const newModelInd = model.findIndex((m) => m.value === oldValue);
598
+ let newModel = { label: oldValue, value: oldValue };
601
599
  if (newModelInd >= 0) {
602
600
  model[newModelInd] = newModel;
603
601
  } else {
@@ -606,17 +604,17 @@ export function AjaxSelectMain({
606
604
 
607
605
  setModel([...model]);
608
606
  if (updateOptions) {
609
- onOptions(model.concat({ label: oldValue || t("New"), value: "new" }));
607
+ onOptions(model.concat({ label: oldValue || t("New"), value: oldValue }));
610
608
  }
611
- setModelValue("new");
609
+ setModelValue(oldValue);
612
610
  inst.current.blur();
613
611
  if (!onNewSetValue) {
614
612
  const otherValues = onNewSetValue
615
613
  ? {
616
614
  [onNewSetValue]: searchValue,
617
- [name]: "new",
615
+ [name]: oldValue,
618
616
  }
619
- : { [name]: "new" };
617
+ : { [name]: oldValue };
620
618
 
621
619
  // remove keys, because can be from prev selection
622
620
  toRemoveKeysOnNew.forEach((k) => {
@@ -664,7 +662,7 @@ export function AjaxSelectMain({
664
662
  }
665
663
 
666
664
  setTimeout(() => {
667
- onChange("new", model || []);
665
+ onChange(oldValue, model || []);
668
666
  addNewValueKey(searchValue, true);
669
667
  }, 200);
670
668
  };