@amp-labs/react 1.5.1 → 1.5.2
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/build/src/components/Configure/content/fields/OptionalFields/OptionalFields.js +21 -9
- package/build/src/components/Configure/content/fields/RequiredFields.js +1 -1
- package/build/src/components/Oauth/WorkspaceEntry/WorkspaceOauthFlow.js +2 -5
- package/build/src/components/Oauth/fetchOAuthPopupURL.js +1 -1
- package/build/src/services/version.d.ts +1 -1
- package/build/src/services/version.js +1 -1
- package/package.json +1 -1
- package/build/src/components/Oauth/OAuthPopup.d.ts +0 -20
- package/build/src/components/Oauth/OAuthPopup.js +0 -85
|
@@ -8,7 +8,7 @@ const useSelectedConfigureState_1 = require("../../useSelectedConfigureState");
|
|
|
8
8
|
const FieldHeader_1 = require("../FieldHeader");
|
|
9
9
|
const setOptionalField_1 = require("./setOptionalField");
|
|
10
10
|
function OptionalFields() {
|
|
11
|
-
var _a, _b
|
|
11
|
+
var _a, _b;
|
|
12
12
|
const { appName, configureState, setConfigureState, selectedObjectName, } = (0, useSelectedConfigureState_1.useSelectedConfigureState)();
|
|
13
13
|
const selectedOptionalFields = (_a = configureState === null || configureState === void 0 ? void 0 : configureState.read) === null || _a === void 0 ? void 0 : _a.selectedOptionalFields;
|
|
14
14
|
const onCheckboxChange = (e) => {
|
|
@@ -17,13 +17,25 @@ function OptionalFields() {
|
|
|
17
17
|
(0, setOptionalField_1.setOptionalField)(selectedObjectName, setConfigureState, name, checked);
|
|
18
18
|
}
|
|
19
19
|
};
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
20
|
+
const readOptionalFields = (_b = configureState === null || configureState === void 0 ? void 0 : configureState.read) === null || _b === void 0 ? void 0 : _b.optionalFields;
|
|
21
|
+
const onSelectAllCheckboxChange = (e) => {
|
|
22
|
+
const { checked } = e.target;
|
|
23
|
+
if (selectedObjectName && readOptionalFields) {
|
|
24
|
+
readOptionalFields.forEach((field) => {
|
|
25
|
+
if (!(0, utils_1.isIntegrationFieldMapping)(field)) {
|
|
26
|
+
(0, setOptionalField_1.setOptionalField)(selectedObjectName, setConfigureState, field.fieldName, checked);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
const shouldRender = !!(readOptionalFields && readOptionalFields.length > 0);
|
|
32
|
+
const isAllChecked = Object.keys(selectedOptionalFields || {}).length === (readOptionalFields === null || readOptionalFields === void 0 ? void 0 : readOptionalFields.length);
|
|
33
|
+
const isIndeterminate = !isAllChecked && Object.keys(selectedOptionalFields || {}).length > 0;
|
|
34
|
+
return (shouldRender && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(FieldHeader_1.FieldHeader, { string: `${appName} reads the following optional fields` }), (0, jsx_runtime_1.jsxs)(react_1.Stack, { marginBottom: 10, maxHeight: 300, overflowY: "scroll", border: "2px solid #EFEFEF", borderRadius: 8, gap: 0, children: [((readOptionalFields === null || readOptionalFields === void 0 ? void 0 : readOptionalFields.length) || 0) >= 2 && ((0, jsx_runtime_1.jsx)(react_1.Box, { backgroundColor: "gray.50", paddingX: 4, paddingY: 2, children: (0, jsx_runtime_1.jsx)(react_1.Checkbox, { name: "selectAll", id: "selectAll", onChange: onSelectAllCheckboxChange, isIndeterminate: isIndeterminate, isChecked: isAllChecked, children: "Select all" }) })), readOptionalFields.map((field) => {
|
|
35
|
+
if (!(0, utils_1.isIntegrationFieldMapping)(field)) {
|
|
36
|
+
return ((0, jsx_runtime_1.jsx)(react_1.Box, { paddingX: 4, paddingY: 2, borderBottom: "1px", borderColor: "gray.100", children: (0, jsx_runtime_1.jsx)(react_1.Checkbox, { name: field.fieldName, id: field.fieldName, isChecked: !!(selectedOptionalFields === null || selectedOptionalFields === void 0 ? void 0 : selectedOptionalFields[field === null || field === void 0 ? void 0 : field.fieldName]), onChange: onCheckboxChange, children: field.displayName }) }, field.fieldName));
|
|
37
|
+
}
|
|
38
|
+
return null; // fallback for customed mapped fields
|
|
39
|
+
})] })] })));
|
|
28
40
|
}
|
|
29
41
|
exports.OptionalFields = OptionalFields;
|
|
@@ -11,7 +11,7 @@ function RequiredFields() {
|
|
|
11
11
|
var _a, _b, _c;
|
|
12
12
|
const { configureState, selectedObjectName } = (0, useSelectedConfigureState_1.useSelectedConfigureState)();
|
|
13
13
|
const { appName } = (0, ProjectContextProvider_1.useProject)();
|
|
14
|
-
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(FieldHeader_1.FieldHeader, { string: `${appName} reads the following ${selectedObjectName} fields` }), (0, jsx_runtime_1.jsx)(react_1.Box, { marginBottom: "20px", children: ((_b = (_a = configureState === null || configureState === void 0 ? void 0 : configureState.read) === null || _a === void 0 ? void 0 : _a.requiredFields) === null || _b === void 0 ? void 0 : _b.length)
|
|
14
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(FieldHeader_1.FieldHeader, { string: `${appName} reads the following ${selectedObjectName} fields` }), (0, jsx_runtime_1.jsx)(react_1.Box, { marginBottom: "20px", display: "flex", gap: 1, children: ((_b = (_a = configureState === null || configureState === void 0 ? void 0 : configureState.read) === null || _a === void 0 ? void 0 : _a.requiredFields) === null || _b === void 0 ? void 0 : _b.length)
|
|
15
15
|
? ((_c = configureState.read) === null || _c === void 0 ? void 0 : _c.requiredFields.map((field) => {
|
|
16
16
|
if (!(0, utils_1.isIntegrationFieldMapping)(field)) {
|
|
17
17
|
return (0, jsx_runtime_1.jsx)(react_1.Tag, { children: field.displayName }, field.fieldName);
|
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.WorkspaceOauthFlow = void 0;
|
|
7
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
@@ -10,7 +7,7 @@ const ApiKeyContextProvider_1 = require("../../../context/ApiKeyContextProvider"
|
|
|
10
7
|
const ProjectContextProvider_1 = require("../../../context/ProjectContextProvider");
|
|
11
8
|
const utils_1 = require("../../../utils");
|
|
12
9
|
const fetchOAuthPopupURL_1 = require("../fetchOAuthPopupURL");
|
|
13
|
-
const
|
|
10
|
+
const OAuthWindow_1 = require("../OAuthWindow/OAuthWindow");
|
|
14
11
|
const SalesforceSubdomainEntry_1 = require("../Salesforce/SalesforceSubdomainEntry");
|
|
15
12
|
const WorkspaceEntry_1 = require("./WorkspaceEntry");
|
|
16
13
|
const PROVIDER_SALESFORCE = 'salesforce';
|
|
@@ -51,6 +48,6 @@ function WorkspaceOauthFlow({ provider, consumerRef, consumerName, groupRef, gro
|
|
|
51
48
|
? ((0, jsx_runtime_1.jsx)(SalesforceSubdomainEntry_1.SalesforceSubdomainEntry, { handleSubmit: handleSubmit, setWorkspace: setWorkspace, error: error, isButtonDisabled: workspace.length === 0 })) : (
|
|
52
49
|
// general workspace entry component
|
|
53
50
|
(0, jsx_runtime_1.jsx)(WorkspaceEntry_1.WorkspaceEntry, { provider: provider, handleSubmit: handleSubmit, setWorkspace: setWorkspace, error: error, isButtonDisabled: workspace.length === 0 }));
|
|
54
|
-
return ((0, jsx_runtime_1.jsx)(
|
|
51
|
+
return ((0, jsx_runtime_1.jsx)(OAuthWindow_1.OAuthWindow, { windowTitle: `Connect to ${(0, utils_1.capitalize)(provider)}`, oauthUrl: oAuthCallbackURL, onClose: onClose, children: workspaceEntryComponent }));
|
|
55
52
|
}
|
|
56
53
|
exports.WorkspaceOauthFlow = WorkspaceOauthFlow;
|
|
@@ -9,7 +9,7 @@ const fetchOAuthPopupURL = async (projectId, consumerRef, groupRef, apiKey, prov
|
|
|
9
9
|
});
|
|
10
10
|
const app = providerApps.find((a) => a.provider === provider);
|
|
11
11
|
if (!app) {
|
|
12
|
-
throw new Error(`You must first set up a ${(0, utils_1.capitalize)(provider)}
|
|
12
|
+
throw new Error(`You must first set up a ${(0, utils_1.capitalize)(provider)} Provider App using the Ampersand Console.`);
|
|
13
13
|
}
|
|
14
14
|
const request = {
|
|
15
15
|
connectOAuthParams: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const LIB_VERSION = "1.5.
|
|
1
|
+
export declare const LIB_VERSION = "1.5.2";
|
package/package.json
CHANGED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* OAuthPopup.tsx
|
|
3
|
-
* @deprecated - this page will be deleted in the future
|
|
4
|
-
* Takes a URL and creates a popup showing that page.
|
|
5
|
-
*/
|
|
6
|
-
import React from 'react';
|
|
7
|
-
type PopupProps = {
|
|
8
|
-
url: string | null;
|
|
9
|
-
title: string;
|
|
10
|
-
onClose: (err: string | null) => void;
|
|
11
|
-
children: React.ReactNode;
|
|
12
|
-
};
|
|
13
|
-
/**
|
|
14
|
-
* v1 popup to manage oauth flow
|
|
15
|
-
* @deprecated
|
|
16
|
-
* @param param0
|
|
17
|
-
* @returns
|
|
18
|
-
*/
|
|
19
|
-
declare function OAuthPopup({ title, url, children, onClose, }: PopupProps): import("react/jsx-runtime").JSX.Element;
|
|
20
|
-
export default OAuthPopup;
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
4
|
-
/**
|
|
5
|
-
* OAuthPopup.tsx
|
|
6
|
-
* @deprecated - this page will be deleted in the future
|
|
7
|
-
* Takes a URL and creates a popup showing that page.
|
|
8
|
-
*/
|
|
9
|
-
const react_1 = require("react");
|
|
10
|
-
const ApiKeyContextProvider_1 = require("../../context/ApiKeyContextProvider");
|
|
11
|
-
const ConnectionsContextProvider_1 = require("../../context/ConnectionsContextProvider");
|
|
12
|
-
const ProjectContextProvider_1 = require("../../context/ProjectContextProvider");
|
|
13
|
-
const api_1 = require("../../services/api");
|
|
14
|
-
const DEFAULT_WIDTH = 600; // px
|
|
15
|
-
const DEFAULT_HEIGHT = 600; // px
|
|
16
|
-
const DEFAULT_INTERVAL = 500; // ms
|
|
17
|
-
const SUCCESS_EVENT = 'AUTHORIZATION_SUCCEEDED';
|
|
18
|
-
const FAILURE_EVENT = 'AUTHORIZATION_FAILED';
|
|
19
|
-
const createPopup = ({ url, title, }) => {
|
|
20
|
-
const left = window.screenX + (window.outerWidth - DEFAULT_WIDTH) / 2;
|
|
21
|
-
const top = window.screenY + (window.outerHeight - DEFAULT_HEIGHT) / 2.5; // a lil shorter
|
|
22
|
-
const popup = window.open(url, title, `width=${DEFAULT_WIDTH},height=${DEFAULT_HEIGHT},left=${left},top=${top}`);
|
|
23
|
-
return popup;
|
|
24
|
-
};
|
|
25
|
-
/**
|
|
26
|
-
* v1 popup to manage oauth flow
|
|
27
|
-
* @deprecated
|
|
28
|
-
* @param param0
|
|
29
|
-
* @returns
|
|
30
|
-
*/
|
|
31
|
-
function OAuthPopup({ title = '', url, children, onClose, }) {
|
|
32
|
-
const { projectId } = (0, ProjectContextProvider_1.useProject)();
|
|
33
|
-
const apiKey = (0, ApiKeyContextProvider_1.useApiKey)();
|
|
34
|
-
const [externalWindow, setExternalWindow] = (0, react_1.useState)();
|
|
35
|
-
const intervalRef = (0, react_1.useRef)();
|
|
36
|
-
const clearTimer = () => window.clearInterval(intervalRef.current);
|
|
37
|
-
const { setSelectedConnection } = (0, ConnectionsContextProvider_1.useConnections)();
|
|
38
|
-
(0, react_1.useEffect)(() => {
|
|
39
|
-
if (url)
|
|
40
|
-
setExternalWindow(createPopup({ url, title }));
|
|
41
|
-
}, [url, title]);
|
|
42
|
-
const refreshConnections = (0, react_1.useCallback)(async (connectionId) => {
|
|
43
|
-
const connection = await (0, api_1.api)().connectionApi.getConnection({ projectId, connectionId }, {
|
|
44
|
-
headers: { 'X-Api-Key': apiKey !== null && apiKey !== void 0 ? apiKey : '' },
|
|
45
|
-
});
|
|
46
|
-
setSelectedConnection(connection);
|
|
47
|
-
}, [projectId, apiKey, setSelectedConnection]);
|
|
48
|
-
(0, react_1.useEffect)(() => {
|
|
49
|
-
window.addEventListener('message', (event) => {
|
|
50
|
-
var _a, _b, _c, _d, _e;
|
|
51
|
-
if (event.origin === api_1.AMP_SERVER) {
|
|
52
|
-
// this event come from our own server
|
|
53
|
-
if (((_a = event.data) === null || _a === void 0 ? void 0 : _a.eventType) === SUCCESS_EVENT) {
|
|
54
|
-
clearTimer();
|
|
55
|
-
const connectionId = (_b = event.data.data) === null || _b === void 0 ? void 0 : _b.connection;
|
|
56
|
-
if (!connectionId) {
|
|
57
|
-
console.error('Ampersand server returned a successful authorization event, but did not return a connection ID.');
|
|
58
|
-
onClose('There is an unexpected server issue.');
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
refreshConnections(connectionId);
|
|
62
|
-
onClose(null);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
else if (((_c = event.data) === null || _c === void 0 ? void 0 : _c.eventType) === FAILURE_EVENT) {
|
|
66
|
-
clearTimer();
|
|
67
|
-
onClose((_e = (_d = event.data.data) === null || _d === void 0 ? void 0 : _d.message) !== null && _e !== void 0 ? _e : 'There was an error logging you in. Please try again.');
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
}, [externalWindow, onClose, refreshConnections]);
|
|
72
|
-
(0, react_1.useEffect)(() => {
|
|
73
|
-
if (externalWindow && !intervalRef.current) {
|
|
74
|
-
intervalRef.current = window.setInterval(() => {
|
|
75
|
-
// Check if window was closed prematurely.
|
|
76
|
-
if (!externalWindow || externalWindow.closed) {
|
|
77
|
-
clearTimer();
|
|
78
|
-
onClose('The popup was closed too quickly. Please try again.');
|
|
79
|
-
}
|
|
80
|
-
}, DEFAULT_INTERVAL);
|
|
81
|
-
}
|
|
82
|
-
}, [externalWindow, onClose]);
|
|
83
|
-
return ((0, jsx_runtime_1.jsx)("div", { children: children }));
|
|
84
|
-
}
|
|
85
|
-
exports.default = OAuthPopup;
|