Skip to content

Commit c1c874b

Browse files
committed
test managed linked object
1 parent cde8c0c commit c1c874b

File tree

2 files changed

+64
-3
lines changed

2 files changed

+64
-3
lines changed

client/packages/lowcoder/src/pages/setting/environments/services/managed-objects.service.ts

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ export async function isManagedObject(
6868
export async function setManagedObject(
6969
objGid: string,
7070
environmentId: string,
71-
objType: ManagedObjectType
71+
objType: ManagedObjectType,
72+
managedId?: string
7273
): Promise<boolean> {
7374
try {
7475
if (!objGid || !environmentId || !objType) {
@@ -78,7 +79,8 @@ export async function setManagedObject(
7879
const requestBody = {
7980
objGid,
8081
environmentId,
81-
objType
82+
objType,
83+
...(managedId && { managedId })
8284
};
8385

8486
const response = await axios.post(`/api/plugins/enterprise/managed-obj`, requestBody);
@@ -150,3 +152,41 @@ export async function getManagedObjects(
150152
}
151153
}
152154

155+
/**
156+
* Get a single managed object by its parameters
157+
* @param objGid - Object's global ID
158+
* @param environmentId - Environment ID
159+
* @param objType - Object type (ORG, APP, QUERY, DATASOURCE)
160+
* @returns Promise with ManagedObject if found
161+
*/
162+
export async function getSingleManagedObject(
163+
objGid: string,
164+
environmentId: string,
165+
objType: ManagedObjectType
166+
): Promise<ManagedObject | null> {
167+
try {
168+
if (!objGid || !environmentId || !objType) {
169+
throw new Error("Missing required parameters");
170+
}
171+
172+
const response = await axios.get(`/api/plugins/enterprise/managed-obj`, {
173+
params: {
174+
objGid,
175+
environmentId,
176+
objType
177+
}
178+
});
179+
180+
return response.data.data || null;
181+
} catch (error) {
182+
// If the object doesn't exist as managed, return null instead of throwing
183+
if (axios.isAxiosError(error) && error.response?.status === 404) {
184+
return null;
185+
}
186+
187+
const errorMessage = error instanceof Error ? error.message : "Failed to fetch managed object";
188+
message.error(errorMessage);
189+
throw error;
190+
}
191+
}
192+

client/packages/lowcoder/src/pages/setting/environments/services/workspace.service.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// services/workspacesService.ts (or wherever makes sense in your structure)
22
import { message } from "antd";
33
import { getEnvironmentWorkspaces } from "./environments.service";
4-
import { getManagedObjects, ManagedObject, ManagedObjectType } from "./managed-objects.service";
4+
import { getManagedObjects, getSingleManagedObject, ManagedObject, ManagedObjectType, setManagedObject } from "./managed-objects.service";
55
import { Workspace } from "../types/workspace.types";
66
import { ManagedOrg } from "../types/enterprise.types";
77
import axios from "axios";
@@ -95,6 +95,27 @@ export async function deployWorkspace(params: {
9595
targetEnvId: params.targetEnvId
9696
}
9797
});
98+
99+
// After successful deployment, set the managed object in target environment
100+
if (response.status === 200) {
101+
const res = await getSingleManagedObject(
102+
params.workspaceId,
103+
params.envId,
104+
ManagedObjectType.ORG
105+
);
106+
// managedID => res.managedId
107+
//objGID = res.objGid
108+
// targetEnvId = params.targetEnvId
109+
// objType = ManagedObjectType.ORG
110+
await setManagedObject(
111+
res?.objGid!,
112+
params.targetEnvId,
113+
ManagedObjectType.ORG,
114+
res?.managedId!
115+
);
116+
}
117+
118+
98119
return response.status === 200;
99120
} catch (error) {
100121
const errorMessage = error instanceof Error ? error.message : 'Failed to deploy workspace';

0 commit comments

Comments
 (0)