Skip to content

Commit 8f2129c

Browse files
authored
Merge pull request #706 from raheeliftikhar5/lowcoder-marketplace
separate marketplace apps in self hosting env
2 parents e8d875c + a087797 commit 8f2129c

File tree

8 files changed

+114
-20
lines changed

8 files changed

+114
-20
lines changed
Lines changed: 12 additions & 0 deletions
Loading
Lines changed: 16 additions & 0 deletions
Loading

client/packages/lowcoder-design/src/icons/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,14 @@ export { ReactComponent as HomeQueryLibraryIcon } from "./icon-application-query
177177
export { ReactComponent as HomeDataSourceIcon } from "./icon-application-datasource.svg";
178178
export { ReactComponent as RecyclerIcon } from "./icon-application-recycler.svg";
179179
export { ReactComponent as MarketplaceIcon } from "./icon-application-marketplace.svg";
180+
export { ReactComponent as LowcoderMarketplaceIcon } from "./icon-lowcoder-marketplace.svg";
180181
export { ReactComponent as HomeActiveIcon } from "./icon-application-home-active.svg";
181182
export { ReactComponent as HomeModuleActiveIcon } from "./icon-application-module-active.svg";
182183
export { ReactComponent as HomeQueryLibraryActiveIcon } from "./icon-application-query-library-active.svg";
183184
export { ReactComponent as HomeDataSourceActiveIcon } from "./icon-application-datasource-active.svg";
184185
export { ReactComponent as RecyclerActiveIcon } from "./icon-application-recycler-active.svg";
185186
export { ReactComponent as MarketplaceActiveIcon } from "./icon-application-marketplace-active.svg";
187+
export { ReactComponent as LowcoderMarketplaceActiveIcon } from "./icon-lowcoder-marketplace-active.svg";
186188
export { ReactComponent as FavoritesIcon } from "./icon-application-favorites.svg";
187189
export { ReactComponent as HomeSettingIcon } from "./icon-application-setting.svg";
188190
export { ReactComponent as FolderIcon } from "./icon-application-folder.svg";

client/packages/lowcoder/src/app.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
IMPORT_APP_FROM_TEMPLATE_URL,
1515
INVITE_LANDING_URL,
1616
isAuthUnRequired,
17+
MARKETPLACE_TYPE_URL,
1718
MARKETPLACE_URL,
1819
ORG_AUTH_LOGIN_URL,
1920
ORG_AUTH_REGISTER_URL,

client/packages/lowcoder/src/constants/applicationConstants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,5 @@ export type AppSnapshotList = {
115115
count: number; // total count
116116
list: AppSnapshot[];
117117
};
118+
119+
export type MarketplaceType = "local" | "lowcoder";

client/packages/lowcoder/src/constants/routesURL.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AppViewMode } from "constants/applicationConstants";
1+
import { AppViewMode, MarketplaceType } from "constants/applicationConstants";
22
import { LocationDescriptor } from "history";
33
import { UserGuideLocationState } from "pages/tutorials/tutorialsConstant";
44
import { DatasourceType } from "@lowcoder-ee/constants/queryConstants";
@@ -43,10 +43,14 @@ export const LDAP_AUTH_LOGIN_URL = `${USER_AUTH_URL}/ldap/login`;
4343
export const INVITE_LANDING_URL = "/invite/:invitationId";
4444
export const ORG_AUTH_LOGIN_URL = `/org/:orgId/auth/login`;
4545
export const ORG_AUTH_REGISTER_URL = `/org/:orgId/auth/register`;
46+
export const MARKETPLACE_TYPE_URL = `${MARKETPLACE_URL}/:marketplaceType`;
4647

4748
export const APPLICATION_VIEW_URL = (appId: string, viewMode: AppViewMode) =>
4849
`${ALL_APPLICATIONS_URL}/${appId}/${viewMode}`;
4950

