mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-05-31 10:29:39 +08:00
🐛 fix(DataGrid): 修复筛选字段名显示不完整
- 扩展筛选与排序字段下拉宽度 - 为字段选项补充完整 title 与省略显示 - 补充字段名完整展示回归测试 Refs #481
This commit is contained in:
@@ -3,6 +3,7 @@ import { renderToStaticMarkup } from 'react-dom/server';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
|
||||
import DataGrid, {
|
||||
buildGridFieldSelectOptions,
|
||||
formatCellDisplayText,
|
||||
resolveContextMenuFieldName,
|
||||
resolveDefaultGridFilterOperator,
|
||||
@@ -140,6 +141,16 @@ describe('DataGrid layout', () => {
|
||||
})).toBe('STARTS_WITH');
|
||||
});
|
||||
|
||||
it('keeps full field names in filter field select options', () => {
|
||||
const [option] = buildGridFieldSelectOptions(['mes_manufacture_order_really_long_column_name']);
|
||||
|
||||
expect(option).toEqual({
|
||||
value: 'mes_manufacture_order_really_long_column_name',
|
||||
label: 'mes_manufacture_order_really_long_column_name',
|
||||
title: 'mes_manufacture_order_really_long_column_name',
|
||||
});
|
||||
});
|
||||
|
||||
it('renders a DDL action for table data pages only', () => {
|
||||
const tableMarkup = renderToStaticMarkup(
|
||||
<DataGrid
|
||||
|
||||
@@ -1049,6 +1049,19 @@ type ForeignKeyTarget = {
|
||||
|
||||
const EXACT_GRID_FILTER_OPERATOR = '=';
|
||||
const CONTAINS_GRID_FILTER_OPERATOR = 'CONTAINS';
|
||||
const FILTER_FIELD_SELECT_STYLE: React.CSSProperties = {
|
||||
width: 320,
|
||||
flex: '0 1 320px',
|
||||
minWidth: 260,
|
||||
maxWidth: 'min(460px, 100%)',
|
||||
};
|
||||
const FILTER_FIELD_POPUP_WIDTH = 520;
|
||||
const FILTER_FIELD_OPTION_STYLE: React.CSSProperties = {
|
||||
display: 'block',
|
||||
overflow: 'hidden',
|
||||
textOverflow: 'ellipsis',
|
||||
whiteSpace: 'nowrap',
|
||||
};
|
||||
const STRING_LIKE_GRID_FILTER_TYPES = new Set([
|
||||
'bpchar',
|
||||
'char',
|
||||
@@ -1109,6 +1122,26 @@ export const resolveNextGridFilterOperatorForColumnChange = ({
|
||||
return current === previousDefault ? resolveDefaultGridFilterOperator(nextColumnType) : current;
|
||||
};
|
||||
|
||||
export const buildGridFieldSelectOptions = (columnNames: string[]) => (
|
||||
(columnNames || []).map((columnName) => {
|
||||
const text = String(columnName || '');
|
||||
return {
|
||||
value: text,
|
||||
label: text,
|
||||
title: text,
|
||||
};
|
||||
})
|
||||
);
|
||||
|
||||
const renderGridFieldSelectOption = (option: { label?: React.ReactNode; value?: unknown; title?: unknown }) => {
|
||||
const text = String(option?.title ?? option?.label ?? option?.value ?? '');
|
||||
return (
|
||||
<span title={text} style={FILTER_FIELD_OPTION_STYLE}>
|
||||
{text}
|
||||
</span>
|
||||
);
|
||||
};
|
||||
|
||||
type NormalizeCommitCellValue = (columnName: string, value: any, mode: 'insert' | 'update') => any;
|
||||
|
||||
type DataGridCommitChangeSet = {
|
||||
@@ -2786,6 +2819,11 @@ const DataGrid: React.FC<DataGridProps> = ({
|
||||
}));
|
||||
}, [allTableColumnNames, displayColumnNames, quickWhereDraft, dbType, darkMode]);
|
||||
|
||||
const gridFieldSelectOptions = useMemo(
|
||||
() => buildGridFieldSelectOptions(displayColumnNames),
|
||||
[displayColumnNames],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (!showFilter) {
|
||||
return;
|
||||
@@ -6363,12 +6401,14 @@ const DataGrid: React.FC<DataGridProps> = ({
|
||||
disabled={condIndex === 0}
|
||||
/>
|
||||
<Select
|
||||
style={{ width: 180 }}
|
||||
style={FILTER_FIELD_SELECT_STYLE}
|
||||
value={cond.column}
|
||||
onChange={v => updateFilter(cond.id, 'column', v)}
|
||||
options={displayColumnNames.map(c => ({ value: c, label: c }))}
|
||||
options={gridFieldSelectOptions}
|
||||
showSearch
|
||||
optionFilterProp="label"
|
||||
optionRender={renderGridFieldSelectOption}
|
||||
popupMatchSelectWidth={FILTER_FIELD_POPUP_WIDTH}
|
||||
filterOption={(input, option) =>
|
||||
String(option?.label ?? '')
|
||||
.toLowerCase()
|
||||
@@ -6448,7 +6488,7 @@ const DataGrid: React.FC<DataGridProps> = ({
|
||||
/>
|
||||
<span style={{ fontSize: 12, color: 'inherit', opacity: 0.7, whiteSpace: 'nowrap', minWidth: 32 }}>{idx === 0 ? '排序' : '然后'}</span>
|
||||
<Select
|
||||
style={{ width: 180 }}
|
||||
style={FILTER_FIELD_SELECT_STYLE}
|
||||
value={s.columnKey || undefined}
|
||||
onChange={v => {
|
||||
const next = [...sortInfo];
|
||||
@@ -6458,9 +6498,11 @@ const DataGrid: React.FC<DataGridProps> = ({
|
||||
}}
|
||||
options={displayColumnNames
|
||||
.filter(c => c === s.columnKey || !sortInfo.some(si => si.columnKey === c))
|
||||
.map(c => ({ value: c, label: c }))}
|
||||
.map(c => ({ value: c, label: c, title: c }))}
|
||||
showSearch
|
||||
optionFilterProp="label"
|
||||
optionRender={renderGridFieldSelectOption}
|
||||
popupMatchSelectWidth={FILTER_FIELD_POPUP_WIDTH}
|
||||
filterOption={(input, option) =>
|
||||
String(option?.label ?? '')
|
||||
.toLowerCase()
|
||||
|
||||
Reference in New Issue
Block a user