@vulcanjs/react-ui 0.7.2-alpha.5 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/components/Datatable/Datatable.d.ts +39 -0
- package/dist/components/Datatable/DatatableCell.d.ts +26 -0
- package/dist/components/Datatable/DatatableContents.d.ts +53 -0
- package/dist/components/Datatable/DatatableFilter.d.ts +33 -0
- package/dist/components/Datatable/DatatableHeader.d.ts +23 -0
- package/dist/components/Datatable/DatatableRow.d.ts +25 -0
- package/dist/components/Datatable/DatatableSelect.d.ts +11 -0
- package/dist/components/Datatable/DatatableSorter.d.ts +8 -0
- package/dist/components/Datatable/DatatableSubmitSelected.d.ts +6 -0
- package/dist/components/Datatable/others/DeleteButton.d.ts +13 -0
- package/dist/components/Datatable/others/EditButton.d.ts +20 -0
- package/dist/components/Datatable/others/NewButton.d.ts +20 -0
- package/dist/components/HeadTags.d.ts +13 -0
- package/dist/components/LoadingButton.d.ts +11 -0
- package/dist/components/MutationButton.d.ts +20 -0
- package/dist/components/VulcanComponents/Context.d.ts.map +1 -1
- package/dist/components/VulcanComponents/defaultVulcanComponents/cellComponents.d.ts +3 -0
- package/dist/components/VulcanComponents/defaultVulcanComponents/coreComponents.d.ts +3 -0
- package/dist/components/VulcanComponents/defaultVulcanComponents/datatableComponents.d.ts +3 -0
- package/dist/components/VulcanComponents/defaultVulcanComponents/formComponents.d.ts +3 -0
- package/dist/components/bootstrap/Dropdown.d.ts +24 -0
- package/dist/components/bootstrap/Modal.d.ts +25 -0
- package/dist/components/bootstrap/ModalTrigger.d.ts +18 -0
- package/dist/components/bootstrap/TooltipTrigger.d.ts +6 -0
- package/dist/components/cell/CardItem.d.ts +14 -0
- package/dist/components/cell/CardItemArray.d.ts +6 -0
- package/dist/components/cell/CardItemDate.d.ts +5 -0
- package/dist/components/cell/CardItemDefault.d.ts +5 -0
- package/dist/components/cell/CardItemHTML.d.ts +5 -0
- package/dist/components/cell/CardItemImage.d.ts +6 -0
- package/dist/components/cell/CardItemNumber.d.ts +5 -0
- package/dist/components/cell/CardItemObject.d.ts +3 -0
- package/dist/components/cell/CardItemRelationHasMany.d.ts +3 -0
- package/dist/components/cell/CardItemRelationHasOne.d.ts +3 -0
- package/dist/components/cell/CardItemRelationItem.d.ts +15 -0
- package/dist/components/cell/CardItemString.d.ts +5 -0
- package/dist/components/cell/CardItemURL.d.ts +6 -0
- package/dist/components/core/Button.d.ts +4 -0
- package/dist/components/core/Loading.d.ts +3 -0
- package/dist/components/form/FieldErrors.d.ts +6 -0
- package/dist/components/form/Form/Form.d.ts +4 -0
- package/dist/components/form/Form/fields.d.ts +22 -0
- package/dist/components/form/Form/index.d.ts +3 -0
- package/dist/components/form/Form/typings.d.ts +76 -0
- package/dist/components/form/Form/utils.d.ts +2 -0
- package/dist/components/form/FormComponent.d.ts +31 -0
- package/dist/components/form/FormComponentInner.d.ts +32 -0
- package/dist/components/form/FormComponentLoader.d.ts +15 -0
- package/dist/components/form/FormContainer.d.ts +18 -0
- package/dist/components/form/FormContext.d.ts +25 -0
- package/dist/components/form/FormElement.d.ts +4 -0
- package/dist/components/form/FormError.d.ts +11 -0
- package/dist/components/form/FormErrors.d.ts +3 -0
- package/dist/components/form/FormGroup.d.ts +30 -0
- package/dist/components/form/FormIntl.d.ts +15 -0
- package/dist/components/form/FormLayout.d.ts +10 -0
- package/dist/components/form/FormNestedArray.d.ts +26 -0
- package/dist/components/form/FormNestedArrayLayout.d.ts +18 -0
- package/dist/components/form/FormNestedDivider.d.ts +13 -0
- package/dist/components/form/FormNestedItem.d.ts +52 -0
- package/dist/components/form/FormNestedObject.d.ts +35 -0
- package/dist/components/form/FormOptionLabel.d.ts +5 -0
- package/dist/components/form/FormSubmit.d.ts +38 -0
- package/dist/components/form/core/Button.d.ts +4 -0
- package/dist/components/form/core/Form/Form.d.ts.map +1 -1
- package/dist/components/form/core/Form/hooks.d.ts +16 -0
- package/dist/components/form/core/Form/hooks.d.ts.map +1 -0
- package/dist/components/form/core/FormComponent.d.ts +31 -0
- package/dist/components/form/core/FormComponentInner.d.ts +32 -0
- package/dist/components/form/core/FormComponentLoader.d.ts +15 -0
- package/dist/components/form/core/FormContainer.d.ts.map +1 -1
- package/dist/components/form/core/FormContext.d.ts +4 -7
- package/dist/components/form/core/FormContext.d.ts.map +1 -1
- package/dist/components/form/core/FormGroup.d.ts +30 -0
- package/dist/components/form/core/Loading.d.ts +3 -0
- package/dist/components/form/elements/FieldErrors.d.ts +5 -0
- package/dist/components/form/elements/FormElement.d.ts +4 -0
- package/dist/components/form/elements/FormError.d.ts +11 -0
- package/dist/components/form/elements/FormErrors.d.ts +3 -0
- package/dist/components/form/elements/FormLayout.d.ts +10 -0
- package/dist/components/form/elements/FormSubmit.d.ts +38 -0
- package/dist/components/form/elements/index.d.ts +7 -0
- package/dist/components/form/inputs/AutocompleteMultiple.d.ts +6 -0
- package/dist/components/form/inputs/BasicInputs.d.ts +16 -0
- package/dist/components/form/inputs/Checkboxgroup.d.ts +9 -0
- package/dist/components/form/inputs/FormItem.d.ts +4 -0
- package/dist/components/form/inputs/FormOptionLabel.d.ts +7 -0
- package/dist/components/form/inputs/RadioGroup.d.ts +4 -0
- package/dist/components/form/inputs/SelectInputs.d.ts +5 -0
- package/dist/components/form/inputs/consts.d.ts +9 -0
- package/dist/components/form/inputs/index.d.ts +8 -0
- package/dist/components/form/intl/FormIntl.d.ts +15 -0
- package/dist/components/form/modules/formFragments.d.ts +16 -0
- package/dist/components/form/modules/path_utils.d.ts +6 -0
- package/dist/components/form/modules/schema_utils.d.ts +14 -0
- package/dist/components/form/modules/utils.d.ts +17 -0
- package/dist/components/form/nested/FormNestedArray.d.ts +26 -0
- package/dist/components/form/nested/FormNestedArrayLayout.d.ts +18 -0
- package/dist/components/form/nested/FormNestedDivider.d.ts +13 -0
- package/dist/components/form/nested/FormNestedItem.d.ts +52 -0
- package/dist/components/form/nested/FormNestedObject.d.ts +35 -0
- package/dist/components/form/nested/index.d.ts +6 -0
- package/dist/components/form/ui_utils.d.ts +3 -0
- package/dist/components/form/useBlockTransition/block.d.ts +4 -0
- package/dist/components/form/useBlockTransition/useBlockTransition.d.ts +5 -0
- package/dist/components/form/useWarnOnUnsaved/index.d.ts +2 -0
- package/dist/components/form/useWarnOnUnsaved/useWarnOnUnsaved.d.ts +5 -0
- package/dist/decorators/autocomplete.d.ts +8 -0
- package/dist/decorators/index.d.ts +4 -0
- package/dist/index.d.ts +5 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +125 -99
- package/dist/index.js.map +1 -1
- package/package.json +11 -11
package/dist/index.js
CHANGED
@@ -665,11 +665,14 @@ var LoadingButton = /* @__PURE__ */ __name((_a) => {
|
|
665
665
|
className: `loading-button ${loading ? "loading-button-loading" : "loading-button-notloading"} ${className}`,
|
666
666
|
onClick
|
667
667
|
}, rest), /* @__PURE__ */ React4.createElement("span", {
|
668
|
-
style: wrapperStyle
|
668
|
+
style: wrapperStyle,
|
669
|
+
className: "loading-button-inner"
|
669
670
|
}, /* @__PURE__ */ React4.createElement("span", {
|
670
|
-
style: labelStyle
|
671
|
+
style: labelStyle,
|
672
|
+
className: "loading-button-label"
|
671
673
|
}, label || children), /* @__PURE__ */ React4.createElement("span", {
|
672
|
-
style: loadingStyle
|
674
|
+
style: loadingStyle,
|
675
|
+
className: "loading-button-loader"
|
673
676
|
}, /* @__PURE__ */ React4.createElement(Components2.Loading, null))));
|
674
677
|
}, "LoadingButton");
|
675
678
|
|
@@ -899,7 +902,7 @@ var useFormContext = /* @__PURE__ */ __name(() => {
|
|
899
902
|
}, "useFormContext");
|
900
903
|
|
901
904
|
// components/form/core/Form/Form.tsx
|
902
|
-
import React7, { useEffect as useEffect2, useRef as useRef2, useState as
|
905
|
+
import React7, { useEffect as useEffect2, useRef as useRef2, useState as useState3 } from "react";
|
903
906
|
import { runCallbacks, getErrors } from "@vulcanjs/core";
|
904
907
|
import { useIntlContext as useIntlContext2 } from "@vulcanjs/react-i18n";
|
905
908
|
import { removeProperty } from "@vulcanjs/utils";
|
@@ -1553,6 +1556,46 @@ var useWarnOnUnsaved = /* @__PURE__ */ __name(({ isChanged, warnUnsavedChanges }
|
|
1553
1556
|
});
|
1554
1557
|
}, "useWarnOnUnsaved");
|
1555
1558
|
|
1559
|
+
// components/form/core/Form/hooks.ts
|
1560
|
+
import { useState as useState2 } from "react";
|
1561
|
+
var useSubmitCallbacks = /* @__PURE__ */ __name(() => {
|
1562
|
+
const [callbacks, setCallbacks] = useState2({
|
1563
|
+
submitFormCallbacks: [],
|
1564
|
+
successFormCallbacks: [],
|
1565
|
+
failureFormCallbacks: []
|
1566
|
+
});
|
1567
|
+
const addToSubmitForm = /* @__PURE__ */ __name((callback) => {
|
1568
|
+
setCallbacks((cbs) => __spreadProps(__spreadValues({}, cbs), {
|
1569
|
+
submitFormCallbacks: [
|
1570
|
+
...cbs.submitFormCallbacks,
|
1571
|
+
callback
|
1572
|
+
]
|
1573
|
+
}));
|
1574
|
+
}, "addToSubmitForm");
|
1575
|
+
const addToSuccessForm = /* @__PURE__ */ __name((callback) => {
|
1576
|
+
setCallbacks((cbs) => __spreadProps(__spreadValues({}, cbs), {
|
1577
|
+
successFormCallbacks: [
|
1578
|
+
...cbs.successFormCallbacks,
|
1579
|
+
callback
|
1580
|
+
]
|
1581
|
+
}));
|
1582
|
+
}, "addToSuccessForm");
|
1583
|
+
const addToFailureForm = /* @__PURE__ */ __name((callback) => {
|
1584
|
+
setCallbacks((cbs) => __spreadProps(__spreadValues({}, cbs), {
|
1585
|
+
failureFormCallbacks: [
|
1586
|
+
...cbs.failureFormCallbacks,
|
1587
|
+
callback
|
1588
|
+
]
|
1589
|
+
}));
|
1590
|
+
}, "addToFailureForm");
|
1591
|
+
return {
|
1592
|
+
callbacks,
|
1593
|
+
addToSuccessForm,
|
1594
|
+
addToSubmitForm,
|
1595
|
+
addToFailureForm
|
1596
|
+
};
|
1597
|
+
}, "useSubmitCallbacks");
|
1598
|
+
|
1556
1599
|
// components/form/core/Form/Form.tsx
|
1557
1600
|
function _extends4() {
|
1558
1601
|
_extends4 = Object.assign || function(target) {
|
@@ -1569,6 +1612,8 @@ function _extends4() {
|
|
1569
1612
|
return _extends4.apply(this, arguments);
|
1570
1613
|
}
|
1571
1614
|
__name(_extends4, "_extends");
|
1615
|
+
var NEW_FORM_TYPE = "new";
|
1616
|
+
var EDIT_FORM_TYPE = "edit";
|
1572
1617
|
var compactParent = /* @__PURE__ */ __name((object, path) => {
|
1573
1618
|
const parentPath = getParentPath(path);
|
1574
1619
|
const compactIfArray = /* @__PURE__ */ __name((x) => Array.isArray(x) ? compact2(x) : x, "compactIfArray");
|
@@ -1581,8 +1626,8 @@ var compactObject = /* @__PURE__ */ __name((o) => omitBy(o, (f) => f === null ||
|
|
1581
1626
|
var getInitialStateFromProps = /* @__PURE__ */ __name((nextProps) => {
|
1582
1627
|
const schema = nextProps.schema || nextProps.model.schema;
|
1583
1628
|
const convertedSchema = convertSchema(schema);
|
1584
|
-
const formType = nextProps.document ?
|
1585
|
-
const defaultValues = formType ===
|
1629
|
+
const formType = nextProps.document ? EDIT_FORM_TYPE : NEW_FORM_TYPE;
|
1630
|
+
const defaultValues = formType === NEW_FORM_TYPE ? getDefaultValues(convertedSchema) : {};
|
1586
1631
|
const initialDocument = merge2({}, defaultValues, nextProps.prefilledProps, compactObject(nextProps.document));
|
1587
1632
|
Object.keys(convertedSchema).forEach((key) => {
|
1588
1633
|
let minCount = convertedSchema[key].minCount;
|
@@ -1645,7 +1690,7 @@ var getChildrenProps = /* @__PURE__ */ __name((props, state, options, callbacks)
|
|
1645
1690
|
cancelCallback,
|
1646
1691
|
revertCallback,
|
1647
1692
|
document: currentDocument,
|
1648
|
-
deleteDocument: formType ===
|
1693
|
+
deleteDocument: formType === EDIT_FORM_TYPE && showRemove && showDelete && deleteDocument || null
|
1649
1694
|
};
|
1650
1695
|
const formLayoutProps = {
|
1651
1696
|
formProps,
|
@@ -1719,11 +1764,10 @@ var Form = /* @__PURE__ */ __name((props) => {
|
|
1719
1764
|
};
|
1720
1765
|
const allProps = __spreadValues(__spreadValues({}, defaultProps), props);
|
1721
1766
|
const defaultValues = {};
|
1722
|
-
const submitFormCallbacks = [];
|
1723
|
-
const successFormCallbacks = [];
|
1724
|
-
const failureFormCallbacks = [];
|
1725
1767
|
const intl = useIntlContext2();
|
1726
|
-
const
|
1768
|
+
const { callbacks, addToFailureForm, addToSubmitForm, addToSuccessForm } = useSubmitCallbacks();
|
1769
|
+
const { submitFormCallbacks, successFormCallbacks, failureFormCallbacks } = callbacks;
|
1770
|
+
const [errors, setErrors] = useState3([]);
|
1727
1771
|
const throwError = /* @__PURE__ */ __name((error) => {
|
1728
1772
|
let formErrors = getErrors(error);
|
1729
1773
|
console.log(formErrors);
|
@@ -1735,49 +1779,18 @@ var Form = /* @__PURE__ */ __name((props) => {
|
|
1735
1779
|
const clearFieldErrors = /* @__PURE__ */ __name((path) => {
|
1736
1780
|
setErrors((prevErrors) => prevErrors.filter((error) => error.path !== path));
|
1737
1781
|
}, "clearFieldErrors");
|
1738
|
-
const [deletedValues, setDeletedValues] =
|
1782
|
+
const [deletedValues, setDeletedValues] = useState3([]);
|
1739
1783
|
const addToDeletedValues = /* @__PURE__ */ __name((name) => {
|
1740
1784
|
setDeletedValues((prevDeletedValues) => [
|
1741
1785
|
...prevDeletedValues,
|
1742
1786
|
name
|
1743
1787
|
]);
|
1744
1788
|
}, "addToDeletedValues");
|
1745
|
-
const [
|
1746
|
-
|
1747
|
-
|
1748
|
-
failureFormCallbacks: []
|
1749
|
-
});
|
1750
|
-
const addToSubmitForm = /* @__PURE__ */ __name((callback) => {
|
1751
|
-
setCallbacks((cbs) => __spreadValues({}, cbs));
|
1752
|
-
}, "addToSubmitForm");
|
1753
|
-
const addToSuccessForm = /* @__PURE__ */ __name((callback) => {
|
1754
|
-
setCallbacks((cbs) => __spreadProps(__spreadValues({}, cbs), {
|
1755
|
-
successFormCallbacks: [
|
1756
|
-
...cbs.successFormCallbacks,
|
1757
|
-
callback
|
1758
|
-
]
|
1759
|
-
}));
|
1760
|
-
}, "addToSuccessForm");
|
1761
|
-
const addToFailureForm = /* @__PURE__ */ __name((callback) => {
|
1762
|
-
setCallbacks((cbs) => __spreadProps(__spreadValues({}, cbs), {
|
1763
|
-
failureFormCallbacks: [
|
1764
|
-
...cbs.failureFormCallbacks,
|
1765
|
-
callback
|
1766
|
-
]
|
1767
|
-
}));
|
1768
|
-
}, "addToFailureForm");
|
1769
|
-
const clearFormCallbacks = /* @__PURE__ */ __name(() => {
|
1770
|
-
setCallbacks({
|
1771
|
-
submitFormCallbacks: [],
|
1772
|
-
successFormCallbacks: [],
|
1773
|
-
failureFormCallbacks: []
|
1774
|
-
});
|
1775
|
-
}, "clearFormCallbacks");
|
1776
|
-
const [currentValues, setCurrentValues] = useState2({});
|
1777
|
-
const submitFormContext = /* @__PURE__ */ __name((formType) => (event) => {
|
1778
|
-
submitForm(formType)(event);
|
1789
|
+
const [currentValues, setCurrentValues] = useState3({});
|
1790
|
+
const submitFormContext = /* @__PURE__ */ __name(async (event) => {
|
1791
|
+
await submitForm(event);
|
1779
1792
|
}, "submitFormContext");
|
1780
|
-
const [currentDocument, setCurrentDocument] =
|
1793
|
+
const [currentDocument, setCurrentDocument] = useState3(initialDocument);
|
1781
1794
|
const updateCurrentValues = /* @__PURE__ */ __name((newValues, options = {}) => {
|
1782
1795
|
const { mode = "overwrite" } = options;
|
1783
1796
|
const { changeCallback } = props;
|
@@ -1818,8 +1831,8 @@ var Form = /* @__PURE__ */ __name((props) => {
|
|
1818
1831
|
props.refetch();
|
1819
1832
|
}
|
1820
1833
|
}, "refetchForm");
|
1821
|
-
const [disabled, setDisabled] =
|
1822
|
-
const [success, setSuccess] =
|
1834
|
+
const [disabled, setDisabled] = useState3(!!props.disabled);
|
1835
|
+
const [success, setSuccess] = useState3(false);
|
1823
1836
|
const clearForm = /* @__PURE__ */ __name((options = {}) => {
|
1824
1837
|
const { document: optionsDocument } = options;
|
1825
1838
|
const document = optionsDocument ? merge2({}, props.prefilledProps, optionsDocument) : null;
|
@@ -1830,21 +1843,21 @@ var Form = /* @__PURE__ */ __name((props) => {
|
|
1830
1843
|
setDisabled(false);
|
1831
1844
|
}, "clearForm");
|
1832
1845
|
const newMutationSuccessCallback = /* @__PURE__ */ __name(function(result) {
|
1833
|
-
mutationSuccessCallback(result,
|
1846
|
+
mutationSuccessCallback(result, NEW_FORM_TYPE);
|
1834
1847
|
}, "newMutationSuccessCallback");
|
1835
1848
|
const editMutationSuccessCallback = /* @__PURE__ */ __name(function(result) {
|
1836
|
-
mutationSuccessCallback(result,
|
1849
|
+
mutationSuccessCallback(result, EDIT_FORM_TYPE);
|
1837
1850
|
}, "editMutationSuccessCallback");
|
1838
1851
|
const formRef = useRef2(null);
|
1839
1852
|
const mutationSuccessCallback = /* @__PURE__ */ __name(function(result, mutationType) {
|
1840
1853
|
setDisabled(false);
|
1841
1854
|
setSuccess(true);
|
1842
|
-
if (mutationType ===
|
1855
|
+
if (mutationType === NEW_FORM_TYPE)
|
1843
1856
|
refetchForm();
|
1844
1857
|
let { document } = result;
|
1845
1858
|
if (formRef.current) {
|
1846
1859
|
clearForm({
|
1847
|
-
document: mutationType ===
|
1860
|
+
document: mutationType === EDIT_FORM_TYPE ? document : void 0
|
1848
1861
|
});
|
1849
1862
|
}
|
1850
1863
|
document = runCallbacks({
|
@@ -1883,16 +1896,7 @@ var Form = /* @__PURE__ */ __name((props) => {
|
|
1883
1896
|
form: void 0
|
1884
1897
|
});
|
1885
1898
|
}, "mutationErrorCallback");
|
1886
|
-
const
|
1887
|
-
var _a, _b;
|
1888
|
-
event && event.preventDefault();
|
1889
|
-
event && event.stopPropagation();
|
1890
|
-
const { contextName } = props;
|
1891
|
-
if (disabled) {
|
1892
|
-
return;
|
1893
|
-
}
|
1894
|
-
setErrors([]);
|
1895
|
-
setDisabled(true);
|
1899
|
+
const getSubmitData = /* @__PURE__ */ __name(() => {
|
1896
1900
|
let data = getData({
|
1897
1901
|
replaceIntlFields: true,
|
1898
1902
|
addExtraFields: false,
|
@@ -1907,42 +1911,64 @@ var Form = /* @__PURE__ */ __name((props) => {
|
|
1907
1911
|
if (props.submitCallback) {
|
1908
1912
|
data = props.submitCallback(data) || data;
|
1909
1913
|
}
|
1910
|
-
|
1911
|
-
|
1912
|
-
|
1913
|
-
|
1914
|
-
|
1915
|
-
|
1916
|
-
|
1917
|
-
|
1918
|
-
|
1919
|
-
|
1920
|
-
|
1921
|
-
|
1914
|
+
return data;
|
1915
|
+
}, "getSubmitData");
|
1916
|
+
const submitFormCreate = /* @__PURE__ */ __name(async (event) => {
|
1917
|
+
var _a;
|
1918
|
+
event && event.preventDefault();
|
1919
|
+
event && event.stopPropagation();
|
1920
|
+
const { contextName } = props;
|
1921
|
+
if (disabled) {
|
1922
|
+
return;
|
1923
|
+
}
|
1924
|
+
setErrors([]);
|
1925
|
+
setDisabled(true);
|
1926
|
+
const data = getSubmitData();
|
1927
|
+
try {
|
1928
|
+
const result = await createDocument({
|
1929
|
+
input: {
|
1930
|
+
data,
|
1931
|
+
contextName
|
1922
1932
|
}
|
1923
|
-
}
|
1924
|
-
|
1933
|
+
});
|
1934
|
+
if ((_a = result.errors) == null ? void 0 : _a.length) {
|
1935
|
+
mutationErrorCallback(document1, result.errors[0]);
|
1936
|
+
} else {
|
1937
|
+
newMutationSuccessCallback(result);
|
1925
1938
|
}
|
1926
|
-
}
|
1927
|
-
|
1928
|
-
|
1929
|
-
|
1930
|
-
|
1931
|
-
|
1932
|
-
|
1933
|
-
|
1934
|
-
|
1935
|
-
|
1936
|
-
|
1937
|
-
|
1938
|
-
|
1939
|
-
|
1939
|
+
} catch (error) {
|
1940
|
+
mutationErrorCallback(document1, error);
|
1941
|
+
}
|
1942
|
+
}, "submitFormCreate");
|
1943
|
+
const submitFormUpdate = /* @__PURE__ */ __name(async (event) => {
|
1944
|
+
var _a;
|
1945
|
+
event && event.preventDefault();
|
1946
|
+
event && event.stopPropagation();
|
1947
|
+
const { contextName } = props;
|
1948
|
+
if (disabled) {
|
1949
|
+
return;
|
1950
|
+
}
|
1951
|
+
setErrors([]);
|
1952
|
+
setDisabled(true);
|
1953
|
+
const data = getSubmitData();
|
1954
|
+
try {
|
1955
|
+
const documentId = currentDocument._id;
|
1956
|
+
const result = await updateDocument({
|
1957
|
+
input: {
|
1958
|
+
id: documentId,
|
1959
|
+
data,
|
1960
|
+
contextName
|
1940
1961
|
}
|
1941
|
-
}
|
1942
|
-
|
1962
|
+
});
|
1963
|
+
if ((_a = result.errors) == null ? void 0 : _a.length) {
|
1964
|
+
mutationErrorCallback(document1, result.errors[0]);
|
1965
|
+
} else {
|
1966
|
+
editMutationSuccessCallback(result);
|
1943
1967
|
}
|
1968
|
+
} catch (error) {
|
1969
|
+
mutationErrorCallback(document1, error);
|
1944
1970
|
}
|
1945
|
-
}, "
|
1971
|
+
}, "submitFormUpdate");
|
1946
1972
|
const deleteDocumentWithConfirm = /* @__PURE__ */ __name(() => {
|
1947
1973
|
const document = currentDocument;
|
1948
1974
|
const documentId = props.document._id;
|
@@ -1971,13 +1997,14 @@ var Form = /* @__PURE__ */ __name((props) => {
|
|
1971
1997
|
}, "deleteDocumentWithConfirm");
|
1972
1998
|
const { successComponent, document: document1, currentUser, model, warnUnsavedChanges } = props;
|
1973
1999
|
const FormComponents = useVulcanComponents();
|
1974
|
-
const
|
1975
|
-
const
|
2000
|
+
const formType = document1 ? EDIT_FORM_TYPE : NEW_FORM_TYPE;
|
2001
|
+
const submitForm = formType === NEW_FORM_TYPE ? submitFormCreate : submitFormUpdate;
|
2002
|
+
const mutableFields = formType === EDIT_FORM_TYPE ? getEditableFields(schema, currentUser, initialDocument) : getInsertableFields(schema, currentUser);
|
1976
2003
|
const { formLayoutProps, formGroupProps } = getChildrenProps(props, {
|
1977
2004
|
disabled,
|
1978
2005
|
currentDocument
|
1979
2006
|
}, {
|
1980
|
-
formType
|
2007
|
+
formType
|
1981
2008
|
}, {
|
1982
2009
|
deleteDocument: deleteDocumentWithConfirm
|
1983
2010
|
});
|
@@ -1991,7 +2018,7 @@ var Form = /* @__PURE__ */ __name((props) => {
|
|
1991
2018
|
clearForm,
|
1992
2019
|
refetchForm,
|
1993
2020
|
isChanged,
|
1994
|
-
submitForm: submitFormContext
|
2021
|
+
submitForm: submitFormContext,
|
1995
2022
|
addToDeletedValues,
|
1996
2023
|
updateCurrentValues,
|
1997
2024
|
getDocument: () => currentDocument,
|
@@ -2000,7 +2027,6 @@ var Form = /* @__PURE__ */ __name((props) => {
|
|
2000
2027
|
addToSubmitForm,
|
2001
2028
|
addToSuccessForm,
|
2002
2029
|
addToFailureForm,
|
2003
|
-
clearFormCallbacks,
|
2004
2030
|
errors,
|
2005
2031
|
currentValues,
|
2006
2032
|
deletedValues,
|