Skip to content

Commit c96b993

Browse files
committed
add utility function for merge workspaces
1 parent 1348756 commit c96b993

File tree

5 files changed

+58
-9
lines changed

5 files changed

+58
-9
lines changed

client/packages/lowcoder/src/pages/setting/environments/EnvironmentDetail.tsx

+5-2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import { useEnvironmentContext } from "./context/EnvironmentContext";
2828
import { useEnvironmentWorkspaces } from "./hooks/useEnvironmentWorkspaces";
2929
import { useEnvironmentUserGroups } from "./hooks/useEnvironmentUserGroups";
3030
import { useManagedWorkspaces } from "./hooks/enterprise/useManagedWorkspaces";
31+
import { getMergedWorkspaces } from "./utils/getMergedWorkspaces";
32+
3133

3234
const { Title, Text } = Typography;
3335
const { TabPane } = Tabs;
@@ -51,7 +53,6 @@ const EnvironmentDetail: React.FC = () => {
5153
loading: workspacesLoading,
5254
error: workspacesError,
5355
refresh: refreshWorkspaces,
54-
workspaceStats,
5556
} = useEnvironmentWorkspaces(environment);
5657

5758
const {
@@ -120,6 +121,8 @@ const EnvironmentDetail: React.FC = () => {
120121
);
121122
}
122123

124+
const { merged, stats: workspaceStats } = getMergedWorkspaces(workspaces, managedWorkspaces);
125+
123126
return (
124127
<div className="environment-detail-container" style={{ padding: "24px" }}>
125128
{/* Header with environment name and controls */}
@@ -294,7 +297,7 @@ const EnvironmentDetail: React.FC = () => {
294297

295298
{/* Workspaces List */}
296299
<WorkspacesList
297-
workspaces={workspaces}
300+
workspaces={merged}
298301
loading={workspacesLoading && !workspacesError}
299302
error={workspacesError}
300303
environmentId={environment.environmentId}

client/packages/lowcoder/src/pages/setting/environments/components/WorkspacesList.tsx

+15-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ interface WorkspacesListProps {
88
workspaces: Workspace[];
99
loading: boolean;
1010
error?: string | null;
11-
environmentId: string
11+
environmentId: string;
1212
}
1313

1414
/**
@@ -18,7 +18,7 @@ const WorkspacesList: React.FC<WorkspacesListProps> = ({
1818
workspaces,
1919
loading,
2020
error,
21-
environmentId
21+
environmentId,
2222
}) => {
2323
// Format timestamp to date string
2424
const formatDate = (timestamp?: number): string => {
@@ -66,7 +66,16 @@ const WorkspacesList: React.FC<WorkspacesListProps> = ({
6666
{status}
6767
</Tag>
6868
),
69-
}
69+
},
70+
{
71+
title: 'Managed',
72+
key: 'managed',
73+
render: (record: Workspace) => (
74+
<Tag color={record.managed ? 'green' : 'default'}>
75+
{record.managed ? 'Managed' : 'Unmanaged'}
76+
</Tag>
77+
),
78+
},
7079
];
7180

7281
// If loading, show spinner
@@ -82,7 +91,7 @@ const WorkspacesList: React.FC<WorkspacesListProps> = ({
8291
if (!workspaces || workspaces.length === 0 || error) {
8392
return (
8493
<Empty
85-
description={error || "No workspaces found"}
94+
description={error || 'No workspaces found'}
8695
image={Empty.PRESENTED_IMAGE_SIMPLE}
8796
/>
8897
);
@@ -97,10 +106,10 @@ const WorkspacesList: React.FC<WorkspacesListProps> = ({
97106
size="middle"
98107
onRow={(record) => ({
99108
onClick: () => handleRowClick(record),
100-
style: { cursor: 'pointer' } // Add pointer cursor to indicate clickable rows
109+
style: { cursor: 'pointer' }, // Add pointer cursor to indicate clickable rows
101110
})}
102111
/>
103112
);
104113
};
105114

106-
export default WorkspacesList;
115+
export default WorkspacesList;
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Workspace } from "../types/workspace.types";
12
export interface ManagedOrg {
23
orgGid: string;
34
environmentId: string;
@@ -6,4 +7,6 @@ export interface ManagedOrg {
67
createdAt: string;
78
updatedAt: string;
89
}
9-
10+
11+
12+
export type MergedWorkspace = Workspace & { managed: boolean };

client/packages/lowcoder/src/pages/setting/environments/types/workspace.types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ export interface Workspace {
1212
createdBy?: string;
1313
isAutoGeneratedOrganization?: boolean | null;
1414
logoUrl?: string;
15+
managed?: boolean;
1516
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { Workspace } from "../types/workspace.types";
2+
import { ManagedOrg } from "../types/enterprise.types";
3+
4+
5+
export interface MergedWorkspaceResult {
6+
merged: Workspace[];
7+
stats: {
8+
total: number;
9+
managed: number;
10+
unmanaged: number;
11+
};
12+
}
13+
14+
export function getMergedWorkspaces(
15+
standard: Workspace[],
16+
managed: ManagedOrg[]
17+
): MergedWorkspaceResult {
18+
const merged = standard.map((ws) => ({
19+
...ws,
20+
managed: managed.some((m) => m.orgGid === ws.gid),
21+
}));
22+
23+
const managedCount = merged.filter((ws) => ws.managed).length;
24+
25+
return {
26+
merged,
27+
stats: {
28+
total: merged.length,
29+
managed: managedCount,
30+
unmanaged: merged.length - managedCount,
31+
},
32+
};
33+
}

0 commit comments

Comments
 (0)