in source/idea/idea-cluster-manager/webapp/src/pages/cluster-admin/configure-project.tsx [792:1045]
buildCreateProjectForm() {
let {isUpdate, project} = this.state
let values: { [x: string]: any; } | undefined = undefined
if (isUpdate) {
let scripts = project?.scripts ? this.reverseScripts(project.scripts) : {};
values = {
...project,
...scripts,
"budget": project?.budget == Constants.BUDGET_NOT_FOUND ? { budget_name: Constants.BUDGET_NOT_FOUND } : project?.budget,
"budget.budget_name": project?.budget?.budget_name,
"advanced_options": !!(project?.scripts || project?.policy_arns || project?.security_groups)
}
}
const toggleBudgetNotFoundMessage = (event: any) => {
const currentBudgetName = this.getConfigureProjectForm().getValue("budget.budget_name");
this.setState({ budgetNotFound: currentBudgetName == Constants.BUDGET_NOT_FOUND })
}
return (
<div onClick={this.state.budgetNotFound ? toggleBudgetNotFoundMessage : undefined}>
<IdeaForm
name="create-update-project"
ref={this.configureProjectForm}
modal={false}
showHeader={false}
showActions={false}
useContainers={true}
values={values}
onFetchOptions={(request) => {
if (request.param === "add_filesystems") {
let promises: Promise<any>[] = [];
promises.push(this.clusterSettings().getModuleSettings({ module_id: Constants.MODULE_SHARED_STORAGE }));
return Promise.all(promises).then((result) => {
const choices: SocaUserInputChoice[] = [];
const sharedFileSystem = result[0].settings;
Object.keys(sharedFileSystem).forEach((name) => {
const storage = dot.pick(name, sharedFileSystem);
const title = dot.pick("title", storage);
const provider = dot.pick("provider", storage);
const mount_dir = dot.pick("mount_dir", storage);
if (Utils.isEmpty(provider)) {
return true;
}
const isInternal = name === "internal";
if (!isInternal && mount_dir && mount_dir !== Constants.SHARED_STORAGE_HOME_MOUNT_DIRECTORY) {
let choice: SocaUserInputChoice = {
title: `${title} [${provider}]`,
description: `${name}`,
value: `${name}`,
};
choices.push(choice);
}
});
return { listing: choices };
});
}
else if (request.param === "add_home_directory_filesystem") {
let promises: Promise<any>[] = [];
promises.push(this.clusterSettings().getModuleSettings({ module_id: Constants.MODULE_SHARED_STORAGE }));
return Promise.all(promises).then((result) => {
const choices: SocaUserInputChoice[] = [];
choices.push({
title: "Elastic Block Store volume [ebs]",
description: "home",
value: `${Constants.SHARED_STORAGE_EBS_VOLUME}`
})
const sharedFileSystem = result[0].settings;
Object.keys(sharedFileSystem).forEach((name) => {
const storage = dot.pick(name, sharedFileSystem);
const title = dot.pick("title", storage);
const provider = dot.pick("provider", storage);
const mount_dir = dot.pick("mount_dir", storage);
if (Utils.isEmpty(provider)) {
return true;
}
// S3 Bucket is not supported for home directory
if (mount_dir === Constants.SHARED_STORAGE_HOME_MOUNT_DIRECTORY && provider !== Constants.SHARED_STORAGE_PROVIDER_S3_BUCKET) {
let choice: SocaUserInputChoice = {
title: `${title} [${provider}]`,
description: name === "home" ? `global ${name}` : name,
value: name,
};
choices.push(choice);
}
});
return { listing: choices };
});
}
else if (request.param === "security_groups") {
if (!this.isAdmin()) {
return Promise.resolve({ listing: [] });
}
return this.projects().listSecurityGroups().then((result) => {
const security_groups = result.security_groups
if (!security_groups || security_groups?.length === 0) {
return {
listing: [],
}
} else {
const choices: SocaUserInputChoice[] = []
security_groups.forEach((security_group) => {
choices.push({
title: security_group.group_name,
value: security_group.group_id
})
})
return {
listing: choices
}
}
})
}
else if (request.param === "policy_arns") {
if (!this.isAdmin()) {
return Promise.resolve({ listing: [] });
}
return this.projects().listPolicies().then((result) => {
const policies = result.policies
if(!policies || policies?.length === 0) {
return {
listing: []
}
}
else{
const choices: SocaUserInputChoice[] = []
policies.forEach((policy) => {
choices.push({
title: policy.policy_name,
value: policy.policy_arn
})
})
return {
listing: choices
}
}
})
}
else if (request.param === "budget.budget_name") {
return this.getBudgets().then((result) => {
return {listing: result}
})
}
else {
return Promise.resolve({
listing: [],
});
}
}}
containerGroups={[
{
title: "Project Definition",
name: "project_definition",
},
{
title: "Resource Configurations",
name: "resource_configurations",
},
]}
params={[
{
name: "title",
title: "Title",
description: "Enter a user friendly project title.",
data_type: "str",
param_type: "text",
validate: {
required: true,
},
container_group_name: "project_definition",
readonly: !this.isAdmin(),
},
{
name: "name",
title: "Project ID",
description: "Enter a project-id.",
help_text: "Project ID can only use lowercase alphabets, numbers, hyphens (-), underscores (_), or periods (.). Must be between 3 and 40 characters long.",
data_type: "str",
param_type: "text",
readonly: isUpdate,
validate: {
required: true,
regex: "^[a-z0-9-_.]{3,40}$",
message: "Only use lowercase alphabets, numbers, hyphens (-), underscores (_), or periods (.). Must be between 3 and 40 characters long.",
},
container_group_name: "project_definition"
},
{
name: "description",
title: "Description",
description: "Enter the project description.",
data_type: "str",
param_type: "text",
multiline: true,
container_group_name: "project_definition",
readonly: !this.isAdmin(),
},
...this.buildAddFileSystemParam(isUpdate),
...this.buildAddHomeDirectoryFileSystemParam(isUpdate),
{
name: "allowed_sessions_per_user",
title: "Allowed sessions per user",
description: "Maximum number of sessions a user can launch in this project",
data_type: "int",
param_type: "text",
default: this.state.default_allowed_sessions_per_user_per_project,
multiline: false,
container_group_name: "project_definition",
validate: {
required: true,
min: 1,
},
readonly: !this.isAdmin(),
},
{
name: "enable_budgets",
title: "Enable budget assignment and tracking",
description: "To track budget status in the cost dashboard, specify the budget created in AWS Budgets",
data_type: "bool",
param_type: "confirm",
default: false,
validate: {
required: true,
},
container_group_name: "project_definition",
readonly: !this.isAdmin(),
},
{
name: "budget.budget_name",
title: "Budget name",
description: this.state.budgetNotFound ? <span style={{color: "red"}}> Budget associated with this project can not be found in the AWS account, please choose another one. </span> : "\n" +
"Select budget name that you have created in AWS Budget",
data_type: "str",
param_type: "select_or_text",
validate: {
required: true,
},
when: {
param: "enable_budgets",
eq: true,
},
container_group_name: "project_definition",
readonly: !this.isAdmin(),
dynamic_choices: true,
},
...this.buildResourceConfigurationAdvancedOptions()
]}
toolsOpen={this.props.toolsOpen}
tools={this.props.tools}
onToolsChange={this.props.onToolsChange}
/>
</div>
)
}