Skip to content

Commit

Permalink
fix(table): select all control
Browse files Browse the repository at this point in the history
  • Loading branch information
yevhenii1337 committed Nov 22, 2024
1 parent 03c7dbb commit 41da6a5
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export interface DataTableProps<D extends object> extends TableOptions<D> {
onColumnOrderChange: () => void;
isRoundStyles?: boolean;
roundChartTitle?: string;
showAllSizeOption?: boolean;
}

export interface RenderHTMLCellProps extends HTMLProps<HTMLTableCellElement> {
Expand Down
10 changes: 7 additions & 3 deletions superset-frontend/plugins/plugin-chart-table/src/TableChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ export default function TableChart<D extends DataRecord = DataRecord>(
allowRearrangeColumns = false,
onContextMenu,
emitCrossFilters,
showAllSizeOption,
} = props;
const timestampFormatter = useCallback(
value => getTimeFormatterForGranularity(timeGrain)(value),
Expand All @@ -293,10 +294,12 @@ export default function TableChart<D extends DataRecord = DataRecord>(
// only take relevant page size options
const pageSizeOptions = useMemo(() => {
const getServerPagination = (n: number) => n <= rowCount;
return PAGE_SIZE_OPTIONS.filter(([n]) =>
return PAGE_SIZE_OPTIONS.filter(item =>
!showAllSizeOption ? item[0] !== 0 : showAllSizeOption,
).filter(([n]) =>
serverPagination ? getServerPagination(n) : n <= 2 * data.length,
) as SizeOption[];
}, [data.length, rowCount, serverPagination]);
}, [data.length, rowCount, serverPagination, showAllSizeOption]);

const getValueRange = useCallback(
function getValueRange(key: string, alignPositiveNegative: boolean) {
Expand Down Expand Up @@ -788,7 +791,7 @@ export default function TableChart<D extends DataRecord = DataRecord>(
)}
isRoundStyles={isRoundStyles}
roundChartTitle={roundChartTitle}
pageSize={pageSize}
pageSize={showAllSizeOption ? pageSize : pageSize === 0 ? 10 : pageSize}
serverPaginationData={serverPaginationData}
pageSizeOptions={pageSizeOptions}
width={fullDisplay ? '100%' : widthFromState}
Expand All @@ -798,6 +801,7 @@ export default function TableChart<D extends DataRecord = DataRecord>(
onColumnOrderChange={() => setColumnOrderToggle(!columnOrderToggle)}
maxPageItemCount={5}
noResults={getNoResultsMessage}
showAllSizeOption={showAllSizeOption}
searchInput={includeSearch && SelectedSearchInput}
selectPageSize={pageSize !== null && SelectPageSize}
// not in use in Superset, but needed for unit tests
Expand Down
19 changes: 19 additions & 0 deletions superset-frontend/plugins/plugin-chart-table/src/controlPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,25 @@ const percentMetricsControl: typeof sharedControls.metrics = {

const config: ControlPanelConfig = {
controlPanelSections: [
{
label: t('Table Options'),
expanded: true,
controlSetRows: [
[
{
name: 'showAllSizeOption',
config: {
type: 'CheckboxControl',
label: 'Show select all size option',
renderTrigger: true,
default: false,
initialValue: false,
description: 'Show select all size option',
},
},
],
],
},
{
label: t('Show Loader'),
expanded: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ const transformProps = (
show_totals: showTotals,
conditional_formatting: conditionalFormatting,
allow_rearrange_columns: allowRearrangeColumns,
showAllSizeOption,
} = formData;
const timeGrain = extractTimegrain(formData);

Expand Down Expand Up @@ -300,6 +301,7 @@ const transformProps = (
timeGrain,
allowRearrangeColumns,
onContextMenu,
showAllSizeOption: !!showAllSizeOption,
};
};

Expand Down
2 changes: 2 additions & 0 deletions superset-frontend/plugins/plugin-chart-table/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export type TableChartFormData = QueryFormData & {
include_search?: boolean;
query_mode?: QueryMode;
showPopUpLegend?: boolean;
showAllSizeOption?: boolean;
showPopUpVideoLegend?: boolean;
page_length?: string | number | null; // null means auto-paginate
metrics?: QueryFormMetric[] | null;
Expand Down Expand Up @@ -131,6 +132,7 @@ export interface TableChartTransformedProps<D extends DataRecord = DataRecord> {
noMainBorder?: boolean;
hideControlsOnCustomerView?: boolean;
isRoundStyles?: boolean;
showAllSizeOption?: boolean;
roundChartTitle?: string;
// These are dashboard filters, don't be confused with in-chart search filter
// enabled by `includeSearch`
Expand Down

0 comments on commit 41da6a5

Please sign in to comment.