Skip to content

Commit 9a8329e

Browse files
committed
create utils for different env colors
1 parent 7f4d11f commit 9a8329e

File tree

3 files changed

+37
-54
lines changed

3 files changed

+37
-54
lines changed

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

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import WorkspacesTab from "./components/WorkspacesTab";
2626
import UserGroupsTab from "./components/UserGroupsTab";
2727
import EnvironmentHeader from "./components/EnvironmentHeader";
2828
import ModernBreadcrumbs from "./components/ModernBreadcrumbs";
29+
import { getEnvironmentTagColor } from "./utils/environmentUtils";
2930
const { Title, Text } = Typography;
3031
const { TabPane } = Tabs;
3132

@@ -74,15 +75,7 @@ const EnvironmentDetail: React.FC = () => {
7475
}
7576
};
7677

77-
// Dropdown menu for environment actions
78-
const actionsMenu = (
79-
<Menu>
80-
<Menu.Item key="edit" icon={<EditOutlined />} onClick={handleEditClick}>
81-
Edit Environment
82-
</Menu.Item>
83-
{/* Add more menu items here if needed */}
84-
</Menu>
85-
);
78+
8679

8780
if (isLoading) {
8881
return (
@@ -149,18 +142,6 @@ const EnvironmentDetail: React.FC = () => {
149142
title: environment.environmentName
150143
}
151144
];
152-
153-
// Get environment type tag color
154-
const getEnvironmentTypeColor = () => {
155-
switch(environment.environmentType) {
156-
case 'production':
157-
return 'red';
158-
case 'testing':
159-
return 'orange';
160-
default:
161-
return 'blue';
162-
}
163-
};
164145

165146
return (
166147
<div
@@ -202,7 +183,7 @@ const EnvironmentDetail: React.FC = () => {
202183
</Descriptions.Item>
203184
<Descriptions.Item label="Environment Type">
204185
<Tag
205-
color={getEnvironmentTypeColor()}
186+
color={getEnvironmentTagColor(environment.environmentType)}
206187
style={{ borderRadius: '12px' }}
207188
>
208189
{environment.environmentType}

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

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from 'react';
22
import { Button, Tag, Typography, Row, Col } from 'antd';
33
import { EditOutlined, EnvironmentOutlined } from '@ant-design/icons';
44
import { Environment } from '../types/environment.types';
5+
import { getEnvironmentTagColor, getEnvironmentHeaderGradient } from '../utils/environmentUtils';
56

67
const { Title, Text } = Typography;
78

@@ -18,36 +19,12 @@ const EnvironmentHeader: React.FC<EnvironmentHeaderProps> = ({
1819
environment,
1920
onEditClick
2021
}) => {
21-
// Determine header gradient based on environment type
22-
const getHeaderGradient = () => {
23-
switch(environment.environmentType) {
24-
case 'production':
25-
return 'linear-gradient(135deg, #f5222d 0%, #fa8c16 100%)';
26-
case 'testing':
27-
return 'linear-gradient(135deg, #fa8c16 0%, #faad14 100%)';
28-
default:
29-
return 'linear-gradient(135deg, #1890ff 0%, #096dd9 100%)';
30-
}
31-
};
32-
33-
// Get environment type tag color
34-
const getEnvironmentTypeColor = () => {
35-
switch(environment.environmentType) {
36-
case 'production':
37-
return 'red';
38-
case 'testing':
39-
return 'orange';
40-
default:
41-
return 'blue';
42-
}
43-
};
44-
4522
return (
4623
<div
4724
className="environment-header"
4825
style={{
4926
marginBottom: "24px",
50-
background: getHeaderGradient(),
27+
background: getEnvironmentHeaderGradient(environment.environmentType),
5128
padding: '20px 24px',
5229
borderRadius: '8px',
5330
color: 'white',
@@ -78,7 +55,7 @@ const EnvironmentHeader: React.FC<EnvironmentHeaderProps> = ({
7855
ID: {environment.environmentId}
7956
</Text>
8057
<Tag
81-
color={getEnvironmentTypeColor()}
58+
color={getEnvironmentTagColor(environment.environmentType)}
8259
style={{ marginLeft: 0, borderRadius: '12px' }}
8360
>
8461
{environment.environmentType}

client/packages/lowcoder/src/pages/setting/environments/utils/environmentUtils.ts

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
/**
66
* Get the appropriate color for an environment tag based on its type
7-
* @param envType The environment type/stage (e.g. 'PROD', 'DEV', 'STAGING')
7+
* @param envType The environment type/stage (DEV, TEST, PREPROD, PROD)
88
* @returns A color string to use with Ant Design's Tag component
99
*/
1010
export const getEnvironmentTagColor = (envType: string | undefined): string => {
@@ -14,27 +14,52 @@ export const getEnvironmentTagColor = (envType: string | undefined): string => {
1414
const type = envType.toUpperCase();
1515

1616
switch (type) {
17-
// Production environment
1817
case 'PROD':
1918
return 'red'; // Red for production - indicates caution
2019

21-
// Pre-production environment
2220
case 'PREPROD':
2321
return 'orange'; // Orange for pre-production
2422

25-
// Test environment
2623
case 'TEST':
2724
return 'purple'; // Purple for test environment
2825

29-
// Development environment
3026
case 'DEV':
31-
return 'green'; // Green for development - safe to use
27+
return 'blue'; // Blue for development
3228

3329
default:
3430
return 'default'; // Default gray for unknown types
3531
}
3632
};
3733

34+
/**
35+
* Get the appropriate background gradient for an environment based on its type
36+
* @param envType The environment type/stage (DEV, TEST, PREPROD, PROD)
37+
* @returns A CSS linear gradient string for the background
38+
*/
39+
export const getEnvironmentHeaderGradient = (envType: string | undefined): string => {
40+
if (!envType) return 'linear-gradient(135deg, #1890ff 0%, #096dd9 100%)';
41+
42+
// Normalize to uppercase for consistent comparison
43+
const type = envType.toUpperCase();
44+
45+
switch (type) {
46+
case 'PROD':
47+
return 'linear-gradient(135deg, #f5222d 0%, #fa8c16 100%)';
48+
49+
case 'PREPROD':
50+
return 'linear-gradient(135deg, #fa8c16 0%, #faad14 100%)';
51+
52+
case 'TEST':
53+
return 'linear-gradient(135deg, #722ed1 0%, #b37feb 100%)';
54+
55+
case 'DEV':
56+
return 'linear-gradient(135deg, #1890ff 0%, #096dd9 100%)';
57+
58+
default:
59+
return 'linear-gradient(135deg, #1890ff 0%, #096dd9 100%)';
60+
}
61+
};
62+
3863
/**
3964
* Format an environment type for display
4065
* @param envType The environment type string

0 commit comments

Comments
 (0)