fix: 修复列过滤选择与实际展示不一致问题

This commit is contained in:
2betop 2023-11-07 14:50:20 +08:00
parent 01ccd777b2
commit 1c0415cd46
2 changed files with 59 additions and 49 deletions

View File

@ -1108,3 +1108,13 @@
}
}
}
.#{$ns}AutoFilterToolbar {
display: block;
text-align: right;
white-space: nowrap;
> .#{$ns}Button {
margin-top: 0;
}
}

View File

@ -71,7 +71,7 @@ export function AutoFilterForm({
})
);
let showExpander = searchableColumns.length >= columnsNum;
let showExpander = activedSearchableColumns.length >= columnsNum;
// todo 以后做动画
if (!searchFormExpanded && body.length) {
@ -100,7 +100,7 @@ export function AutoFilterForm({
}
lastGroup.body.push({
type: 'container',
className: 'ButtonToolbar text-right block',
className: 'AutoFilterToolbar',
wrapperBody: false,
body: [
{
@ -114,32 +114,31 @@ export function AutoFilterForm({
visible: showBtnToolbar,
buttons: searchableColumns.map(column => {
return {
type: 'checkbox',
label: false,
className: cx('Table-searchableForm-checkbox'),
inputClassName: cx('Table-searchableForm-checkbox-inner'),
name: `${
column.searchable.strategy === 'jsonql' ? '' : '__search_'
}${column.searchable?.name ?? column.name}`,
option: column.searchable?.label ?? column.label,
/**
* syncLocation开启后Query中二次同步到数据域中(boolean)
* eg:
* true ==> "true"
* false ==> "false"
*
*/
trueValue: '1',
falseValue: '0',
value: !!column.enableSearch ? '1' : '0',
badge: {
offset: [-10, 5],
visibleOn: `${
column.toggable && !column.toggled && column.enableSearch
}`
},
onChange: (value: '1' | '0') =>
onItemToggleExpanded?.(column, value === '1' ? true : false)
children: ({render}: any) =>
render(
`column-search-toggler-${column.id}`,
{
type: 'checkbox',
label: false,
className: cx('Table-searchableForm-checkbox'),
inputClassName: cx('Table-searchableForm-checkbox-inner'),
name: `__whatever_name`,
option: column.searchable?.label ?? column.label,
badge: {
offset: [-10, 5],
visibleOn: `${
column.toggable &&
!column.toggled &&
column.enableSearch
}`
}
},
{
value: activedSearchableColumns.includes(column),
onChange: (value: any) =>
onItemToggleExpanded?.(column, value)
}
)
};
})
},
@ -147,34 +146,35 @@ export function AutoFilterForm({
{
type: 'submit',
label: __('search'),
size: 'sm',
level: 'primary',
className: 'w-18'
className: 'w-18 mr-2'
},
{
type: 'reset',
label: __('reset'),
size: 'sm',
className: 'w-18'
},
showExpander
? {
children: () => (
<a
className={cx(
'Table-SFToggler',
searchFormExpanded ? 'is-expanded' : ''
)}
onClick={onToggleExpanded}
>
{__(searchFormExpanded ? 'collapse' : 'expand')}
<span className={cx('Table-SFToggler-arrow')}>
<Icon icon="right-arrow-bold" className="icon" />
</span>
</a>
)
}
: null
].filter(item => item)
{
children: () =>
showExpander ? (
<a
className={cx(
'Table-SFToggler',
searchFormExpanded ? 'is-expanded' : ''
)}
onClick={onToggleExpanded}
>
{__(searchFormExpanded ? 'collapse' : 'expand')}
<span className={cx('Table-SFToggler-arrow')}>
<Icon icon="right-arrow-bold" className="icon" />
</span>
</a>
) : null
}
]
});
return {
@ -227,7 +227,7 @@ export default observer(
const onItemToggleExpanded = React.useCallback(
(column: IColumn, value: boolean) => {
column.setEnableSearch(value);
store.setSearchFormExpanded(true);
value && store.setSearchFormExpanded(true);
},
[]
);