import React from 'react'; import DataFilterControl from '../datagrid/DataFilterControl'; import { CheckboxField, SelectField, TextField } from '../utility/inputs'; import TableControl, { TableColumn } from '../utility/TableControl'; import InlineButton from '../widgets/InlineButton'; import { findDesignerFilterType } from './designerTools'; function getTableDisplayName(column, tables) { const table = (tables || []).find(x => x.designerId == column.designerId); if (table) return table.alias || table.pureName; return ''; } export default function QueryDesignColumns({ value, onChange }) { const { columns, tables } = value || {}; const changeColumn = React.useCallback( col => { onChange(current => ({ ...current, columns: (current.columns || []).map(x => x.designerId == col.designerId && x.columnName == col.columnName ? col : x ), })); }, [onChange] ); const removeColumn = React.useCallback( col => { onChange(current => ({ ...current, columns: (current.columns || []).filter(x => x.designerId != col.designerId || x.columnName != col.columnName), })); }, [onChange] ); const hasGroupedColumn = !!(columns || []).find(x => x.isGrouped); return ( getTableDisplayName(row, tables)} /> ( { if (e.target.checked) changeColumn({ ...row, isOutput: true }); else changeColumn({ ...row, isOutput: false }); }} /> )} /> ( { changeColumn({ ...row, alias: e.target.value }); }} /> )} /> ( { if (e.target.checked) changeColumn({ ...row, isGrouped: true }); else changeColumn({ ...row, isGrouped: false }); }} /> )} /> !row.isGrouped && ( { changeColumn({ ...row, aggregate: e.target.value }); }} > ) } /> ( { changeColumn({ ...row, sortOrder: parseInt(e.target.value) }); }} > , )} /> ( { changeColumn({ ...row, filter }); }} /> )} /> {hasGroupedColumn && ( ( { changeColumn({ ...row, groupFilter }); }} /> )} /> )} ( <> removeColumn(row)}>Remove )} /> ); }