Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b5647a7

Browse files
committed
updated managed endpoints
1 parent bb81f1f commit b5647a7

File tree

6 files changed

+223
-18
lines changed

6 files changed

+223
-18
lines changed

‎client/packages/lowcoder/src/pages/setting/environments/config/apps.config.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import { AppstoreOutlined, AuditOutlined } from '@ant-design/icons';
55
import {DeployableItemConfig } from '../types/deployable-item.types';
66
import { Environment } from '../types/environment.types';
77
import { getMergedWorkspaceApps, deployApp } from '../services/apps.service';
8-
import { connectManagedApp, unconnectManagedApp } from '../services/enterprise.service';
8+
import { connectManagedApp, unconnectManagedApp } from '../services/enterprise.service';
9+
import { ManagedObjectType, setManagedObject, unsetManagedObject } from '../services/managed-objects.service';
910
import { App, AppStats } from '../types/app.types';
1011

1112

@@ -161,11 +162,19 @@ export const appsConfig: DeployableItemConfig<App, AppStats> = {
161162
toggleManaged: async ({ item, checked, environment }) => {
162163
try {
163164
if (checked) {
164-
await connectManagedApp(environment.environmentId, item.name, item.applicationGid!);
165+
return await setManagedObject(
166+
item.applicationGid!,
167+
environment.environmentId,
168+
ManagedObjectType.APP,
169+
item.name
170+
);
165171
} else {
166-
await unconnectManagedApp(item.applicationGid!);
172+
return await unsetManagedObject(
173+
item.applicationGid!,
174+
environment.environmentId,
175+
ManagedObjectType.APP
176+
);
167177
}
168-
return true;
169178
} catch (error) {
170179
console.error('Error toggling managed status:', error);
171180
return false;

‎client/packages/lowcoder/src/pages/setting/environments/config/data-sources.config.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { DataSource, DataSourceStats } from '../types/datasource.types';
77
import { Environment } from '../types/environment.types';
88
import { getMergedWorkspaceDataSources, deployDataSource } from '../services/datasources.service';
99
import { connectManagedDataSource, unconnectManagedDataSource } from '../services/enterprise.service';
10+
import { ManagedObjectType, setManagedObject, unsetManagedObject } from '../services/managed-objects.service';
1011
import {
1112
createNameColumn,
1213
createTypeColumn,
@@ -150,11 +151,19 @@ export const dataSourcesConfig: DeployableItemConfig<DataSource, DataSourceStats
150151
toggleManaged: async ({ item, checked, environment }) => {
151152
try {
152153
if (checked) {
153-
await connectManagedDataSource(environment.environmentId, item.name, item.gid);
154+
return await setManagedObject(
155+
item.gid,
156+
environment.environmentId,
157+
ManagedObjectType.DATASOURCE,
158+
item.name
159+
);
154160
} else {
155-
await unconnectManagedDataSource(item.gid);
161+
return await unsetManagedObject(
162+
item.gid,
163+
environment.environmentId,
164+
ManagedObjectType.DATASOURCE
165+
);
156166
}
157-
return true;
158167
} catch (error) {
159168
console.error('Error toggling managed status:', error);
160169
return false;

‎client/packages/lowcoder/src/pages/setting/environments/config/query.config.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { DeployableItemConfig } from '../types/deployable-item.types';
66
import { Query } from '../types/query.types';
77
import { connectManagedQuery, unconnectManagedQuery } from '../services/enterprise.service';
88
import { getMergedWorkspaceQueries, deployQuery } from '../services/query.service';
9+
import { ManagedObjectType, setManagedObject, unsetManagedObject } from '../services/managed-objects.service';
910
import { Environment } from '../types/environment.types';
1011

1112
import {
@@ -145,11 +146,19 @@ export const queryConfig: DeployableItemConfig<Query, QueryStats> = {
145146
toggleManaged: async ({ item, checked, environment }) => {
146147
try {
147148
if (checked) {
148-
await connectManagedQuery(environment.environmentId, item.name, item.gid);
149+
return await setManagedObject(
150+
item.gid,
151+
environment.environmentId,
152+
ManagedObjectType.QUERY,
153+
item.name
154+
);
149155
} else {
150-
await unconnectManagedQuery(item.gid);
156+
return await unsetManagedObject(
157+
item.gid,
158+
environment.environmentId,
159+
ManagedObjectType.QUERY
160+
);
151161
}
152-
return true;
153162
} catch (error) {
154163
console.error('Error toggling managed status:', error);
155164
return false;

‎client/packages/lowcoder/src/pages/setting/environments/config/workspace.config.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Environment } from '../types/environment.types';
77
import { buildEnvironmentWorkspaceId } from '@lowcoder-ee/constants/routesURL';
88
import { getMergedEnvironmentWorkspaces, deployWorkspace } from '../services/workspace.service';
99
import { connectManagedWorkspace, unconnectManagedWorkspace } from '../services/enterprise.service';
10+
import { ManagedObjectType, setManagedObject, unsetManagedObject } from '../services/managed-objects.service';
1011
import {
1112
createNameColumn,
1213
createIdColumn,
@@ -135,11 +136,19 @@ export const workspaceConfig: DeployableItemConfig<Workspace, WorkspaceStats> =
135136
toggleManaged: async ({ item, checked, environment }) => {
136137
try {
137138
if (checked) {
138-
await connectManagedWorkspace(environment.environmentId, item.name, item.gid!);
139+
return await setManagedObject(
140+
item.gid!,
141+
environment.environmentId,
142+
ManagedObjectType.ORG,
143+
item.name
144+
);
139145
} else {
140-
await unconnectManagedWorkspace(item.gid!);
146+
return await unsetManagedObject(
147+
item.gid!,
148+
environment.environmentId,
149+
ManagedObjectType.ORG
150+
);
141151
}
142-
return true;
143152
} catch (error) {
144153
console.error('Error toggling managed status:', error);
145154
return false;

‎client/packages/lowcoder/src/pages/setting/environments/context/WorkspaceContext.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import React, {
1212
import { useSingleEnvironmentContext } from "./SingleEnvironmentContext";
1313
import { fetchWorkspaceById } from "../services/environments.service";
1414
import { Workspace } from "../types/workspace.types";
15-
import { getManagedWorkspaces, connectManagedWorkspace, unconnectManagedWorkspace } from "../services/enterprise.service";
15+
import { getManagedWorkspaces } from "../services/enterprise.service";
16+
import { ManagedObjectType, setManagedObject, unsetManagedObject } from "../services/managed-objects.service";
1617

1718
interface WorkspaceContextState {
1819
// Workspace data
@@ -113,14 +114,20 @@ import React, {
113114
try {
114115
if (checked) {
115116
// Connect the workspace as managed
116-
await connectManagedWorkspace(
117+
await setManagedObject(
118+
workspace.gid!,
117119
environment.environmentId,
118-
workspace.name,
119-
workspace.gid!
120+
ManagedObjectType.ORG,
121+
workspace.name
122+
120123
);
121124
} else {
122125
// Disconnect the managed workspace
123-
await unconnectManagedWorkspace(workspace.gid!);
126+
await unsetManagedObject(
127+
workspace.gid!,
128+
environment.environmentId,
129+
ManagedObjectType.ORG
130+
);
124131
}
125132

126133
// Update local state
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
import axios from "axios";
2+
import { message } from "antd";
3+
4+
// Object types that can be managed
5+
export enum ManagedObjectType {
6+
ORG = "ORG",
7+
APP = "APP",
8+
QUERY = "QUERY",
9+
DATASOURCE = "DATASOURCE"
10+
}
11+
12+
/**
13+
* Check if an object is managed
14+
* @param objGid - Object's global ID
15+
* @param environmentId - Environment ID
16+
* @param objType - Object type (ORG, APP, QUERY, DATASOURCE)
17+
* @returns Promise with boolean indicating if object is managed
18+
*/
19+
export async function isManagedObject(
20+
objGid: string,
21+
environmentId: string,
22+
objType: ManagedObjectType
23+
): Promise<boolean> {
24+
try {
25+
if (!objGid || !environmentId || !objType) {
26+
throw new Error("Missing required parameters");
27+
}
28+
29+
const response = await axios.get(`/api/plugins/enterprise/managed-obj`, {
30+
params: {
31+
objGid,
32+
environmentId,
33+
objType
34+
}
35+
});
36+
37+
return response.data.managed === true;
38+
} catch (error) {
39+
// If the object doesn't exist as managed, it's not an error
40+
if (axios.isAxiosError(error) && error.response?.status === 404) {
41+
return false;
42+
}
43+
44+
const errorMessage = error instanceof Error ? error.message : "Failed to check managed status";
45+
message.error(errorMessage);
46+
throw error;
47+
}
48+
}
49+
50+
/**
51+
* Set an object as managed
52+
* @param objGid - Object's global ID
53+
* @param environmentId - Environment ID
54+
* @param objType - Object type (ORG, APP, QUERY, DATASOURCE)
55+
* @param objName - Object name (optional)
56+
* @param objTags - Object tags (optional)
57+
* @returns Promise with operation result
58+
*/
59+
export async function setManagedObject(
60+
objGid: string,
61+
environmentId: string,
62+
objType: ManagedObjectType,
63+
objName?: string,
64+
objTags: string[] = []
65+
): Promise<boolean> {
66+
try {
67+
if (!objGid || !environmentId || !objType) {
68+
throw new Error("Missing required parameters");
69+
}
70+
71+
const response = await axios.post(`/api/plugins/enterprise/managed-obj`,
72+
// Include optional parameters in the request body instead of query params
73+
{
74+
objName,
75+
objTags: objTags.length > 0 ? objTags : undefined
76+
},
77+
{
78+
params: {
79+
objGid,
80+
environmentId,
81+
objType
82+
}
83+
}
84+
);
85+
86+
return response.status === 200;
87+
} catch (error) {
88+
const errorMessage = error instanceof Error ? error.message : `Failed to set ${objType} as managed`;
89+
message.error(errorMessage);
90+
throw error;
91+
}
92+
}
93+
94+
/**
95+
* Set an object as unmanaged
96+
* @param objGid - Object's global ID
97+
* @param environmentId - Environment ID
98+
* @param objType - Object type (ORG, APP, QUERY, DATASOURCE)
99+
* @returns Promise with operation result
100+
*/
101+
export async function unsetManagedObject(
102+
objGid: string,
103+
environmentId: string,
104+
objType: ManagedObjectType
105+
): Promise<boolean> {
106+
try {
107+
if (!objGid || !environmentId || !objType) {
108+
throw new Error("Missing required parameters");
109+
}
110+
111+
const response = await axios.delete(`/api/plugins/enterprise/managed-obj`, {
112+
params: {
113+
objGid,
114+
environmentId,
115+
objType
116+
}
117+
});
118+
119+
return response.status === 200;
120+
} catch (error) {
121+
const errorMessage = error instanceof Error ? error.message : `Failed to remove ${objType} from managed`;
122+
message.error(errorMessage);
123+
throw error;
124+
}
125+
}
126+
127+
/**
128+
* Get all managed objects of a specific type for an environment
129+
* NOTE: This function is commented out as the endpoint is not yet implemented
130+
* TODO: Uncomment when the /managed-obj/list endpoint is available
131+
*
132+
* @param environmentId - Environment ID
133+
* @param objType - Object type (ORG, APP, QUERY, DATASOURCE)
134+
* @returns Promise with an array of managed objects
135+
*/
136+
/*
137+
export async function getManagedObjects(
138+
environmentId: string,
139+
objType: ManagedObjectType
140+
): Promise<any[]> {
141+
try {
142+
if (!environmentId || !objType) {
143+
throw new Error("Missing required parameters");
144+
}
145+
146+
const response = await axios.get(`/api/plugins/enterprise/managed-obj/list`, {
147+
params: {
148+
environmentId,
149+
objType
150+
}
151+
});
152+
153+
return response.data.data || [];
154+
} catch (error) {
155+
const errorMessage = error instanceof Error
156+
? error.message
157+
: `Failed to fetch managed ${objType.toLowerCase()}s`;
158+
message.error(errorMessage);
159+
throw error;
160+
}
161+
}
162+
*/

0 commit comments

Comments
 (0)