|
| 1 | +/* |
| 2 | + * SPDX-License-Identifier: Apache-2.0 |
| 3 | + * SPDX-FileCopyrightText: Huawei Inc. |
| 4 | + */ |
| 5 | + |
| 6 | +import { Table } from 'antd'; |
| 7 | +import { ColumnsType } from 'antd/es/table'; |
| 8 | +import React from 'react'; |
| 9 | +import catalogStyles from '../../../styles/catalog.module.css'; |
| 10 | +import deploymentVariablesStyles from '../../../styles/deployment-variables.module.css'; |
| 11 | +import { AnsibleScriptConfig, ServiceAction } from '../../../xpanse-api/generated'; |
| 12 | +import { getServiceConfigurationToolIcon } from '../serviceConfigurationManage/getServiceConfigurationToolIcon.ts'; |
| 13 | + |
| 14 | +interface ServiceActionChangeScript { |
| 15 | + type: string; |
| 16 | + changeHandler: string; |
| 17 | + runOnlyOnce: boolean; |
| 18 | + ansibleScriptConfig: AnsibleScriptConfig; |
| 19 | +} |
| 20 | + |
| 21 | +const getServiceActionScript = (serviceAction: ServiceAction) => { |
| 22 | + const serviceActionScript: ServiceActionChangeScript[] = []; |
| 23 | + if (serviceAction.actionManageScripts) { |
| 24 | + serviceAction.actionManageScripts.forEach((actionManageScript) => { |
| 25 | + serviceActionScript.push({ |
| 26 | + type: serviceAction.type, |
| 27 | + changeHandler: actionManageScript.changeHandler, |
| 28 | + runOnlyOnce: actionManageScript.runOnlyOnce, |
| 29 | + ansibleScriptConfig: actionManageScript.ansibleScriptConfig, |
| 30 | + }); |
| 31 | + }); |
| 32 | + } |
| 33 | + return serviceActionScript; |
| 34 | +}; |
| 35 | + |
| 36 | +function ServiceActionScripts({ serviceAction }: { serviceAction: ServiceAction }): React.JSX.Element { |
| 37 | + const columns: ColumnsType<ServiceActionChangeScript> = [ |
| 38 | + { |
| 39 | + title: <div className={deploymentVariablesStyles.variablesColumns}>Type</div>, |
| 40 | + dataIndex: 'type', |
| 41 | + render: (text: string) => { |
| 42 | + return <img src={getServiceConfigurationToolIcon(text)} alt={text} />; |
| 43 | + }, |
| 44 | + width: '5%', |
| 45 | + }, |
| 46 | + { |
| 47 | + title: <div className={deploymentVariablesStyles.variablesColumns}>ChangeHandler</div>, |
| 48 | + dataIndex: 'changeHandler', |
| 49 | + render: (text: string) => { |
| 50 | + return <div className={deploymentVariablesStyles.variablesColumns}>{text}</div>; |
| 51 | + }, |
| 52 | + }, |
| 53 | + { |
| 54 | + title: <div className={deploymentVariablesStyles.variablesColumns}>RunOnlyOnce</div>, |
| 55 | + dataIndex: 'runOnlyOnce', |
| 56 | + render: (text: boolean | undefined | null) => { |
| 57 | + if (text === true) { |
| 58 | + return <div className={deploymentVariablesStyles.variablesColumns}>{`true`}</div>; |
| 59 | + } else if (text === false) { |
| 60 | + return <div className={deploymentVariablesStyles.variablesColumns}>{`false`}</div>; |
| 61 | + } else { |
| 62 | + return null; |
| 63 | + } |
| 64 | + }, |
| 65 | + }, |
| 66 | + { |
| 67 | + title: <div className={deploymentVariablesStyles.variablesColumns}>AnsibleScriptConfig</div>, |
| 68 | + dataIndex: 'ansibleScriptConfig', |
| 69 | + children: [ |
| 70 | + { |
| 71 | + title: <div className={deploymentVariablesStyles.variablesTableChildrenTitle}>Playbook Name</div>, |
| 72 | + dataIndex: ['ansibleScriptConfig', 'playbookName'], |
| 73 | + key: 'playbookName', |
| 74 | + render: (text: string) => { |
| 75 | + return <div className={deploymentVariablesStyles.variablesColumns}>{text}</div>; |
| 76 | + }, |
| 77 | + }, |
| 78 | + { |
| 79 | + title: <div className={deploymentVariablesStyles.variablesTableChildrenTitle}>Virtual Env</div>, |
| 80 | + dataIndex: ['ansibleScriptConfig', 'virtualEnv'], |
| 81 | + key: 'virtualEnv', |
| 82 | + render: (text: string) => { |
| 83 | + return <div className={deploymentVariablesStyles.variablesColumns}>{text}</div>; |
| 84 | + }, |
| 85 | + }, |
| 86 | + { |
| 87 | + title: <div className={deploymentVariablesStyles.variablesTableChildrenTitle}>Python Version</div>, |
| 88 | + dataIndex: ['ansibleScriptConfig', 'pythonVersion'], |
| 89 | + key: 'pythonVersion', |
| 90 | + render: (text: string) => { |
| 91 | + return <div className={deploymentVariablesStyles.variablesColumns}>{text}</div>; |
| 92 | + }, |
| 93 | + }, |
| 94 | + { |
| 95 | + title: ( |
| 96 | + <div className={deploymentVariablesStyles.variablesTableChildrenTitle}> |
| 97 | + Is Prepare Ansible Environment |
| 98 | + </div> |
| 99 | + ), |
| 100 | + dataIndex: ['ansibleScriptConfig', 'isPrepareAnsibleEnvironment'], |
| 101 | + key: 'isPrepareAnsibleEnvironment', |
| 102 | + render: (text: boolean | undefined | null) => { |
| 103 | + if (text === true) { |
| 104 | + return <div className={deploymentVariablesStyles.variablesColumns}>{`true`}</div>; |
| 105 | + } else if (text === false) { |
| 106 | + return <div className={deploymentVariablesStyles.variablesColumns}>{`false`}</div>; |
| 107 | + } else { |
| 108 | + return null; |
| 109 | + } |
| 110 | + }, |
| 111 | + }, |
| 112 | + { |
| 113 | + title: <div className={deploymentVariablesStyles.variablesTableChildrenTitle}>RepoUrl</div>, |
| 114 | + dataIndex: ['ansibleScriptConfig', 'repoUrl'], |
| 115 | + key: 'repoUrl', |
| 116 | + render: (text: string) => { |
| 117 | + return <div className={deploymentVariablesStyles.variablesColumns}>{text}</div>; |
| 118 | + }, |
| 119 | + }, |
| 120 | + { |
| 121 | + title: <div className={deploymentVariablesStyles.variablesTableChildrenTitle}>Branch</div>, |
| 122 | + dataIndex: ['ansibleScriptConfig', 'branch'], |
| 123 | + key: 'branch', |
| 124 | + render: (text: string) => { |
| 125 | + return <div className={deploymentVariablesStyles.variablesColumns}>{text}</div>; |
| 126 | + }, |
| 127 | + }, |
| 128 | + { |
| 129 | + title: ( |
| 130 | + <div className={deploymentVariablesStyles.variablesTableChildrenTitle}>RequirementsFile</div> |
| 131 | + ), |
| 132 | + dataIndex: ['ansibleScriptConfig', 'requirementsFile'], |
| 133 | + key: 'requirementsFile', |
| 134 | + render: (text: string) => { |
| 135 | + return <div className={deploymentVariablesStyles.variablesColumns}>{text}</div>; |
| 136 | + }, |
| 137 | + }, |
| 138 | + { |
| 139 | + title: <div className={deploymentVariablesStyles.variablesTableChildrenTitle}>GalaxyFile</div>, |
| 140 | + dataIndex: ['ansibleScriptConfig', 'galaxyFile'], |
| 141 | + key: 'galaxyFile', |
| 142 | + render: (text: string) => { |
| 143 | + return <div className={deploymentVariablesStyles.variablesColumns}>{text}</div>; |
| 144 | + }, |
| 145 | + }, |
| 146 | + { |
| 147 | + title: ( |
| 148 | + <div className={deploymentVariablesStyles.variablesTableChildrenTitle}> |
| 149 | + AnsibleInventoryRequired |
| 150 | + </div> |
| 151 | + ), |
| 152 | + dataIndex: ['ansibleScriptConfig', 'ansibleInventoryRequired'], |
| 153 | + key: 'ansibleInventoryRequired', |
| 154 | + render: (text: boolean | undefined | null) => { |
| 155 | + if (text === true) { |
| 156 | + return <div className={deploymentVariablesStyles.variablesColumns}>{`true`}</div>; |
| 157 | + } else if (text === false) { |
| 158 | + return <div className={deploymentVariablesStyles.variablesColumns}>{`false`}</div>; |
| 159 | + } else { |
| 160 | + return null; |
| 161 | + } |
| 162 | + }, |
| 163 | + }, |
| 164 | + ], |
| 165 | + }, |
| 166 | + ]; |
| 167 | + |
| 168 | + return ( |
| 169 | + <> |
| 170 | + <div className={`${catalogStyles.catalogDetailsH6} ${catalogStyles.managementVariable}`}> |
| 171 | + Service Action Scripts |
| 172 | + </div> |
| 173 | + <div className={deploymentVariablesStyles.variablesTableContainer}> |
| 174 | + <Table |
| 175 | + bordered |
| 176 | + columns={columns} |
| 177 | + dataSource={getServiceActionScript(serviceAction)} |
| 178 | + rowKey={'name'} |
| 179 | + pagination={false} |
| 180 | + /> |
| 181 | + </div> |
| 182 | + </> |
| 183 | + ); |
| 184 | +} |
| 185 | + |
| 186 | +export default ServiceActionScripts; |
0 commit comments