@atlaskit/link-create 1.3.0 → 1.5.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/dist/cjs/controllers/callback-context/main.js +16 -5
- package/dist/cjs/controllers/edit-post-create-context/index.js +43 -0
- package/dist/cjs/controllers/form-context/main.js +15 -2
- package/dist/cjs/controllers/plugin-context/index.js +39 -0
- package/dist/cjs/ui/create-form/main.js +11 -2
- package/dist/cjs/ui/link-create/confirm-dismiss-dialog/index.js +12 -0
- package/dist/cjs/ui/link-create/confirm-dismiss-dialog/main.js +32 -0
- package/dist/cjs/ui/link-create/confirm-dismiss-dialog/messages.js +29 -0
- package/dist/cjs/ui/link-create/edit-modal/index.js +25 -0
- package/dist/cjs/ui/link-create/main.js +57 -9
- package/dist/cjs/ui/main.js +1 -1
- package/dist/es2019/controllers/callback-context/main.js +11 -5
- package/dist/es2019/controllers/edit-post-create-context/index.js +28 -0
- package/dist/es2019/controllers/form-context/main.js +14 -3
- package/dist/es2019/controllers/plugin-context/index.js +25 -0
- package/dist/es2019/ui/create-form/main.js +10 -3
- package/dist/es2019/ui/link-create/confirm-dismiss-dialog/index.js +1 -0
- package/dist/es2019/ui/link-create/confirm-dismiss-dialog/main.js +23 -0
- package/dist/es2019/ui/link-create/confirm-dismiss-dialog/messages.js +23 -0
- package/dist/es2019/ui/link-create/edit-modal/index.js +17 -0
- package/dist/es2019/ui/link-create/main.js +54 -9
- package/dist/es2019/ui/main.js +1 -1
- package/dist/esm/controllers/callback-context/main.js +16 -5
- package/dist/esm/controllers/edit-post-create-context/index.js +33 -0
- package/dist/esm/controllers/form-context/main.js +16 -3
- package/dist/esm/controllers/plugin-context/index.js +29 -0
- package/dist/esm/ui/create-form/main.js +12 -3
- package/dist/esm/ui/link-create/confirm-dismiss-dialog/index.js +1 -0
- package/dist/esm/ui/link-create/confirm-dismiss-dialog/main.js +22 -0
- package/dist/esm/ui/link-create/confirm-dismiss-dialog/messages.js +23 -0
- package/dist/esm/ui/link-create/edit-modal/index.js +15 -0
- package/dist/esm/ui/link-create/main.js +58 -10
- package/dist/esm/ui/main.js +1 -1
- package/dist/types/controllers/edit-post-create-context/index.d.ts +12 -0
- package/dist/types/controllers/form-context/main.d.ts +3 -0
- package/dist/types/controllers/plugin-context/index.d.ts +18 -0
- package/dist/types/ui/link-create/confirm-dismiss-dialog/index.d.ts +2 -0
- package/dist/types/ui/link-create/confirm-dismiss-dialog/main.d.ts +7 -0
- package/dist/types/ui/link-create/confirm-dismiss-dialog/messages.d.ts +23 -0
- package/dist/types/ui/link-create/edit-modal/index.d.ts +4 -0
- package/dist/types/ui/link-create/main.d.ts +3 -3
- package/dist/types-ts4.5/controllers/edit-post-create-context/index.d.ts +12 -0
- package/dist/types-ts4.5/controllers/form-context/main.d.ts +3 -0
- package/dist/types-ts4.5/controllers/plugin-context/index.d.ts +18 -0
- package/dist/types-ts4.5/ui/link-create/confirm-dismiss-dialog/index.d.ts +2 -0
- package/dist/types-ts4.5/ui/link-create/confirm-dismiss-dialog/main.d.ts +7 -0
- package/dist/types-ts4.5/ui/link-create/confirm-dismiss-dialog/messages.d.ts +23 -0
- package/dist/types-ts4.5/ui/link-create/edit-modal/index.d.ts +4 -0
- package/dist/types-ts4.5/ui/link-create/main.d.ts +3 -3
- package/package.json +6 -2
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { useIntl } from 'react-intl-next';
|
|
3
|
+
import Button from '@atlaskit/button';
|
|
4
|
+
import Modal, { ModalBody, ModalFooter, ModalHeader, ModalTitle, ModalTransition } from '@atlaskit/modal-dialog';
|
|
5
|
+
import messages from './messages';
|
|
6
|
+
export const ConfirmDismissDialog = ({
|
|
7
|
+
active,
|
|
8
|
+
onCancelDismiss,
|
|
9
|
+
onConfirmDismiss
|
|
10
|
+
}) => {
|
|
11
|
+
const intl = useIntl();
|
|
12
|
+
return /*#__PURE__*/React.createElement(ModalTransition, null, active && /*#__PURE__*/React.createElement(Modal, {
|
|
13
|
+
testId: "link-create-confirm-dismiss-dialog",
|
|
14
|
+
onClose: onCancelDismiss,
|
|
15
|
+
width: "small"
|
|
16
|
+
}, /*#__PURE__*/React.createElement(ModalHeader, null, /*#__PURE__*/React.createElement(ModalTitle, null, intl.formatMessage(messages.title))), /*#__PURE__*/React.createElement(ModalBody, null, intl.formatMessage(messages.description)), /*#__PURE__*/React.createElement(ModalFooter, null, /*#__PURE__*/React.createElement(Button, {
|
|
17
|
+
appearance: "subtle",
|
|
18
|
+
onClick: onCancelDismiss
|
|
19
|
+
}, intl.formatMessage(messages.cancelButtonLabel)), /*#__PURE__*/React.createElement(Button, {
|
|
20
|
+
appearance: "primary",
|
|
21
|
+
onClick: onConfirmDismiss
|
|
22
|
+
}, intl.formatMessage(messages.confirmButtonLabel)))));
|
|
23
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { defineMessages } from 'react-intl-next';
|
|
2
|
+
export default defineMessages({
|
|
3
|
+
title: {
|
|
4
|
+
id: 'linkCreate.confirm-dismiss-dialog.modal.title',
|
|
5
|
+
defaultMessage: 'Your changes won’t be saved',
|
|
6
|
+
description: 'Title for confirm-dismiss modal popup'
|
|
7
|
+
},
|
|
8
|
+
cancelButtonLabel: {
|
|
9
|
+
id: 'linkCreate.confirm-dismiss-dialog.modal.cancel-button-label',
|
|
10
|
+
defaultMessage: 'Go back',
|
|
11
|
+
description: 'Label for secondary button for confirm-dismiss modal popup'
|
|
12
|
+
},
|
|
13
|
+
confirmButtonLabel: {
|
|
14
|
+
id: 'linkCreate.confirm-dismiss-dialog.modal.confirm-button-label',
|
|
15
|
+
defaultMessage: 'Discard',
|
|
16
|
+
description: 'Label for primary button for confirm-dismiss modal popup'
|
|
17
|
+
},
|
|
18
|
+
description: {
|
|
19
|
+
id: 'linkCreate.confirm-dismiss-dialog.modal.description',
|
|
20
|
+
defaultMessage: 'We won’t be able to save your information if you move away from this page.',
|
|
21
|
+
description: 'Description for confirm-dismiss modal popup'
|
|
22
|
+
}
|
|
23
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import Modal, { ModalTransition } from '@atlaskit/modal-dialog';
|
|
3
|
+
import { useEditPostCreateModal } from '../../../controllers/edit-post-create-context';
|
|
4
|
+
export const EditModal = ({
|
|
5
|
+
onClose
|
|
6
|
+
}) => {
|
|
7
|
+
const {
|
|
8
|
+
editViewPayload
|
|
9
|
+
} = useEditPostCreateModal();
|
|
10
|
+
return /*#__PURE__*/React.createElement(ModalTransition, null, !!editViewPayload && /*#__PURE__*/React.createElement(Modal, {
|
|
11
|
+
testId: "link-create-edit-modal",
|
|
12
|
+
onClose: onClose,
|
|
13
|
+
shouldScrollInViewport: true,
|
|
14
|
+
width: "calc(100vw - 120px)",
|
|
15
|
+
height: "calc(100vh - 120px)"
|
|
16
|
+
}));
|
|
17
|
+
};
|
|
@@ -1,11 +1,18 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
1
2
|
/** @jsx jsx */
|
|
2
|
-
import { Fragment, useCallback } from 'react';
|
|
3
|
+
import { Fragment, useCallback, useState } from 'react';
|
|
3
4
|
import { jsx } from '@emotion/react';
|
|
4
5
|
import { useIntl } from 'react-intl-next';
|
|
5
6
|
import Modal, { ModalBody, ModalHeader, ModalTitle, ModalTransition } from '@atlaskit/modal-dialog';
|
|
7
|
+
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
8
|
+
import { Box } from '@atlaskit/primitives';
|
|
6
9
|
import { CREATE_FORM_MAX_WIDTH_IN_PX } from '../../common/constants';
|
|
7
10
|
import { LinkCreateCallbackProvider } from '../../controllers/callback-context';
|
|
11
|
+
import { EditPostCreateModalProvider } from '../../controllers/edit-post-create-context';
|
|
8
12
|
import { useFormContext, withLinkCreateFormContext } from '../../controllers/form-context';
|
|
13
|
+
import { LinkCreatePluginsProvider } from '../../controllers/plugin-context';
|
|
14
|
+
import { ConfirmDismissDialog } from './confirm-dismiss-dialog';
|
|
15
|
+
import { EditModal } from './edit-modal';
|
|
9
16
|
import { ErrorBoundary } from './error-boundary';
|
|
10
17
|
import { messages } from './messages';
|
|
11
18
|
import TrackMount from './track-mount';
|
|
@@ -20,7 +27,7 @@ const LinkCreateContent = ({
|
|
|
20
27
|
}
|
|
21
28
|
return jsx(Fragment, null, chosenOne.form);
|
|
22
29
|
};
|
|
23
|
-
const LinkCreate =
|
|
30
|
+
const LinkCreate = ({
|
|
24
31
|
testId = TEST_ID,
|
|
25
32
|
onCreate,
|
|
26
33
|
onFailure,
|
|
@@ -43,29 +50,67 @@ const LinkCreate = withLinkCreateFormContext(({
|
|
|
43
50
|
setFormErrorMessage(error.message);
|
|
44
51
|
onFailure && onFailure(error);
|
|
45
52
|
}, [onFailure, setFormErrorMessage]);
|
|
46
|
-
return jsx(
|
|
47
|
-
|
|
53
|
+
return jsx(Box, {
|
|
54
|
+
testId: testId
|
|
48
55
|
}, jsx(ErrorBoundary, null, jsx(LinkCreateCallbackProvider, {
|
|
49
56
|
onCancel: onCancel,
|
|
50
57
|
onCreate: handleCreate,
|
|
51
58
|
onFailure: handleFailure
|
|
52
59
|
}, jsx(TrackMount, null), jsx(LinkCreateContent, restProps))));
|
|
53
|
-
}
|
|
60
|
+
};
|
|
54
61
|
const LinkCreateWithModal = ({
|
|
55
62
|
active,
|
|
56
63
|
modalTitle,
|
|
64
|
+
onCancel,
|
|
57
65
|
onOpenComplete,
|
|
58
66
|
onCloseComplete,
|
|
59
67
|
...createProps
|
|
60
68
|
}) => {
|
|
69
|
+
const [dismissDialog, setDismissDialog] = useState(false);
|
|
70
|
+
const {
|
|
71
|
+
isFormDirty
|
|
72
|
+
} = useFormContext();
|
|
61
73
|
const intl = useIntl();
|
|
62
|
-
|
|
74
|
+
const handleCancel = useCallback(() => {
|
|
75
|
+
if (getBooleanFF('platform.linking-platform.link-create.confirm-dismiss-dialog')) {
|
|
76
|
+
if (isFormDirty()) {
|
|
77
|
+
return setDismissDialog(true);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
onCancel && onCancel();
|
|
81
|
+
}, [onCancel, isFormDirty]);
|
|
82
|
+
const handleCancelDismiss = useCallback(() => {
|
|
83
|
+
setDismissDialog(false);
|
|
84
|
+
}, []);
|
|
85
|
+
const handleConfirmDismiss = useCallback(() => {
|
|
86
|
+
setDismissDialog(false);
|
|
87
|
+
onCancel && onCancel();
|
|
88
|
+
}, [onCancel]);
|
|
89
|
+
return jsx(Fragment, null, jsx(ModalTransition, null, !!active && jsx(Modal, {
|
|
63
90
|
testId: "link-create-modal",
|
|
64
|
-
onClose:
|
|
91
|
+
onClose: handleCancel,
|
|
65
92
|
shouldScrollInViewport: true,
|
|
66
93
|
onOpenComplete: onOpenComplete,
|
|
67
94
|
onCloseComplete: onCloseComplete,
|
|
68
95
|
width: `${CREATE_FORM_MAX_WIDTH_IN_PX}px`
|
|
69
|
-
}, jsx(ModalHeader, null, jsx(ModalTitle, null, modalTitle || intl.formatMessage(messages.heading))), jsx(ModalBody, null, jsx(LinkCreate, createProps
|
|
96
|
+
}, jsx(ModalHeader, null, jsx(ModalTitle, null, modalTitle || intl.formatMessage(messages.heading))), jsx(ModalBody, null, jsx(LinkCreate, _extends({}, createProps, {
|
|
97
|
+
onCancel: handleCancel
|
|
98
|
+
}))))), getBooleanFF('platform.linking-platform.link-create.enable-edit') && jsx(EditModal, {
|
|
99
|
+
onClose: handleCancel
|
|
100
|
+
}), getBooleanFF('platform.linking-platform.link-create.confirm-dismiss-dialog') && jsx(ConfirmDismissDialog, {
|
|
101
|
+
active: dismissDialog,
|
|
102
|
+
onCancelDismiss: handleCancelDismiss,
|
|
103
|
+
onConfirmDismiss: handleConfirmDismiss
|
|
104
|
+
}));
|
|
70
105
|
};
|
|
71
|
-
export default
|
|
106
|
+
export default withLinkCreateFormContext(props => {
|
|
107
|
+
if (getBooleanFF('platform.linking-platform.link-create.enable-edit')) {
|
|
108
|
+
return jsx(LinkCreatePluginsProvider, {
|
|
109
|
+
plugins: props.plugins,
|
|
110
|
+
entityKey: props.entityKey
|
|
111
|
+
}, jsx(EditPostCreateModalProvider, {
|
|
112
|
+
active: !!props.active
|
|
113
|
+
}, jsx(LinkCreateWithModal, props)));
|
|
114
|
+
}
|
|
115
|
+
return jsx(LinkCreateWithModal, props);
|
|
116
|
+
});
|
package/dist/es2019/ui/main.js
CHANGED
|
@@ -15,7 +15,7 @@ const LinkCreateWithAnalyticsContext = withLinkCreateAnalyticsContext( /*#__PURE
|
|
|
15
15
|
}));
|
|
16
16
|
export const PACKAGE_DATA = {
|
|
17
17
|
packageName: "@atlaskit/link-create" || '',
|
|
18
|
-
packageVersion: "1.
|
|
18
|
+
packageVersion: "1.5.0" || '',
|
|
19
19
|
componentName: COMPONENT_NAME,
|
|
20
20
|
source: COMPONENT_NAME
|
|
21
21
|
};
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
1
2
|
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
3
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
4
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
2
5
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
3
6
|
import React, { useContext, useMemo } from 'react';
|
|
4
7
|
import { useAnalyticsEvents } from '@atlaskit/analytics-next';
|
|
@@ -12,7 +15,7 @@ var LinkCreateCallbackProvider = function LinkCreateCallbackProvider(_ref) {
|
|
|
12
15
|
onCancel = _ref.onCancel;
|
|
13
16
|
var _useAnalyticsEvents = useAnalyticsEvents(),
|
|
14
17
|
createAnalyticsEvent = _useAnalyticsEvents.createAnalyticsEvent;
|
|
15
|
-
var
|
|
18
|
+
var handleCreate = useMemo(function () {
|
|
16
19
|
return {
|
|
17
20
|
onCreate: function () {
|
|
18
21
|
var _onCreate2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(result) {
|
|
@@ -41,7 +44,11 @@ var LinkCreateCallbackProvider = function LinkCreateCallbackProvider(_ref) {
|
|
|
41
44
|
return _onCreate2.apply(this, arguments);
|
|
42
45
|
}
|
|
43
46
|
return onCreate;
|
|
44
|
-
}()
|
|
47
|
+
}()
|
|
48
|
+
};
|
|
49
|
+
}, [createAnalyticsEvent, _onCreate]);
|
|
50
|
+
var handleFailure = useMemo(function () {
|
|
51
|
+
return {
|
|
45
52
|
onFailure: function () {
|
|
46
53
|
var _onFailure2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(error) {
|
|
47
54
|
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
@@ -61,10 +68,14 @@ var LinkCreateCallbackProvider = function LinkCreateCallbackProvider(_ref) {
|
|
|
61
68
|
return _onFailure2.apply(this, arguments);
|
|
62
69
|
}
|
|
63
70
|
return onFailure;
|
|
64
|
-
}()
|
|
65
|
-
onCancel: onCancel
|
|
71
|
+
}()
|
|
66
72
|
};
|
|
67
|
-
}, [
|
|
73
|
+
}, [createAnalyticsEvent, _onFailure]);
|
|
74
|
+
var value = useMemo(function () {
|
|
75
|
+
return _objectSpread(_objectSpread({
|
|
76
|
+
onCancel: onCancel
|
|
77
|
+
}, handleCreate), handleFailure);
|
|
78
|
+
}, [onCancel, handleCreate, handleFailure]);
|
|
68
79
|
return /*#__PURE__*/React.createElement(LinkCreateCallbackContext.Provider, {
|
|
69
80
|
value: value
|
|
70
81
|
}, children);
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
+
import React, { createContext, useContext, useMemo, useState } from 'react';
|
|
3
|
+
var EditPostCreateModalContext = /*#__PURE__*/createContext({
|
|
4
|
+
editViewPayload: undefined,
|
|
5
|
+
setEditViewPayload: function setEditViewPayload() {}
|
|
6
|
+
});
|
|
7
|
+
export var EditPostCreateModalProvider = function EditPostCreateModalProvider(_ref) {
|
|
8
|
+
var active = _ref.active,
|
|
9
|
+
children = _ref.children;
|
|
10
|
+
var _useState = useState(undefined),
|
|
11
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
12
|
+
editViewPayload = _useState2[0],
|
|
13
|
+
setEditViewPayload = _useState2[1];
|
|
14
|
+
var value = useMemo(function () {
|
|
15
|
+
return {
|
|
16
|
+
editViewPayload: editViewPayload,
|
|
17
|
+
setEditViewPayload: setEditViewPayload
|
|
18
|
+
};
|
|
19
|
+
}, [editViewPayload, setEditViewPayload]);
|
|
20
|
+
if (editViewPayload && !active) {
|
|
21
|
+
setEditViewPayload(undefined);
|
|
22
|
+
}
|
|
23
|
+
return /*#__PURE__*/React.createElement(EditPostCreateModalContext.Provider, {
|
|
24
|
+
value: value
|
|
25
|
+
}, children);
|
|
26
|
+
};
|
|
27
|
+
export var useEditPostCreateModal = function useEditPostCreateModal() {
|
|
28
|
+
var value = useContext(EditPostCreateModalContext);
|
|
29
|
+
if (!value) {
|
|
30
|
+
throw new Error('useEditPostCreateModal used outside of useEditPostCreateModalProvider');
|
|
31
|
+
}
|
|
32
|
+
return value;
|
|
33
|
+
};
|
|
@@ -2,14 +2,18 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
|
2
2
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
3
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
4
4
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
5
|
-
import React, { createContext, useCallback, useContext, useState } from 'react';
|
|
5
|
+
import React, { createContext, useCallback, useContext, useRef, useState } from 'react';
|
|
6
6
|
export var FormContext = /*#__PURE__*/createContext({
|
|
7
7
|
assignValidator: function assignValidator() {},
|
|
8
8
|
getValidators: function getValidators() {
|
|
9
9
|
return {};
|
|
10
10
|
},
|
|
11
11
|
setFormErrorMessage: function setFormErrorMessage() {},
|
|
12
|
-
enableEditView: undefined
|
|
12
|
+
enableEditView: undefined,
|
|
13
|
+
setFormDirty: function setFormDirty() {},
|
|
14
|
+
isFormDirty: function isFormDirty() {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
13
17
|
});
|
|
14
18
|
var FormContextProvider = function FormContextProvider(_ref) {
|
|
15
19
|
var enableEditView = _ref.enableEditView,
|
|
@@ -22,6 +26,13 @@ var FormContextProvider = function FormContextProvider(_ref) {
|
|
|
22
26
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
23
27
|
validators = _useState4[0],
|
|
24
28
|
setValidators = _useState4[1];
|
|
29
|
+
var dirty = useRef(false);
|
|
30
|
+
var isFormDirty = useCallback(function () {
|
|
31
|
+
return dirty.current;
|
|
32
|
+
}, [dirty]);
|
|
33
|
+
var setFormDirty = useCallback(function (isDirty) {
|
|
34
|
+
dirty.current = !!isDirty;
|
|
35
|
+
}, [dirty]);
|
|
25
36
|
|
|
26
37
|
// Add validators to the form
|
|
27
38
|
var assignValidator = useCallback(function (name, fieldValidators) {
|
|
@@ -45,7 +56,9 @@ var FormContextProvider = function FormContextProvider(_ref) {
|
|
|
45
56
|
getValidators: getValidators,
|
|
46
57
|
setFormErrorMessage: setFormErrorMessage,
|
|
47
58
|
formErrorMessage: error,
|
|
48
|
-
enableEditView: enableEditView
|
|
59
|
+
enableEditView: enableEditView,
|
|
60
|
+
setFormDirty: setFormDirty,
|
|
61
|
+
isFormDirty: isFormDirty
|
|
49
62
|
}
|
|
50
63
|
}, children);
|
|
51
64
|
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
+
import React, { createContext, useContext, useMemo, useState } from 'react';
|
|
3
|
+
var LinkCreatePluginsContext = /*#__PURE__*/createContext(null);
|
|
4
|
+
export var LinkCreatePluginsProvider = function LinkCreatePluginsProvider(_ref) {
|
|
5
|
+
var plugins = _ref.plugins,
|
|
6
|
+
propEntityKey = _ref.entityKey,
|
|
7
|
+
children = _ref.children;
|
|
8
|
+
var _useState = useState(propEntityKey),
|
|
9
|
+
_useState2 = _slicedToArray(_useState, 1),
|
|
10
|
+
entityKey = _useState2[0];
|
|
11
|
+
var value = useMemo(function () {
|
|
12
|
+
var _plugins$find;
|
|
13
|
+
return {
|
|
14
|
+
activePlugin: (_plugins$find = plugins.find(function (plugin) {
|
|
15
|
+
return plugin.key === entityKey;
|
|
16
|
+
})) !== null && _plugins$find !== void 0 ? _plugins$find : null
|
|
17
|
+
};
|
|
18
|
+
}, [entityKey, plugins]);
|
|
19
|
+
return /*#__PURE__*/React.createElement(LinkCreatePluginsContext.Provider, {
|
|
20
|
+
value: value
|
|
21
|
+
}, children);
|
|
22
|
+
};
|
|
23
|
+
export var useLinkCreatePlugins = function useLinkCreatePlugins() {
|
|
24
|
+
var value = useContext(LinkCreatePluginsContext);
|
|
25
|
+
if (!value) {
|
|
26
|
+
throw new Error('useLinkCreatePlugins used outside of LinkCreatePluginsProvider');
|
|
27
|
+
}
|
|
28
|
+
return value;
|
|
29
|
+
};
|
|
@@ -5,8 +5,9 @@ import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
|
5
5
|
/** @jsx jsx */
|
|
6
6
|
import { useCallback } from 'react';
|
|
7
7
|
import { css, jsx } from '@emotion/react';
|
|
8
|
-
import { Form } from 'react-final-form';
|
|
8
|
+
import { Form, FormSpy } from 'react-final-form';
|
|
9
9
|
import { useAnalyticsEvents } from '@atlaskit/analytics-next';
|
|
10
|
+
import { Box } from '@atlaskit/primitives';
|
|
10
11
|
import { ANALYTICS_CHANNEL, CREATE_FORM_MAX_WIDTH_IN_PX } from '../../common/constants';
|
|
11
12
|
import createEventPayload from '../../common/utils/analytics/analytics.codegen';
|
|
12
13
|
import { useFormContext } from '../../controllers/form-context';
|
|
@@ -32,7 +33,8 @@ export var CreateForm = function CreateForm(_ref) {
|
|
|
32
33
|
createAnalyticsEvent = _useAnalyticsEvents.createAnalyticsEvent;
|
|
33
34
|
var _useFormContext = useFormContext(),
|
|
34
35
|
getValidators = _useFormContext.getValidators,
|
|
35
|
-
formErrorMessage = _useFormContext.formErrorMessage
|
|
36
|
+
formErrorMessage = _useFormContext.formErrorMessage,
|
|
37
|
+
setFormDirty = _useFormContext.setFormDirty;
|
|
36
38
|
var handleSubmit = useCallback( /*#__PURE__*/function () {
|
|
37
39
|
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(data) {
|
|
38
40
|
var validators, errors;
|
|
@@ -87,7 +89,14 @@ export var CreateForm = function CreateForm(_ref) {
|
|
|
87
89
|
name: "link-create-form",
|
|
88
90
|
"data-testid": testId,
|
|
89
91
|
css: formStyles
|
|
90
|
-
}, jsx(
|
|
92
|
+
}, jsx(FormSpy, {
|
|
93
|
+
subscription: {
|
|
94
|
+
dirty: true
|
|
95
|
+
},
|
|
96
|
+
onChange: function onChange(state) {
|
|
97
|
+
return setFormDirty(state.dirty);
|
|
98
|
+
}
|
|
99
|
+
}), jsx(Box, null, children), !hideFooter && jsx(CreateFormFooter, {
|
|
91
100
|
formErrorMessage: formErrorMessage,
|
|
92
101
|
handleCancel: handleCancel,
|
|
93
102
|
submitting: submitting,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ConfirmDismissDialog } from './main';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { useIntl } from 'react-intl-next';
|
|
3
|
+
import Button from '@atlaskit/button';
|
|
4
|
+
import Modal, { ModalBody, ModalFooter, ModalHeader, ModalTitle, ModalTransition } from '@atlaskit/modal-dialog';
|
|
5
|
+
import messages from './messages';
|
|
6
|
+
export var ConfirmDismissDialog = function ConfirmDismissDialog(_ref) {
|
|
7
|
+
var active = _ref.active,
|
|
8
|
+
onCancelDismiss = _ref.onCancelDismiss,
|
|
9
|
+
onConfirmDismiss = _ref.onConfirmDismiss;
|
|
10
|
+
var intl = useIntl();
|
|
11
|
+
return /*#__PURE__*/React.createElement(ModalTransition, null, active && /*#__PURE__*/React.createElement(Modal, {
|
|
12
|
+
testId: "link-create-confirm-dismiss-dialog",
|
|
13
|
+
onClose: onCancelDismiss,
|
|
14
|
+
width: "small"
|
|
15
|
+
}, /*#__PURE__*/React.createElement(ModalHeader, null, /*#__PURE__*/React.createElement(ModalTitle, null, intl.formatMessage(messages.title))), /*#__PURE__*/React.createElement(ModalBody, null, intl.formatMessage(messages.description)), /*#__PURE__*/React.createElement(ModalFooter, null, /*#__PURE__*/React.createElement(Button, {
|
|
16
|
+
appearance: "subtle",
|
|
17
|
+
onClick: onCancelDismiss
|
|
18
|
+
}, intl.formatMessage(messages.cancelButtonLabel)), /*#__PURE__*/React.createElement(Button, {
|
|
19
|
+
appearance: "primary",
|
|
20
|
+
onClick: onConfirmDismiss
|
|
21
|
+
}, intl.formatMessage(messages.confirmButtonLabel)))));
|
|
22
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { defineMessages } from 'react-intl-next';
|
|
2
|
+
export default defineMessages({
|
|
3
|
+
title: {
|
|
4
|
+
id: 'linkCreate.confirm-dismiss-dialog.modal.title',
|
|
5
|
+
defaultMessage: 'Your changes won’t be saved',
|
|
6
|
+
description: 'Title for confirm-dismiss modal popup'
|
|
7
|
+
},
|
|
8
|
+
cancelButtonLabel: {
|
|
9
|
+
id: 'linkCreate.confirm-dismiss-dialog.modal.cancel-button-label',
|
|
10
|
+
defaultMessage: 'Go back',
|
|
11
|
+
description: 'Label for secondary button for confirm-dismiss modal popup'
|
|
12
|
+
},
|
|
13
|
+
confirmButtonLabel: {
|
|
14
|
+
id: 'linkCreate.confirm-dismiss-dialog.modal.confirm-button-label',
|
|
15
|
+
defaultMessage: 'Discard',
|
|
16
|
+
description: 'Label for primary button for confirm-dismiss modal popup'
|
|
17
|
+
},
|
|
18
|
+
description: {
|
|
19
|
+
id: 'linkCreate.confirm-dismiss-dialog.modal.description',
|
|
20
|
+
defaultMessage: 'We won’t be able to save your information if you move away from this page.',
|
|
21
|
+
description: 'Description for confirm-dismiss modal popup'
|
|
22
|
+
}
|
|
23
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import Modal, { ModalTransition } from '@atlaskit/modal-dialog';
|
|
3
|
+
import { useEditPostCreateModal } from '../../../controllers/edit-post-create-context';
|
|
4
|
+
export var EditModal = function EditModal(_ref) {
|
|
5
|
+
var onClose = _ref.onClose;
|
|
6
|
+
var _useEditPostCreateMod = useEditPostCreateModal(),
|
|
7
|
+
editViewPayload = _useEditPostCreateMod.editViewPayload;
|
|
8
|
+
return /*#__PURE__*/React.createElement(ModalTransition, null, !!editViewPayload && /*#__PURE__*/React.createElement(Modal, {
|
|
9
|
+
testId: "link-create-edit-modal",
|
|
10
|
+
onClose: onClose,
|
|
11
|
+
shouldScrollInViewport: true,
|
|
12
|
+
width: "calc(100vw - 120px)",
|
|
13
|
+
height: "calc(100vh - 120px)"
|
|
14
|
+
}));
|
|
15
|
+
};
|
|
@@ -1,16 +1,24 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
1
3
|
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
4
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
5
|
var _excluded = ["testId", "onCreate", "onFailure", "onCancel", "triggeredFrom"],
|
|
4
|
-
_excluded2 = ["active", "modalTitle", "onOpenComplete", "onCloseComplete"];
|
|
6
|
+
_excluded2 = ["active", "modalTitle", "onCancel", "onOpenComplete", "onCloseComplete"];
|
|
5
7
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
6
8
|
/** @jsx jsx */
|
|
7
|
-
import { Fragment, useCallback } from 'react';
|
|
9
|
+
import { Fragment, useCallback, useState } from 'react';
|
|
8
10
|
import { jsx } from '@emotion/react';
|
|
9
11
|
import { useIntl } from 'react-intl-next';
|
|
10
12
|
import Modal, { ModalBody, ModalHeader, ModalTitle, ModalTransition } from '@atlaskit/modal-dialog';
|
|
13
|
+
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
14
|
+
import { Box } from '@atlaskit/primitives';
|
|
11
15
|
import { CREATE_FORM_MAX_WIDTH_IN_PX } from '../../common/constants';
|
|
12
16
|
import { LinkCreateCallbackProvider } from '../../controllers/callback-context';
|
|
17
|
+
import { EditPostCreateModalProvider } from '../../controllers/edit-post-create-context';
|
|
13
18
|
import { useFormContext, withLinkCreateFormContext } from '../../controllers/form-context';
|
|
19
|
+
import { LinkCreatePluginsProvider } from '../../controllers/plugin-context';
|
|
20
|
+
import { ConfirmDismissDialog } from './confirm-dismiss-dialog';
|
|
21
|
+
import { EditModal } from './edit-modal';
|
|
14
22
|
import { ErrorBoundary } from './error-boundary';
|
|
15
23
|
import { messages } from './messages';
|
|
16
24
|
import TrackMount from './track-mount';
|
|
@@ -26,7 +34,7 @@ var LinkCreateContent = function LinkCreateContent(_ref) {
|
|
|
26
34
|
}
|
|
27
35
|
return jsx(Fragment, null, chosenOne.form);
|
|
28
36
|
};
|
|
29
|
-
var LinkCreate =
|
|
37
|
+
var LinkCreate = function LinkCreate(_ref2) {
|
|
30
38
|
var _ref2$testId = _ref2.testId,
|
|
31
39
|
testId = _ref2$testId === void 0 ? TEST_ID : _ref2$testId,
|
|
32
40
|
onCreate = _ref2.onCreate,
|
|
@@ -64,28 +72,68 @@ var LinkCreate = withLinkCreateFormContext(function (_ref2) {
|
|
|
64
72
|
setFormErrorMessage(error.message);
|
|
65
73
|
onFailure && onFailure(error);
|
|
66
74
|
}, [onFailure, setFormErrorMessage]);
|
|
67
|
-
return jsx(
|
|
68
|
-
|
|
75
|
+
return jsx(Box, {
|
|
76
|
+
testId: testId
|
|
69
77
|
}, jsx(ErrorBoundary, null, jsx(LinkCreateCallbackProvider, {
|
|
70
78
|
onCancel: onCancel,
|
|
71
79
|
onCreate: handleCreate,
|
|
72
80
|
onFailure: handleFailure
|
|
73
81
|
}, jsx(TrackMount, null), jsx(LinkCreateContent, restProps))));
|
|
74
|
-
}
|
|
82
|
+
};
|
|
75
83
|
var LinkCreateWithModal = function LinkCreateWithModal(_ref4) {
|
|
76
84
|
var active = _ref4.active,
|
|
77
85
|
modalTitle = _ref4.modalTitle,
|
|
86
|
+
onCancel = _ref4.onCancel,
|
|
78
87
|
onOpenComplete = _ref4.onOpenComplete,
|
|
79
88
|
onCloseComplete = _ref4.onCloseComplete,
|
|
80
89
|
createProps = _objectWithoutProperties(_ref4, _excluded2);
|
|
90
|
+
var _useState = useState(false),
|
|
91
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
92
|
+
dismissDialog = _useState2[0],
|
|
93
|
+
setDismissDialog = _useState2[1];
|
|
94
|
+
var _useFormContext2 = useFormContext(),
|
|
95
|
+
isFormDirty = _useFormContext2.isFormDirty;
|
|
81
96
|
var intl = useIntl();
|
|
82
|
-
|
|
97
|
+
var handleCancel = useCallback(function () {
|
|
98
|
+
if (getBooleanFF('platform.linking-platform.link-create.confirm-dismiss-dialog')) {
|
|
99
|
+
if (isFormDirty()) {
|
|
100
|
+
return setDismissDialog(true);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
onCancel && onCancel();
|
|
104
|
+
}, [onCancel, isFormDirty]);
|
|
105
|
+
var handleCancelDismiss = useCallback(function () {
|
|
106
|
+
setDismissDialog(false);
|
|
107
|
+
}, []);
|
|
108
|
+
var handleConfirmDismiss = useCallback(function () {
|
|
109
|
+
setDismissDialog(false);
|
|
110
|
+
onCancel && onCancel();
|
|
111
|
+
}, [onCancel]);
|
|
112
|
+
return jsx(Fragment, null, jsx(ModalTransition, null, !!active && jsx(Modal, {
|
|
83
113
|
testId: "link-create-modal",
|
|
84
|
-
onClose:
|
|
114
|
+
onClose: handleCancel,
|
|
85
115
|
shouldScrollInViewport: true,
|
|
86
116
|
onOpenComplete: onOpenComplete,
|
|
87
117
|
onCloseComplete: onCloseComplete,
|
|
88
118
|
width: "".concat(CREATE_FORM_MAX_WIDTH_IN_PX, "px")
|
|
89
|
-
}, jsx(ModalHeader, null, jsx(ModalTitle, null, modalTitle || intl.formatMessage(messages.heading))), jsx(ModalBody, null, jsx(LinkCreate, createProps
|
|
119
|
+
}, jsx(ModalHeader, null, jsx(ModalTitle, null, modalTitle || intl.formatMessage(messages.heading))), jsx(ModalBody, null, jsx(LinkCreate, _extends({}, createProps, {
|
|
120
|
+
onCancel: handleCancel
|
|
121
|
+
}))))), getBooleanFF('platform.linking-platform.link-create.enable-edit') && jsx(EditModal, {
|
|
122
|
+
onClose: handleCancel
|
|
123
|
+
}), getBooleanFF('platform.linking-platform.link-create.confirm-dismiss-dialog') && jsx(ConfirmDismissDialog, {
|
|
124
|
+
active: dismissDialog,
|
|
125
|
+
onCancelDismiss: handleCancelDismiss,
|
|
126
|
+
onConfirmDismiss: handleConfirmDismiss
|
|
127
|
+
}));
|
|
90
128
|
};
|
|
91
|
-
export default
|
|
129
|
+
export default withLinkCreateFormContext(function (props) {
|
|
130
|
+
if (getBooleanFF('platform.linking-platform.link-create.enable-edit')) {
|
|
131
|
+
return jsx(LinkCreatePluginsProvider, {
|
|
132
|
+
plugins: props.plugins,
|
|
133
|
+
entityKey: props.entityKey
|
|
134
|
+
}, jsx(EditPostCreateModalProvider, {
|
|
135
|
+
active: !!props.active
|
|
136
|
+
}, jsx(LinkCreateWithModal, props)));
|
|
137
|
+
}
|
|
138
|
+
return jsx(LinkCreateWithModal, props);
|
|
139
|
+
});
|
package/dist/esm/ui/main.js
CHANGED
|
@@ -16,7 +16,7 @@ var LinkCreateWithAnalyticsContext = withLinkCreateAnalyticsContext( /*#__PURE__
|
|
|
16
16
|
}));
|
|
17
17
|
export var PACKAGE_DATA = {
|
|
18
18
|
packageName: "@atlaskit/link-create" || '',
|
|
19
|
-
packageVersion: "1.
|
|
19
|
+
packageVersion: "1.5.0" || '',
|
|
20
20
|
componentName: COMPONENT_NAME,
|
|
21
21
|
source: COMPONENT_NAME
|
|
22
22
|
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { CreatePayload } from '../../common/types';
|
|
3
|
+
type EditPostCreateModalContextValue = {
|
|
4
|
+
editViewPayload?: CreatePayload | undefined;
|
|
5
|
+
setEditViewPayload: (payload?: CreatePayload) => void;
|
|
6
|
+
};
|
|
7
|
+
export declare const EditPostCreateModalProvider: ({ active, children, }: {
|
|
8
|
+
active: boolean;
|
|
9
|
+
children: React.ReactNode;
|
|
10
|
+
}) => JSX.Element;
|
|
11
|
+
export declare const useEditPostCreateModal: () => EditPostCreateModalContextValue;
|
|
12
|
+
export {};
|
|
@@ -4,6 +4,8 @@ interface FormContextType {
|
|
|
4
4
|
getValidators: () => ValidatorMap;
|
|
5
5
|
assignValidator: (name: string, validators: Validator[]) => void;
|
|
6
6
|
setFormErrorMessage: (errorMessage?: string) => void;
|
|
7
|
+
setFormDirty: (dirty?: boolean) => void;
|
|
8
|
+
isFormDirty: () => boolean;
|
|
7
9
|
formErrorMessage?: string;
|
|
8
10
|
/**
|
|
9
11
|
* Callback that updates link create to tell it that it should/should not open the current plugins
|
|
@@ -11,6 +13,7 @@ interface FormContextType {
|
|
|
11
13
|
* is not defined as a prop at the `LinkCreate` props level
|
|
12
14
|
*/
|
|
13
15
|
enableEditView?: ((editButtonClicked: boolean) => void) | undefined;
|
|
16
|
+
formDirty?: boolean;
|
|
14
17
|
}
|
|
15
18
|
export declare const FormContext: React.Context<FormContextType>;
|
|
16
19
|
declare const FormContextProvider: React.FC<{
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { LinkCreatePlugin } from '../../common/types';
|
|
3
|
+
type LinkCreatePluginsProviderProps = {
|
|
4
|
+
/**
|
|
5
|
+
* The list of plugins provided as a prop to Link Create component
|
|
6
|
+
*/
|
|
7
|
+
plugins: LinkCreatePlugin[];
|
|
8
|
+
/**
|
|
9
|
+
* The entity key as provided as prop to link create which controls the initially active plugin
|
|
10
|
+
*/
|
|
11
|
+
entityKey: string;
|
|
12
|
+
children: React.ReactNode;
|
|
13
|
+
};
|
|
14
|
+
export declare const LinkCreatePluginsProvider: ({ plugins, entityKey: propEntityKey, children, }: LinkCreatePluginsProviderProps) => JSX.Element;
|
|
15
|
+
export declare const useLinkCreatePlugins: () => {
|
|
16
|
+
activePlugin: LinkCreatePlugin | null;
|
|
17
|
+
};
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export type ConfirmDismissDialogProps = {
|
|
3
|
+
active: boolean;
|
|
4
|
+
onCancelDismiss?: () => void;
|
|
5
|
+
onConfirmDismiss?: () => void;
|
|
6
|
+
};
|
|
7
|
+
export declare const ConfirmDismissDialog: ({ active, onCancelDismiss, onConfirmDismiss, }: ConfirmDismissDialogProps) => JSX.Element;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
title: {
|
|
3
|
+
id: string;
|
|
4
|
+
defaultMessage: string;
|
|
5
|
+
description: string;
|
|
6
|
+
};
|
|
7
|
+
cancelButtonLabel: {
|
|
8
|
+
id: string;
|
|
9
|
+
defaultMessage: string;
|
|
10
|
+
description: string;
|
|
11
|
+
};
|
|
12
|
+
confirmButtonLabel: {
|
|
13
|
+
id: string;
|
|
14
|
+
defaultMessage: string;
|
|
15
|
+
description: string;
|
|
16
|
+
};
|
|
17
|
+
description: {
|
|
18
|
+
id: string;
|
|
19
|
+
defaultMessage: string;
|
|
20
|
+
description: string;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
export default _default;
|