1- import { MoveOperation } from "../modalHelpers/moveOperation"
2- import { makeSelectBox } from "../utils"
3- import { validatePolicy } from "./utils"
41import React from "react"
2+ import { MoveOperation } from "../componentHelpers/MoveOperation"
3+ import { SelectBox } from "../componentHelpers/SelectBox"
4+ import { TextInput } from "../componentHelpers/TextInput"
5+ import { validatePolicy } from "./utils"
56
67const actionOptions = [
78 { value : "protect" , label : "Protect image" } ,
@@ -45,24 +46,6 @@ const GCPoliciesEditRow = ({
4546 setPolicyAttribute,
4647 removePolicy,
4748} ) => {
48- const makeTextInput = ( attr , value ) => {
49- value = value || ""
50- if ( ! isEditable ) {
51- if ( value === "" ) {
52- return < em > Any</ em >
53- }
54- return < code > { value || "" } </ code >
55- }
56- return (
57- < input
58- type = "text"
59- value = { value }
60- className = "form-control"
61- onChange = { ( e ) => setPolicyAttribute ( index , attr , e . target . value ) }
62- />
63- )
64- }
65-
6649 const makeNumberInput = ( attr , value ) => {
6750 value = value || 0
6851 if ( ! isEditable ) {
@@ -74,130 +57,147 @@ const GCPoliciesEditRow = ({
7457 value = { value . toString ( ) }
7558 className = "form-control"
7659 min = "1"
77- onChange = { ( e ) =>
78- setPolicyAttribute ( index , attr , parseInt ( e . target . value , 10 ) )
79- }
60+ onChange = { ( e ) => setPolicyAttribute ( index , attr , parseInt ( e . target . value , 10 ) ) }
8061 />
8162 )
8263 }
8364
8465 const timeConstraint = policy . time_constraint || { }
8566 const currentTimestampOption = timeConstraint . on || "off"
86- const currentTimeConstraintOption = timeConstraintOptions
87- . map ( ( o ) => o . value )
88- . find ( ( key ) => key in timeConstraint )
67+ const currentTimeConstraintOption = timeConstraintOptions . map ( ( o ) => o . value ) . find ( ( key ) => key in timeConstraint )
8968
9069 const validationError = validatePolicy ( policy )
9170
9271 return (
9372 < tr >
9473 { isEditable ? (
9574 < td key = "order" className = "policy-order-buttons" >
96- < MoveOperation
97- index = { index }
98- itemCount = { policyCount }
99- onMove = { movePolicy }
100- />
75+ < MoveOperation index = { index } itemCount = { policyCount } onMove = { movePolicy } />
10176 </ td >
10277 ) : (
10378 < td key = "order" className = "policy-order-buttons" > </ td >
10479 ) }
10580 < td >
106- { makeSelectBox ( {
107- isEditable,
108- options : actionOptions ,
109- value : policy . action ,
110- onChange : ( e ) => setPolicyAttribute ( index , "action" , e . target . value ) ,
111- } ) }
81+ {
82+ < SelectBox
83+ isEditable = { isEditable }
84+ options = { actionOptions }
85+ value = { policy . action }
86+ onChange = { ( e ) => setPolicyAttribute ( index , "action" , e . target . value ) }
87+ />
88+ }
11289 </ td >
11390 < td className = "form-inline" >
11491 < div className = "policy-matching-rule-line" >
115- { makeSelectBox ( {
116- isEditable,
117- options : repoFilterOptions ,
118- value : policy . ui_hints . repo_filter ,
119- onChange : ( e ) =>
120- setPolicyAttribute ( index , "repo_filter" , e . target . value ) ,
121- } ) }
92+ {
93+ < SelectBox
94+ isEditable = { isEditable }
95+ options = { repoFilterOptions }
96+ value = { policy . ui_hints . repo_filter }
97+ onChange = { ( e ) => setPolicyAttribute ( index , "repo_filter" , e . target . value ) }
98+ />
99+ }
122100 { policy . ui_hints . repo_filter === "on" && (
123101 < >
124102 { " regex " }
125- { makeTextInput ( "match_repository" , policy . match_repository ) }
103+ < TextInput
104+ value = { policy . match_repository }
105+ isEditable = { isEditable }
106+ onChange = { ( e ) => {
107+ setPolicyAttribute ( index , "match_repository" , e . target . value )
108+ } }
109+ />
126110 { ( isEditable || policy . except_repository ) && (
127111 < >
128112 { " but not regex " }
129- { makeTextInput ( "except_repository" , policy . except_repository ) }
113+ < TextInput
114+ value = { policy . except_repository }
115+ isEditable = { isEditable }
116+ onChange = { ( e ) => {
117+ setPolicyAttribute ( index , "except_repository" , e . target . value )
118+ } }
119+ />
130120 </ >
131121 ) }
132122 </ >
133123 ) }
134124 </ div >
135125 < div className = "policy-matching-rule-line" >
136- { makeSelectBox ( {
137- isEditable,
138- options : tagFilterOptions ,
139- value : policy . ui_hints . tag_filter ,
140- onChange : ( e ) =>
141- setPolicyAttribute ( index , "tag_filter" , e . target . value ) ,
142- } ) }
126+ {
127+ < SelectBox
128+ isEditable = { isEditable }
129+ options = { tagFilterOptions }
130+ value = { policy . ui_hints . tag_filter }
131+ onChange = { ( e ) => setPolicyAttribute ( index , "tag_filter" , e . target . value ) }
132+ />
133+ }
143134 { policy . ui_hints . tag_filter === "on" && (
144135 < >
145136 { " regex " }
146- { makeTextInput ( "match_tag" , policy . match_tag ) }
137+ < TextInput
138+ value = { policy . match_tag }
139+ isEditable = { isEditable }
140+ onChange = { ( e ) => {
141+ setPolicyAttribute ( index , "match_tag" , e . target . value )
142+ } }
143+ />
147144 { ( isEditable || policy . except_tag ) && (
148145 < >
149146 { " but not regex " }
150- { makeTextInput ( "except_tag" , policy . except_tag ) }
147+ < TextInput
148+ value = { policy . match_tag }
149+ isEditable = { isEditable }
150+ onChange = { ( e ) => {
151+ setPolicyAttribute ( index , "except_tag" , e . target . value )
152+ } }
153+ />
151154 </ >
152155 ) }
153156 </ >
154157 ) }
155158 </ div >
156159 < div className = "policy-matching-rule-line" >
157- { makeSelectBox ( {
158- isEditable,
159- options : timestampOptions ,
160- value : currentTimestampOption ,
161- onChange : ( e ) =>
162- setPolicyAttribute ( index , "timestamp" , e . target . value ) ,
163- } ) }
160+ {
161+ < SelectBox
162+ isEditable = { isEditable }
163+ options = { timestampOptions }
164+ value = { currentTimestampOption }
165+ onChange = { ( e ) => setPolicyAttribute ( index , "timestamp" , e . target . value ) }
166+ />
167+ }
164168 { currentTimestampOption !== "off" && (
165169 < >
166170 { " " }
167- { makeSelectBox ( {
168- isEditable ,
169- options : timeConstraintOptions ,
170- value : currentTimeConstraintOption ,
171- onChange : ( e ) =>
172- setPolicyAttribute ( index , "time_constraint" , e . target . value ) ,
173- } ) }
174- { ( currentTimeConstraintOption === "oldest" ||
175- currentTimeConstraintOption == "newest" ) && (
171+ {
172+ < SelectBox
173+ isEditable = { isEditable }
174+ options = { timeConstraintOptions }
175+ value = { currentTimeConstraintOption }
176+ onChange = { ( e ) => setPolicyAttribute ( index , "time_constraint" , e . target . value ) }
177+ />
178+ }
179+ { ( currentTimeConstraintOption === "oldest" || currentTimeConstraintOption == "newest" ) && (
176180 < >
177181 { " " }
178- { makeNumberInput (
179- currentTimeConstraintOption ,
180- policy . time_constraint [ currentTimeConstraintOption ]
181- ) }
182+ { makeNumberInput ( currentTimeConstraintOption , policy . time_constraint [ currentTimeConstraintOption ] ) }
182183 { " in this repository" }
183184 </ >
184185 ) }
185- { ( currentTimeConstraintOption === "older_than" ||
186- currentTimeConstraintOption == "newer_than" ) && (
186+ { ( currentTimeConstraintOption === "older_than" || currentTimeConstraintOption == "newer_than" ) && (
187187 < >
188188 { " " }
189189 { makeNumberInput (
190190 currentTimeConstraintOption ,
191191 policy . time_constraint [ currentTimeConstraintOption ] . value
192192 ) } { " " }
193- { makeSelectBox ( {
194- isEditable ,
195- options : timeUnitOptions ,
196- value :
197- policy . time_constraint [ currentTimeConstraintOption ] . unit ,
198- onChange : ( e ) =>
199- setPolicyAttribute ( index , "time_unit" , e . target . value ) ,
200- } ) }
193+ {
194+ < SelectBox
195+ isEditable = { isEditable }
196+ options = { timeUnitOptions }
197+ value = { policy . time_constraint [ currentTimeConstraintOption ] . unit }
198+ onChange = { ( e ) => setPolicyAttribute ( index , "time_unit" , e . target . value ) }
199+ />
200+ }
201201 </ >
202202 ) }
203203 </ >
0 commit comments