Fix types selection for statistics-graph-card (#16988)

This commit is contained in:
karwosts 2023-06-21 08:10:00 -07:00 committed by GitHub
parent e9961b93f9
commit 752bc192cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 12 deletions

View File

@ -260,10 +260,10 @@ export const calculateStatisticsSumGrowth = (
export const statisticsHaveType = ( export const statisticsHaveType = (
stats: StatisticValue[], stats: StatisticValue[],
type: StatisticType type: StatisticType
) => stats.some((stat) => stat[type] !== null); ) => stats.some((stat) => stat[type] !== undefined && stat[type] !== null);
const mean_stat_types: readonly StatisticType[] = ["mean", "min", "max"]; const mean_stat_types: readonly StatisticType[] = ["mean", "min", "max"];
const sum_stat_types: readonly StatisticType[] = ["sum"]; const sum_stat_types: readonly StatisticType[] = ["sum", "state", "change"];
export const statisticsMetaHasType = ( export const statisticsMetaHasType = (
metadata: StatisticsMetaData, metadata: StatisticsMetaData,

View File

@ -187,7 +187,7 @@ export class HuiStatisticsGraphCardEditor
), ),
disabled: disabled:
!metaDatas || !metaDatas ||
!metaDatas.every((metaData) => !metaDatas.some((metaData) =>
statisticsMetaHasType( statisticsMetaHasType(
metaData, metaData,
supportedStatTypeMap[stat_type] supportedStatTypeMap[stat_type]
@ -246,12 +246,10 @@ export class HuiStatisticsGraphCardEditor
); );
const configured_stat_types = this._config!.stat_types const configured_stat_types = this._config!.stat_types
? ensureArray(this._config.stat_types) ? ensureArray(this._config.stat_types)
: stat_types.filter( : stat_types.filter((stat_type) =>
(stat_type) => this._metaDatas?.some((metaData) =>
stat_type !== "change" && statisticsMetaHasType(metaData, stat_type)
this._metaDatas?.every((metaData) => )
statisticsMetaHasType(metaData, stat_type)
)
); );
const data = { const data = {
chart_type: "line", chart_type: "line",
@ -320,9 +318,7 @@ export class HuiStatisticsGraphCardEditor
: undefined; : undefined;
if (config.stat_types && config.entities.length) { if (config.stat_types && config.entities.length) {
config.stat_types = ensureArray(config.stat_types).filter((stat_type) => config.stat_types = ensureArray(config.stat_types).filter((stat_type) =>
metadata!.every((metaData) => metadata!.some((metaData) => statisticsMetaHasType(metaData, stat_type))
statisticsMetaHasType(metaData, stat_type)
)
); );
if (!config.stat_types.length) { if (!config.stat_types.length) {
delete config.stat_types; delete config.stat_types;