Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 25c3bfb

Browse files
fetch lowcoder-comps meta when app loads + set version no. when fetching latest lowcoder-comps
1 parent 10a9948 commit 25c3bfb

File tree

9 files changed

+62
-18
lines changed

9 files changed

+62
-18
lines changed

‎client/packages/lowcoder/src/app.tsx‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ import { buildMaterialPreviewURL } from "./util/materialUtils";
5656
import GlobalInstances from 'components/GlobalInstances';
5757
// import posthog from 'posthog-js'
5858
import { fetchHomeData } from "./redux/reduxActions/applicationActions";
59+
import { getNpmPackageMeta } from "./comps/utils/remote";
60+
import { packageMetaReadyAction, setLowcoderCompsLoading } from "./redux/reduxActions/npmPluginActions";
5961

6062
const LazyUserAuthComp = React.lazy(() => import("pages/userAuth"));
6163
const LazyInviteLanding = React.lazy(() => import("pages/common/inviteLanding"));
@@ -90,6 +92,7 @@ type AppIndexProps = {
9092
fetchHomeDataFinished: boolean;
9193
fetchConfig: (orgId?: string) => void;
9294
fetchHomeData: (currentUserAnonymous?: boolean | undefined) => void;
95+
fetchLowcoderCompVersions: () => void;
9396
getCurrentUser: () => void;
9497
favicon: string;
9598
brandName: string;
@@ -112,6 +115,7 @@ class AppIndex extends React.Component<AppIndexProps, any> {
112115
this.props.fetchConfig(this.props.currentOrgId);
113116
if (!this.props.currentUserAnonymous) {
114117
this.props.fetchHomeData(this.props.currentUserAnonymous);
118+
this.props.fetchLowcoderCompVersions();
115119
}
116120
}
117121
}
@@ -418,10 +422,20 @@ const mapDispatchToProps = (dispatch: any) => ({
418422
dispatch(fetchUserAction());
419423
},
420424
fetchConfig: (orgId?: string) => dispatch(fetchConfigAction(orgId)),
421-
422425
fetchHomeData: (currentUserAnonymous: boolean | undefined) => {
423426
dispatch(fetchHomeData({}));
424-
}
427+
},
428+
fetchLowcoderCompVersions: async () => {
429+
try {
430+
dispatch(setLowcoderCompsLoading(true));
431+
const packageMeta = await getNpmPackageMeta('lowcoder-comps');
432+
if (packageMeta?.versions) {
433+
dispatch(packageMetaReadyAction('lowcoder-comps', packageMeta));
434+
}
435+
} catch (_) {
436+
dispatch(setLowcoderCompsLoading(false));
437+
}
438+
},
425439
});
426440

427441
const AppIndexWithProps = connect(mapStateToProps, mapDispatchToProps)(AppIndex);

‎client/packages/lowcoder/src/comps/comps/appSettingsComp.tsx‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { ApplicationCategoriesEnum } from "constants/applicationConstants";
2121
import { BoolControl } from "../controls/boolControl";
2222
import { getNpmPackageMeta } from "../utils/remote";
2323
import { getPromiseAfterDispatch } from "@lowcoder-ee/util/promiseUtils";
24+
import type { AppState } from "@lowcoder-ee/redux/reducers";
2425

2526
const TITLE = trans("appSetting.title");
2627
const USER_DEFINE = "__USER_DEFINE";
@@ -195,6 +196,7 @@ type ChildrenInstance = RecordConstructorToComp<typeof childrenMap> & {
195196
};
196197

