Skip to content

Commit 878af1f

Browse files
canpturaOhKaiFelipeTrost
authored
Ms2/config editor layout overhaul (#400)
* styling for parameter keys and nested parameter cards changed * editor style improvements * editor layout now more compact * "defaultParameter"-function rework * refactoring of types and component names, also small styling improvements for config editor * nesting indentation fixed * show/hide internal ID toolip improved * Action Button added to Target Config in Editor * removed old debug code and comments * unnecessary useRef removed * config creation modal now supports arrow key inputs * missing description on creation fixed --------- Co-authored-by: Kai Rohwer <[email protected]> Co-authored-by: Felipe Trost H. <[email protected]>
1 parent eb54bfd commit 878af1f

19 files changed

+448
-435
lines changed

src/management-system-v2/app/(dashboard)/[environmentId]/machine-config/[configId]/action-buttons.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ type ActionButtonsProps = {
1515
const ActionButtons: React.FC<ActionButtonsProps> = ({ editable, options, actions }) => {
1616
return (
1717
<Space.Compact className={styles.ActionButtons} size="small">
18-
{options.includes('copy') && (
18+
{editable && options.includes('copy') && (
1919
<Tooltip title="Copy">
2020
<Button icon={<CopyOutlined />} type="text" onClick={actions?.copy} />
2121
</Tooltip>
2222
)}
23-
{options.includes('edit') && (
23+
{editable && options.includes('edit') && (
2424
<Tooltip title="Edit">
2525
<Button icon={<EditOutlined />} type="text" onClick={actions?.edit} />
2626
</Tooltip>

src/management-system-v2/app/(dashboard)/[environmentId]/machine-config/[configId]/config-content.tsx

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { useRouter } from 'next/navigation';
55

66
import { KeyOutlined, EyeInvisibleOutlined, EyeOutlined } from '@ant-design/icons';
77
import { useState } from 'react';
8-
import { Button, Input, Col, Row, Tooltip } from 'antd';
8+
import { Button, Input, Col, Row, Tooltip, Space } from 'antd';
99
import { defaultParameter } from '../configuration-helper';
1010
import AddButton from './add-button';
1111
import CreateParameterModal, { CreateParameterModalReturnType } from './create-parameter-modal';
@@ -38,8 +38,9 @@ const Content: React.FC<MachineDataViewProps> = ({
3838
const addParameter = async (values: CreateParameterModalReturnType[]) => {
3939
const valuesFromModal = values[0];
4040
const newParameter = defaultParameter(
41-
valuesFromModal.displayName,
41+
valuesFromModal.key ?? '',
4242
valuesFromModal.value,
43+
valuesFromModal.displayName,
4344
valuesFromModal.language,
4445
valuesFromModal.unit,
4546
);
@@ -61,6 +62,7 @@ const Content: React.FC<MachineDataViewProps> = ({
6162
return (
6263
<>
6364
{(idVisible || editable) && contentType === 'metadata' && (
65+
// Row: ID
6466
<Row gutter={[24, 24]} align="middle" style={{ margin: '10px 0' }}>
6567
<Col span={3} className="gutter-row">
6668
Internal ID
@@ -70,33 +72,38 @@ const Content: React.FC<MachineDataViewProps> = ({
7072
</Col>
7173
{editable && (
7274
<Col span={1}>
73-
<Tooltip title="Hide Internal ID">
75+
<Tooltip title={idVisible ? 'Hide Internal ID' : 'Show Internal ID'}>
7476
<Button
7577
size="small"
7678
disabled={!editable}
7779
onClick={() => {
7880
setIdVisible(!idVisible);
7981
}}
80-
icon={idVisible ? <EyeInvisibleOutlined /> : <EyeOutlined />}
82+
icon={idVisible ? <EyeOutlined /> : <EyeInvisibleOutlined />}
8183
type="text"
8284
/>
8385
</Tooltip>
8486
</Col>
8587
)}
8688
</Row>
8789
)}
88-
{Object.entries(data).map(([key, val]) => (
89-
<CustomField
90-
parentConfig={parentConfig}
91-
key={key}
92-
keyId={key}
93-
parameter={val}
94-
editable={editable}
95-
/>
96-
))}
90+
91+
<Space direction="vertical" style={{ display: 'flex' }}>
92+
{Object.entries(data).map(([key, val]) => (
93+
// Rows: Metadata, Parameter, Nested Parameters, Linked Parameter
94+
<CustomField
95+
parentConfig={parentConfig}
96+
key={key}
97+
keyId={key}
98+
parameter={val}
99+
editable={editable}
100+
/>
101+
))}
102+
</Space>
103+
97104
{editable && (
105+
// Row: Add Meta/Parameter
98106
<Row gutter={[24, 24]} align="middle" style={{ margin: '10px 0' }}>
99-
{/* <Col span={3} className="gutter-row" /> */}
100107
<Col span={21} className="gutter-row">
101108
<AddButton label={addButtonTitle} onClick={() => setCreateFieldOpen(true)} />
102109
</Col>

src/management-system-v2/app/(dashboard)/[environmentId]/machine-config/[configId]/config-editor.tsx

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,16 @@ import Title from 'antd/es/typography/Title';
4646
import { spaceURL } from '@/lib/utils';
4747
import VersionCreationButton from '@/components/version-creation-button';
4848
import AddButton from './add-button';
49-
import MachineConfigModal from '@/components/machine-config-modal';
49+
import ConfigModal from '@/components/config-modal';
5050
import {
5151
addMachineConfig,
5252
addTargetConfig,
53+
removeTargetConfig,
5354
updateMachineConfig,
5455
updateParentConfig,
5556
updateTargetConfig,
5657
} from '@/lib/data/legacy/machine-config';
58+
import ActionButtons from './action-buttons';
5759
type MachineDataViewProps = {
5860
selectedConfig: AbstractConfig;
5961
parentConfig: ParentConfig;
@@ -127,9 +129,11 @@ const ConfigEditor: React.FC<MachineDataViewProps> = ({
127129

128130
const { token } = theme.useToken();
129131
const panelStyle = {
130-
marginBottom: 16,
132+
marginBottom: 32,
131133
background: token.colorFillAlter,
132134
borderRadius: token.borderRadiusLG,
135+
boxShadow:
136+
'2px 2px 6px -4px rgba(0, 0, 0, 0.12), 4px 4px 16px 0px rgba(0, 0, 0, 0.08), 6px 6px 28px 8px rgba(0, 0, 0, 0.05)',
133137
//border: 'none',
134138
};
135139

@@ -193,6 +197,11 @@ const ConfigEditor: React.FC<MachineDataViewProps> = ({
193197
router.refresh();
194198
};
195199

200+
const handleDelete = async (id: string) => {
201+
if (id) await removeTargetConfig(id);
202+
router.refresh();
203+
};
204+
196205
const exportCurrentConfig = () => {
197206
const blob = new Blob([JSON.stringify([selectedConfig], null, 2)], {
198207
type: 'application/json',
@@ -222,9 +231,9 @@ const ConfigEditor: React.FC<MachineDataViewProps> = ({
222231
editingEnabled={editable}
223232
/>
224233
),
225-
/* extra: <Tooltip editable={editable} options={['copy', 'edit']} actions={...}/>, */ ///TODO
226-
style: { ...panelStyle, border: '1px solid #87e8de' }, //cyan-3
234+
style: { ...panelStyle, border: '1px solid #87e8de', background: 'rgba(255, 255, 255, 0.9)' }, //cyan-3
227235
});
236+
228237
if (selectedConfig.type === 'config') {
229238
const currentConfig = selectedConfig as ParentConfig;
230239
if (currentConfig.targetConfig) {
@@ -233,8 +242,19 @@ const ConfigEditor: React.FC<MachineDataViewProps> = ({
233242
key: '2',
234243
label: title,
235244
children: <TargetConfiguration parentConfig={parentConfig} editingEnabled={editable} />,
236-
/* extra: <Tooltip editable={editable} options={['copy', 'edit', 'delete']} actions={...}/> */ //TODO
237-
style: { ...panelStyle, border: '1px solid #91caff' }, //blue-3
245+
extra: (
246+
// TODO stop propagation to collapse component on click
247+
<ActionButtons
248+
editable={editable}
249+
options={['delete']}
250+
actions={{ delete: () => handleDelete(currentConfig.targetConfig?.id ?? '') }}
251+
/>
252+
),
253+
style: {
254+
...panelStyle,
255+
border: '1px solid #91caff',
256+
background: '#f0f4f9',
257+
}, //blue-3
238258
});
239259
}
240260
} else if (
@@ -261,7 +281,7 @@ const ConfigEditor: React.FC<MachineDataViewProps> = ({
261281
return panels;
262282
}, [editable, selectedConfig]);
263283

264-
const machineConfigModalTitle =
284+
const configModalTitle =
265285
createConfigType === 'target' ? 'Create Target Tech Data Set' : 'Create Machine Tech Data Set';
266286

267287
return (
@@ -411,15 +431,16 @@ const ConfigEditor: React.FC<MachineDataViewProps> = ({
411431
}}
412432
items={collapseItems}
413433
/>
434+
414435
{selectedConfig.type === 'config' && (
415436
<MachineConfigurations parentConfig={parentConfig} editingEnabled={editable} />
416437
)}
417438
</Content>
418439
</Layout>
419440

420-
<MachineConfigModal
441+
<ConfigModal
421442
open={!!createConfigType}
422-
title={machineConfigModalTitle}
443+
title={configModalTitle}
423444
onCancel={() => setCreateConfigType('')}
424445
onSubmit={handleCreateConfig}
425446
configType={createConfigType}

src/management-system-v2/app/(dashboard)/[environmentId]/machine-config/[configId]/config-page-content.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ const ConfigContent: React.FC<VariablesEditorProps> = ({ parentConfig }) => {
260260
</div>
261261
)}
262262
</ResizableBox>
263+
263264
<Row style={{ flexGrow: 1, flexShrink: 1 }}>
264265
<Col style={{ width: '100%', height: '100%' }}>
265266
{'content' in selectedNode ? (

src/management-system-v2/app/(dashboard)/[environmentId]/machine-config/[configId]/config-tree-view.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
findConfig,
2020
findParameter,
2121
} from '../configuration-helper';
22-
import MachineConfigModal from '@/components/machine-config-modal';
22+
import ConfigModal from '@/components/config-modal';
2323
import CreateParameterModal, { CreateParameterModalReturnType } from './create-parameter-modal';
2424

2525
import {
@@ -115,7 +115,7 @@ const ConfigurationTreeView: React.FC<ConfigurationTreeViewProps> = ({
115115
addType: 'parameters' | 'metadata',
116116
) => {
117117
const { key, displayName, value, language, unit } = valuesFromModal;
118-
const newParameter = defaultParameter(key || displayName, value, language, unit);
118+
const newParameter = defaultParameter(key ?? '', value, displayName, language, unit);
119119
let type: StoredParameter['parentType'] =
120120
rightClickedType === 'config' ? 'parent-config' : rightClickedType;
121121
await backendAddParameter(rightClickedId, type, addType, key || displayName, newParameter);
@@ -249,7 +249,7 @@ const ConfigurationTreeView: React.FC<ConfigurationTreeViewProps> = ({
249249
</p>
250250
</Modal>
251251

252-
<MachineConfigModal
252+
<ConfigModal
253253
open={openModal === 'machine-config' || openModal === 'target-config'}
254254
title={`Creating ${openModal === 'target-config' ? 'target' : 'machine'} configuration`}
255255
onCancel={closeModal}

src/management-system-v2/app/(dashboard)/[environmentId]/machine-config/[configId]/create-parameter-modal.tsx

Lines changed: 42 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use client';
22

33
import React, { useEffect, useRef, useState } from 'react';
4-
import { Modal, Form, Input, App, Collapse, CollapseProps, Select } from 'antd';
4+
import { Modal, Form, Input, App, Collapse, CollapseProps, Select, Card, Typography } from 'antd';
55
import { UserError } from '@/lib/user-error';
66
import { Localization, languageItemsSelect } from '@/lib/data/locale';
77

@@ -139,42 +139,47 @@ const ParameterInputs = ({ index, showKey }: CreateParameterInputsProps) => {
139139
<Input />
140140
</Form.Item>
141141
)}
142-
<Form.Item
143-
name={[index, 'displayName']}
144-
label="Display Name"
145-
rules={[{ required: true, message: 'Please fill out the Display Name' }]}
146-
>
147-
<Input />
148-
</Form.Item>
149-
<Form.Item
150-
name={[index, 'value']}
151-
label="Value"
152-
rules={[{ required: false, message: 'Please fill out the Value' }]}
153-
>
154-
<Input />
155-
</Form.Item>
156-
<Form.Item
157-
name={[index, 'unit']}
158-
label="Unit"
159-
rules={[{ required: false, message: 'Please fill out the Unit' }]}
160-
>
161-
<Input />
162-
</Form.Item>
163-
<Form.Item
164-
name={[index, 'language']}
165-
label="Language"
166-
rules={[{ required: false, message: 'Please fill out the Language' }]}
167-
>
168-
<Select
169-
showSearch
170-
placeholder="Search to Select"
171-
optionFilterProp="label"
172-
filterSort={(optionA, optionB) =>
173-
(optionA?.label ?? '').toLowerCase().localeCompare((optionB?.label ?? '').toLowerCase())
174-
}
175-
options={languageItemsSelect}
176-
/>
177-
</Form.Item>
142+
<Card size="small" style={{ background: 'rgba(0,0,0,0.02)' }}>
143+
<Typography.Paragraph strong>Entry Data</Typography.Paragraph>
144+
<Form.Item
145+
name={[index, 'displayName']}
146+
label="Display Name"
147+
rules={[{ required: false, message: 'Please fill out the Display Name' }]}
148+
>
149+
<Input />
150+
</Form.Item>
151+
<Form.Item
152+
name={[index, 'value']}
153+
label="Value"
154+
rules={[{ required: false, message: 'Please fill out the Value' }]}
155+
>
156+
<Input />
157+
</Form.Item>
158+
<Form.Item
159+
name={[index, 'unit']}
160+
label="Unit"
161+
rules={[{ required: false, message: 'Please fill out the Unit' }]}
162+
>
163+
<Input />
164+
</Form.Item>
165+
<Form.Item
166+
name={[index, 'language']}
167+
label="Language"
168+
rules={[{ required: false, message: 'Please fill out the Language' }]}
169+
>
170+
<Select
171+
showSearch
172+
placeholder="Search to Select"
173+
optionFilterProp="label"
174+
filterSort={(optionA, optionB) =>
175+
(optionA?.label ?? '')
176+
.toLowerCase()
177+
.localeCompare((optionB?.label ?? '').toLowerCase())
178+
}
179+
options={languageItemsSelect}
180+
/>
181+
</Form.Item>
182+
</Card>
178183
</>
179184
);
180185
};

0 commit comments

Comments
 (0)