-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support for search in pivot data store (#6172)
* Move config out * Add support for search in pivot data store
- Loading branch information
Showing
6 changed files
with
170 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
152 changes: 152 additions & 0 deletions
152
web-common/src/features/dashboards/pivot/pivot-data-config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
import { mergeMeasureFilters } from "@rilldata/web-common/features/dashboards/filters/measure-filters/measure-filter-utils"; | ||
import { allDimensions } from "@rilldata/web-common/features/dashboards/state-managers/selectors/dimensions"; | ||
import { allMeasures } from "@rilldata/web-common/features/dashboards/state-managers/selectors/measures"; | ||
import type { StateManagers } from "@rilldata/web-common/features/dashboards/state-managers/state-managers"; | ||
import { | ||
dimensionSearchText, | ||
metricsExplorerStore, | ||
} from "@rilldata/web-common/features/dashboards/stores/dashboard-stores"; | ||
import { timeControlStateSelector } from "@rilldata/web-common/features/dashboards/time-controls/time-control-store"; | ||
import type { TimeRangeString } from "@rilldata/web-common/lib/time/types"; | ||
import { type Readable, derived } from "svelte/store"; | ||
import { canEnablePivotComparison, getPivotConfigKey } from "./pivot-utils"; | ||
import { | ||
COMPARISON_DELTA, | ||
COMPARISON_PERCENT, | ||
PivotChipType, | ||
type PivotDataStoreConfig, | ||
type PivotTimeConfig, | ||
} from "./types"; | ||
|
||
let lastKey: string | undefined = undefined; | ||
|
||
/** | ||
* Extract out config relevant to pivot from dashboard and meta store | ||
*/ | ||
export function getPivotConfig( | ||
ctx: StateManagers, | ||
): Readable<PivotDataStoreConfig> { | ||
return derived( | ||
[ | ||
ctx.validSpecStore, | ||
ctx.timeRangeSummaryStore, | ||
ctx.dashboardStore, | ||
dimensionSearchText, | ||
], | ||
([validSpec, timeRangeSummary, dashboardStore, searchText]) => { | ||
if ( | ||
!validSpec?.data?.metricsView || | ||
!validSpec?.data?.explore || | ||
timeRangeSummary.isFetching | ||
) { | ||
return { | ||
measureNames: [], | ||
rowDimensionNames: [], | ||
colDimensionNames: [], | ||
allMeasures: [], | ||
allDimensions: [], | ||
whereFilter: dashboardStore.whereFilter, | ||
pivot: dashboardStore.pivot, | ||
time: {} as PivotTimeConfig, | ||
comparisonTime: undefined, | ||
enableComparison: false, | ||
searchText, | ||
}; | ||
} | ||
|
||
const { metricsView, explore } = validSpec.data; | ||
|
||
// This indirection makes sure only one update of dashboard store triggers this | ||
const timeControl = timeControlStateSelector([ | ||
metricsView, | ||
explore, | ||
timeRangeSummary, | ||
dashboardStore, | ||
]); | ||
|
||
const time: PivotTimeConfig = { | ||
timeStart: timeControl.timeStart, | ||
timeEnd: timeControl.timeEnd, | ||
timeZone: dashboardStore?.selectedTimezone || "UTC", | ||
timeDimension: metricsView.timeDimension || "", | ||
}; | ||
|
||
const enableComparison = | ||
canEnablePivotComparison( | ||
dashboardStore.pivot, | ||
timeControl.comparisonTimeStart, | ||
) && !!timeControl.showTimeComparison; | ||
|
||
let comparisonTime: TimeRangeString | undefined = undefined; | ||
if (enableComparison) { | ||
comparisonTime = { | ||
start: timeControl.comparisonTimeStart, | ||
end: timeControl.comparisonTimeEnd, | ||
}; | ||
} | ||
|
||
const measureNames = dashboardStore.pivot.columns.measure.flatMap((m) => { | ||
const measureName = m.id; | ||
const group = [measureName]; | ||
|
||
if (enableComparison) { | ||
group.push( | ||
`${measureName}${COMPARISON_DELTA}`, | ||
`${measureName}${COMPARISON_PERCENT}`, | ||
); | ||
} | ||
return group; | ||
}); | ||
|
||
// This is temporary until we have a better way to handle time grains | ||
const rowDimensionNames = dashboardStore.pivot.rows.dimension.map((d) => { | ||
if (d.type === PivotChipType.Time) { | ||
return `${time.timeDimension}_rill_${d.id}`; | ||
} | ||
return d.id; | ||
}); | ||
|
||
const colDimensionNames = dashboardStore.pivot.columns.dimension.map( | ||
(d) => { | ||
if (d.type === PivotChipType.Time) { | ||
return `${time.timeDimension}_rill_${d.id}`; | ||
} | ||
return d.id; | ||
}, | ||
); | ||
|
||
const config: PivotDataStoreConfig = { | ||
measureNames, | ||
rowDimensionNames, | ||
colDimensionNames, | ||
allMeasures: allMeasures({ | ||
validMetricsView: metricsView, | ||
validExplore: explore, | ||
}), | ||
allDimensions: allDimensions({ | ||
validMetricsView: metricsView, | ||
validExplore: explore, | ||
}), | ||
whereFilter: mergeMeasureFilters(dashboardStore), | ||
pivot: dashboardStore.pivot, | ||
enableComparison, | ||
comparisonTime, | ||
time, | ||
searchText, | ||
}; | ||
|
||
const currentKey = getPivotConfigKey(config); | ||
|
||
if (lastKey !== currentKey) { | ||
// Reset rowPage when pivot config changes | ||
lastKey = currentKey; | ||
if (config.pivot.rowPage !== 1) { | ||
metricsExplorerStore.setPivotRowPage(dashboardStore.name, 1); | ||
config.pivot.rowPage = 1; | ||
} | ||
} | ||
|
||
return config; | ||
}, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a3de19c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 Published on https://ui.rilldata.in as production
🚀 Deployed on https://674602f55958cfb9235a362a--rill-ui-dev.netlify.app