Skip to content

Consistent UI for the Environments #1718

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
May 28, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Only 1 master environment can be created
  • Loading branch information
iamfaran committed May 28, 2025
commit 68e39e56f975779aad4878977ce794da46e68a73
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import React, { useState } from 'react';
import { Modal, Form, Input, Select, Switch, Button, Alert } from 'antd';
import { Modal, Form, Input, Select, Switch, Button, Alert, Tooltip } from 'antd';
import { useSelector } from 'react-redux';
import { selectMasterEnvironment, selectHasMasterEnvironment } from 'redux/selectors/enterpriseSelectors';
import { Environment } from '../types/environment.types';

const { Option } = Select;
Expand All @@ -20,6 +22,10 @@ const CreateEnvironmentModal: React.FC<CreateEnvironmentModalProps> = ({
const [form] = Form.useForm();
const [submitLoading, setSubmitLoading] = useState(false);

// Redux selectors to check for existing master environment
const hasMasterEnvironment = useSelector(selectHasMasterEnvironment);
const masterEnvironment = useSelector(selectMasterEnvironment);

const handleSubmit = async () => {
try {
const values = await form.validateFields();
Expand Down Expand Up @@ -151,9 +157,23 @@ const CreateEnvironmentModal: React.FC<CreateEnvironmentModalProps> = ({
label="Master Environment"
valuePropName="checked"
>
<Switch />
<Tooltip
title={hasMasterEnvironment ? `${masterEnvironment?.environmentName || 'Unknown'} is already the Master environment` : ""}
>
<Switch disabled={hasMasterEnvironment} />
</Tooltip>
</Form.Item>

{hasMasterEnvironment && (
<Alert
message="Master Environment Already Exists"
description={`The environment "${masterEnvironment?.environmentName || 'Unknown'}" is already set as the Master environment. Only one Master environment is allowed.`}
type="warning"
showIcon
style={{ marginBottom: '16px' }}
/>
)}

<Alert
message="License Information"
description="After creating the environment, the system will automatically check the license status. Make sure the API service URL and API key are correctly configured for license validation."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,13 @@ export const selectLicensedEnvironments = (state: AppState) => {
return environments.filter(env => env.isLicensed !== false);
};

export const selectMasterEnvironment = (state: AppState) => {
const environments = state.ui.enterprise?.environments ?? [];
return environments.find(env => env.isMaster) ?? null;
};

export const selectHasMasterEnvironment = (state: AppState) => {
const environments = state.ui.enterprise?.environments ?? [];
return environments.some(env => env.isMaster);
};