197198
function AppSettingsModal(props: ChildrenInstance) {
199+
const lowcoderCompsMeta = useSelector((state: AppState) => state.npmPlugin.packageMeta['lowcoder-comps']);
198200
const [lowcoderCompVersions, setLowcoderCompVersions] = useState(['latest']);
199201
const {
200202
themeList,
@@ -209,7 +211,7 @@ function AppSettingsModal(props: ChildrenInstance) {
209211
preventAppStylesOverwriting,
210212
lowcoderCompVersion,
211213
} = props;
212-
214+
213215
const THEME_OPTIONS = themeList?.map((theme) => ({
214216
label: theme.name,
215217
value: theme.id + "",
@@ -230,14 +232,11 @@ function AppSettingsModal(props: ChildrenInstance) {
230232
}, [themeWithDefault]);
231233

232234
useEffect(() => {
233-
const fetchCompsPackageMeta = async () => {
234-
const packageMeta = await getNpmPackageMeta('lowcoder-comps');
235-
if (packageMeta?.versions) {
236-
setLowcoderCompVersions(Object.keys(packageMeta.versions).reverse())
237-
}
238-
}
239-
fetchCompsPackageMeta();
240-
}, [])
235+
setLowcoderCompVersions([
236+
'latest',
237+
...Object.keys(lowcoderCompsMeta.versions).reverse()
238+
])
239+
}, [lowcoderCompsMeta])
241240

242241

243242
const DropdownItem = (params: { value: string }) => {

‎client/packages/lowcoder/src/comps/comps/remoteComp/remoteComp.tsx‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import { withErrorBoundary } from "comps/generators/withErrorBoundary";
1414
import { EditorContext } from "@lowcoder-ee/comps/editorState";
1515
import { CompContext } from "@lowcoder-ee/comps/utils/compContext";
1616
import React from "react";
17+
import type { AppState } from "@lowcoder-ee/redux/reducers";
18+
import { useSelector } from "react-redux";
1719

1820
const ViewError = styled.div`
1921
display: flex;
@@ -60,11 +62,14 @@ const RemoteCompView = React.memo((props: React.PropsWithChildren<RemoteCompView
6062
const editorState = useContext(EditorContext);
6163
const compState = useContext(CompContext);
6264
const lowcoderCompPackageVersion = editorState?.getAppSettings().lowcoderCompVersion || 'latest';
65+
const latestLowcoderCompsVersion = useSelector((state: AppState) => state.npmPlugin.packageVersion['lowcoder-comps']);
6366

6467
let packageVersion = 'latest';
6568
// lowcoder-comps's package version
6669
if (isLowcoderComp) {
67-
packageVersion = lowcoderCompPackageVersion;
70+
packageVersion = lowcoderCompPackageVersion === 'latest' && Boolean(latestLowcoderCompsVersion)
71+
? latestLowcoderCompsVersion
72+
: lowcoderCompPackageVersion;
6873
}
6974
// component plugin's package version
7075
else if (compState.comp?.comp?.version) {

‎client/packages/lowcoder/src/constants/reduxActionConstants.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ export const ReduxActionTypes = {
185185
/* npm plugin */
186186
PACKAGE_META_READY: "PACKAGE_META_READY",
187187
SELECT_PACKAGE_VERSION: "SELECT_PACKAGE_VERSION",
188+
LOWCODER_COMPS_LOADING: "LOWCODER_COMPS_LOADING",
188189

189190
/* js library */
190191
FETCH_JS_LIB_METAS: "FETCH_JS_LIB_METAS",

‎client/packages/lowcoder/src/pages/ApplicationV2/HomeLayout.tsx‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,6 @@ export function HomeLayout(props: HomeLayoutProps) {
307307

308308
const { breadcrumb = [], elements = [], localMarketplaceApps = [], globalMarketplaceApps = [], mode } = props;
309309

310-
console.log("HomeLayout props: ", props);
311-
312310
const categoryOptions = [
313311
{ label: <FilterMenuItem>{trans("home.allCategories")}</FilterMenuItem>, value: 'All' },
314312
...Object.entries(ApplicationCategoriesEnum).map(([key, value]) => ({

‎client/packages/lowcoder/src/pages/ApplicationV2/index.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import {
3535
EnterpriseIcon,
3636
UserIcon,
3737
} from "lowcoder-design";
38-
import React, { useEffect, useState } from "react";
38+
import React, { useCallback,useEffect, useState } from "react";
3939
import { fetchAllApplications, fetchHomeData } from "redux/reduxActions/applicationActions";
4040
import { fetchSubscriptionsAction } from "redux/reduxActions/subscriptionActions";
4141
import { getHomeOrg, normalAppListSelector } from "redux/selectors/applicationSelector";

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import React from "react";
3535
import dayjs from "dayjs";
3636
import { currentApplication } from "@lowcoder-ee/redux/selectors/applicationSelector";
3737
import { notificationInstance } from "components/GlobalInstances";
38+
import { AppState } from "@lowcoder-ee/redux/reducers";
3839

3940
const AppSnapshot = lazy(() => {
4041
return import("pages/editor/appSnapshot")
@@ -55,6 +56,7 @@ const AppEditor = React.memo(() => {
5556
const fetchOrgGroupsFinished = useSelector(getFetchOrgGroupsFinished);
5657
const isCommonSettingsFetching = useSelector(getIsCommonSettingFetching);
5758
const application = useSelector(currentApplication);
59+
const isLowcoderCompLoading = useSelector((state: AppState) => state.npmPlugin.loading.lowcoderComps);
5860

5961
const isUserViewMode = useMemo(
6062
() => params.viewMode ? isUserViewModeCheck : true,
@@ -184,8 +186,10 @@ const AppEditor = React.memo(() => {
184186
}, [viewMode, applicationId, dispatch, fetchJSDataSourceByApp]);
185187

186188
useEffect(() => {
187-
fetchApplication();
188-
}, [fetchApplication]);
189+
if(!isLowcoderCompLoading) {
190+
fetchApplication();
191+
}
192+
}, [isLowcoderCompLoading, fetchApplication]);
189193

190194
const fallbackUI = useMemo(() => (
191195
<Flex align="center" justify="center" vertical style={{

‎client/packages/lowcoder/src/redux/reducers/npmPluginReducers/index.ts‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,17 @@ import { NpmPackageMeta } from "types/remoteComp";
55
export interface NPMPluginState {
66
packageMeta: Record<string, NpmPackageMeta>;
77
packageVersion: Record<string, string>;
8+
loading: {
9+
lowcoderComps: boolean,
10+
},
811
}
912

1013
const initialState: NPMPluginState = {
1114
packageMeta: {},
1215
packageVersion: {},
16+
loading: {
17+
lowcoderComps: false,
18+
}
1319
};
1420

1521
const npmPluginReducer = createReducer(initialState, {
@@ -45,7 +51,6 @@ const npmPluginReducer = createReducer(initialState, {
4551
}
4652
selectVersions[i] = defaultVersion;
4753
});
48-
4954
return {
5055
...state,
5156
packageMeta: {
@@ -58,6 +63,17 @@ const npmPluginReducer = createReducer(initialState, {
5863
},
5964
};
6065
},
66+
[ReduxActionTypes.LOWCODER_COMPS_LOADING]: (
67+
state: NPMPluginState,
68+
action: ReduxAction<{loading: boolean}>
69+
): NPMPluginState => {
70+
return {
71+
...state,
72+
loading: {
73+
lowcoderComps: action.payload.loading,
74+
},
75+
};
76+
},
6177
});
6278

6379
export default npmPluginReducer;

‎client/packages/lowcoder/src/redux/reduxActions/npmPluginActions.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,10 @@ export const selectNpmPluginVersionAction = (packageName: string, version: strin
1414
[packageName]: version,
1515
},
1616
});
17+
18+
export const setLowcoderCompsLoading = (loading: boolean) => ({
19+
type: ReduxActionTypes.LOWCODER_COMPS_LOADING,
20+
payload: {
21+
loading,
22+
},
23+
});

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /