Skip to content

Commit

Permalink
Merge pull request #5033 from gooddata/ine-lx-183
Browse files Browse the repository at this point in the history
feat: attribute filter with secondary label
  • Loading branch information
xMort authored Jun 20, 2024
2 parents 928455e + 0b32771 commit c78e1a9
Show file tree
Hide file tree
Showing 67 changed files with 2,436 additions and 84 deletions.
3 changes: 3 additions & 0 deletions libs/api-client-tiger/api/api-client-tiger.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { AxiosInstance } from 'axios';
import { AxiosPromise } from 'axios';
import { AxiosRequestConfig } from 'axios';
import { AxiosResponse } from 'axios';
import { IAttributeFilterConfigs } from '@gooddata/sdk-model';
import { IBucket } from '@gooddata/sdk-model';
import { IDashboardAttributeFilterConfig } from '@gooddata/sdk-model';
import { IDashboardDateFilterConfig } from '@gooddata/sdk-model';
Expand Down Expand Up @@ -6960,6 +6961,8 @@ interface IVisualizationObject {

// @public
interface IVisualizationObject_2 {
// (undocumented)
attributeFilterConfigs?: IAttributeFilterConfigs;
// (undocumented)
buckets: IBucket[];
// (undocumented)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
// (C) 2019-2021 GoodData Corporation
// (C) 2019-2024 GoodData Corporation
import isEmpty from "lodash/isEmpty.js";
import { IBucket, IFilter, ISortItem, VisualizationProperties } from "@gooddata/sdk-model";
import {
IBucket,
IFilter,
IAttributeFilterConfigs,
ISortItem,
VisualizationProperties,
} from "@gooddata/sdk-model";

/**
* Visualization object used to store its data as a metadata object
Expand All @@ -11,6 +17,7 @@ export interface IVisualizationObject {
visualizationUrl: string;
buckets: IBucket[];
filters: IFilter[];
attributeFilterConfigs?: IAttributeFilterConfigs;
sorts: ISortItem[];
properties: VisualizationProperties;
}
Expand Down
2 changes: 2 additions & 0 deletions libs/sdk-backend-base/api/sdk-backend-base.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ export class AttributeDisplayFormMetadataObjectBuilder<T extends IAttributeDispl
displayFormType(type: string | undefined): this;
// (undocumented)
isDefault(value: boolean | undefined): this;
// (undocumented)
isPrimary(value: boolean | undefined): this;
}

// @beta
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// (C) 2019-2022 GoodData Corporation
// (C) 2019-2024 GoodData Corporation
import identity from "lodash/identity.js";
import { ObjRef, IAttributeDisplayFormMetadataObject } from "@gooddata/sdk-model";
import { MetadataObjectBuilder } from "./factory.js";
Expand Down Expand Up @@ -27,6 +27,11 @@ export class AttributeDisplayFormMetadataObjectBuilder<
this.item.isDefault = value;
return this;
}

public isPrimary(value: boolean | undefined): this {
this.item.isPrimary = value;
return this;
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ export class RecordedDashboards implements IWorkspaceDashboardsService {
return Promise.resolve([
{
negativeAttributeFilter: {
localIdentifier: "naf_01",
displayForm: {
uri: "/example/md/mock/123",
},
Expand Down
1 change: 1 addition & 0 deletions libs/sdk-backend-spi/api/sdk-backend-spi.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ export interface IElementsQueryOptions {
elements?: ElementsQueryOptionsElementsSpecification;
excludePrimaryLabel?: boolean;
filter?: string;
filterByPrimaryLabel?: boolean;
includeTotalCountWithoutFilters?: boolean;
order?: SortDirection;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,14 @@ export interface IElementsQueryOptions {
*/
excludePrimaryLabel?: boolean;

/**
* Provided filter uses values from primary label.
*
* @remarks
* This is to allow getting elements of requested label corresponding to primary label values in filter.
*/
filterByPrimaryLabel?: boolean;

/**
* Cache ID to use when requesting subsequent elements from the backend.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,11 @@ class TigerWorkspaceElementsQuery implements IElementsQuery {
}),
...(this.validateBy && { validateBy: this.validateBy.map(this.mapValidationItems) }),
...(cacheId && { cacheId: cacheId }),
...(options?.filterByPrimaryLabel && {
filterBy: {
labelType: FilterByLabelTypeEnum.PRIMARY,
},
}),
};

const elementsRequestWrapped: Parameters<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,16 @@ const commonGroupableCatalogItemModifications =
const tigerLabelToDisplayFormMd = (
label: JsonApiLabelOutWithLinks,
attributeRef: ObjRef,
defaultLabelId?: string,
): IAttributeDisplayFormMetadataObject => {
return newAttributeDisplayFormMetadataObject(idRef(label.id, "displayForm"), (builder) => {
const labelBuilder = commonMetadataObjectModifications(label)(
builder,
) as AttributeDisplayFormMetadataObjectBuilder;
labelBuilder.displayFormType(convertLabelType(label.attributes?.valueType));
labelBuilder.attribute(attributeRef);
labelBuilder.isPrimary(!!label.attributes?.primary);
labelBuilder.isDefault(label.id === defaultLabelId);
return labelBuilder;
});
};
Expand All @@ -66,7 +69,7 @@ export const convertAttribute = (
const attributeRef = idRef(attribute.id, "attribute");

const geoPinDisplayForms = geoLabels.map((df) => tigerLabelToDisplayFormMd(df, attributeRef));
const displayForms = allLabels.map((df) => tigerLabelToDisplayFormMd(df, attributeRef));
const displayForms = allLabels.map((df) => tigerLabelToDisplayFormMd(df, attributeRef, defaultLabel.id));
const defaultDisplayForm = displayForms.find((df) => df.id === defaultLabel.id)!;

return newCatalogAttribute((catalogA) =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// (C) 2019-2023 GoodData Corporation
// (C) 2019-2024 GoodData Corporation
import {
JsonApiAnalyticalDashboardOutWithLinks,
JsonApiAttributeOut,
Expand Down Expand Up @@ -78,9 +78,11 @@ function convertAttributeLabels(
return undefined;
}

const isDefault = defaultView ? defaultView.id === label.id : !!label.attributes?.primary;
const isPrimary = !!label.attributes?.primary;

return convertLabelWithLinks(label, attribute.id, isDefault);
const isDefault = defaultView ? defaultView.id === label.id : isPrimary;

return convertLabelWithLinks(label, attribute.id, isDefault, isPrimary);
})
.filter((df): df is IAttributeDisplayFormMetadataObject => df !== undefined);
}
Expand Down Expand Up @@ -126,6 +128,7 @@ function convertLabelWithLinks(
label: JsonApiLabelOutWithLinks,
attributeId: string,
isDefault: boolean,
isPrimary: boolean,
): IAttributeDisplayFormMetadataObject {
return newAttributeDisplayFormMetadataObject(idRef(label.id, "displayForm"), (m) =>
m
Expand All @@ -135,6 +138,7 @@ function convertLabelWithLinks(
.uri(label.links!.self)
.attribute(idRef(attributeId, "attribute"))
.isDefault(isDefault)
.isPrimary(isPrimary)
.displayFormType(convertLabelType(label.attributes?.valueType)),
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// (C) 2019-2022 GoodData Corporation
// (C) 2019-2024 GoodData Corporation
import { IInsightDefinition } from "@gooddata/sdk-model";
import { VisualizationObjectModelV2 } from "@gooddata/api-client-tiger";
import { cloneWithSanitizedIds } from "../../IdSanitization.js";
Expand All @@ -19,6 +19,9 @@ export function convertVisualizationObject(
summary: description,
buckets: cloneWithSanitizedIds(visualizationObject.buckets) ?? [],
filters: cloneWithSanitizedIds(visualizationObject.filters) ?? [],
...(visualizationObject.attributeFilterConfigs
? { attributeFilterConfigs: visualizationObject.attributeFilterConfigs }
: {}),
sorts: cloneWithSanitizedIds(visualizationObject.sorts) ?? [],
tags,
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// (C) 2019-2021 GoodData Corporation
// (C) 2019-2024 GoodData Corporation
import { IInsight, IInsightDefinition } from "@gooddata/sdk-model";
import { VisualizationObjectModelV2 } from "@gooddata/api-client-tiger";
import { cloneWithSanitizedIds } from "./IdSanitization.js";
Expand Down Expand Up @@ -35,6 +35,9 @@ export const convertInsight = (
return {
buckets: cloneWithSanitizedIds(sanitizedInsight.insight.buckets),
filters: cloneWithSanitizedIds(sanitizedInsight.insight.filters),
...(sanitizedInsight.insight.attributeFilterConfigs
? { attributeFilterConfigs: sanitizedInsight.insight.attributeFilterConfigs }
: {}),
sorts: cloneWithSanitizedIds(sanitizedInsight.insight.sorts),
properties: sanitizedInsight.insight.properties,
visualizationUrl: sanitizedInsight.insight.visualizationUrl,
Expand Down
Loading

0 comments on commit c78e1a9

Please sign in to comment.