@@ -4,6 +4,8 @@ import styled from "styled-components";
4
4
5
5
import { Button } from "components" ;
6
6
7
+ import { ConnectionFormMode } from "views/Connection/ConnectionForm/ConnectionForm" ;
8
+
7
9
import { EditorHeader } from "./components/EditorHeader" ;
8
10
import { EditorRow } from "./components/EditorRow" ;
9
11
@@ -26,7 +28,7 @@ const Content = styled.div`
26
28
margin-bottom: 20px;
27
29
` ;
28
30
29
- type ArrayOfObjectsEditorProps < T extends { name : string } > = {
31
+ export interface ArrayOfObjectsEditorProps < T extends { name : string } > {
30
32
items : T [ ] ;
31
33
editableItemIndex ?: number | string | null ;
32
34
children : ( item ?: T ) => React . ReactNode ;
@@ -36,20 +38,26 @@ type ArrayOfObjectsEditorProps<T extends { name: string }> = {
36
38
onCancelEdit ?: ( ) => void ;
37
39
onDone ?: ( ) => void ;
38
40
onRemove : ( index : number ) => void ;
39
- } ;
41
+ mode ?: ConnectionFormMode ;
42
+ }
40
43
41
- function ArrayOfObjectsEditor < T extends { name : string } = { name : string } > (
42
- props : ArrayOfObjectsEditorProps < T >
43
- ) : JSX . Element {
44
- const { onStartEdit, onDone, onRemove, onCancelEdit, items, editableItemIndex, children, mainTitle, addButtonText } =
45
- props ;
44
+ export function ArrayOfObjectsEditor < T extends { name : string } = { name : string } > ( {
45
+ onStartEdit,
46
+ onDone,
47
+ onRemove,
48
+ onCancelEdit,
49
+ items,
50
+ editableItemIndex,
51
+ children,
52
+ mainTitle,
53
+ addButtonText,
54
+ mode,
55
+ } : ArrayOfObjectsEditorProps < T > ) : JSX . Element {
46
56
const onAddItem = React . useCallback ( ( ) => onStartEdit ( items . length ) , [ onStartEdit , items ] ) ;
47
57
48
- const isEditMode = editableItemIndex !== null && editableItemIndex !== undefined ;
49
-
50
- if ( isEditMode ) {
58
+ const isEditable = editableItemIndex !== null && editableItemIndex !== undefined ;
59
+ if ( mode !== "readonly" && isEditable ) {
51
60
const item = typeof editableItemIndex === "number" ? items [ editableItemIndex ] : undefined ;
52
-
53
61
return (
54
62
< Content >
55
63
{ children ( item ) }
@@ -78,6 +86,7 @@ function ArrayOfObjectsEditor<T extends { name: string } = { name: string }>(
78
86
onAddItem = { onAddItem }
79
87
mainTitle = { mainTitle }
80
88
addButtonText = { addButtonText }
89
+ mode = { mode }
81
90
/>
82
91
{ items . length ? (
83
92
< ItemsList >
@@ -89,6 +98,3 @@ function ArrayOfObjectsEditor<T extends { name: string } = { name: string }>(
89
98
</ Content >
90
99
) ;
91
100
}
92
-
93
- export { ArrayOfObjectsEditor } ;
94
- export type { ArrayOfObjectsEditorProps } ;
0 commit comments