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

[Bug]: Data Configuration panel for Logs view remains disabled. #1057

Merged
merged 9 commits into from
Sep 30, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,35 @@ export const Explorer = ({
[GROUPBY]: [{ bucketSize: '', bucketOffset: '' }],
[AGGREGATIONS]: [],
};
case VIS_CHART_TYPES.LogsView: {
const dimensions = statsToken.aggregations
.map((agg) => {
const logViewField = `${agg.function.name}(${agg.function.value_expression})` ?? '';
return {
label: logViewField,
name: logViewField,
};
})
.concat(
groupByToken.group_fields?.map((agg) => ({
label: agg.name ?? '',
name: agg.name ?? '',
}))
);
if (span !== undefined) {
const { time_field, interval, unit } = span;
const timespanField = `span(${time_field[0].name},${interval}${unit[0].value})`;
dimensions.push({
label: timespanField,
name: timespanField,
});
}
return {
[AGGREGATIONS]: [],
[GROUPBY]: dimensions,
};
}

default:
return {
[AGGREGATIONS]: statsToken.aggregations.map((agg) => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const LogsViewConfigPanelItem = ({
const { tabId, curVisId, changeVisualizationConfig } = useContext<any>(TabContext);
const explorerFields = useSelector(selectFields)[tabId];
const { data } = visualizations;
const { availableFields, queriedFields, selectedFields } = data.explorer?.explorerFields;
const { userConfigs } = data;

const initialConfigEntry = {
Expand All @@ -64,7 +65,7 @@ export const LogsViewConfigPanelItem = ({
}, [userConfigs?.dataConfig, visualizations.vis.name]);

useEffect(() => {
if (fieldOptionList.length === 0) {
if (queriedFields.length === 0) {
setConfigList({
[AGGREGATIONS]: [],
[GROUPBY]: visualizations?.data?.explorer?.explorerFields?.selectedFields.map((field) => ({
Expand All @@ -76,7 +77,7 @@ export const LogsViewConfigPanelItem = ({
}, [visualizations.data.explorer.explorerFields]);

const handleServiceRemove = (index: number, name: string) => {
if (fieldOptionList.length !== 0) {
if (queriedFields.length !== 0) {
return;
}
const list = { ...configList };
Expand Down Expand Up @@ -141,7 +142,7 @@ export const LogsViewConfigPanelItem = ({
};

const getAvailableLogsViewOptions = () => {
if (fieldOptionList.length !== 0) {
if (queriedFields.length !== 0) {
return [];
}
const dimensionNames = (configList[GROUPBY] as ConfigListEntry[]).map((field) => field.name);
Expand Down Expand Up @@ -188,7 +189,7 @@ export const LogsViewConfigPanelItem = ({
singleSelection={{ asPlainText: true }}
options={getAvailableLogsViewOptions()}
selectedOptions={[{ label: field.label }]}
isDisabled={fieldOptionList.length !== 0}
isDisabled={queriedFields.length !== 0}
onChange={(e) =>
updateLogsViewConfig(e.length > 0 ? e[0].label : '', field as ConfigListEntry)
}
Expand All @@ -206,7 +207,7 @@ export const LogsViewConfigPanelItem = ({
iconType="plusInCircleFilled"
color="primary"
onClick={() => handleServiceAdd(GROUPBY)}
disabled={fieldOptionList.length !== 0}
disabled={queriedFields.length !== 0}
>
Add
</EuiButton>
Expand Down Expand Up @@ -236,7 +237,7 @@ export const LogsViewConfigPanelItem = ({
iconType="play"
onClick={updateChart}
size="s"
isDisabled={fieldOptionList.length !== 0}
isDisabled={queriedFields.length !== 0}
>
Update chart
</EuiButton>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,20 +110,32 @@ const defaultUserConfigs = (queryString, visualizationName: string) => {
},
};
if (visualizationName === VIS_CHART_TYPES.LogsView) {
tempUserConfigs = {
...tempUserConfigs,
[AGGREGATIONS]: [],
[GROUPBY]: statsTokens.aggregations
.map((agg) => ({
const dimensions = statsTokens.aggregations
.map((agg) => {
const logViewField = `${agg.function.name}(${agg.function.value_expression})` ?? '';
return {
label: logViewField,
name: logViewField,
};
})
.concat(
statsTokens.groupby.group_fields?.map((agg) => ({
label: agg.name ?? '',
name: agg.name ?? '',
}))
.concat(
statsTokens.groupby?.group_fields?.map((agg) => ({
label: agg.name ?? '',
name: agg.name ?? '',
}))
),
);
if (statsTokens.groupby.span !== null) {
const { field, literal_value, time_unit } = statsTokens.groupby.span.span_expression;
const timespanField = `span(${field},${literal_value}${time_unit})`;
dimensions.push({
label: timespanField,
name: timespanField,
});
}
tempUserConfigs = {
...tempUserConfigs,
[AGGREGATIONS]: [],
[GROUPBY]: dimensions,
};
} else if (visualizationName === VIS_CHART_TYPES.HeatMap) {
tempUserConfigs = {
Expand Down