51+
export const MARKETPLACE_URL_BY_TYPE = (type: MarketplaceType) =>
52+
`${MARKETPLACE_URL}/${type}`;
53+
5054
export const isAuthUnRequired = (pathname: string): boolean => {
5155
return (
5256
pathname.startsWith("/invite/") ||

client/packages/lowcoder/src/pages/ApplicationV2/MarketplaceView.tsx

Lines changed: 49 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,66 @@
11
import { useEffect, useState } from "react";
2-
import { useDispatch, useSelector } from "react-redux";
32
import { HomeLayout } from "./HomeLayout";
4-
import { MARKETPLACE_URL } from "constants/routesURL";
5-
import { marketplaceSelector } from "redux/selectors/applicationSelector";
6-
import { fetchAllMarketplaceApps } from "redux/reduxActions/applicationActions";
3+
import { MARKETPLACE_TYPE_URL, MARKETPLACE_URL } from "constants/routesURL";
74
import { trans } from "../../i18n";
5+
import axios, { AxiosResponse } from "axios";
6+
import ApplicationApi from "@lowcoder-ee/api/applicationApi";
7+
import { ApplicationMeta, MarketplaceType } from "@lowcoder-ee/constants/applicationConstants";
8+
import { GenericApiResponse } from "@lowcoder-ee/api/apiResponses";
9+
import { validateResponse } from "@lowcoder-ee/api/apiUtils";
10+
import { messageInstance } from "lowcoder-design";
11+
import { matchPath } from "react-router";
12+
import log from "loglevel";
813

914
export function MarketplaceView() {
10-
const [haveFetchedApps, setHaveFetchApps] = useState<boolean>(false);
15+
const [ marketplaceApps, setMarketplaceApps ] = useState<Array<ApplicationMeta>>([]);
16+
const marketplaceType = matchPath<{marketplaceType?: MarketplaceType}>(window.location.pathname, MARKETPLACE_TYPE_URL)?.params
17+
.marketplaceType;
18+
const isLowcoderMarketplace = marketplaceType === 'lowcoder';
19+
const marketplaceBreadcrumbText = !marketplaceType?.length
20+
? trans("home.marketplace")
21+
: marketplaceType === 'lowcoder'
22+
? `${trans("home.marketplace")} (Lowcoder)`
23+
: `${trans("home.marketplace")} (Local)`;
1124

12-
const dispatch = useDispatch();
13-
const marketplaceApps = useSelector(marketplaceSelector);
25+
const fetchLowcoderMarketplaceApps = () => {
26+
const http = axios.create({
27+
baseURL: 'https://api-service.lowcoder.cloud',
28+
withCredentials: false,
29+
});
30+
return http.get(`/api/v1/applications/marketplace-apps`);
31+
};
1432

15-
useEffect(() => {
16-
if (!marketplaceApps.length && !haveFetchedApps) {
17-
dispatch(fetchAllMarketplaceApps());
18-
setHaveFetchApps(true);
33+
const fetchLocalMarketplaceApps = () => {
34+
return ApplicationApi.fetchAllMarketplaceApps()
35+
}
36+
37+
const fetchMarketplaceApps = async () => {
38+
try {
39+
let response: AxiosResponse<GenericApiResponse<ApplicationMeta[]>>;
40+
if(isLowcoderMarketplace) {
41+
response = await fetchLowcoderMarketplaceApps();
42+
} else {
43+
response = await fetchLocalMarketplaceApps();
44+
}
45+
46+
const isValidResponse: boolean = validateResponse(response);
47+
if (isValidResponse) {
48+
setMarketplaceApps(response.data.data);
49+
}
50+
} catch (error: any) {
51+
messageInstance.error(error.message);
52+
log.debug("fetch marketplace apps error: ", error);
1953
}
20-
}, []);
54+
}
2155

2256
useEffect(() => {
23-
if (marketplaceApps.length) {
24-
setHaveFetchApps(true);
25-
}
26-
}, [marketplaceApps])
57+
fetchMarketplaceApps();
58+
}, [marketplaceType]);
2759

2860
return (
2961
<HomeLayout
3062
elements={marketplaceApps}
31-
breadcrumb={[{ text: trans("home.marketplace"), path: MARKETPLACE_URL }]}
63+
breadcrumb={[{ text: marketplaceBreadcrumbText, path: MARKETPLACE_URL }]}
3264
mode={"marketplace"}
3365
/>
3466
);

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

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
FOLDER_URL_PREFIX,
66
FOLDERS_URL,
77
MARKETPLACE_URL,
8+
MARKETPLACE_URL_BY_TYPE,
89
MODULE_APPLICATIONS_URL,
910
QUERY_LIBRARY_URL,
1011
SETTING,
@@ -33,6 +34,8 @@ import {
3334
RecyclerIcon,
3435
MarketplaceIcon,
3536
MarketplaceActiveIcon,
37+
LowcoderMarketplaceActiveIcon,
38+
LowcoderMarketplaceIcon,
3639
} from "lowcoder-design";
3740
import React, { useEffect, useState } from "react";
3841
import { fetchAllApplications, fetchHomeData } from "redux/reduxActions/applicationActions";
@@ -245,6 +248,7 @@ export default function ApplicationHome() {
245248
const allAppCount = allApplications.length;
246249
const allFoldersCount = allFolders.length;
247250
const orgHomeId = "root";
251+
const isSelfHost = window.location.host !== 'app.lowcoder.cloud';
248252

249253
const handleFolderCreate = useCreateFolder();
250254

@@ -357,8 +361,16 @@ export default function ApplicationHome() {
357361
visible: ({ user }) => user.orgDev,
358362
},
359363
{
360-
text: <TabLabel>{trans("home.marketplace")}</TabLabel>,
361-
routePath: MARKETPLACE_URL,
364+
text: (
365+
<TabLabel>
366+
{
367+
isSelfHost
368+
? `${trans("home.marketplace")} (Local)`
369+
: trans("home.marketplace")
370+
}
371+
</TabLabel>
372+
),
373+
routePath: isSelfHost ? MARKETPLACE_URL_BY_TYPE('local') : MARKETPLACE_URL,
362374
routePathExact: false,
363375
routeComp: MarketplaceView,
364376
icon: ({ selected, ...otherProps }) =>
@@ -369,6 +381,19 @@ export default function ApplicationHome() {
369381
),
370382
visible: ({ user }) => user.orgDev,
371383
},
384+
{
385+
text: <TabLabel>{`${trans("home.marketplace")} (Lowcoder)`}</TabLabel>,
386+
routePath: MARKETPLACE_URL_BY_TYPE('lowcoder'),
387+
routePathExact: false,
388+
routeComp: MarketplaceView,
389+
icon: ({ selected, ...otherProps }) =>
390+
selected ? (
391+
<LowcoderMarketplaceActiveIcon {...otherProps} />
392+
) : (
393+
<LowcoderMarketplaceIcon {...otherProps} />
394+
),
395+
visible: ({ user }) => user.orgDev && isSelfHost,
396+
},
372397
{
373398
text: <TabLabel>{trans("home.trash")}</TabLabel>,
374399
routePath: TRASH_URL,

0 commit comments

Comments
 (0)