@atlaskit/link-create 0.9.1 → 1.0.0
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/CHANGELOG.md +12 -0
- package/analytics.spec.yaml +9 -0
- package/dist/cjs/common/utils/analytics/analytics.codegen.js +1 -1
- package/dist/cjs/controllers/callback-context/main.js +22 -3
- package/dist/cjs/controllers/create-field/index.js +12 -0
- package/dist/cjs/controllers/create-field/main.js +62 -0
- package/dist/cjs/index.js +12 -0
- package/dist/cjs/ui/create-form/async-select/main.js +117 -35
- package/dist/cjs/ui/create-form/form-footer/main.js +9 -2
- package/dist/cjs/ui/create-form/form-spy/index.js +27 -0
- package/dist/cjs/ui/create-form/index.js +15 -1
- package/dist/cjs/ui/create-form/main.js +20 -10
- package/dist/cjs/ui/create-form/select/index.js +12 -0
- package/dist/cjs/ui/create-form/select/main.js +50 -0
- package/dist/cjs/ui/create-form/select/types.js +5 -0
- package/dist/cjs/ui/create-form/textfield/main.js +26 -48
- package/dist/cjs/ui/index.js +15 -1
- package/dist/cjs/ui/link-create/main.js +3 -3
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/common/utils/analytics/analytics.codegen.js +1 -1
- package/dist/es2019/controllers/callback-context/main.js +6 -1
- package/dist/es2019/controllers/create-field/index.js +1 -0
- package/dist/es2019/controllers/create-field/main.js +57 -0
- package/dist/es2019/index.js +1 -1
- package/dist/es2019/ui/create-form/async-select/main.js +75 -34
- package/dist/es2019/ui/create-form/form-footer/main.js +9 -2
- package/dist/es2019/ui/create-form/form-spy/index.js +18 -0
- package/dist/es2019/ui/create-form/index.js +3 -1
- package/dist/es2019/ui/create-form/main.js +25 -16
- package/dist/es2019/ui/create-form/select/index.js +1 -0
- package/dist/es2019/ui/create-form/select/main.js +40 -0
- package/dist/es2019/ui/create-form/textfield/main.js +24 -48
- package/dist/es2019/ui/index.js +3 -1
- package/dist/es2019/ui/link-create/main.js +3 -3
- package/dist/es2019/version.json +1 -1
- package/dist/esm/common/utils/analytics/analytics.codegen.js +1 -1
- package/dist/esm/controllers/callback-context/main.js +22 -3
- package/dist/esm/controllers/create-field/index.js +1 -0
- package/dist/esm/controllers/create-field/main.js +56 -0
- package/dist/esm/controllers/create-field/types.js +1 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/ui/create-form/async-select/main.js +118 -36
- package/dist/esm/ui/create-form/form-footer/main.js +9 -2
- package/dist/esm/ui/create-form/form-spy/index.js +19 -0
- package/dist/esm/ui/create-form/index.js +3 -1
- package/dist/esm/ui/create-form/main.js +19 -8
- package/dist/esm/ui/create-form/select/index.js +1 -0
- package/dist/esm/ui/create-form/select/main.js +42 -0
- package/dist/esm/ui/create-form/select/types.js +1 -0
- package/dist/esm/ui/create-form/textfield/main.js +25 -47
- package/dist/esm/ui/index.js +3 -1
- package/dist/esm/ui/link-create/main.js +3 -3
- package/dist/esm/version.json +1 -1
- package/dist/types/common/utils/analytics/analytics.codegen.d.ts +5 -1
- package/dist/types/common/utils/form/index.d.ts +2 -2
- package/dist/types/controllers/callback-context/main.d.ts +1 -1
- package/dist/types/controllers/create-field/index.d.ts +1 -0
- package/dist/types/controllers/create-field/main.d.ts +3 -0
- package/dist/types/controllers/create-field/types.d.ts +24 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/ui/create-form/async-select/main.d.ts +5 -5
- package/dist/types/ui/create-form/async-select/types.d.ts +9 -4
- package/dist/types/ui/create-form/form-spy/index.d.ts +12 -0
- package/dist/types/ui/create-form/index.d.ts +2 -0
- package/dist/types/ui/create-form/main.d.ts +2 -1
- package/dist/types/ui/create-form/select/index.d.ts +1 -0
- package/dist/types/ui/create-form/select/main.d.ts +12 -0
- package/dist/types/ui/create-form/select/types.d.ts +18 -0
- package/dist/types/ui/create-form/textfield/main.d.ts +2 -1
- package/dist/types/ui/index.d.ts +2 -0
- package/dist/types-ts4.5/common/utils/analytics/analytics.codegen.d.ts +5 -1
- package/dist/types-ts4.5/common/utils/form/index.d.ts +2 -2
- package/dist/types-ts4.5/controllers/callback-context/main.d.ts +1 -1
- package/dist/types-ts4.5/controllers/create-field/index.d.ts +1 -0
- package/dist/types-ts4.5/controllers/create-field/main.d.ts +3 -0
- package/dist/types-ts4.5/controllers/create-field/types.d.ts +24 -0
- package/dist/types-ts4.5/index.d.ts +1 -1
- package/dist/types-ts4.5/ui/create-form/async-select/main.d.ts +5 -5
- package/dist/types-ts4.5/ui/create-form/async-select/types.d.ts +9 -4
- package/dist/types-ts4.5/ui/create-form/form-spy/index.d.ts +12 -0
- package/dist/types-ts4.5/ui/create-form/index.d.ts +2 -0
- package/dist/types-ts4.5/ui/create-form/main.d.ts +2 -1
- package/dist/types-ts4.5/ui/create-form/select/index.d.ts +1 -0
- package/dist/types-ts4.5/ui/create-form/select/main.d.ts +12 -0
- package/dist/types-ts4.5/ui/create-form/select/types.d.ts +18 -0
- package/dist/types-ts4.5/ui/create-form/textfield/main.d.ts +2 -1
- package/dist/types-ts4.5/ui/index.d.ts +2 -0
- package/example-helpers/mock-plugin-form.tsx +3 -4
- package/package.json +6 -3
- package/report.api.md +55 -12
- package/tmp/api-report-tmp.d.ts +164 -0
- package/dist/cjs/ui/group-selection/index.js +0 -22
- package/dist/es2019/ui/group-selection/index.js +0 -16
- package/dist/esm/ui/group-selection/index.js +0 -15
- package/dist/types/ui/group-selection/index.d.ts +0 -4
- package/dist/types/ui/group-selection/types.d.ts +0 -12
- package/dist/types-ts4.5/ui/group-selection/index.d.ts +0 -4
- package/dist/types-ts4.5/ui/group-selection/types.d.ts +0 -12
- /package/dist/cjs/{ui/group-selection → controllers/create-field}/types.js +0 -0
- /package/dist/es2019/{ui/group-selection → controllers/create-field}/types.js +0 -0
- /package/dist/{esm/ui/group-selection → es2019/ui/create-form/select}/types.js +0 -0
|
@@ -8,7 +8,7 @@ var LinkCreateCallbackContext = /*#__PURE__*/React.createContext({});
|
|
|
8
8
|
var LinkCreateCallbackProvider = function LinkCreateCallbackProvider(_ref) {
|
|
9
9
|
var children = _ref.children,
|
|
10
10
|
_onCreate = _ref.onCreate,
|
|
11
|
-
|
|
11
|
+
_onFailure = _ref.onFailure,
|
|
12
12
|
onCancel = _ref.onCancel;
|
|
13
13
|
var _useAnalyticsEvents = useAnalyticsEvents(),
|
|
14
14
|
createAnalyticsEvent = _useAnalyticsEvents.createAnalyticsEvent;
|
|
@@ -42,10 +42,29 @@ var LinkCreateCallbackProvider = function LinkCreateCallbackProvider(_ref) {
|
|
|
42
42
|
}
|
|
43
43
|
return onCreate;
|
|
44
44
|
}(),
|
|
45
|
-
onFailure:
|
|
45
|
+
onFailure: function () {
|
|
46
|
+
var _onFailure2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(error) {
|
|
47
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
48
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
49
|
+
case 0:
|
|
50
|
+
createAnalyticsEvent(createEventPayload('track.object.createFailed.linkCreate', {
|
|
51
|
+
failureType: error.name
|
|
52
|
+
})).fire(ANALYTICS_CHANNEL);
|
|
53
|
+
_onFailure && _onFailure(error);
|
|
54
|
+
case 2:
|
|
55
|
+
case "end":
|
|
56
|
+
return _context2.stop();
|
|
57
|
+
}
|
|
58
|
+
}, _callee2);
|
|
59
|
+
}));
|
|
60
|
+
function onFailure(_x2) {
|
|
61
|
+
return _onFailure2.apply(this, arguments);
|
|
62
|
+
}
|
|
63
|
+
return onFailure;
|
|
64
|
+
}(),
|
|
46
65
|
onCancel: onCancel
|
|
47
66
|
};
|
|
48
|
-
}, [
|
|
67
|
+
}, [_onFailure, onCancel, createAnalyticsEvent, _onCreate]);
|
|
49
68
|
return /*#__PURE__*/React.createElement(LinkCreateCallbackContext.Provider, {
|
|
50
69
|
value: value
|
|
51
70
|
}, children);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { CreateField } from './main';
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
3
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
|
+
/** @jsx jsx */
|
|
5
|
+
import { Fragment, useEffect, useMemo } from 'react';
|
|
6
|
+
import { css, jsx } from '@emotion/react';
|
|
7
|
+
import { Field } from 'react-final-form';
|
|
8
|
+
import { ErrorMessage, HelperMessage, Label, RequiredAsterisk } from '@atlaskit/form';
|
|
9
|
+
import { validateSubmitErrors } from '../../common/utils/form';
|
|
10
|
+
import { useFormContext } from '../form-context';
|
|
11
|
+
var fieldWrapperStyles = css({
|
|
12
|
+
marginTop: "var(--ds-space-100, 8px)"
|
|
13
|
+
});
|
|
14
|
+
export function CreateField(_ref) {
|
|
15
|
+
var id = _ref.id,
|
|
16
|
+
name = _ref.name,
|
|
17
|
+
label = _ref.label,
|
|
18
|
+
isRequired = _ref.isRequired,
|
|
19
|
+
validators = _ref.validators,
|
|
20
|
+
validationHelpText = _ref.validationHelpText,
|
|
21
|
+
testId = _ref.testId,
|
|
22
|
+
children = _ref.children;
|
|
23
|
+
var _useFormContext = useFormContext(),
|
|
24
|
+
assignValidator = _useFormContext.assignValidator;
|
|
25
|
+
useEffect(function () {
|
|
26
|
+
if (validators) {
|
|
27
|
+
assignValidator(name, validators);
|
|
28
|
+
}
|
|
29
|
+
}, [name, validators, assignValidator]);
|
|
30
|
+
var fieldId = useMemo(function () {
|
|
31
|
+
return id ? id : "link-create-field-".concat(name);
|
|
32
|
+
}, [id, name]);
|
|
33
|
+
return jsx("div", {
|
|
34
|
+
css: fieldWrapperStyles,
|
|
35
|
+
"data-testid": testId
|
|
36
|
+
}, jsx(Field, {
|
|
37
|
+
name: name
|
|
38
|
+
}, function (_ref2) {
|
|
39
|
+
var input = _ref2.input,
|
|
40
|
+
meta = _ref2.meta;
|
|
41
|
+
var isInvalid = validateSubmitErrors(meta);
|
|
42
|
+
var submitError = meta.submitError;
|
|
43
|
+
return jsx(Fragment, null, label && jsx(Label, {
|
|
44
|
+
htmlFor: fieldId,
|
|
45
|
+
id: "".concat(fieldId, "-label"),
|
|
46
|
+
testId: "".concat(testId, "-label")
|
|
47
|
+
}, label, isRequired && jsx(RequiredAsterisk, null)), children(_objectSpread(_objectSpread({}, input), {}, {
|
|
48
|
+
fieldId: fieldId,
|
|
49
|
+
isInvalid: isInvalid
|
|
50
|
+
})), !submitError && validationHelpText && jsx(HelperMessage, {
|
|
51
|
+
testId: "".concat(testId, "-helper-message")
|
|
52
|
+
}, validationHelpText), submitError && isInvalid && jsx(ErrorMessage, {
|
|
53
|
+
testId: "".concat(testId, "-error-message")
|
|
54
|
+
}, submitError));
|
|
55
|
+
}));
|
|
56
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/esm/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { default, TextField, CreateForm, AsyncSelect, CreateFormLoader } from './ui/index';
|
|
1
|
+
export { default, TextField, CreateForm, Select, AsyncSelect, CreateFormLoader, FormSpy } from './ui/index';
|
|
2
2
|
export { useLinkCreateCallback, LinkCreateCallbackProvider } from './controllers/callback-context';
|
|
@@ -1,55 +1,137 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
3
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
4
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
|
-
var _excluded = ["
|
|
5
|
+
var _excluded = ["id", "name", "label", "isRequired", "validators", "validationHelpText", "testId", "defaultOption", "loadOptions"],
|
|
6
|
+
_excluded2 = ["fieldId"];
|
|
7
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
4
8
|
/** @jsx jsx */
|
|
5
|
-
import {
|
|
9
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
6
10
|
import { jsx } from '@emotion/react';
|
|
7
|
-
import
|
|
11
|
+
import debounce from 'debounce-promise';
|
|
12
|
+
import { useForm } from 'react-final-form';
|
|
8
13
|
import { AsyncSelect as AkAsyncSelect } from '@atlaskit/select';
|
|
9
|
-
import {
|
|
10
|
-
import { useFormContext } from '../../../controllers/form-context';
|
|
14
|
+
import { CreateField } from '../../../controllers/create-field';
|
|
11
15
|
export var TEST_ID = 'link-create-async-select';
|
|
16
|
+
|
|
12
17
|
/**
|
|
13
|
-
* An async select utilising the Atlaskit AsyncSelect and Field
|
|
14
|
-
* Validation is handled by the form
|
|
15
|
-
* the handleSubmit function passed to the form <Form> that
|
|
16
|
-
* of this
|
|
18
|
+
* An async select utilising the Atlaskit AsyncSelect and Field components from
|
|
19
|
+
* `@atlaskit/form`. Validation is handled by the form on form submission. Any
|
|
20
|
+
* errors returned by the handleSubmit function passed to the form <Form> that
|
|
21
|
+
* have a key matching the `name` of this field are shown below the field.
|
|
17
22
|
*/
|
|
18
23
|
export function AsyncSelect(_ref) {
|
|
19
|
-
var
|
|
24
|
+
var id = _ref.id,
|
|
20
25
|
name = _ref.name,
|
|
21
|
-
|
|
26
|
+
label = _ref.label,
|
|
22
27
|
isRequired = _ref.isRequired,
|
|
28
|
+
validators = _ref.validators,
|
|
29
|
+
validationHelpText = _ref.validationHelpText,
|
|
23
30
|
_ref$testId = _ref.testId,
|
|
24
31
|
testId = _ref$testId === void 0 ? TEST_ID : _ref$testId,
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
var
|
|
29
|
-
|
|
32
|
+
propsDefaultValue = _ref.defaultOption,
|
|
33
|
+
loadOptions = _ref.loadOptions,
|
|
34
|
+
restProps = _objectWithoutProperties(_ref, _excluded);
|
|
35
|
+
var _useForm = useForm(),
|
|
36
|
+
mutators = _useForm.mutators;
|
|
37
|
+
var _useState = useState(propsDefaultValue),
|
|
38
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
39
|
+
defaultValue = _useState2[0],
|
|
40
|
+
setDefaultValue = _useState2[1];
|
|
41
|
+
var _useState3 = useState(false),
|
|
42
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
43
|
+
isLoadingDefaultOptions = _useState4[0],
|
|
44
|
+
setIsLoadingDefaultOptions = _useState4[1];
|
|
45
|
+
var _useState5 = useState([]),
|
|
46
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
47
|
+
defaultOptions = _useState6[0],
|
|
48
|
+
setDefaultOptions = _useState6[1];
|
|
49
|
+
useEffect(function () {
|
|
50
|
+
var current = true;
|
|
51
|
+
var fetch = /*#__PURE__*/function () {
|
|
52
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
53
|
+
var query,
|
|
54
|
+
options,
|
|
55
|
+
_args = arguments;
|
|
56
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
57
|
+
while (1) switch (_context.prev = _context.next) {
|
|
58
|
+
case 0:
|
|
59
|
+
query = _args.length > 0 && _args[0] !== undefined ? _args[0] : '';
|
|
60
|
+
if (loadOptions) {
|
|
61
|
+
_context.next = 3;
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
return _context.abrupt("return");
|
|
65
|
+
case 3:
|
|
66
|
+
_context.prev = 3;
|
|
67
|
+
/**
|
|
68
|
+
* If we are fetching default options, clear the
|
|
69
|
+
* value the user has set
|
|
70
|
+
*/
|
|
71
|
+
mutators.setField(name, null);
|
|
72
|
+
setIsLoadingDefaultOptions(true);
|
|
73
|
+
setDefaultOptions([]);
|
|
74
|
+
_context.next = 9;
|
|
75
|
+
return loadOptions(query);
|
|
76
|
+
case 9:
|
|
77
|
+
options = _context.sent;
|
|
78
|
+
if (current) {
|
|
79
|
+
setDefaultOptions(options);
|
|
80
|
+
setIsLoadingDefaultOptions(false);
|
|
81
|
+
}
|
|
82
|
+
_context.next = 16;
|
|
83
|
+
break;
|
|
84
|
+
case 13:
|
|
85
|
+
_context.prev = 13;
|
|
86
|
+
_context.t0 = _context["catch"](3);
|
|
87
|
+
if (current) {
|
|
88
|
+
setIsLoadingDefaultOptions(false);
|
|
89
|
+
}
|
|
90
|
+
case 16:
|
|
91
|
+
case "end":
|
|
92
|
+
return _context.stop();
|
|
93
|
+
}
|
|
94
|
+
}, _callee, null, [[3, 13]]);
|
|
95
|
+
}));
|
|
96
|
+
return function fetch() {
|
|
97
|
+
return _ref2.apply(this, arguments);
|
|
98
|
+
};
|
|
99
|
+
}();
|
|
100
|
+
fetch();
|
|
101
|
+
return function () {
|
|
102
|
+
current = false;
|
|
103
|
+
};
|
|
104
|
+
}, [loadOptions, setIsLoadingDefaultOptions, setDefaultOptions, mutators, name]);
|
|
30
105
|
useEffect(function () {
|
|
31
|
-
|
|
32
|
-
|
|
106
|
+
/**
|
|
107
|
+
* Mutate the form state to set a default value for this field
|
|
108
|
+
* if `defaultOption` is a prop and we have not set a value for it yet
|
|
109
|
+
*/
|
|
110
|
+
if (!defaultValue && propsDefaultValue) {
|
|
111
|
+
setDefaultValue(propsDefaultValue);
|
|
112
|
+
mutators.setField(name, propsDefaultValue);
|
|
33
113
|
}
|
|
34
|
-
}, [
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
},
|
|
114
|
+
}, [defaultValue, propsDefaultValue, name, mutators]);
|
|
115
|
+
var debouncedLoadOptions = useMemo(function () {
|
|
116
|
+
return loadOptions ? debounce(loadOptions, 300) : undefined;
|
|
117
|
+
}, [loadOptions]);
|
|
118
|
+
return jsx(CreateField, {
|
|
119
|
+
id: id,
|
|
38
120
|
name: name,
|
|
39
121
|
label: label,
|
|
40
122
|
isRequired: isRequired,
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
return jsx(
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
})
|
|
123
|
+
validators: validators,
|
|
124
|
+
validationHelpText: validationHelpText,
|
|
125
|
+
testId: testId
|
|
126
|
+
}, function (_ref3) {
|
|
127
|
+
var fieldId = _ref3.fieldId,
|
|
128
|
+
fieldProps = _objectWithoutProperties(_ref3, _excluded2);
|
|
129
|
+
return jsx(AkAsyncSelect, _extends({
|
|
130
|
+
inputId: fieldId
|
|
131
|
+
}, fieldProps, restProps, {
|
|
132
|
+
loadOptions: debouncedLoadOptions,
|
|
133
|
+
defaultOptions: defaultOptions,
|
|
134
|
+
isLoading: isLoadingDefaultOptions
|
|
135
|
+
}));
|
|
136
|
+
});
|
|
55
137
|
}
|
|
@@ -3,9 +3,13 @@ import { css, jsx } from '@emotion/react';
|
|
|
3
3
|
import { useIntl } from 'react-intl-next';
|
|
4
4
|
import Button, { ButtonGroup } from '@atlaskit/button';
|
|
5
5
|
import LoadingButton from '@atlaskit/button/loading-button';
|
|
6
|
-
import { FormFooter } from '@atlaskit/form';
|
|
7
6
|
import ErrorIcon from '@atlaskit/icon/glyph/error';
|
|
8
7
|
import { messages } from './messages';
|
|
8
|
+
var formFooterWrapperStyles = css({
|
|
9
|
+
display: 'flex',
|
|
10
|
+
marginTop: "var(--ds-space-300, 24px)",
|
|
11
|
+
justifyContent: 'flex-end'
|
|
12
|
+
});
|
|
9
13
|
var errorStyles = css({
|
|
10
14
|
display: 'flex',
|
|
11
15
|
alignItems: 'center',
|
|
@@ -17,7 +21,10 @@ export function CreateFormFooter(_ref) {
|
|
|
17
21
|
submitting = _ref.submitting,
|
|
18
22
|
testId = _ref.testId;
|
|
19
23
|
var intl = useIntl();
|
|
20
|
-
return jsx(
|
|
24
|
+
return jsx("footer", {
|
|
25
|
+
"data-testid": "".concat(testId, "-footer"),
|
|
26
|
+
css: formFooterWrapperStyles
|
|
27
|
+
}, formErrorMessage && jsx("div", {
|
|
21
28
|
css: errorStyles,
|
|
22
29
|
"data-testid": "".concat(testId, "-error")
|
|
23
30
|
}, jsx(ErrorIcon, {
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { FormSpy as FinalFormSpy } from 'react-final-form';
|
|
3
|
+
/**
|
|
4
|
+
* Lightweight wrapper around the react-final-form
|
|
5
|
+
* FormSpy component so that we can control selectively
|
|
6
|
+
* how much of the API we are commited to.
|
|
7
|
+
*/
|
|
8
|
+
export var FormSpy = function FormSpy(_ref) {
|
|
9
|
+
var children = _ref.children;
|
|
10
|
+
return /*#__PURE__*/React.createElement(FinalFormSpy, {
|
|
11
|
+
subscription: {
|
|
12
|
+
values: true
|
|
13
|
+
}
|
|
14
|
+
}, function (props) {
|
|
15
|
+
return children({
|
|
16
|
+
values: props.values
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
};
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export { CreateForm } from './main';
|
|
2
|
+
export { Select } from './select';
|
|
2
3
|
export { AsyncSelect } from './async-select';
|
|
3
4
|
export { CreateFormLoader } from './form-loader';
|
|
4
|
-
export { TextField } from './textfield';
|
|
5
|
+
export { TextField } from './textfield';
|
|
6
|
+
export { FormSpy } from './form-spy';
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import
|
|
1
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
2
2
|
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
3
|
+
var _excluded = ["submitting"];
|
|
3
4
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
4
5
|
/** @jsx jsx */
|
|
5
6
|
import { useCallback } from 'react';
|
|
6
7
|
import { css, jsx } from '@emotion/react';
|
|
8
|
+
import { Form } from 'react-final-form';
|
|
7
9
|
import { useAnalyticsEvents } from '@atlaskit/analytics-next';
|
|
8
|
-
import Form from '@atlaskit/form';
|
|
9
10
|
import { ANALYTICS_CHANNEL, CREATE_FORM_MAX_WIDTH_IN_PX } from '../../common/constants';
|
|
10
11
|
import createEventPayload from '../../common/utils/analytics/analytics.codegen';
|
|
11
12
|
import { useFormContext } from '../../controllers/form-context';
|
|
@@ -25,7 +26,8 @@ export var CreateForm = function CreateForm(_ref) {
|
|
|
25
26
|
onSubmit = _ref.onSubmit,
|
|
26
27
|
onCancel = _ref.onCancel,
|
|
27
28
|
isLoading = _ref.isLoading,
|
|
28
|
-
hideFooter = _ref.hideFooter
|
|
29
|
+
hideFooter = _ref.hideFooter,
|
|
30
|
+
initialValues = _ref.initialValues;
|
|
29
31
|
var _useAnalyticsEvents = useAnalyticsEvents(),
|
|
30
32
|
createAnalyticsEvent = _useAnalyticsEvents.createAnalyticsEvent;
|
|
31
33
|
var _useFormContext = useFormContext(),
|
|
@@ -68,15 +70,24 @@ export var CreateForm = function CreateForm(_ref) {
|
|
|
68
70
|
return jsx(CreateFormLoader, null);
|
|
69
71
|
}
|
|
70
72
|
return jsx(Form, {
|
|
71
|
-
onSubmit: handleSubmit
|
|
73
|
+
onSubmit: handleSubmit,
|
|
74
|
+
initialValues: initialValues,
|
|
75
|
+
mutators: {
|
|
76
|
+
setField: function setField(args, state, tools) {
|
|
77
|
+
tools.changeValue(state, args[0], function () {
|
|
78
|
+
return args[1];
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
72
82
|
}, function (_ref3) {
|
|
73
|
-
var
|
|
74
|
-
|
|
75
|
-
return jsx("form",
|
|
83
|
+
var submitting = _ref3.submitting,
|
|
84
|
+
formProps = _objectWithoutProperties(_ref3, _excluded);
|
|
85
|
+
return jsx("form", {
|
|
86
|
+
onSubmit: formProps.handleSubmit,
|
|
76
87
|
name: "link-create-form",
|
|
77
88
|
"data-testid": testId,
|
|
78
89
|
css: formStyles
|
|
79
|
-
}
|
|
90
|
+
}, jsx("div", null, children), !hideFooter && jsx(CreateFormFooter, {
|
|
80
91
|
formErrorMessage: formErrorMessage,
|
|
81
92
|
handleCancel: handleCancel,
|
|
82
93
|
submitting: submitting,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Select } from './main';
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
|
+
var _excluded = ["id", "name", "label", "isRequired", "validators", "validationHelpText", "testId"],
|
|
4
|
+
_excluded2 = ["fieldId"];
|
|
5
|
+
/** @jsx jsx */
|
|
6
|
+
|
|
7
|
+
import { jsx } from '@emotion/react';
|
|
8
|
+
import AkSelect from '@atlaskit/select';
|
|
9
|
+
import { CreateField } from '../../../controllers/create-field';
|
|
10
|
+
export var TEST_ID = 'link-create-select';
|
|
11
|
+
/**
|
|
12
|
+
* A select utilising the Atlaskit Select and Field components from
|
|
13
|
+
* `@atlaskit/form`. Validation is handled by the form on form submission. Any
|
|
14
|
+
* errors returned by the handleSubmit function passed to the form <Form> that
|
|
15
|
+
* have a key matching the `name` of this field are shown below the field.
|
|
16
|
+
*/
|
|
17
|
+
export function Select(_ref) {
|
|
18
|
+
var id = _ref.id,
|
|
19
|
+
name = _ref.name,
|
|
20
|
+
label = _ref.label,
|
|
21
|
+
isRequired = _ref.isRequired,
|
|
22
|
+
validators = _ref.validators,
|
|
23
|
+
validationHelpText = _ref.validationHelpText,
|
|
24
|
+
_ref$testId = _ref.testId,
|
|
25
|
+
testId = _ref$testId === void 0 ? TEST_ID : _ref$testId,
|
|
26
|
+
restProps = _objectWithoutProperties(_ref, _excluded);
|
|
27
|
+
return jsx(CreateField, {
|
|
28
|
+
id: id,
|
|
29
|
+
name: name,
|
|
30
|
+
label: label,
|
|
31
|
+
isRequired: isRequired,
|
|
32
|
+
validators: validators,
|
|
33
|
+
validationHelpText: validationHelpText,
|
|
34
|
+
testId: testId
|
|
35
|
+
}, function (_ref2) {
|
|
36
|
+
var fieldId = _ref2.fieldId,
|
|
37
|
+
fieldProps = _objectWithoutProperties(_ref2, _excluded2);
|
|
38
|
+
return jsx(AkSelect, _extends({
|
|
39
|
+
inputId: fieldId
|
|
40
|
+
}, fieldProps, restProps));
|
|
41
|
+
});
|
|
42
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
2
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
|
-
var _excluded = ["
|
|
3
|
+
var _excluded = ["id", "name", "label", "isRequired", "validators", "validationHelpText", "testId"],
|
|
4
|
+
_excluded2 = ["fieldId"];
|
|
4
5
|
/** @jsx jsx */
|
|
5
|
-
import { Fragment, useEffect } from 'react';
|
|
6
6
|
import { jsx } from '@emotion/react';
|
|
7
|
-
import { ErrorMessage, Field, HelperMessage } from '@atlaskit/form';
|
|
8
7
|
import AkTextfield from '@atlaskit/textfield';
|
|
9
|
-
import {
|
|
10
|
-
import { useFormContext } from '../../../controllers/form-context';
|
|
8
|
+
import { CreateField } from '../../../controllers/create-field';
|
|
11
9
|
export var TEST_ID = 'link-create-text-field';
|
|
12
10
|
|
|
13
11
|
/**
|
|
@@ -18,50 +16,30 @@ export var TEST_ID = 'link-create-text-field';
|
|
|
18
16
|
*/
|
|
19
17
|
|
|
20
18
|
export function TextField(_ref) {
|
|
21
|
-
var
|
|
19
|
+
var id = _ref.id,
|
|
22
20
|
name = _ref.name,
|
|
21
|
+
label = _ref.label,
|
|
22
|
+
isRequired = _ref.isRequired,
|
|
23
|
+
validators = _ref.validators,
|
|
24
|
+
validationHelpText = _ref.validationHelpText,
|
|
23
25
|
_ref$testId = _ref.testId,
|
|
24
26
|
testId = _ref$testId === void 0 ? TEST_ID : _ref$testId,
|
|
25
|
-
validationHelpText = _ref.validationHelpText,
|
|
26
|
-
validators = _ref.validators,
|
|
27
|
-
defaultValue = _ref.defaultValue,
|
|
28
|
-
isRequired = _ref.isRequired,
|
|
29
27
|
restProps = _objectWithoutProperties(_ref, _excluded);
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
name: name,
|
|
48
|
-
label: label,
|
|
49
|
-
isRequired: isRequired,
|
|
50
|
-
defaultValue: defaultValue !== null && defaultValue !== void 0 ? defaultValue : ''
|
|
51
|
-
}, function (_ref2) {
|
|
52
|
-
var fieldProps = _ref2.fieldProps,
|
|
53
|
-
meta = _ref2.meta,
|
|
54
|
-
error = _ref2.error;
|
|
55
|
-
var isInvalid = validateSubmitErrors(meta);
|
|
56
|
-
return jsx(Fragment, null, jsx(AkTextfield, _extends({}, fieldProps, restProps, {
|
|
57
|
-
testId: testId,
|
|
58
|
-
isInvalid: isInvalid,
|
|
59
|
-
isRequired: false // Remove the default browser validation
|
|
60
|
-
})), !error && validationHelpText && jsx(HelperMessage, {
|
|
61
|
-
testId: "".concat(testId, "-helper-message")
|
|
62
|
-
}, validationHelpText), error && isInvalid && jsx(ErrorMessage, {
|
|
63
|
-
testId: "".concat(testId, "-error-message")
|
|
64
|
-
}, error));
|
|
65
|
-
})
|
|
66
|
-
);
|
|
28
|
+
return jsx(CreateField, {
|
|
29
|
+
id: id,
|
|
30
|
+
name: name,
|
|
31
|
+
label: label,
|
|
32
|
+
isRequired: isRequired,
|
|
33
|
+
validators: validators,
|
|
34
|
+
validationHelpText: validationHelpText,
|
|
35
|
+
testId: testId
|
|
36
|
+
}, function (_ref2) {
|
|
37
|
+
var fieldId = _ref2.fieldId,
|
|
38
|
+
fieldProps = _objectWithoutProperties(_ref2, _excluded2);
|
|
39
|
+
return jsx(AkTextfield, _extends({
|
|
40
|
+
id: fieldId
|
|
41
|
+
}, fieldProps, restProps, {
|
|
42
|
+
isRequired: false // Remove the default browser validation
|
|
43
|
+
}));
|
|
44
|
+
});
|
|
67
45
|
}
|
package/dist/esm/ui/index.js
CHANGED
|
@@ -2,4 +2,6 @@ export { default } from './main';
|
|
|
2
2
|
export { TextField } from './create-form/textfield';
|
|
3
3
|
export { CreateForm } from './create-form/main';
|
|
4
4
|
export { CreateFormLoader } from './create-form/form-loader';
|
|
5
|
-
export {
|
|
5
|
+
export { Select } from './create-form/select';
|
|
6
|
+
export { AsyncSelect } from './create-form/async-select';
|
|
7
|
+
export { FormSpy } from './create-form/form-spy';
|
|
@@ -58,10 +58,10 @@ var LinkCreate = withLinkCreateFormContext(function (_ref2) {
|
|
|
58
58
|
return _ref3.apply(this, arguments);
|
|
59
59
|
};
|
|
60
60
|
}(), [onCreate, setFormErrorMessage]);
|
|
61
|
-
var handleFailure = useCallback(function (
|
|
61
|
+
var handleFailure = useCallback(function (error) {
|
|
62
62
|
// Set the form error message
|
|
63
|
-
setFormErrorMessage(
|
|
64
|
-
onFailure && onFailure(
|
|
63
|
+
setFormErrorMessage(error.message);
|
|
64
|
+
onFailure && onFailure(error);
|
|
65
65
|
}, [onFailure, setFormErrorMessage]);
|
|
66
66
|
return jsx("div", {
|
|
67
67
|
"data-testid": testId
|
package/dist/esm/version.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Generates Typescript types for analytics events from analytics.spec.yaml
|
|
5
5
|
*
|
|
6
|
-
* @codegen <<SignedSource::
|
|
6
|
+
* @codegen <<SignedSource::50073590468fe2604f65d3e0b23d517b>>
|
|
7
7
|
* @codegenCommand yarn workspace @atlaskit/link-create run codegen-analytics
|
|
8
8
|
*/
|
|
9
9
|
export type PackageMetaDataType = {
|
|
@@ -30,6 +30,9 @@ export type ObjectCreatedLinkCreateAttributesType = {
|
|
|
30
30
|
objectId: string;
|
|
31
31
|
objectType: string;
|
|
32
32
|
};
|
|
33
|
+
export type ObjectCreateFailedLinkCreateAttributesType = {
|
|
34
|
+
failureType: string;
|
|
35
|
+
};
|
|
33
36
|
type AnalyticsEventAttributes = {
|
|
34
37
|
'screen.linkCreateScreen.viewed': LinkCreateScreenViewedAttributesType;
|
|
35
38
|
'ui.button.clicked.create': ButtonClickedCreateAttributesType;
|
|
@@ -37,6 +40,7 @@ type AnalyticsEventAttributes = {
|
|
|
37
40
|
'ui.modalDialog.closed.linkCreate': ModalDialogClosedLinkCreateAttributesType;
|
|
38
41
|
'operational.linkCreate.unhandledErrorCaught': LinkCreateUnhandledErrorCaughtAttributesType;
|
|
39
42
|
'track.object.created.linkCreate': ObjectCreatedLinkCreateAttributesType;
|
|
43
|
+
'track.object.createFailed.linkCreate': ObjectCreateFailedLinkCreateAttributesType;
|
|
40
44
|
};
|
|
41
45
|
declare function createEventPayload<K extends keyof AnalyticsEventAttributes>(eventKey: K, attributes: AnalyticsEventAttributes[K]): {
|
|
42
46
|
eventType: string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FieldMetaState } from 'react-final-form';
|
|
2
2
|
/**
|
|
3
3
|
* This function checks if there have been changes since last submit
|
|
4
4
|
* to let a Field know if it should hide the error message until
|
|
5
5
|
* the next submit, or if it returns to the previous error state
|
|
6
6
|
*/
|
|
7
|
-
export declare const validateSubmitErrors: (meta:
|
|
7
|
+
export declare const validateSubmitErrors: (meta: FieldMetaState<any>) => boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { CreateField } from './main';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { FieldInputProps } from 'react-final-form';
|
|
3
|
+
import { Validator } from '../../common/types';
|
|
4
|
+
type FieldProps = FieldInputProps<any, HTMLElement> & {
|
|
5
|
+
fieldId: string;
|
|
6
|
+
isInvalid: boolean;
|
|
7
|
+
};
|
|
8
|
+
export type CreateFieldProps = {
|
|
9
|
+
id?: string;
|
|
10
|
+
/** Name passed to the <Field>.*/
|
|
11
|
+
name: string;
|
|
12
|
+
label?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Optional text below the textfield explaining any requirements for a valid value.
|
|
15
|
+
* eg. "Must be 4 or more letters"
|
|
16
|
+
*/
|
|
17
|
+
validationHelpText?: string;
|
|
18
|
+
/** Validators for this field */
|
|
19
|
+
validators?: Validator[];
|
|
20
|
+
isRequired?: boolean;
|
|
21
|
+
testId: string;
|
|
22
|
+
children: (fieldProps: FieldProps) => React.ReactNode;
|
|
23
|
+
};
|
|
24
|
+
export {};
|