Skip to content

Commit fd9dbf9

Browse files
fix(table-chart): fix page size label visibility and improve header
control wrapping
1 parent 9751854 commit fd9dbf9

File tree

2 files changed

+241
-207
lines changed

2 files changed

+241
-207
lines changed

superset-frontend/plugins/plugin-chart-table/src/DataTable/DataTable.tsx

Lines changed: 30 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {
2727
DragEvent,
2828
useEffect,
2929
} from 'react';
30-
import { styled, typedMemo, usePrevious } from '@superset-ui/core';
30+
import { typedMemo, usePrevious } from '@superset-ui/core';
3131
import {
3232
useTable,
3333
usePagination,
@@ -42,7 +42,7 @@ import {
4242
} from 'react-table';
4343
import { matchSorter, rankings } from 'match-sorter';
4444
import { isEqual } from 'lodash';
45-
import { Space } from '@superset-ui/core/components';
45+
import { Flex, Space } from '@superset-ui/core/components';
4646
import GlobalFilter, { GlobalFilterProps } from './components/GlobalFilter';
4747
import SelectPageSize, {
4848
SelectPageSizeProps,
@@ -77,7 +77,7 @@ export interface DataTableProps<D extends object> extends TableOptions<D> {
7777
sticky?: boolean;
7878
rowCount: number;
7979
wrapperRef?: MutableRefObject<HTMLDivElement>;
80-
onColumnOrderChange: () => void;
80+
onColumnOrderChange?: () => void;
8181
renderGroupingHeaders?: () => JSX.Element;
8282
renderTimeComparisonDropdown?: () => JSX.Element;
8383
handleSortByChange: (sortBy: SortByItem[]) => void;
@@ -98,24 +98,6 @@ const sortTypes = {
9898
alphanumeric: sortAlphanumericCaseInsensitive,
9999
};
100100

101-
const StyledSpace = styled(Space)`
102-
display: flex;
103-
justify-content: flex-end;
104-
105-
.search-select-container {
106-
display: flex;
107-
}
108-
109-
.search-by-label {
110-
align-self: center;
111-
margin-right: 4px;
112-
}
113-
`;
114-
115-
const StyledRow = styled.div`
116-
display: flex;
117-
`;
118-
119101
// Be sure to pass our updateMyData and the skipReset option
120102
export default typedMemo(function DataTable<D extends object>({
121103
tableClassName,
@@ -336,8 +318,7 @@ export default typedMemo(function DataTable<D extends object>({
336318
const colToBeMoved = currentCols.splice(columnBeingDragged, 1);
337319
currentCols.splice(newPosition, 0, colToBeMoved[0]);
338320
setColumnOrder(currentCols);
339-
// toggle value in TableChart to trigger column width recalc
340-
onColumnOrderChange();
321+
onColumnOrderChange?.();
341322
}
342323
e.preventDefault();
343324
};
@@ -450,30 +431,36 @@ export default typedMemo(function DataTable<D extends object>({
450431
>
451432
{hasGlobalControl ? (
452433
<div ref={globalControlRef} className="form-inline dt-controls">
453-
<StyledRow className="row">
454-
<StyledSpace size="middle">
455-
{hasPagination ? (
456-
<SelectPageSize
457-
total={resultsSize}
458-
current={resultCurrentPageSize}
459-
options={pageSizeOptions}
460-
selectRenderer={
461-
typeof selectPageSize === 'boolean'
462-
? undefined
463-
: selectPageSize
464-
}
465-
onChange={setPageSize}
466-
/>
467-
) : null}
434+
<Flex
435+
wrap
436+
className="row"
437+
align="center"
438+
justify="space-between"
439+
gap="middle"
440+
>
441+
{hasPagination ? (
442+
<SelectPageSize
443+
total={resultsSize}
444+
current={resultCurrentPageSize}
445+
options={pageSizeOptions}
446+
selectRenderer={
447+
typeof selectPageSize === 'boolean'
448+
? undefined
449+
: selectPageSize
450+
}
451+
onChange={setPageSize}
452+
/>
453+
) : null}
454+
<Flex wrap align="center" gap="middle">
468455
{serverPagination && (
469-
<div className="search-select-container">
470-
<span className="search-by-label">Search by: </span>
456+
<Space size="small" className="search-select-container">
457+
<span className="search-by-label">Search by:</span>
471458
<SearchSelectDropdown
472459
searchOptions={searchOptions}
473460
value={serverPaginationData?.searchColumn || ''}
474461
onChange={onSearchColChange}
475462
/>
476-
</div>
463+
</Space>
477464
)}
478465
{searchInput && (
479466
<GlobalFilter<D>
@@ -493,8 +480,8 @@ export default typedMemo(function DataTable<D extends object>({
493480
{renderTimeComparisonDropdown
494481
? renderTimeComparisonDropdown()
495482
: null}
496-
</StyledSpace>
497-
</StyledRow>
483+
</Flex>
484+
</Flex>
498485
</div>
499486
) : null}
500487
{wrapStickyTable ? wrapStickyTable(renderTable) : renderTable()}

0 commit comments

Comments
 (0)