1414
1515import m from 'mithril' ;
1616import { ColumnInfo } from './column_info' ;
17- import {
18- OutlinedField ,
19- ResultsPanelEmptyState ,
20- SelectDeselectAllButtons ,
21- } from './widgets' ;
17+ import { OutlinedField , ResultsPanelEmptyState } from './widgets' ;
18+ import { ColumnSelector } from './column_selector' ;
2219import { classNames } from '../../../base/classnames' ;
2320import { Card } from '../../../widgets/card' ;
2421import { Checkbox } from '../../../widgets/checkbox' ;
@@ -279,65 +276,46 @@ export interface JoinColumnSelectorAttrs {
279276 rightAlias : string ;
280277 leftColumns : ColumnInfo [ ] ;
281278 rightColumns : ColumnInfo [ ] ;
282- onLeftColumnToggle : ( index : number , checked : boolean ) => void ;
283- onRightColumnToggle : ( index : number , checked : boolean ) => void ;
284- onLeftColumnAlias : ( index : number , alias : string ) => void ;
285- onRightColumnAlias : ( index : number , alias : string ) => void ;
286- onSelectAllLeft : ( ) => void ;
287- onDeselectAllLeft : ( ) => void ;
288- onSelectAllRight : ( ) => void ;
289- onDeselectAllRight : ( ) => void ;
279+ onLeftColumnsChange : ( columns : ColumnInfo [ ] ) => void ;
280+ onRightColumnsChange : ( columns : ColumnInfo [ ] ) => void ;
290281}
291282
292283export class JoinColumnSelector
293284 implements m . ClassComponent < JoinColumnSelectorAttrs >
294285{
295- private renderColumnRow (
296- col : ColumnInfo ,
297- index : number ,
298- onToggle : ( index : number , checked : boolean ) => void ,
299- onAlias : ( index : number , alias : string ) => void ,
300- ) : m . Child {
301- return m (
302- '.pf-join-column-row' ,
303- m ( Checkbox , {
304- checked : col . checked ,
305- label : col . column . name ,
306- onchange : ( e ) => {
307- onToggle ( index , ( e . target as HTMLInputElement ) . checked ) ;
308- } ,
309- } ) ,
310- m ( TextInput , {
311- oninput : ( e : Event ) => {
312- const inputValue = ( e . target as HTMLInputElement ) . value ;
313- // Normalize empty strings to undefined (no alias)
314- onAlias ( index , inputValue . trim ( ) === '' ? '' : inputValue ) ;
315- } ,
316- placeholder : 'alias' ,
317- value : col . alias ?? '' ,
318- } ) ,
319- ) ;
320- }
321-
322286 view ( { attrs} : m . Vnode < JoinColumnSelectorAttrs > ) {
323287 const {
324288 leftAlias,
325289 rightAlias,
326290 leftColumns,
327291 rightColumns,
328- onLeftColumnToggle,
329- onRightColumnToggle,
330- onLeftColumnAlias,
331- onRightColumnAlias,
332- onSelectAllLeft,
333- onDeselectAllLeft,
334- onSelectAllRight,
335- onDeselectAllRight,
292+ onLeftColumnsChange,
293+ onRightColumnsChange,
336294 } = attrs ;
337295
338296 const leftSelectedCount = leftColumns . filter ( ( c ) => c . checked ) . length ;
339297 const rightSelectedCount = rightColumns . filter ( ( c ) => c . checked ) . length ;
340298
299+ const renderAliasInput = (
300+ col : ColumnInfo ,
301+ index : number ,
302+ columns : ColumnInfo [ ] ,
303+ onColumnsChange : ( columns : ColumnInfo [ ] ) => void ,
304+ ) =>
305+ m ( TextInput , {
306+ oninput : ( e : Event ) => {
307+ const inputValue = ( e . target as HTMLInputElement ) . value ;
308+ const newColumns = [ ...columns ] ;
309+ newColumns [ index ] = {
310+ ...newColumns [ index ] ,
311+ alias : inputValue . trim ( ) === '' ? undefined : inputValue ,
312+ } ;
313+ onColumnsChange ( newColumns ) ;
314+ } ,
315+ placeholder : 'alias' ,
316+ value : col . alias ?? '' ,
317+ } ) ;
318+
341319 return m ( '.pf-join-column-selector' , [
342320 // Left columns section
343321 m ( '.pf-join-column-section' , [
@@ -347,27 +325,17 @@ export class JoinColumnSelector
347325 'h4' ,
348326 `${ leftAlias } (${ leftSelectedCount } / ${ leftColumns . length } selected)` ,
349327 ) ,
350- m ( SelectDeselectAllButtons , {
351- onSelectAll : onSelectAllLeft ,
352- onDeselectAll : onDeselectAllLeft ,
353- } ) ,
354- ) ,
355- m (
356- '.pf-join-column-list' ,
357- leftColumns . length === 0
358- ? m ( ResultsPanelEmptyState , {
359- icon : 'cable' ,
360- title : 'Connect left source' ,
361- } )
362- : leftColumns . map ( ( col , i ) =>
363- this . renderColumnRow (
364- col ,
365- i ,
366- onLeftColumnToggle ,
367- onLeftColumnAlias ,
368- ) ,
369- ) ,
370328 ) ,
329+ m ( ColumnSelector , {
330+ columns : leftColumns ,
331+ onColumnsChange : onLeftColumnsChange ,
332+ renderExtra : ( col , index ) =>
333+ renderAliasInput ( col , index , leftColumns , onLeftColumnsChange ) ,
334+ emptyState : m ( ResultsPanelEmptyState , {
335+ icon : 'cable' ,
336+ title : 'Connect left source' ,
337+ } ) ,
338+ } ) ,
371339 ] ) ,
372340 // Right columns section
373341 m ( '.pf-join-column-section' , [
@@ -377,27 +345,17 @@ export class JoinColumnSelector
377345 'h4' ,
378346 `${ rightAlias } (${ rightSelectedCount } / ${ rightColumns . length } selected)` ,
379347 ) ,
380- m ( SelectDeselectAllButtons , {
381- onSelectAll : onSelectAllRight ,
382- onDeselectAll : onDeselectAllRight ,
383- } ) ,
384- ) ,
385- m (
386- '.pf-join-column-list' ,
387- rightColumns . length === 0
388- ? m ( ResultsPanelEmptyState , {
389- icon : 'cable' ,
390- title : 'Connect right source' ,
391- } )
392- : rightColumns . map ( ( col , i ) =>
393- this . renderColumnRow (
394- col ,
395- i ,
396- onRightColumnToggle ,
397- onRightColumnAlias ,
398- ) ,
399- ) ,
400348 ) ,
349+ m ( ColumnSelector , {
350+ columns : rightColumns ,
351+ onColumnsChange : onRightColumnsChange ,
352+ renderExtra : ( col , index ) =>
353+ renderAliasInput ( col , index , rightColumns , onRightColumnsChange ) ,
354+ emptyState : m ( ResultsPanelEmptyState , {
355+ icon : 'cable' ,
356+ title : 'Connect right source' ,
357+ } ) ,
358+ } ) ,
401359 ] ) ,
402360 ] ) ;
403361 }
0 commit comments