Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/cldn 1773 #269

Merged
merged 11 commits into from
Mar 10, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ const config: ControlPanelConfig = {

return newState;
},
rerender: ['metrics', 'percent_metrics', ],
rerender: ['metrics', 'percent_metrics', 'default_group_by',],
},
},
],
Expand Down Expand Up @@ -329,7 +329,7 @@ const config: ControlPanelConfig = {
: [];
return newState;
},
rerender: ['principalColumns'],
rerender: ['principalColumns', 'default_group_by'],
visibility: isRawMode,
canCopy: true,
}
Expand Down Expand Up @@ -595,6 +595,73 @@ config.controlPanelSections.push({
},
},
],
[
{
name: 'default_group_by',
config: {
type: 'SelectControl',
label: t('Default columns for row grouping'),
description: t(
'Preselect a set of columns for row grouping in the grid.',
),
multi: true,
freeForm: true,
allowAll: true,
default: [],
canSelectAll: true,
renderTrigger: true,
optionRenderer: (c: ColumnMeta) => (
// eslint-disable-next-line react/react-in-jsx-scope
<StyledColumnOption showType column={c} />
),
// eslint-disable-next-line react/react-in-jsx-scope
valueRenderer: (c: ColumnMeta) => (
// eslint-disable-next-line react/react-in-jsx-scope
<StyledColumnOption column={c} />
),
valueKey: 'column_name',
mapStateToProps: (
state: ControlPanelState,
controlState: ControlState,
) => {
const { controls } = state;
const originalMapStateToProps = isRawMode({ controls }) ?
sharedControls?.columns?.mapStateToProps :
sharedControls?.groupby?.mapStateToProps;
const newState =
originalMapStateToProps?.(state, controlState) ?? {};
const choices = isRawMode({ controls })
? controls?.columns?.value
: controls?.groupby?.value;
newState.options = newState.options.filter(
(o: { column_name: string }) =>
ensureIsArray(choices).includes(o.column_name),
);
const invalidOptions = ensureIsArray(
controlState.value,
).filter(c => !ensureIsArray(choices).includes(c));
newState.externalValidationErrors =
invalidOptions.length > 0
? invalidOptions.length > 1
? [
`'${invalidOptions.join(', ')}'${t(
' are not valid options',
)}`,
]
: [
`'${invalidOptions}'${t(
' is not a valid option',
)}`,
]
: [];
return newState;
},
visibility: ({ controls }) =>
Boolean(controls?.enable_grouping?.value),
canCopy: true,
},
}
],
[
{
name: 'enable_row_numbers',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export default function transformProps(chartProps: CccsGridChartProps) {
column_state,
enable_row_numbers,
jump_action_configs,
default_group_by,
}: CccsGridQueryFormData = { ...DEFAULT_FORM_DATA, ...formData };
const data = queriesData[0].data as TimeseriesDataRecord[];
const agGridLicenseKey = queriesData[0].agGridLicenseKey as String;
Expand Down Expand Up @@ -232,6 +233,11 @@ export default function transformProps(chartProps: CccsGridChartProps) {
const isSortable = true;
const enableRowGroup = true;
const columnDescription = columnDescriptionMap[column];
const rowGroupIndex = default_group_by.findIndex((element: any) => {
return element === column
});
const rowGroup = rowGroupIndex >= 0
const hide = rowGroup;
return {
field: column,
headerName: columnHeader,
Expand All @@ -240,6 +246,9 @@ export default function transformProps(chartProps: CccsGridChartProps) {
sort: sortDirection,
sortIndex,
enableRowGroup,
rowGroup,
hide,
rowGroupIndex,
getQuickFilterText: (params: any) => valueFormatter(params),
headerTooltip: columnDescription,
};
Expand All @@ -261,12 +270,22 @@ export default function transformProps(chartProps: CccsGridChartProps) {
const isSortable = true;
const enableRowGroup = true;
const columnDescription = columnDescriptionMap[column];
const rowGroupIndex = default_group_by.findIndex((element: any) => {
return element === column
});
const initialRowGroupIndex = rowGroupIndex;
const rowGroup = (rowGroupIndex >= 0)
const hide = rowGroup;
return {
field: column,
headerName: columnHeader,
cellRenderer,
sortable: isSortable,
enableRowGroup,
rowGroup,
rowGroupIndex,
initialRowGroupIndex,
hide,
getQuickFilterText: (params: any) => valueFormatter(params),
headerTooltip: columnDescription,
};
Expand Down