Skip to content

Commit b6d74d2

Browse files
committed
create a util function and add tags in Deployment Modal
1 parent 9883336 commit b6d74d2

File tree

3 files changed

+72
-17
lines changed

3 files changed

+72
-17
lines changed

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

+23-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
// components/DeployItemModal.tsx
22
import React, { useState, useEffect } from 'react';
3-
import { Modal, Form, Select, Checkbox, Button, message, Spin, Input } from 'antd';
3+
import { Modal, Form, Select, Checkbox, Button, message, Spin, Input, Tag, Space } from 'antd';
44
import { Environment } from '../types/environment.types';
55
import { DeployableItem, BaseStats, DeployableItemConfig } from '../types/deployable-item.types';
66
import { useEnvironmentContext } from '../context/EnvironmentContext';
7+
import { getEnvironmentTagColor, formatEnvironmentType } from '../utils/environmentUtils';
8+
79
interface DeployItemModalProps<T extends DeployableItem, S extends BaseStats> {
810
visible: boolean;
911
item: T | null;
@@ -84,6 +86,18 @@ function DeployItemModal<T extends DeployableItem, S extends BaseStats>({
8486
form={form}
8587
layout="vertical"
8688
>
89+
{/* Source environment display */}
90+
<Form.Item label="Source Environment">
91+
<Space>
92+
<strong>{sourceEnvironment.environmentName}</strong>
93+
{sourceEnvironment.environmentType && (
94+
<Tag color={getEnvironmentTagColor(sourceEnvironment.environmentType)}>
95+
{formatEnvironmentType(sourceEnvironment.environmentType)}
96+
</Tag>
97+
)}
98+
</Space>
99+
</Form.Item>
100+
87101
<Form.Item
88102
name="targetEnvId"
89103
label="Target Environment"
@@ -92,7 +106,14 @@ function DeployItemModal<T extends DeployableItem, S extends BaseStats>({
92106
<Select placeholder="Select target environment">
93107
{targetEnvironments.map((env) => (
94108
<Select.Option key={env.environmentId} value={env.environmentId}>
95-
{env.environmentName}
109+
<Space>
110+
{env.environmentName}
111+
{env.environmentType && (
112+
<Tag color={getEnvironmentTagColor(env.environmentType)}>
113+
{formatEnvironmentType(env.environmentType)}
114+
</Tag>
115+
)}
116+
</Space>
96117
</Select.Option>
97118
))}
98119
</Select>

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

+3-15
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from 'react';
22
import { Table, Tag, Button, Tooltip, Space } from 'antd';
33
import { EditOutlined, AuditOutlined} from '@ant-design/icons';
44
import { Environment } from '../types/environment.types';
5+
import { getEnvironmentTagColor, formatEnvironmentType } from '../utils/environmentUtils';
56

67

78

@@ -20,19 +21,6 @@ const EnvironmentsTable: React.FC<EnvironmentsTableProps> = ({
2021
loading,
2122
onRowClick,
2223
}) => {
23-
// Get color for environment type/stage
24-
const getTypeColor = (type: string): string => {
25-
if (!type) return 'default';
26-
27-
switch (type.toUpperCase()) {
28-
case 'DEV': return 'blue';
29-
case 'TEST': return 'orange';
30-
case 'PREPROD': return 'purple';
31-
case 'PROD': return 'green';
32-
default: return 'default';
33-
}
34-
};
35-
3624
// Open audit page in new tab
3725
const openAuditPage = (environmentId: string, e: React.MouseEvent) => {
3826
e.stopPropagation(); // Prevent row click from triggering
@@ -65,8 +53,8 @@ const EnvironmentsTable: React.FC<EnvironmentsTableProps> = ({
6553
dataIndex: 'environmentType',
6654
key: 'environmentType',
6755
render: (type: string) => (
68-
<Tag color={getTypeColor(type || '')}>
69-
{type ? type.toUpperCase() : 'UNKNOWN'}
56+
<Tag color={getEnvironmentTagColor(type)}>
57+
{formatEnvironmentType(type)}
7058
</Tag>
7159
),
7260
},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/**
2+
* Utility functions for environment-related features
3+
*/
4+
5+
/**
6+
* Get the appropriate color for an environment tag based on its type
7+
* @param envType The environment type/stage (e.g. 'PROD', 'DEV', 'STAGING')
8+
* @returns A color string to use with Ant Design's Tag component
9+
*/
10+
export const getEnvironmentTagColor = (envType: string | undefined): string => {
11+
if (!envType) return 'default';
12+
13+
// Normalize to uppercase for consistent comparison
14+
const type = envType.toUpperCase();
15+
16+
switch (type) {
17+
// Production environment
18+
case 'PROD':
19+
return 'red'; // Red for production - indicates caution
20+
21+
// Pre-production environment
22+
case 'PREPROD':
23+
return 'orange'; // Orange for pre-production
24+
25+
// Test environment
26+
case 'TEST':
27+
return 'purple'; // Purple for test environment
28+
29+
// Development environment
30+
case 'DEV':
31+
return 'green'; // Green for development - safe to use
32+
33+
default:
34+
return 'default'; // Default gray for unknown types
35+
}
36+
};
37+
38+
/**
39+
* Format an environment type for display
40+
* @param envType The environment type string
41+
* @returns Formatted environment type string
42+
*/
43+
export const formatEnvironmentType = (envType: string | undefined): string => {
44+
if (!envType) return 'UNKNOWN';
45+
return envType.toUpperCase();
46+
};

0 commit comments

Comments
 (0)