ui: fix filter options reset, fix dashboard chart density
This commit is contained in:
parent
a009ff928c
commit
d2d886b322
6 changed files with 32 additions and 12 deletions
|
|
@ -181,9 +181,10 @@ function WidgetChart(props: Props) {
|
||||||
}
|
}
|
||||||
prevMetricRef.current = _metric;
|
prevMetricRef.current = _metric;
|
||||||
const timestmaps = drillDownPeriod.toTimestamps();
|
const timestmaps = drillDownPeriod.toTimestamps();
|
||||||
|
const density = props.isPreview ? metric.density : dashboardStore.selectedDensity
|
||||||
const payload = isSaved
|
const payload = isSaved
|
||||||
? { ...metricParams }
|
? { ...metricParams, density }
|
||||||
: { ...params, ...timestmaps, ..._metric.toJson() };
|
: { ...params, ...timestmaps, ..._metric.toJson(), density };
|
||||||
debounceRequest(
|
debounceRequest(
|
||||||
_metric,
|
_metric,
|
||||||
payload,
|
payload,
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ function RangeGranularity({
|
||||||
}
|
}
|
||||||
|
|
||||||
const PAST_24_HR_MS = 24 * 60 * 60 * 1000;
|
const PAST_24_HR_MS = 24 * 60 * 60 * 1000;
|
||||||
function calculateGranularities(periodDurationMs: number) {
|
export function calculateGranularities(periodDurationMs: number) {
|
||||||
const granularities = [
|
const granularities = [
|
||||||
{ label: 'Hourly', durationMs: 60 * 60 * 1000 },
|
{ label: 'Hourly', durationMs: 60 * 60 * 1000 },
|
||||||
{ label: 'Daily', durationMs: 24 * 60 * 60 * 1000 },
|
{ label: 'Daily', durationMs: 24 * 60 * 60 * 1000 },
|
||||||
|
|
|
||||||
|
|
@ -125,7 +125,7 @@ export function AutocompleteModal({
|
||||||
if (index === blocksAmount - 1 && blocksAmount > 1) {
|
if (index === blocksAmount - 1 && blocksAmount > 1) {
|
||||||
str += ' and ';
|
str += ' and ';
|
||||||
}
|
}
|
||||||
str += `"${block.trim()}"`;
|
str += block.trim();
|
||||||
if (index < blocksAmount - 2) {
|
if (index < blocksAmount - 2) {
|
||||||
str += ', ';
|
str += ', ';
|
||||||
}
|
}
|
||||||
|
|
@ -188,10 +188,10 @@ export function AutocompleteModal({
|
||||||
{query.length ? (
|
{query.length ? (
|
||||||
<div className="border-y border-y-gray-light py-2">
|
<div className="border-y border-y-gray-light py-2">
|
||||||
<div
|
<div
|
||||||
className="whitespace-normal rounded cursor-pointer text-teal hover:bg-active-blue px-2 py-1"
|
className="whitespace-nowrap truncate w-full rounded cursor-pointer text-teal hover:bg-active-blue px-2 py-1"
|
||||||
onClick={applyQuery}
|
onClick={applyQuery}
|
||||||
>
|
>
|
||||||
{t('Apply')} {queryStr}
|
{t('Apply')} <span className='font-semibold'>{queryStr}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
|
||||||
|
|
@ -128,8 +128,10 @@ const FilterAutoComplete = observer(
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleFocus = () => {
|
const handleFocus = () => {
|
||||||
|
if (!initialFocus) {
|
||||||
|
setOptions(topValues.map((i) => ({ value: i.value, label: i.value })));
|
||||||
|
}
|
||||||
setInitialFocus(true);
|
setInitialFocus(true);
|
||||||
setOptions(topValues.map((i) => ({ value: i.value, label: i.value })));
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { makeAutoObservable, runInAction } from 'mobx';
|
import { makeAutoObservable, runInAction, reaction } from 'mobx';
|
||||||
import { dashboardService, metricService } from 'App/services';
|
import { dashboardService, metricService } from 'App/services';
|
||||||
import { toast } from 'react-toastify';
|
import { toast } from 'react-toastify';
|
||||||
import Period, { LAST_24_HOURS, LAST_7_DAYS } from 'Types/app/period';
|
import Period, { LAST_24_HOURS, LAST_7_DAYS } from 'Types/app/period';
|
||||||
|
|
@ -6,6 +6,7 @@ import { getRE } from 'App/utils';
|
||||||
import Filter from './types/filter';
|
import Filter from './types/filter';
|
||||||
import Widget from './types/widget';
|
import Widget from './types/widget';
|
||||||
import Dashboard from './types/dashboard';
|
import Dashboard from './types/dashboard';
|
||||||
|
import { calculateGranularities } from '@/components/Dashboard/components/WidgetDateRange/RangeGranularity';
|
||||||
|
|
||||||
interface DashboardFilter {
|
interface DashboardFilter {
|
||||||
query?: string;
|
query?: string;
|
||||||
|
|
@ -36,7 +37,7 @@ export default class DashboardStore {
|
||||||
|
|
||||||
drillDownPeriod: Record<string, any> = Period({ rangeName: LAST_24_HOURS });
|
drillDownPeriod: Record<string, any> = Period({ rangeName: LAST_24_HOURS });
|
||||||
|
|
||||||
selectedDensity: number = 7; // depends on default drilldown, 7 points here!!!;
|
selectedDensity: number = 7;
|
||||||
|
|
||||||
comparisonPeriods: Record<string, any> = {};
|
comparisonPeriods: Record<string, any> = {};
|
||||||
|
|
||||||
|
|
@ -83,10 +84,25 @@ export default class DashboardStore {
|
||||||
makeAutoObservable(this);
|
makeAutoObservable(this);
|
||||||
|
|
||||||
this.resetDrillDownFilter();
|
this.resetDrillDownFilter();
|
||||||
|
|
||||||
|
this.createDensity(this.period.getDuration());
|
||||||
|
reaction(
|
||||||
|
() => this.period,
|
||||||
|
(period) => {
|
||||||
|
this.createDensity(period.getDuration());
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
setDensity = (density: any) => {
|
createDensity = (duration: number) => {
|
||||||
this.selectedDensity = parseInt(density, 10);
|
const densityOpts = calculateGranularities(duration);
|
||||||
|
const defaultOption = densityOpts[densityOpts.length - 2];
|
||||||
|
|
||||||
|
this.setDensity(defaultOption.key)
|
||||||
|
}
|
||||||
|
|
||||||
|
setDensity = (density: number) => {
|
||||||
|
this.selectedDensity = density;
|
||||||
};
|
};
|
||||||
|
|
||||||
get sortedDashboards() {
|
get sortedDashboards() {
|
||||||
|
|
@ -529,7 +545,7 @@ export default class DashboardStore {
|
||||||
const data = await metricService.getMetricChartData(
|
const data = await metricService.getMetricChartData(
|
||||||
metric,
|
metric,
|
||||||
params,
|
params,
|
||||||
isSaved,
|
isSaved
|
||||||
);
|
);
|
||||||
resolve(metric.setData(data, period, isComparison, density));
|
resolve(metric.setData(data, period, isComparison, density));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
||||||
|
|
@ -163,6 +163,7 @@ export default class Widget {
|
||||||
fromJson(json: any, period?: any) {
|
fromJson(json: any, period?: any) {
|
||||||
json.config = json.config || {};
|
json.config = json.config || {};
|
||||||
runInAction(() => {
|
runInAction(() => {
|
||||||
|
this.dashboardId = json.dashboardId;
|
||||||
this.metricId = json.metricId;
|
this.metricId = json.metricId;
|
||||||
this.widgetId = json.widgetId;
|
this.widgetId = json.widgetId;
|
||||||
this.metricValue = this.metricValueFromArray(
|
this.metricValue = this.metricValueFromArray(
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue