Skip to content

Commit 9e14af4

Browse files
fix infinite loop issue on accessing app view page without permission
1 parent 3bc6cd4 commit 9e14af4

File tree

3 files changed

+34
-8
lines changed

3 files changed

+34
-8
lines changed

client/packages/lowcoder/src/pages/editor/AppEditor.tsx

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { AppPathParams, AppTypeEnum } from "constants/applicationConstants";
2-
import { Suspense, lazy, useEffect, useRef, useState } from "react";
2+
import { Suspense, lazy, useCallback, useEffect, useMemo, useRef, useState } from "react";
33
import { useDispatch, useSelector } from "react-redux";
44
import { useParams } from "react-router";
55
import { AppSummaryInfo, fetchApplicationInfo } from "redux/reduxActions/applicationActions";
@@ -30,6 +30,7 @@ import EditorSkeletonView from "./editorSkeletonView";
3030
import {ErrorBoundary, FallbackProps} from 'react-error-boundary';
3131
import { ALL_APPLICATIONS_URL } from "@lowcoder-ee/constants/routesURL";
3232
import history from "util/history";
33+
import Flex from "antd/es/flex";
3334

3435
const AppSnapshot = lazy(() => {
3536
return import("pages/editor/appSnapshot")
@@ -56,6 +57,7 @@ export default function AppEditor() {
5657
const orgId = currentUser.currentOrgId;
5758
const firstRendered = useRef(false);
5859
const [isDataSourcePluginRegistered, setIsDataSourcePluginRegistered] = useState(false);
60+
const [appError, setAppError] = useState('');
5961

6062
setGlobalSettings({ applicationId, isViewMode: paramViewMode === "view" });
6163

@@ -132,15 +134,37 @@ export default function AppEditor() {
132134
setAppInfo(info);
133135
fetchJSDataSourceByApp();
134136
},
137+
onError: (errorMessage) => {
138+
setAppError(errorMessage);
139+
}
135140
})
136141
);
137142
}, [viewMode, applicationId, dispatch]);
138-
const fallbackUI = (
139-
<div style={{display:'flex', height:'100%', width:'100%', alignItems:'center',justifyContent:'center', gap:'8px',marginTop:'10px'}}>
140-
<p style={{margin:0}}>Something went wrong while displaying this webpage</p>
141-
<button onClick={() => history.push(ALL_APPLICATIONS_URL)} style={{background: '#4965f2',border: '1px solid #4965f2', color: '#ffffff',borderRadius:'6px'}}>Go to Apps</button>
142-
</div>
143-
);
143+
144+
const fallbackUI = useMemo(() => (
145+
<Flex align="center" justify="center" vertical style={{
146+
height: '300px',
147+
width: '400px',
148+
margin: '0 auto',
149+
}}>
150+
<h4 style={{margin: 0}}>Something went wrong while displaying this webpage</h4>
151+
<button onClick={() => history.push(ALL_APPLICATIONS_URL)} style={{background: '#4965f2',border: '1px solid #4965f2', color: '#ffffff',borderRadius:'6px'}}>Go to Apps</button>
152+
</Flex>
153+
), []);
154+
155+
if (Boolean(appError)) {
156+
return (
157+
<Flex align="center" justify="center" vertical style={{
158+
height: '300px',
159+
width: '400px',
160+
margin: '0 auto',
161+
}}>
162+
<h4>{appError}</h4>
163+
<button onClick={() => history.push(ALL_APPLICATIONS_URL)} style={{background: '#4965f2',border: '1px solid #4965f2', color: '#ffffff',borderRadius:'6px'}}>Back to Home</button>
164+
</Flex>
165+
)
166+
}
167+
144168
return (
145169
<ErrorBoundary fallback={fallbackUI}>
146170
{showAppSnapshot ? (

client/packages/lowcoder/src/redux/reduxActions/applicationActions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ export type FetchAppInfoPayload = {
132132
applicationId: string;
133133
type: ApplicationDSLType;
134134
onSuccess?: (info: AppSummaryInfo) => void;
135+
onError?: (error: string) => void;
135136
};
136137
export const fetchApplicationInfo = (payload: FetchAppInfoPayload) => ({
137138
type: ReduxActionTypes.FETCH_APPLICATION_DETAIL,

client/packages/lowcoder/src/redux/sagas/applicationSagas.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,8 @@ export function* fetchApplicationDetailSaga(action: ReduxAction<FetchAppInfoPayl
242242
return;
243243
} else if (!isValidResponse) {
244244
if (response.data.code === SERVER_ERROR_CODES.NO_PERMISSION_TO_REQUEST_APP) {
245-
history.push(BASE_URL);
245+
// history.push(BASE_URL);
246+
action.payload.onError?.(response.data.message);
246247
}
247248
throw Error(response.data.message);
248249
}

0 commit comments

Comments
 (0)