@redocly/theme 0.9.11 → 0.9.12
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.
|
@@ -31,11 +31,13 @@ const React = __importStar(require("react"));
|
|
|
31
31
|
const styled_components_1 = __importDefault(require("styled-components"));
|
|
32
32
|
const Button_1 = require("../Button/Button");
|
|
33
33
|
const usePageData_1 = require("../mocks/hooks/usePageData");
|
|
34
|
+
const usePreloadHistory_1 = require("../mocks/usePreloadHistory");
|
|
34
35
|
const Dropdown_1 = require("./Dropdown");
|
|
35
36
|
function DevOnboardingTryItSecurity(props) {
|
|
36
37
|
const apiId = props.apiId;
|
|
37
38
|
// @ts-ignore
|
|
38
39
|
const { userData } = (0, usePageData_1.usePageData)('userData') || {};
|
|
40
|
+
const history = (0, usePreloadHistory_1.usePreloadHistory)();
|
|
39
41
|
// TODO: handle error
|
|
40
42
|
const [_error, setError] = React.useState();
|
|
41
43
|
const [apps, setApps] = React.useState();
|
|
@@ -45,6 +47,7 @@ function DevOnboardingTryItSecurity(props) {
|
|
|
45
47
|
const [selectedAppSecret, setSelectedAppSecret] = React.useState();
|
|
46
48
|
const [acceptValueUpdate, setAcceptValueUpdate] = React.useState(true);
|
|
47
49
|
const initialRender = React.useRef(true);
|
|
50
|
+
const hasApiAccess = !loading && !!(apps === null || apps === void 0 ? void 0 : apps.length);
|
|
48
51
|
React.useEffect(() => {
|
|
49
52
|
if (!props.value && initialRender.current)
|
|
50
53
|
return;
|
|
@@ -110,7 +113,11 @@ function DevOnboardingTryItSecurity(props) {
|
|
|
110
113
|
.finally(() => setAppLoading(false));
|
|
111
114
|
});
|
|
112
115
|
};
|
|
113
|
-
const placeholder = loading
|
|
116
|
+
const placeholder = loading
|
|
117
|
+
? 'Loading your apps...'
|
|
118
|
+
: hasApiAccess
|
|
119
|
+
? undefined
|
|
120
|
+
: 'You do not have access to this API';
|
|
114
121
|
return (React.createElement(React.Fragment, null,
|
|
115
122
|
React.createElement(FormLabel, { htmlFor: "server" }, "Select app: "),
|
|
116
123
|
React.createElement(FormControl, null,
|
|
@@ -118,7 +125,14 @@ function DevOnboardingTryItSecurity(props) {
|
|
|
118
125
|
setAppId(value);
|
|
119
126
|
loadAppCredentials(value);
|
|
120
127
|
} }),
|
|
121
|
-
React.createElement(UseKeyButton, { disabled: !selectedAppSecret || appLoading, color: "secondary", onClick: () =>
|
|
128
|
+
React.createElement(UseKeyButton, { disabled: (!selectedAppSecret && hasApiAccess) || appLoading, color: "secondary", onClick: () => {
|
|
129
|
+
if (selectedAppSecret) {
|
|
130
|
+
props.onChange(selectedAppSecret);
|
|
131
|
+
}
|
|
132
|
+
else if (!hasApiAccess) {
|
|
133
|
+
history.push('/apps/?createApp&apiId=' + apiId);
|
|
134
|
+
}
|
|
135
|
+
} }, appLoading ? 'Loading...' : hasApiAccess ? 'Use key' : 'Request access'))));
|
|
122
136
|
}
|
|
123
137
|
exports.DevOnboardingTryItSecurity = DevOnboardingTryItSecurity;
|
|
124
138
|
const TryItDropdown = (0, styled_components_1.default)(Dropdown_1.Dropdown) `
|
|
@@ -156,7 +170,7 @@ const FormLabel = styled_components_1.default.label `
|
|
|
156
170
|
`}
|
|
157
171
|
`;
|
|
158
172
|
const UseKeyButton = (0, styled_components_1.default)(Button_1.Button) `
|
|
159
|
-
width: 100px;
|
|
173
|
+
min-width: 100px;
|
|
160
174
|
align-self: flex-end;
|
|
161
175
|
margin-top: 10px;
|
|
162
176
|
margin-right: 0;
|
package/package.json
CHANGED
|
@@ -5,6 +5,7 @@ import type { TryItSecurityAppsProps } from './TryItSecurityApps';
|
|
|
5
5
|
|
|
6
6
|
import { Button } from '@theme/Button/Button';
|
|
7
7
|
import { usePageData } from '@portal/hooks/usePageData';
|
|
8
|
+
import { usePreloadHistory } from '@portal/usePreloadHistory';
|
|
8
9
|
|
|
9
10
|
import { Dropdown } from './Dropdown';
|
|
10
11
|
|
|
@@ -13,6 +14,7 @@ export function DevOnboardingTryItSecurity(props: TryItSecurityAppsProps) {
|
|
|
13
14
|
|
|
14
15
|
// @ts-ignore
|
|
15
16
|
const { userData } = usePageData('userData') || {};
|
|
17
|
+
const history = usePreloadHistory();
|
|
16
18
|
|
|
17
19
|
// TODO: handle error
|
|
18
20
|
const [_error, setError] = React.useState<string | undefined>();
|
|
@@ -26,6 +28,8 @@ export function DevOnboardingTryItSecurity(props: TryItSecurityAppsProps) {
|
|
|
26
28
|
const [acceptValueUpdate, setAcceptValueUpdate] = React.useState(true);
|
|
27
29
|
const initialRender = React.useRef(true);
|
|
28
30
|
|
|
31
|
+
const hasApiAccess = !loading && !!apps?.length;
|
|
32
|
+
|
|
29
33
|
React.useEffect(() => {
|
|
30
34
|
if (!props.value && initialRender.current) return;
|
|
31
35
|
if (acceptValueUpdate) {
|
|
@@ -92,7 +96,11 @@ export function DevOnboardingTryItSecurity(props: TryItSecurityAppsProps) {
|
|
|
92
96
|
});
|
|
93
97
|
};
|
|
94
98
|
|
|
95
|
-
const placeholder = loading
|
|
99
|
+
const placeholder = loading
|
|
100
|
+
? 'Loading your apps...'
|
|
101
|
+
: hasApiAccess
|
|
102
|
+
? undefined
|
|
103
|
+
: 'You do not have access to this API';
|
|
96
104
|
|
|
97
105
|
return (
|
|
98
106
|
<>
|
|
@@ -109,11 +117,17 @@ export function DevOnboardingTryItSecurity(props: TryItSecurityAppsProps) {
|
|
|
109
117
|
}}
|
|
110
118
|
/>
|
|
111
119
|
<UseKeyButton
|
|
112
|
-
disabled={!selectedAppSecret || appLoading}
|
|
120
|
+
disabled={(!selectedAppSecret && hasApiAccess) || appLoading}
|
|
113
121
|
color="secondary"
|
|
114
|
-
onClick={() =>
|
|
122
|
+
onClick={() => {
|
|
123
|
+
if (selectedAppSecret) {
|
|
124
|
+
props.onChange(selectedAppSecret);
|
|
125
|
+
} else if (!hasApiAccess) {
|
|
126
|
+
history.push('/apps/?createApp&apiId=' + apiId);
|
|
127
|
+
}
|
|
128
|
+
}}
|
|
115
129
|
>
|
|
116
|
-
{appLoading ? 'Loading...' : 'Use key'}
|
|
130
|
+
{appLoading ? 'Loading...' : hasApiAccess ? 'Use key' : 'Request access'}
|
|
117
131
|
</UseKeyButton>
|
|
118
132
|
</FormControl>
|
|
119
133
|
</>
|
|
@@ -159,7 +173,7 @@ const FormLabel = styled.label<{ required?: boolean }>`
|
|
|
159
173
|
`;
|
|
160
174
|
|
|
161
175
|
const UseKeyButton = styled(Button)`
|
|
162
|
-
width: 100px;
|
|
176
|
+
min-width: 100px;
|
|
163
177
|
align-self: flex-end;
|
|
164
178
|
margin-top: 10px;
|
|
165
179
|
margin-right: 0;
|