@atlaskit/link-create 3.1.1 → 4.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.
Files changed (166) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/cjs/common/constants.js +1 -1
  3. package/dist/cjs/common/ui/error-boundary-modal/index.js +1 -9
  4. package/dist/cjs/common/ui/error-boundary-ui/error-svg/index.js +1 -10
  5. package/dist/cjs/common/ui/icon/index.js +1 -9
  6. package/dist/cjs/common/ui/message/index.js +1 -9
  7. package/dist/cjs/common/ui/modal-hero/index.js +1 -9
  8. package/dist/cjs/controllers/create-field/main.js +1 -9
  9. package/dist/cjs/ui/create-form/async-select/main.js +1 -9
  10. package/dist/cjs/ui/create-form/form-footer/main.js +1 -9
  11. package/dist/cjs/ui/create-form/form-loader/main.js +1 -9
  12. package/dist/cjs/ui/create-form/main.js +1 -9
  13. package/dist/cjs/ui/create-form/select/main.js +7 -33
  14. package/dist/cjs/ui/create-form/textfield/main.js +1 -9
  15. package/dist/cjs/ui/create-form/user-picker/main.js +1 -9
  16. package/dist/cjs/ui/inline-create/index.js +1 -9
  17. package/dist/cjs/ui/inline-create/main.js +1 -9
  18. package/dist/cjs/ui/modal-create/index.js +1 -9
  19. package/dist/cjs/ui/modal-create/main.js +1 -9
  20. package/dist/es2019/common/constants.js +1 -1
  21. package/dist/es2019/common/ui/error-boundary-modal/index.js +1 -9
  22. package/dist/es2019/common/ui/error-boundary-ui/error-svg/index.js +1 -9
  23. package/dist/es2019/common/ui/icon/index.js +1 -9
  24. package/dist/es2019/common/ui/message/index.js +1 -9
  25. package/dist/es2019/common/ui/modal-hero/index.js +1 -9
  26. package/dist/es2019/controllers/create-field/main.js +1 -9
  27. package/dist/es2019/ui/create-form/async-select/main.js +1 -9
  28. package/dist/es2019/ui/create-form/form-footer/main.js +1 -9
  29. package/dist/es2019/ui/create-form/form-loader/main.js +1 -9
  30. package/dist/es2019/ui/create-form/main.js +1 -9
  31. package/dist/es2019/ui/create-form/select/main.js +8 -34
  32. package/dist/es2019/ui/create-form/textfield/main.js +1 -9
  33. package/dist/es2019/ui/create-form/user-picker/main.js +1 -9
  34. package/dist/es2019/ui/inline-create/index.js +1 -9
  35. package/dist/es2019/ui/inline-create/main.js +1 -9
  36. package/dist/es2019/ui/modal-create/index.js +1 -9
  37. package/dist/es2019/ui/modal-create/main.js +1 -9
  38. package/dist/esm/common/constants.js +1 -1
  39. package/dist/esm/common/ui/error-boundary-modal/index.js +1 -9
  40. package/dist/esm/common/ui/error-boundary-ui/error-svg/index.js +1 -9
  41. package/dist/esm/common/ui/icon/index.js +1 -9
  42. package/dist/esm/common/ui/message/index.js +1 -9
  43. package/dist/esm/common/ui/modal-hero/index.js +1 -9
  44. package/dist/esm/controllers/create-field/main.js +1 -9
  45. package/dist/esm/ui/create-form/async-select/main.js +1 -9
  46. package/dist/esm/ui/create-form/form-footer/main.js +1 -9
  47. package/dist/esm/ui/create-form/form-loader/main.js +1 -9
  48. package/dist/esm/ui/create-form/main.js +1 -9
  49. package/dist/esm/ui/create-form/select/main.js +7 -33
  50. package/dist/esm/ui/create-form/textfield/main.js +1 -9
  51. package/dist/esm/ui/create-form/user-picker/main.js +1 -9
  52. package/dist/esm/ui/inline-create/index.js +1 -9
  53. package/dist/esm/ui/inline-create/main.js +1 -9
  54. package/dist/esm/ui/modal-create/index.js +1 -9
  55. package/dist/esm/ui/modal-create/main.js +1 -9
  56. package/dist/types/common/ui/error-boundary-modal/index.d.ts +2 -2
  57. package/dist/types/common/ui/icon/index.d.ts +1 -1
  58. package/dist/types/common/ui/message/index.d.ts +1 -1
  59. package/dist/types/common/ui/modal-hero/index.d.ts +1 -1
  60. package/dist/types/controllers/create-field/main.d.ts +1 -1
  61. package/dist/types/ui/create-form/async-select/main.d.ts +8 -2
  62. package/dist/types/ui/create-form/form-footer/main.d.ts +6 -1
  63. package/dist/types/ui/create-form/form-loader/main.d.ts +5 -1
  64. package/dist/types/ui/create-form/main.d.ts +1 -1
  65. package/dist/types/ui/create-form/select/main.d.ts +11 -5
  66. package/dist/types/ui/create-form/textfield/main.d.ts +8 -2
  67. package/dist/types/ui/create-form/user-picker/main.d.ts +5 -2
  68. package/dist/types-ts4.5/common/ui/error-boundary-modal/index.d.ts +2 -2
  69. package/dist/types-ts4.5/common/ui/icon/index.d.ts +1 -1
  70. package/dist/types-ts4.5/common/ui/message/index.d.ts +1 -1
  71. package/dist/types-ts4.5/common/ui/modal-hero/index.d.ts +1 -1
  72. package/dist/types-ts4.5/controllers/create-field/main.d.ts +1 -1
  73. package/dist/types-ts4.5/ui/create-form/async-select/main.d.ts +8 -2
  74. package/dist/types-ts4.5/ui/create-form/form-footer/main.d.ts +6 -1
  75. package/dist/types-ts4.5/ui/create-form/form-loader/main.d.ts +5 -1
  76. package/dist/types-ts4.5/ui/create-form/main.d.ts +1 -1
  77. package/dist/types-ts4.5/ui/create-form/select/main.d.ts +11 -5
  78. package/dist/types-ts4.5/ui/create-form/textfield/main.d.ts +8 -2
  79. package/dist/types-ts4.5/ui/create-form/user-picker/main.d.ts +5 -2
  80. package/package.json +1 -9
  81. package/report.api.md +1 -1
  82. package/dist/cjs/common/ui/error-boundary-modal/old/index.js +0 -34
  83. package/dist/cjs/common/ui/error-boundary-ui/error-svg/old/index.js +0 -67
  84. package/dist/cjs/common/ui/icon/old/index.js +0 -26
  85. package/dist/cjs/common/ui/message/old/index.js +0 -81
  86. package/dist/cjs/common/ui/modal-hero/old/index.js +0 -27
  87. package/dist/cjs/controllers/create-field/old/main.js +0 -76
  88. package/dist/cjs/ui/create-form/async-select/old/main.js +0 -195
  89. package/dist/cjs/ui/create-form/form-footer/old/main.js +0 -64
  90. package/dist/cjs/ui/create-form/form-loader/old/main.js +0 -39
  91. package/dist/cjs/ui/create-form/old/main.js +0 -177
  92. package/dist/cjs/ui/create-form/select/old/main.js +0 -127
  93. package/dist/cjs/ui/create-form/textfield/old/main.js +0 -55
  94. package/dist/cjs/ui/create-form/user-picker/old/main.js +0 -72
  95. package/dist/cjs/ui/inline-create/old/index.js +0 -38
  96. package/dist/cjs/ui/inline-create/old/main.js +0 -120
  97. package/dist/cjs/ui/modal-create/old/index.js +0 -44
  98. package/dist/cjs/ui/modal-create/old/main.js +0 -164
  99. package/dist/es2019/common/ui/error-boundary-modal/old/index.js +0 -26
  100. package/dist/es2019/common/ui/error-boundary-ui/error-svg/old/index.js +0 -58
  101. package/dist/es2019/common/ui/icon/old/index.js +0 -18
  102. package/dist/es2019/common/ui/message/old/index.js +0 -74
  103. package/dist/es2019/common/ui/modal-hero/old/index.js +0 -19
  104. package/dist/es2019/controllers/create-field/old/main.js +0 -74
  105. package/dist/es2019/ui/create-form/async-select/old/main.js +0 -137
  106. package/dist/es2019/ui/create-form/form-footer/old/main.js +0 -57
  107. package/dist/es2019/ui/create-form/form-loader/old/main.js +0 -31
  108. package/dist/es2019/ui/create-form/old/main.js +0 -145
  109. package/dist/es2019/ui/create-form/select/old/main.js +0 -106
  110. package/dist/es2019/ui/create-form/textfield/old/main.js +0 -45
  111. package/dist/es2019/ui/create-form/user-picker/old/main.js +0 -59
  112. package/dist/es2019/ui/inline-create/old/index.js +0 -30
  113. package/dist/es2019/ui/inline-create/old/main.js +0 -96
  114. package/dist/es2019/ui/modal-create/old/index.js +0 -36
  115. package/dist/es2019/ui/modal-create/old/main.js +0 -137
  116. package/dist/esm/common/ui/error-boundary-modal/old/index.js +0 -25
  117. package/dist/esm/common/ui/error-boundary-ui/error-svg/old/index.js +0 -60
  118. package/dist/esm/common/ui/icon/old/index.js +0 -18
  119. package/dist/esm/common/ui/message/old/index.js +0 -73
  120. package/dist/esm/common/ui/modal-hero/old/index.js +0 -18
  121. package/dist/esm/controllers/create-field/old/main.js +0 -72
  122. package/dist/esm/ui/create-form/async-select/old/main.js +0 -188
  123. package/dist/esm/ui/create-form/form-footer/old/main.js +0 -56
  124. package/dist/esm/ui/create-form/form-loader/old/main.js +0 -31
  125. package/dist/esm/ui/create-form/old/main.js +0 -174
  126. package/dist/esm/ui/create-form/select/old/main.js +0 -117
  127. package/dist/esm/ui/create-form/textfield/old/main.js +0 -47
  128. package/dist/esm/ui/create-form/user-picker/old/main.js +0 -64
  129. package/dist/esm/ui/inline-create/old/index.js +0 -30
  130. package/dist/esm/ui/inline-create/old/main.js +0 -112
  131. package/dist/esm/ui/modal-create/old/index.js +0 -36
  132. package/dist/esm/ui/modal-create/old/main.js +0 -156
  133. package/dist/types/common/ui/error-boundary-modal/old/index.d.ts +0 -11
  134. package/dist/types/common/ui/error-boundary-ui/error-svg/old/index.d.ts +0 -7
  135. package/dist/types/common/ui/icon/old/index.d.ts +0 -7
  136. package/dist/types/common/ui/message/old/index.d.ts +0 -15
  137. package/dist/types/common/ui/modal-hero/old/index.d.ts +0 -4
  138. package/dist/types/controllers/create-field/old/main.d.ts +0 -7
  139. package/dist/types/ui/create-form/async-select/old/main.d.ts +0 -11
  140. package/dist/types/ui/create-form/form-footer/old/main.d.ts +0 -16
  141. package/dist/types/ui/create-form/form-loader/old/main.d.ts +0 -11
  142. package/dist/types/ui/create-form/old/main.d.ts +0 -54
  143. package/dist/types/ui/create-form/select/old/main.d.ts +0 -24
  144. package/dist/types/ui/create-form/textfield/old/main.d.ts +0 -14
  145. package/dist/types/ui/create-form/user-picker/old/main.d.ts +0 -11
  146. package/dist/types/ui/inline-create/old/index.d.ts +0 -5
  147. package/dist/types/ui/inline-create/old/main.d.ts +0 -8
  148. package/dist/types/ui/modal-create/old/index.d.ts +0 -5
  149. package/dist/types/ui/modal-create/old/main.d.ts +0 -4
  150. package/dist/types-ts4.5/common/ui/error-boundary-modal/old/index.d.ts +0 -11
  151. package/dist/types-ts4.5/common/ui/error-boundary-ui/error-svg/old/index.d.ts +0 -7
  152. package/dist/types-ts4.5/common/ui/icon/old/index.d.ts +0 -7
  153. package/dist/types-ts4.5/common/ui/message/old/index.d.ts +0 -15
  154. package/dist/types-ts4.5/common/ui/modal-hero/old/index.d.ts +0 -4
  155. package/dist/types-ts4.5/controllers/create-field/old/main.d.ts +0 -7
  156. package/dist/types-ts4.5/ui/create-form/async-select/old/main.d.ts +0 -11
  157. package/dist/types-ts4.5/ui/create-form/form-footer/old/main.d.ts +0 -16
  158. package/dist/types-ts4.5/ui/create-form/form-loader/old/main.d.ts +0 -11
  159. package/dist/types-ts4.5/ui/create-form/old/main.d.ts +0 -56
  160. package/dist/types-ts4.5/ui/create-form/select/old/main.d.ts +0 -24
  161. package/dist/types-ts4.5/ui/create-form/textfield/old/main.d.ts +0 -14
  162. package/dist/types-ts4.5/ui/create-form/user-picker/old/main.d.ts +0 -11
  163. package/dist/types-ts4.5/ui/inline-create/old/index.d.ts +0 -5
  164. package/dist/types-ts4.5/ui/inline-create/old/main.d.ts +0 -8
  165. package/dist/types-ts4.5/ui/modal-create/old/index.d.ts +0 -5
  166. package/dist/types-ts4.5/ui/modal-create/old/main.d.ts +0 -4
