Skip to content

Commit

Permalink
fix: show warning on big period, is forecast enable check segment
Browse files Browse the repository at this point in the history
JIRA: F1-316
JIRA: F1-319
  • Loading branch information
hackerstanislav committed May 9, 2024
1 parent 5be9069 commit a532126
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 4 deletions.
6 changes: 5 additions & 1 deletion libs/sdk-ui-charts/src/forecast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ export function isForecastEnabled(
const buckets = insightBuckets(insight);
const measures = bucketsFind(buckets, (b) => b.localIdentifier === BucketNames.MEASURES);
const trends = bucketsFind(buckets, (b) => b.localIdentifier === BucketNames.TREND);
const segments = bucketsFind(buckets, (b) => b.localIdentifier === BucketNames.SEGMENT);

//TODO: s.hacker check if the trend is date attribute somehow
return {
enabled: measures?.items.length === 1 && trends?.items.length === 1,
enabled:
measures?.items.length === 1 &&
trends?.items.length === 1 &&
(segments?.items.length ?? 0) === 0,
visible: true,
};
}
Expand Down
42 changes: 42 additions & 0 deletions libs/sdk-ui-charts/src/tests/forecast.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,46 @@ describe("isForecastEnabled", () => {
visible: true,
});
});

it("should be disabled if more buckets 3", () => {
const res = isForecastEnabled(
{
...insight,
insight: {
...insight.insight,
buckets: [
...insight.insight.buckets,
{
localIdentifier: "segment",
items: [
{
attribute: {
localIdentifier: "date",
alias: "",
displayForm: {
uri: "dateUri",
},
},
},
{
attribute: {
localIdentifier: "date1",
alias: "",
displayForm: {
uri: "dateUri1",
},
},
},
],
},
],
},
},
"line",
);
expect(res).toEqual({
enabled: false,
visible: true,
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import InputControl from "../InputControl.js";
import { messages } from "../../../../locales.js";
import noop from "lodash/noop.js";
import CheckboxControl from "../CheckboxControl.js";
import { Message } from "@gooddata/sdk-ui-kit";
import { FormattedMessage } from "react-intl";

export interface IForecastSection {
controlsDisabled: boolean;
Expand Down Expand Up @@ -35,6 +37,7 @@ class ForecastSection extends React.PureComponent<IForecastSection> {
const forecastPeriod = this.props.properties?.controls?.forecast?.period ?? 3;
const forecastSeasonal = this.props.properties?.controls?.forecast?.seasonal ?? false;
const forecastToggleDisabledByVisualization = !(this.props.propertiesMeta?.forecast_enabled ?? true);
const slicedForecast = this.props.propertiesMeta?.slicedForecast ?? false;

const toggleDisabled = controlsDisabled || forecastToggleDisabledByVisualization || !enabled;
const forecastControlsDisabled = !forecastEnabled || toggleDisabled;
Expand All @@ -44,6 +47,7 @@ class ForecastSection extends React.PureComponent<IForecastSection> {
<ConfigSection
id="forecast_section"
valuePath="forecast.enabled"
className="gd-forecast-section"
title={messages.forecastTitle.id}
propertiesMeta={this.props.propertiesMeta}
properties={properties}
Expand Down Expand Up @@ -78,6 +82,13 @@ class ForecastSection extends React.PureComponent<IForecastSection> {
properties={properties}
pushData={pushData}
/>

{slicedForecast && (
<Message type="warning" className="adi-input-warning gd-slicedForecast-message">
<FormattedMessage id={messages.forecastSlicedWarningTitle.id} tagName="strong" />
<FormattedMessage id={messages.forecastSlicedWarningDescription.id} tagName="div" />
</Message>
)}
</ConfigSection>
);
}
Expand Down
10 changes: 10 additions & 0 deletions libs/sdk-ui-ext/src/internal/translations/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,16 @@
"comment": "",
"limit": 0
},
"properties.forecastSliced.title": {
"value": "Displaying partial results.",
"comment": "",
"limit": 0
},
"properties.forecastSliced.description": {
"value": "Try changing the visualization settings to display all results.",
"comment": "",
"limit": 0
},
"properties.canvas.totalLabels": {
"value": "Total Labels",
"comment": "",
Expand Down
2 changes: 2 additions & 0 deletions libs/sdk-ui-ext/src/locales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ export const messages: Record<string, MessageDescriptor> = defineMessages({
forecastConfidence85: { id: "properties.forecastConfidence.85" },
forecastConfidence90: { id: "properties.forecastConfidence.90" },
forecastConfidence95: { id: "properties.forecastConfidence.95" },
forecastSlicedWarningTitle: { id: "properties.forecastSliced.title" },
forecastSlicedWarningDescription: { id: "properties.forecastSliced.description" },
});

export const comparisonMessages: Record<string, MessageDescriptor> = defineMessages({
Expand Down
8 changes: 7 additions & 1 deletion libs/sdk-ui-ext/styles/internal/scss/config_panel.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// (C) 2007-2021 GoodData Corporation
// (C) 2007-2024 GoodData Corporation
@use "sass:color";
@use "variables.scss";
@use "@gooddata/sdk-ui-kit/styles/scss/colorPicker";
Expand Down Expand Up @@ -161,3 +161,9 @@ $color-picker-spacing: 5px;
.gd-table-canvas-section.adi-bucket-configuration {
padding: 0;
}

.gd-forecast-section.adi-bucket-configuration {
.gd-slicedForecast-message {
margin-top: 15px;
}
}
11 changes: 9 additions & 2 deletions libs/sdk-ui/src/base/react/legacy/withEntireDataView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ export function withEntireDataView<T extends IDataVisualizationProps>(
return;
}

if (dataView.forecastConfig) {
if (dataView.forecastConfig && forecastConfig) {
try {
const forecastResult = await executionResult.readForecastAll(dataView.forecastConfig);
const updatedDataView = dataView.withForecast(
Expand All @@ -271,7 +271,14 @@ export function withEntireDataView<T extends IDataVisualizationProps>(
);
this.setState((s) => ({ ...s, dataView: updatedDataView }));
if (pushData) {
pushData({ dataView: updatedDataView });
pushData({
dataView: updatedDataView,
propertiesMeta: {
slicedForecast:
forecastConfig.forecastPeriod !==
dataView.forecastConfig?.forecastPeriod,
},
});
}
} catch (e) {
const updatedDataView = dataView.withForecast(undefined);
Expand Down

0 comments on commit a532126

Please sign in to comment.