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

add visibility actions for measures and dimensions #5736

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,32 @@ export const setPrimaryDimension = (
}
};

export const toggleDimensionVisibility = (
{ dashboard }: DashboardMutables,

dimensionName: string,
) => {
const deleted = dashboard.visibleDimensionKeys.delete(dimensionName);

if (!deleted) {
dashboard.visibleDimensionKeys.add(dimensionName);
}
};

export const setVisibleDimensions = (
{ dashboard }: DashboardMutables,
dimensions: string[],
) => {
dashboard.visibleDimensionKeys = new Set(dimensions);
};

export const dimensionActions = {
/**
* Sets the primary dimension for the dashboard, which
* activates the dimension table. Setting the primary dimension
* to undefined closes the dimension table.
*/
setPrimaryDimension,
toggleDimensionVisibility,
setVisibleDimensions,
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import type {
DashboardUpdaters,
} from "./types";
import { dimensionActions } from "./dimensions";
import { measureActions } from "./measures";
import { comparisonActions } from "./comparison";
import { dimensionFilterActions } from "./dimension-filters";

Expand Down Expand Up @@ -55,6 +56,11 @@ export const createStateManagerActions = (
*/
dimensions: createDashboardUpdaters(actionArgs, dimensionActions),

/**
* Actions related to measures.
*/
measures: createDashboardUpdaters(actionArgs, measureActions),

/**
* Common filter actions
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import type { DashboardMutables } from "./types";

export const toggleMeasureVisibility = (
{ dashboard }: DashboardMutables,

measureName: string,
) => {
const deleted = dashboard.visibleMeasureKeys.delete(measureName);

if (!deleted) {
dashboard.visibleMeasureKeys.add(measureName);
}
};

export const setVisibleMeasures = (
{ dashboard }: DashboardMutables,
measureNames: string[],
) => {
dashboard.visibleMeasureKeys = new Set(measureNames);
};

export const measureActions = {
setVisibleMeasures,
toggleMeasureVisibility,
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@ import type { DashboardDataSources } from "./types";

export const allDimensions = ({
metricsSpecQueryResult,
}: DashboardDataSources): MetricsViewSpecDimensionV2[] | undefined => {
}: DashboardDataSources) => {
return metricsSpecQueryResult.data?.dimensions;
};

export const visibleDimensions = ({
metricsSpecQueryResult,
dashboard,
}: DashboardDataSources): MetricsViewSpecDimensionV2[] => {
const dimensions = metricsSpecQueryResult.data?.dimensions?.filter(
}: DashboardDataSources) => {
return metricsSpecQueryResult.data?.dimensions.filter(
(d) => d.name && dashboard.visibleDimensionKeys.has(d.name),
);
return dimensions === undefined ? [] : dimensions;
};

export const dimensionTableDimName = ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,17 @@ import type { DashboardDataSources } from "./types";

export const allMeasures = ({
metricsSpecQueryResult,
}: DashboardDataSources): MetricsViewSpecMeasureV2[] => {
const measures = metricsSpecQueryResult.data?.measures;
return measures === undefined ? [] : measures;
}: DashboardDataSources) => {
return metricsSpecQueryResult.data?.measures;
};

export const visibleMeasures = ({
metricsSpecQueryResult,
dashboard,
}: DashboardDataSources): MetricsViewSpecMeasureV2[] => {
const measures = metricsSpecQueryResult.data?.measures?.filter(
}: DashboardDataSources) => {
return metricsSpecQueryResult.data?.measures.filter(
(d) => d.name && dashboard.visibleMeasureKeys.has(d.name),
);
return measures === undefined ? [] : measures;
};

export const getMeasureByName = (
Expand Down
Loading