@@ -1,74 +0,0 @@
1
- /**
2
- * @jsxRuntime classic
3
- * @jsx jsx
4
- */
5
-
6
- // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled
7
- import { css, jsx } from '@emotion/react';
8
- import { Field } from 'react-final-form';
9
- import { Label, RequiredAsterisk } from '@atlaskit/form';
10
- import { Message } from '../../../common/ui/message';
11
- import { shouldShowValidationErrors } from '../../../common/utils/form';
12
- const fieldWrapperStyles = css({
13
- marginTop: "var(--ds-space-100, 8px)"
14
- });
15
- export function CreateFieldOld({
16
- id,
17
- name,
18
- label,
19
- isRequired,
20
- validators,
21
- validationHelpText,
22
- testId,
23
- children
24
- }) {
25
- const fieldId = id ? id : `link-create-field-${name}`;
26
- return jsx(Field, {
27
- name: name,
28
- validate: value => {
29
- var _find;
30
- return (_find = (validators !== null && validators !== void 0 ? validators : []).find(validator => {
31
- return !validator.isValid(value);
32
- })) === null || _find === void 0 ? void 0 : _find.errorMessage;
33
- }
34
- }, ({
35
- input,
36
- meta
37
- }) => {
38
- const isInvalid = shouldShowValidationErrors(meta);
39
- const {
40
- submitError,
41
- error
42
- } = meta;
43
- const hasError = !!submitError || !!error;
44
- const showErrorMessage = hasError && isInvalid;
45
- const describedById = `${fieldId}-description`;
46
- const errorMessageId = `${fieldId}-error`;
47
- const ariaErrorMessage = showErrorMessage ? errorMessageId : undefined;
48
- return jsx("div", {
49
- css: fieldWrapperStyles,
50
- "data-testid": testId
51
- }, label && jsx(Label, {
52
- htmlFor: fieldId,
53
- id: `${fieldId}-label`,
54
- testId: `${testId}-label`
55
- }, label, isRequired && jsx(RequiredAsterisk, null)), children({
56
- ...input,
57
- fieldId,
58
- isInvalid,
59
- isRequired,
60
- 'aria-errormessage': ariaErrorMessage,
61
- 'aria-describedby': describedById
62
- }), jsx("div", {
63
- id: describedById
64
- }, !hasError && validationHelpText && jsx(Message, {
65
- testId: `${testId}-helper-message`
66
- }, validationHelpText), jsx("div", {
67
- "aria-live": "polite"
68
- }, showErrorMessage && jsx(Message, {
69
- id: errorMessageId,
70
- appearance: "error",
71
- testId: `${testId}-error-message`
72
- }, submitError || error))));
73
- });
74
- }
@@ -1,137 +0,0 @@
1
- import _extends from "@babel/runtime/helpers/extends";
2
- /* eslint-disable @atlassian/tangerine/import/no-parent-imports */
3
- /**
4
- * @jsxRuntime classic
5
- * @jsx jsx
6
- */
7
- import { useEffect, useMemo, useState } from 'react';
8
-
9
- // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
10
- import { jsx } from '@emotion/react';
11
- import debounce from 'debounce-promise';
12
- import { useForm } from 'react-final-form';
13
- import { useIntl } from 'react-intl-next';
14
- import { AsyncSelect as AkAsyncSelect } from '@atlaskit/select';
15
- import messages from '../../../../common/messages';
16
- import { useLinkCreateCallback } from '../../../../controllers/callback-context';
17
- import { CreateField } from '../../../../controllers/create-field';
18
- import { useFormContext } from '../../../../controllers/form-context';
19
- export const TEST_ID = 'link-create-async-select';
20
-
21
- /**
22
- * An async select utilising the Atlaskit AsyncSelect and CreateField.
23
- * Validation is handled by the form on form submission. Any
24
- * errors returned by the handleSubmit function passed to the form <Form> that
25
- * have a key matching the `name` of this field are shown below the field.
26
- */
27
- export function AsyncSelectOld({
28
- id,
29
- name,
30
- label,
31
- isRequired,
32
- validators,
33
- validationHelpText,
34
- testId = TEST_ID,
35
- //@ts-ignore react-select unsupported props
36
- defaultOption: propsDefaultValue,
37
- loadOptions: loadOptionsFn,
38
- ...restProps
39
- }) {
40
- const {
41
- mutators
42
- } = useForm();
43
- const {
44
- onFailure
45
- } = useLinkCreateCallback();
46
- const {
47
- setFormErrorMessage
48
- } = useFormContext();
49
- const intl = useIntl();
50
- const [defaultValue, setDefaultValue] = useState(propsDefaultValue);
51
- const [isLoadingDefaultOptions, setIsLoadingDefaultOptions] = useState(false);
52
- const [defaultOptions, setDefaultOptions] = useState([]);
53
-
54
- /**
55
- * This binds experience to fail if async fetch ever fails to load
56
- */
57
- const loadOptions = useMemo(() => {
58
- if (loadOptionsFn) {
59
- return async function (...args) {
60
- try {
61
- return await loadOptionsFn(...args);
62
- } catch (err) {
63
- onFailure === null || onFailure === void 0 ? void 0 : onFailure(err);
64
- setFormErrorMessage(intl.formatMessage(messages.genericErrorMessage));
65
- return [];
66
- }
67
- };
68
- }
69
- }, [intl, onFailure, loadOptionsFn, setFormErrorMessage]);
70
- useEffect(() => {
71
- let current = true;
72
- const fetch = async (query = '') => {
73
- if (!loadOptions) {
74
- return;
75
- }
76
- try {
77
- /**
78
- * If we are fetching default options, clear the
79
- * value the user has set
80
- */
81
- if (mutators.setField) {
82
- mutators.setField(name, null);
83
- }
84
- setIsLoadingDefaultOptions(true);
85
- setDefaultOptions([]);
86
- const options = await loadOptions(query);
87
- if (current) {
88
- setDefaultOptions(options);
89
- setIsLoadingDefaultOptions(false);
90
- }
91
- } catch (err) {
92
- if (current) {
93
- setIsLoadingDefaultOptions(false);
94
- }
95
- }
96
- };
97
- fetch();
98
- return () => {
99
- current = false;
100
- };
101
- }, [loadOptions, setIsLoadingDefaultOptions, setDefaultOptions, mutators, name]);
102
- useEffect(() => {
103
- /**
104
- * Mutate the form state to set a default value for this field
105
- * if `defaultOption` is a prop and we have not set a value for it yet
106
- */
107
- if (!defaultValue && propsDefaultValue) {
108
- setDefaultValue(propsDefaultValue);
109
- if (mutators.setField) {
110
- mutators.setField(name, propsDefaultValue);
111
- }
112
- }
113
- }, [defaultValue, propsDefaultValue, name, mutators]);
114
- const debouncedLoadOptions = useMemo(() => loadOptions ? debounce(loadOptions, 300) : undefined, [loadOptions]);
115
- return jsx(CreateField, {
116
- id: id,
117
- name: name,
118
- label: label,
119
- isRequired: isRequired,
120
- validators: validators,
121
- validationHelpText: validationHelpText,
122
- testId: testId
123
- }, ({
124
- fieldId,
125
- isRequired,
126
- ...fieldProps
127
- }) => {
128
- return jsx(AkAsyncSelect, _extends({
129
- inputId: fieldId
130
- }, fieldProps, restProps, {
131
- required: isRequired,
132
- loadOptions: debouncedLoadOptions,
133
- defaultOptions: defaultOptions,
134
- isLoading: isLoadingDefaultOptions
135
- }));
136
- });
137
- }
@@ -1,57 +0,0 @@
1
- /* eslint-disable @atlassian/tangerine/import/no-parent-imports */
2
- /**
3
- * @jsxRuntime classic
4
- * @jsx jsx
5
- */
6
- // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
7
- import { css, jsx } from '@emotion/react';
8
- import { useIntl } from 'react-intl-next';
9
- import { ButtonGroup } from '@atlaskit/button';
10
- import ErrorIcon from '@atlaskit/icon/core/migration/error';
11
- import { Button } from '../../../../common/ui/Button';
12
- import { EditButton } from '../edit-button';
13
- import { messages } from '../messages';
14
- import { SubmitButton } from '../submit-button';
15
- const formFooterWrapperStyles = css({
16
- display: 'flex',
17
- marginTop: "var(--ds-space-300, 24px)",
18
- justifyContent: 'flex-end'
19
- });
20
- const errorStyles = css({
21
- display: 'flex',
22
- alignItems: 'center',
23
- marginRight: 'auto'
24
- });
25
- /**
26
- * Footer for the Create Form, used as a wrapper for action buttons
27
- * and form error messages. This component is unmounted if
28
- * hideFooter is true in the Create Form.
29
- */
30
- export function CreateFormFooterOld({
31
- formErrorMessage,
32
- handleCancel,
33
- testId
34
- }) {
35
- const intl = useIntl();
36
- return jsx("footer", {
37
- "data-testid": `${testId}-footer`,
38
- css: formFooterWrapperStyles
39
- }, formErrorMessage && jsx("div", {
40
- role: "alert",
41
- css: errorStyles,
42
- "data-testid": `${testId}-error`
43
- }, jsx(ErrorIcon, {
44
- label: formErrorMessage,
45
- color: "var(--ds-icon-danger, #E34935)",
46
- spacing: "spacious"
47
- }), formErrorMessage), jsx(ButtonGroup, null, jsx(Button, {
48
- type: "button",
49
- actionSubjectId: "cancel",
50
- appearance: "subtle",
51
- onClick: e => {
52
- e.stopPropagation();
53
- handleCancel();
54
- },
55
- testId: `${testId}-button-cancel`
56
- }, intl.formatMessage(messages.close)), jsx(EditButton, null), jsx(SubmitButton, null)));
57
- }
@@ -1,31 +0,0 @@
1
- /**
2
- * @jsxRuntime classic
3
- * @jsx jsx
4
- */
5
- // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
6
- import { css, jsx } from '@emotion/react';
7
- import Spinner from '@atlaskit/spinner';
8
- import { CREATE_FORM_MIN_HEIGHT_IN_PX } from '../../../../common/constants';
9
- const formLoaderStyles = css({
10
- display: `flex`,
11
- alignItems: `center`,
12
- justifyContent: `center`,
13
- // eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/ui-styling-standard/no-unsafe-values -- Ignored via go/DSP-18766
14
- minHeight: `${CREATE_FORM_MIN_HEIGHT_IN_PX}px`
15
- });
16
-
17
- /**
18
- * Wrapper component for the Spinner, shows while the form
19
- * performs async functions on load.
20
- */
21
- export function CreateFormLoaderOld({
22
- size = 'large'
23
- }) {
24
- return jsx("div", {
25
- css: formLoaderStyles
26
- }, jsx(Spinner, {
27
- size: size,
28
- interactionName: "load",
29
- testId: "link-create-form-loader"
30
- }));
31
- }
@@ -1,145 +0,0 @@
1
- /* eslint-disable @atlassian/tangerine/import/no-parent-imports */
2
- /**
3
- * @jsxRuntime classic
4
- * @jsx jsx
5
- */
6
- import { useCallback } from 'react';
7
-
8
- // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
9
- import { css, jsx } from '@emotion/react';
10
- import { FORM_ERROR } from 'final-form';
11
- import { Form, FormSpy } from 'react-final-form';
12
- import { useIntl } from 'react-intl-next';
13
- import { RequiredAsterisk } from '@atlaskit/form';
14
- import { Box, Text } from '@atlaskit/primitives';
15
- import { CREATE_FORM_MAX_WIDTH_IN_PX, LINK_CREATE_FORM_POST_CREATE_FIELD } from '../../../common/constants';
16
- import messages from '../../../common/messages';
17
- import { useLinkCreateCallback } from '../../../controllers/callback-context';
18
- import { useExitWarningModal } from '../../../controllers/exit-warning-modal-context';
19
- import { useFormContext } from '../../../controllers/form-context';
20
- import { CreateFormFooter } from '../form-footer';
21
- import { CreateFormLoader } from '../form-loader';
22
- const formStyles = css({
23
- // eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/ui-styling-standard/no-unsafe-values -- Ignored via go/DSP-18766
24
- maxWidth: `${CREATE_FORM_MAX_WIDTH_IN_PX}px`,
25
- padding: `0 0 ${"var(--ds-space-300, 24px)"} 0`,
26
- margin: `${"var(--ds-space-0, 0px)"} auto`
27
- });
28
- const RESERVED_FIELDS = [LINK_CREATE_FORM_POST_CREATE_FIELD];
29
- export const TEST_ID = 'link-create-form';
30
- export const CreateFormOld = ({
31
- children,
32
- testId = TEST_ID,
33
- onSubmit,
34
- onCancel,
35
- isLoading,
36
- hideFooter,
37
- hideRequiredFieldMessage,
38
- initialValues
39
- }) => {
40
- const {
41
- setFormErrorMessage,
42
- formErrorMessage,
43
- enableEditView
44
- } = useFormContext();
45
- const intl = useIntl();
46
- const {
47
- setShouldShowWarning
48
- } = useExitWarningModal();
49
- const {
50
- onFailure
51
- } = useLinkCreateCallback();
52
- const handleSubmit = useCallback(async data => {
53
- const {
54
- [LINK_CREATE_FORM_POST_CREATE_FIELD]: shouldEnableEditView,
55
- ...formData
56
- } = data;
57
-
58
- /**
59
- * If form has post-create field set to trigger post-create edit
60
- * send this to the form context so we know what to do next
61
- * if submission is successful
62
- */
63
- enableEditView === null || enableEditView === void 0 ? void 0 : enableEditView(!!shouldEnableEditView);
64
-
65
- /**
66
- * This is the onSubmit handler provided by the plugin
67
- * It will be async, and it will likely involve awaiting `onCreate` (the adopters handler)
68
- */
69
- return onSubmit(formData);
70
- }, [onSubmit, enableEditView]);
71
- const handleSubmitWithErrorHandling = useCallback(async (...args) => {
72
- try {
73
- /**
74
- * Clear any error message that may have been set by async select fields
75
- * This will immediately remove any indication of an error, but the form likely will fail to submit,
76
- * it will be likely a 400 because the user probably could not set all fields anyway
77
- */
78
- setFormErrorMessage();
79
- return await handleSubmit(...args);
80
- } catch (error) {
81
- /**
82
- * Notify link create of failed experience
83
- */
84
- onFailure === null || onFailure === void 0 ? void 0 : onFailure(error);
85
-
86
- /**
87
- * Return a generic message for react final form to render
88
- */
89
- return {
90
- [FORM_ERROR]: intl.formatMessage(messages.genericErrorMessage)
91
- };
92
- }
93
- }, [handleSubmit, setFormErrorMessage, intl, onFailure]);
94
- const handleCancel = useCallback(() => {
95
- onCancel && onCancel();
96
- }, [onCancel]);
97
- if (isLoading) {
98
- return jsx(CreateFormLoader, null);
99
- }
100
- return jsx(Form, {
101
- onSubmit: handleSubmitWithErrorHandling,
102
- initialValues: initialValues,
103
- mutators: {
104
- setField: (args, state, tools) => {
105
- tools.changeValue(state, args[0].toString(), () => args[1]);
106
- }
107
- }
108
- }, ({
109
- submitError,
110
- ...formProps
111
- }) => {
112
- return jsx("form", {
113
- onSubmit: formProps.handleSubmit,
114
- name: "link-create-form",
115
- noValidate: true,
116
- "data-testid": testId,
117
- css: formStyles
118
- }, jsx(FormSpy, {
119
- subscription: {
120
- modified: true
121
- },
122
- onChange: state => {
123
- // determine if any of the fields have been modified
124
- if (!state.modified) {
125
- setShouldShowWarning(false);
126
- return;
127
- }
128
- const isModified = Object.values(state.modified).some(value => value);
129
- setShouldShowWarning(isModified);
130
- }
131
- }), !hideRequiredFieldMessage && jsx(Text, {
132
- as: "p"
133
- }, intl.formatMessage(messages.requiredFieldInstruction), " ", jsx(RequiredAsterisk, null)), jsx(Box, null, children), !hideFooter && jsx(CreateFormFooter
134
- /**
135
- * We will prefer to render the error message connected to
136
- * react final form state (submitError) otherwise we can
137
- * default to the `formErrorMessage` that we sometimes use with our own
138
- * "form context" (only currently used for AsyncSelect field reporting failed loading)
139
- */, {
140
- formErrorMessage: submitError || formErrorMessage,
141
- handleCancel: handleCancel,
142
- testId: testId
143
- }));
144
- });
145
- };
@@ -1,106 +0,0 @@
1
- import _extends from "@babel/runtime/helpers/extends";
2
- /* eslint-disable @atlassian/tangerine/import/no-parent-imports */
3
- /**
4
- * @jsxRuntime classic
5
- * @jsx jsx
6
- */
7
-
8
- // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
9
- import { jsx } from '@emotion/react';
10
- import { useIntl } from 'react-intl-next';
11
- import { Inline } from '@atlaskit/primitives';
12
- import AkSelect, { components } from '@atlaskit/select';
13
- import { layers } from '@atlaskit/theme/constants';
14
- import { UrlIcon } from '../../../../common/ui/icon';
15
- import { CreateField } from '../../../../controllers/create-field';
16
- import { messages } from '../messages';
17
- export const TEST_ID = 'link-create-select';
18
-
19
- /**
20
- * A select component utilising the Atlaskit Select and CreateField.
21
- * Validation is handled by the form on form submission. Any
22
- * errors returned by the handleSubmit function passed to the form <Form> that
23
- * have a key matching the `name` of this field are shown below the field.
24
- */
25
- export function SelectOld({
26
- id,
27
- name,
28
- label,
29
- isRequired,
30
- validators,
31
- validationHelpText,
32
- testId = TEST_ID,
33
- ...restProps
34
- }) {
35
- return jsx(CreateField, {
36
- id: id,
37
- name: name,
38
- label: label,
39
- isRequired: isRequired,
40
- validators: validators,
41
- validationHelpText: validationHelpText,
42
- testId: testId
43
- }, ({
44
- fieldId,
45
- isRequired,
46
- ...fieldProps
47
- }) => {
48
- return jsx(AkSelect, _extends({
49
- required: isRequired,
50
- inputId: fieldId
51
- }, fieldProps, restProps));
52
- });
53
- }
54
- export const SiteSelectOld = ({
55
- options,
56
- name,
57
- testId
58
- }) => {
59
- const intl = useIntl();
60
- const siteTestId = testId ? testId : 'link-create-site-picker';
61
- return jsx(SelectOld, {
62
- isRequired: true,
63
- isSearchable: true,
64
- name: name !== null && name !== void 0 ? name : 'site',
65
- options: options,
66
- label: intl.formatMessage(messages.siteLabel),
67
- components: {
68
- Option: SitePickerOptionOld,
69
- SingleValue: SitePickerSingleValueOld
70
- },
71
- testId: siteTestId,
72
- styles: {
73
- menuPortal: base => ({
74
- ...base,
75
- zIndex: layers.modal()
76
- }),
77
- option: base => ({
78
- ...base,
79
- display: 'flex',
80
- alignItems: 'center',
81
- cursor: 'pointer'
82
- })
83
- }
84
- });
85
- };
86
- const SiteRow = ({
87
- avatarUrl,
88
- children
89
- }) => jsx(Inline, {
90
- space: "space.100",
91
- alignBlock: "center"
92
- }, avatarUrl ? jsx(UrlIcon, {
93
- url: avatarUrl
94
- }) : null, children);
95
- export const SitePickerOptionOld = ({
96
- children,
97
- ...props
98
- }) => jsx(components.Option, props, jsx(SiteRow, {
99
- avatarUrl: props.data.value.avatarUrl
100
- }, children));
101
- export const SitePickerSingleValueOld = ({
102
- children,
103
- ...props
104
- }) => jsx(components.SingleValue, props, jsx(SiteRow, {
105
- avatarUrl: props.data.value.avatarUrl
106
- }, children));
@@ -1,45 +0,0 @@
1
- import _extends from "@babel/runtime/helpers/extends";
2
- /* eslint-disable @atlassian/tangerine/import/no-parent-imports */
3
- /**
4
- * @jsxRuntime classic
5
- * @jsx jsx
6
- */
7
- // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
8
- import { jsx } from '@emotion/react';
9
- import AkTextfield from '@atlaskit/textfield';
10
- import { CreateField } from '../../../../controllers/create-field';
11
- export const TEST_ID = 'link-create-text-field';
12
-
13
- /**
14
- * A text field utilising the Atlaskit Textfield and CreateField.
15
- * Validation is handled by the form as it is on form submission. Any errors returned by
16
- * the handleSubmit function passed to the form <Form> that have a key matching the `name`
17
- * of this text field are shown above the field.
18
- */
19
- export function TextFieldOld({
20
- id,
21
- name,
22
- label,
23
- isRequired,
24
- validators,
25
- validationHelpText,
26
- testId = TEST_ID,
27
- ...restProps
28
- }) {
29
- return jsx(CreateField, {
30
- id: id,
31
- name: name,
32
- label: label,
33
- isRequired: isRequired,
34
- validators: validators,
35
- validationHelpText: validationHelpText,
36
- testId: testId
37
- }, ({
38
- fieldId,
39
- ...fieldProps
40
- }) => {
41
- return jsx(AkTextfield, _extends({
42
- id: fieldId
43
- }, fieldProps, restProps));
44
- });
45
- }
@@ -1,59 +0,0 @@
1
- /* eslint-disable @atlassian/tangerine/import/no-parent-imports */
2
- /**
3
- * @jsxRuntime classic
4
- * @jsx jsx
5
- */
6
- // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
7
- import { jsx } from '@emotion/react';
8
- import SmartUserPicker from '@atlaskit/smart-user-picker';
9
- import { CreateField } from '../../../../controllers/create-field';
10
- export const TEST_ID = 'link-create-user-picker';
11
- const DEFAULT_DEBOUNCE_TIME = 400;
12
- const UserPickerWidth = '100%';
13
-
14
- /**
15
- * A user picker utilising the SmartUserPicker.
16
- */
17
-
18
- export function UserPickerOld({
19
- productKey,
20
- siteId,
21
- name,
22
- label,
23
- placeholder,
24
- validators,
25
- testId = TEST_ID,
26
- defaultValue
27
- }) {
28
- return jsx(CreateField, {
29
- name: name,
30
- label: label,
31
- isRequired: true,
32
- testId: testId,
33
- validators: validators
34
- }, ({
35
- fieldId,
36
- isRequired,
37
- ...fieldProps
38
- }) => {
39
- return jsx(SmartUserPicker, {
40
- defaultValue: defaultValue ? {
41
- ...defaultValue,
42
- type: 'user'
43
- } : undefined,
44
- placeholder: placeholder,
45
- onChange: value => fieldProps.onChange(value),
46
- subtle: true,
47
- isMulti: false,
48
- productKey: productKey,
49
- siteId: siteId,
50
- fieldId: fieldId,
51
- inputId: fieldId,
52
- debounceTime: DEFAULT_DEBOUNCE_TIME,
53
- prefetch: true,
54
- isClearable: false,
55
- width: UserPickerWidth,
56
- required: isRequired
57
- });
58
- });
59
- }
@@ -1,30 +0,0 @@
1
- /* eslint-disable @atlassian/tangerine/import/no-parent-imports */
2
- /**
3
- * @jsxRuntime classic
4
- * @jsx jsx
5
- */
6
- import { memo } from 'react';
7
-
8
- // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
9
- import { jsx } from '@emotion/react';
10
- import { AnalyticsContext } from '@atlaskit/analytics-next';
11
- import { IntlMessagesProvider } from '@atlaskit/intl-messages-provider';
12
- import { PACKAGE_DATA } from '../../../common/constants';
13
- import { ErrorBoundary } from '../../../common/ui/error-boundary';
14
- import { Experience } from '../../../common/ui/experience-tracker';
15
- import { withLinkCreateAnalyticsContext } from '../../../common/utils/analytics';
16
- import { fetchMessagesForLocale } from '../../../common/utils/locale/fetch-messages-for-locale';
17
- import i18nEN from '../../../i18n/en';
18
- import InlineCreate from '../main';
19
- const LinkCreateWithAnalyticsContext = withLinkCreateAnalyticsContext( /*#__PURE__*/memo(props => {
20
- return jsx(Experience, null, jsx(ErrorBoundary, null, jsx(InlineCreate, props)));
21
- }));
22
- const ComposedLinkCreateOld = /*#__PURE__*/memo(props => {
23
- return jsx(AnalyticsContext, {
24
- data: PACKAGE_DATA
25
- }, jsx(IntlMessagesProvider, {
26
- defaultMessages: i18nEN,
27
- loaderFn: fetchMessagesForLocale
28
- }, jsx(LinkCreateWithAnalyticsContext, props)));
29
- });
30
- export default ComposedLinkCreateOld;