@@ -94,12 +94,15 @@ export default function GroupRules({ ruleModeState, rulesState }) {
9494
9595 if ( Object . keys ( partial ) . includes ( 'name' ) ) {
9696 updatedRule . operandCount = availableRule . operandCount
97+ if ( updatedRule . operandCount === 0 ) {
98+ updatedRule . operands = { }
99+ }
97100 } else if ( Object . keys ( partial ) . includes ( 'field' ) ) {
98101 const availableField = availableFields . find ( ( f ) => f . field === partial . field )
99102
100103 updatedRule . name = findRuleByName ( 'EQUALS' ) . name
101104 updatedRule . propKey = availableField . mapsTo . startsWith ( 'META_' ) ? availableField . mapsTo : ''
102- updatedRule . mapsTo = availableField . mapsTo
105+ updatedRule . mapsTo = availableField . mapsTo . startsWith ( 'META_' ) ? 'props' : availableField . mapsTo
103106 updatedRule . castType = availableField . defaultCastType
104107 for ( const key in updatedRule . operands ) {
105108 updatedRule . operands [ key ] = ''
@@ -142,84 +145,106 @@ export default function GroupRules({ ruleModeState, rulesState }) {
142145 < p className = 'text-sm' > All players</ p >
143146
144147 { rules . length > 0 &&
145- < div className = 'divide-y space-y-4' >
146- { rules . map ( ( rule , idx ) => (
147- < div key = { idx } className = 'text-sm space-y-2 pt-4 first:pt-0' >
148- < div className = 'flex items-center space-x-2' >
149- < div className = '-translate-y-0.5 w-[12px] h-[8px] border-l border-b border-gray-300' />
148+ < div className = 'divide-y space-y-4' >
149+ { rules . map ( ( rule , idx ) => (
150+ < div key = { idx } className = 'text-sm space-y-2 pt-4 first:pt-0' >
151+ < div className = 'flex items-center space-x-2' >
152+ < div className = '-translate-y-0.5 w-[12px] h-[8px] border-l border-b border-gray-300' />
153+
154+ < div >
155+ { idx === 0 && < span className = 'text-gray-500' > where</ span > }
156+
157+ { idx > 0 &&
158+ < DropdownMenu
159+ options = { [
160+ { label : 'and' , onClick : ( ) => setRuleMode ( '$and' ) } ,
161+ { label : 'or' , onClick : ( ) => setRuleMode ( '$or' ) }
162+ ] }
163+ >
164+ { ( setOpen ) => (
165+ < Button
166+ type = 'button'
167+ onClick = { setOpen }
168+ variant = 'small'
169+ >
170+ { ruleMode . substring ( 1 , ruleMode . length ) }
171+ </ Button >
172+ ) }
173+ </ DropdownMenu >
174+ }
175+ </ div >
176+
177+ < DropdownMenu
178+ options = { availableFields . map ( ( { field } ) => ( {
179+ label : field ,
180+ onClick : ( ) => {
181+ updateRule ( idx , { field } )
182+ }
183+ } ) ) }
184+ >
185+ { ( setOpen ) => (
186+ < Button
187+ type = 'button'
188+ onClick = { setOpen }
189+ variant = 'small'
190+ >
191+ { rule . field }
192+ </ Button >
193+ ) }
194+ </ DropdownMenu >
195+
196+ { rule . field === groupPropKeyField &&
197+ < TextInput
198+ id = 'prop-key'
199+ variant = 'modal'
200+ containerClassName = 'w-24 md:w-32'
201+ onChange = { ( propKey ) => updateRule ( idx , { propKey } ) }
202+ value = { rule . propKey ?? '' }
203+ />
204+ }
205+
206+ < div className = '!ml-auto' >
207+ < Button
208+ type = 'button'
209+ onClick = { ( ) => onDeleteClick ( idx ) }
210+ variant = 'small'
211+ icon = { < IconTrash size = { 16 } /> }
212+ extra = { { 'aria-label' : `Delete rule ${ idx + 1 } ` } }
213+ />
214+ </ div >
215+ </ div >
150216
151- < div >
152- { idx === 0 && < span className = 'text-gray-500' > where</ span > }
217+ { rule . field === groupPropKeyField &&
218+ < div className = 'flex items-center space-x-2 ml-5' >
219+ < span > value as</ span >
153220
154- { idx > 0 &&
155221 < DropdownMenu
156- options = { [
157- { label : 'and' , onClick : ( ) => setRuleMode ( '$and' ) } ,
158- { label : 'or' , onClick : ( ) => setRuleMode ( '$or' ) }
159- ] }
222+ options = { [ 'CHAR' , 'DOUBLE' , 'DATETIME' ] . map ( ( castType ) => ( {
223+ label : getCastTypeDescription ( castType ) ,
224+ onClick : ( ) => {
225+ updateRule ( idx , { castType } )
226+ }
227+ } ) ) }
160228 >
161229 { ( setOpen ) => (
162230 < Button
163231 type = 'button'
164232 onClick = { setOpen }
165233 variant = 'small'
166234 >
167- { ruleMode . substring ( 1 , ruleMode . length ) }
235+ < span > { getCastTypeDescription ( rule . castType ) } </ span >
168236 </ Button >
169237 ) }
170238 </ DropdownMenu >
171- }
172- </ div >
173-
174- < DropdownMenu
175- options = { availableFields . map ( ( { field } ) => ( {
176- label : field ,
177- onClick : ( ) => {
178- updateRule ( idx , { field } )
179- }
180- } ) ) }
181- >
182- { ( setOpen ) => (
183- < Button
184- type = 'button'
185- onClick = { setOpen }
186- variant = 'small'
187- >
188- { rule . field }
189- </ Button >
190- ) }
191- </ DropdownMenu >
192-
193- { rule . field === groupPropKeyField &&
194- < TextInput
195- id = 'prop-key'
196- variant = 'modal'
197- containerClassName = 'w-24 md:w-32'
198- onChange = { ( propKey ) => updateRule ( idx , { propKey } ) }
199- value = { rule . propKey ?? '' }
200- />
239+ </ div >
201240 }
202241
203- < div className = '!ml-auto' >
204- < Button
205- type = 'button'
206- onClick = { ( ) => onDeleteClick ( idx ) }
207- variant = 'small'
208- icon = { < IconTrash size = { 16 } /> }
209- extra = { { 'aria-label' : `Delete rule ${ idx + 1 } ` } }
210- />
211- </ div >
212- </ div >
213-
214- { rule . field === groupPropKeyField &&
215242 < div className = 'flex items-center space-x-2 ml-5' >
216- < span > value as</ span >
217-
218243 < DropdownMenu
219- options = { [ 'CHAR' , 'DOUBLE' , 'DATETIME' ] . map ( ( castType ) => ( {
220- label : getCastTypeDescription ( castType ) ,
244+ options = { availableRules . filter ( ( availableRule ) => availableRule . castTypes . includes ( rule . castType ) ) . map ( ( { name , negate } ) => ( {
245+ label : getRuleDescription ( name , negate ) ,
221246 onClick : ( ) => {
222- updateRule ( idx , { castType } )
247+ updateRule ( idx , { name , negate } )
223248 }
224249 } ) ) }
225250 >
@@ -229,61 +254,39 @@ export default function GroupRules({ ruleModeState, rulesState }) {
229254 onClick = { setOpen }
230255 variant = 'small'
231256 >
232- < span > { getCastTypeDescription ( rule . castType ) } </ span >
257+ { getRuleDescription ( rule . name , rule . negate ) }
233258 </ Button >
234259 ) }
235260 </ DropdownMenu >
236- </ div >
237- }
238261
239- < div className = 'flex items-center space-x-2 ml-5' >
240- < DropdownMenu
241- options = { availableRules . filter ( ( availableRule ) => availableRule . castTypes . includes ( rule . castType ) ) . map ( ( { name, negate } ) => ( {
242- label : getRuleDescription ( name , negate ) ,
243- onClick : ( ) => {
244- updateRule ( idx , { name, negate } )
262+ { [ ...new Array ( findRuleByName ( rule . name ) . operandCount ) ] . map ( ( _ , operandIdx ) => {
263+ if ( rule . castType === 'DATETIME' ) {
264+ return (
265+ < DateInput
266+ key = { operandIdx }
267+ id = { `operand-${ operandIdx } ` }
268+ mode = 'single'
269+ onChange = { ( value ) => updateOperands ( idx , operandIdx , value ) }
270+ value = { rule . operands [ operandIdx ] }
271+ />
272+ )
273+ } else {
274+ return (
275+ < TextInput
276+ key = { operandIdx }
277+ id = { `operand-${ operandIdx } ` }
278+ variant = 'modal'
279+ containerClassName = 'w-14 md:w-20'
280+ onChange = { ( value ) => updateOperands ( idx , operandIdx , value ) }
281+ value = { rule . operands [ operandIdx ] ?? '' }
282+ />
283+ )
245284 }
246- } ) ) }
247- >
248- { ( setOpen ) => (
249- < Button
250- type = 'button'
251- onClick = { setOpen }
252- variant = 'small'
253- >
254- { getRuleDescription ( rule . name , rule . negate ) }
255- </ Button >
256- ) }
257- </ DropdownMenu >
258-
259- { [ ...new Array ( findRuleByName ( rule . name ) . operandCount ) ] . map ( ( _ , operandIdx ) => {
260- if ( rule . castType === 'DATETIME' ) {
261- return (
262- < DateInput
263- key = { operandIdx }
264- id = { `operand-${ operandIdx } ` }
265- mode = 'single'
266- onChange = { ( value ) => updateOperands ( idx , operandIdx , value ) }
267- value = { rule . operands [ operandIdx ] }
268- />
269- )
270- } else {
271- return (
272- < TextInput
273- key = { operandIdx }
274- id = { `operand-${ operandIdx } ` }
275- variant = 'modal'
276- containerClassName = 'w-14 md:w-20'
277- onChange = { ( value ) => updateOperands ( idx , operandIdx , value ) }
278- value = { rule . operands [ operandIdx ] ?? '' }
279- />
280- )
281- }
282- } ) }
285+ } ) }
286+ </ div >
283287 </ div >
284- </ div >
285- ) ) }
286- </ div >
288+ ) ) }
289+ </ div >
287290 }
288291
289292 < div className = 'w-32' >
0 commit comments