Skip to content

Commit

Permalink
Remove localization. Let consumers supply the two strings we need. (#404
Browse files Browse the repository at this point in the history
)

* Remove localization. Let consumers supply the two strings we need.

* change
  • Loading branch information
grigasp authored Feb 7, 2024
1 parent 4d177c7 commit 6e8aa1a
Show file tree
Hide file tree
Showing 24 changed files with 117 additions and 223 deletions.
2 changes: 2 additions & 0 deletions .changeset/beige-suns-explode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
5 changes: 0 additions & 5 deletions packages/core-interop/api/presentation-core-interop.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import { IMetadataProvider } from '@itwin/presentation-hierarchy-builder';
import { InstancesNodeKey } from '@itwin/presentation-hierarchy-builder';
import { IPrimitiveValueFormatter } from '@itwin/presentation-hierarchy-builder';
import { KeySet } from '@itwin/presentation-common';
import { Localization } from '@itwin/core-common';
import { LocalizationFunction } from '@itwin/presentation-hierarchy-builder';
import { QueryBinder } from '@itwin/core-common';
import { QueryOptions } from '@itwin/core-common';
import { RulesetVariable } from '@itwin/presentation-common';
Expand Down Expand Up @@ -45,9 +43,6 @@ export interface CreateHierarchyLevelDescriptorProps<TIModel extends ICoreECSqlR
}) | undefined;
}

// @beta
export function createLocalizationFunction(localization: Localization): Promise<LocalizationFunction>;

// @beta
export function createLogger(): ILogger;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ Release Tag;API Item
beta;createECSqlQueryExecutor(imodel: ICoreECSqlReaderFactory): IECSqlQueryExecutor
beta;createHierarchyLevelDescriptor
beta;CreateHierarchyLevelDescriptorProps
beta;createLocalizationFunction(localization: Localization): Promise
beta;createLogger(): ILogger
beta;createMetadataProvider(schemaContext: SchemaContext): IMetadataProvider
beta;createValueFormatter(schemaContext: SchemaContext, unitSystem?: UnitSystemKey, baseFormatter?: IPrimitiveValueFormatter): IPrimitiveValueFormatter
Expand Down
16 changes: 0 additions & 16 deletions packages/core-interop/src/core-interop/Localization.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/core-interop/src/presentation-core-interop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

export * from "./core-interop/Formatting";
export * from "./core-interop/HierarchyLevelDescriptor";
export * from "./core-interop/Localization";
export * from "./core-interop/Logging";
export * from "./core-interop/Metadata";
export * from "./core-interop/QueryExecutor";
Expand Down
24 changes: 0 additions & 24 deletions packages/core-interop/src/test/Localization.test.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ export namespace NodeValidators {
}

export function createForPropertyOtherValuesGroupingNode<TChildren extends ExpectedHierarchyDef[] | boolean>(props: {
label?: string;
autoExpand?: boolean;
children?: TChildren;
}) {
Expand All @@ -188,7 +189,7 @@ export namespace NodeValidators {
}

validateBaseNodeAttributes(node, {
label: "Òthér",
label: props.label,
autoExpand: props.autoExpand,
children: props.children,
});
Expand Down

This file was deleted.

5 changes: 4 additions & 1 deletion packages/full-stack-tests/src/hierarchy-builder/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
createLimitingECSqlQueryExecutor,
HierarchyNodeIdentifiersPath,
HierarchyProvider,
HierarchyProviderLocalizedStrings,
IHierarchyLevelDefinitionsFactory,
IPrimitiveValueFormatter,
parseFullClassName,
Expand Down Expand Up @@ -53,14 +54,16 @@ export function createProvider(props: {
imodel: IModelConnection | IModelDb | ECDb;
hierarchy: IHierarchyLevelDefinitionsFactory;
formatterFactory?: (schemas: SchemaContext) => IPrimitiveValueFormatter;
localizedStrings?: HierarchyProviderLocalizedStrings;
filteredNodePaths?: HierarchyNodeIdentifiersPath[];
}) {
const { imodel, hierarchy, formatterFactory, filteredNodePaths } = props;
const { imodel, hierarchy, formatterFactory, localizedStrings, filteredNodePaths } = props;
return new HierarchyProvider({
metadataProvider: createMetadataProvider(imodel),
hierarchyDefinition: hierarchy,
queryExecutor: createLimitingECSqlQueryExecutor(createECSqlQueryExecutor(imodel), 123),
formatter: formatterFactory ? formatterFactory(createSchemaContext(imodel)) : undefined,
localizedStrings,
filtering: filteredNodePaths ? { paths: filteredNodePaths } : undefined,
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,8 @@

import { Subject } from "@itwin/core-backend";
import { IModel } from "@itwin/core-common";
import { IModelApp, IModelConnection } from "@itwin/core-frontend";
import { createLocalizationFunction } from "@itwin/presentation-core-interop";
import {
ECSqlSelectClausePropertiesGroupingParams,
IHierarchyLevelDefinitionsFactory,
NodeSelectQueryFactory,
setLocalizationFunction,
} from "@itwin/presentation-hierarchy-builder";
import { IModelConnection } from "@itwin/core-frontend";
import { ECSqlSelectClausePropertiesGroupingParams, IHierarchyLevelDefinitionsFactory, NodeSelectQueryFactory } from "@itwin/presentation-hierarchy-builder";
import { buildIModel, importSchema, insertSubject, withECDb } from "../../IModelUtils";
import { initialize, terminate } from "../../IntegrationTests";
import { NodeValidators, validateHierarchy } from "../HierarchyValidation";
Expand Down Expand Up @@ -284,16 +278,18 @@ describe("Stateless hierarchy builder", () => {
propertyGroups: [{ propertyName: "Description", propertyClassAlias: "this" }],
};

const localizationFunction = await createLocalizationFunction(IModelApp.localization);
setLocalizationFunction(localizationFunction);
await validateHierarchy({
provider: createProvider({ imodel, hierarchy: createHierarchyWithSpecifiedGrouping(imodel, groupingParams) }),
provider: createProvider({
imodel,
hierarchy: createHierarchyWithSpecifiedGrouping(imodel, groupingParams),
localizedStrings: { other: "", unspecified: "NOT SPECIFIED" },
}),
expect: [
NodeValidators.createForPropertyValueGroupingNode({
propertyClassName: "BisCore.Subject",
propertyName: "Description",
formattedPropertyValue: "",
label: "Ñót spêçìfíêd",
label: "NOT SPECIFIED",
children: [
NodeValidators.createForInstanceNode({
instanceKeys: [keys.childSubject1],
Expand Down Expand Up @@ -414,13 +410,12 @@ describe("Stateless hierarchy builder", () => {
return [];
},
};
const provider = createProvider({ imodel, hierarchy });
const localizationFunction = await createLocalizationFunction(IModelApp.localization);
setLocalizationFunction(localizationFunction);
const provider = createProvider({ imodel, hierarchy, localizedStrings: { other: "OTHER", unspecified: "" } });
await validateHierarchy({
provider,
expect: [
NodeValidators.createForPropertyOtherValuesGroupingNode({
label: "OTHER",
children: [NodeValidators.createForInstanceNode({ instanceKeys: [x1] }), NodeValidators.createForInstanceNode({ instanceKeys: [x2] })],
}),
],
Expand Down
2 changes: 0 additions & 2 deletions packages/hierarchy-builder/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
!lib/**/*.d.ts.map
!lib/**/*.js
!lib/**/*.js.map
!lib/**/public/**/*

# then ignore some stuff again
lib/**/test/**
lib/**/public/locales/en-PSEUDO/**
Original file line number Diff line number Diff line change
Expand Up @@ -730,13 +730,20 @@ export class HierarchyProvider {
setFormatter(formatter: IPrimitiveValueFormatter | undefined): void;
}

// @beta
export interface HierarchyProviderLocalizedStrings {
other: string;
unspecified: string;
}

// @beta
export interface HierarchyProviderProps {
filtering?: {
paths: HierarchyNodeIdentifiersPath[];
};
formatter?: IPrimitiveValueFormatter;
hierarchyDefinition: IHierarchyLevelDefinitionsFactory;
localizedStrings?: HierarchyProviderLocalizedStrings;
metadataProvider: IMetadataProvider;
queryConcurrency?: number;
queryExecutor: ILimitingECSqlQueryExecutor;
Expand Down Expand Up @@ -846,12 +853,6 @@ export interface LabelGroupingNodeKey extends BaseGroupingNodeKey {
type: "label-grouping";
}

// @beta
export const LOCALIZATION_NAMESPACE = "PresentationHierarchyBuilder";

// @beta
export type LocalizationFunction = (input: string) => string;

// @beta (undocumented)
export type LogFunction = (category: string, message: string) => void;

Expand Down Expand Up @@ -1087,9 +1088,6 @@ export class RowsLimitExceededError extends Error {
readonly limit: number;
}

// @beta
export function setLocalizationFunction(localizationFunction?: LocalizationFunction): void;

// @beta
export function setLogger(logger: ILogger | undefined): void;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ beta;HierarchyNodePropertyValueRange
beta;HierarchyNodesDefinition = CustomHierarchyNodeDefinition | InstanceNodesQueryDefinition
beta;HierarchyNodesDefinition
beta;HierarchyProvider
beta;HierarchyProviderLocalizedStrings
beta;HierarchyProviderProps
beta;Id64String = string
beta;IECSqlQueryExecutor
Expand All @@ -116,8 +117,6 @@ beta;InstancesNodeChildHierarchyLevelDefinition
beta;InstancesNodeKey
beta;IPrimitiveValueFormatter = (value: TypedPrimitiveValue) => Promise
beta;LabelGroupingNodeKey
beta;LOCALIZATION_NAMESPACE = "PresentationHierarchyBuilder"
beta;LocalizationFunction = (input: string) => string
beta;LogFunction = (category: string, message: string) => void
beta;NodeSelectClauseColumnNames
beta;NodeSelectClauseProps
Expand Down Expand Up @@ -155,7 +154,6 @@ beta;RelatedInstanceDescription
beta;RelationshipPath
beta;RelationshipPathStep
beta;RowsLimitExceededError
beta;setLocalizationFunction(localizationFunction?: LocalizationFunction): void
beta;setLogger(logger: ILogger | undefined): void
beta;StandardHierarchyNodeKey = InstancesNodeKey | GroupingNodeKey
beta;TypedPrimitiveValue
5 changes: 2 additions & 3 deletions packages/hierarchy-builder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@
"module": "lib/esm/presentation-hierarchy-builder.js",
"types": "lib/cjs/presentation-hierarchy-builder.d.ts",
"scripts": {
"build": "npm run -s copy:locale && npm run -s build:cjs && npm run -s build:esm",
"build": "npm run -s build:cjs && npm run -s build:esm",
"build:cjs": "tsc -p tsconfig.cjs.json",
"build:esm": "tsc -p tsconfig.esm.json",
"build:watch": "npm run -s copy:locale && npm run -s build:cjs -- -w",
"copy:locale": "cpx \"./public/**/*\" ./lib/public",
"build:watch": "npm run -s build:cjs -- -w",
"clean": "rimraf lib",
"cover": "nyc npm -s test",
"lint": "eslint ./src/**/*.ts",
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,24 @@ const DEFAULT_QUERY_CONCURRENCY = 10;
*/
export type ParentHierarchyNode = Omit<HierarchyNode, "children">;

/**
* Defines the strings used by hierarchy provider.
* @beta
*/
export interface HierarchyProviderLocalizedStrings {
/**
* A string for "Unspecified". Used for labels of property grouping nodes
* that group by an empty value.
*/
unspecified: string;

/**
* A string for "Other". Used for label of a range property grouping node that
* groups values which don't fit into any other range.
*/
other: string;
}

/**
* Props for [[HierarchyProvider]].
* @beta
Expand All @@ -86,6 +104,9 @@ export interface HierarchyProviderProps {
*/
formatter?: IPrimitiveValueFormatter;

/** A set of localized strings to use. Defaults to English strings. */
localizedStrings?: HierarchyProviderLocalizedStrings;

/** Props for filtering the hierarchy. */
filtering?: {
/** A list of node identifiers from root to target node. */
Expand Down Expand Up @@ -120,6 +141,7 @@ export class HierarchyProvider {
private _metadataProvider: IMetadataProvider;
private _queryReader: TreeQueryResultsReader;
private _valuesFormatter: IPrimitiveValueFormatter;
private _localizedStrings: HierarchyProviderLocalizedStrings;
private _queryScheduler: SubscriptionScheduler;
private _nodesCache: ChildNodesCache;

Expand Down Expand Up @@ -153,6 +175,7 @@ export class HierarchyProvider {
this._queryReader = new TreeQueryResultsReader({ parser: props.hierarchyDefinition.parseNode });
}
this._valuesFormatter = props?.formatter ?? createDefaultValueFormatter();
this._localizedStrings = props?.localizedStrings ?? { other: "Other", unspecified: "Not specified" };
this._queryScheduler = new SubscriptionScheduler(props.queryConcurrency ?? DEFAULT_QUERY_CONCURRENCY);
this._nodesCache = new ChildNodesCache();
this.queryExecutor = props.queryExecutor;
Expand Down Expand Up @@ -228,7 +251,7 @@ export class HierarchyProvider {
): Observable<ProcessedHierarchyNode> {
return preprocessedNodesObservable.pipe(
sortNodesByLabelOperator,
createGroupingOperator(this._metadataProvider, this._valuesFormatter, (gn) => this.onGroupingNodeCreated(gn, props)),
createGroupingOperator(this._metadataProvider, this._valuesFormatter, this._localizedStrings, (gn) => this.onGroupingNodeCreated(gn, props)),
);
}

Expand Down
Loading

0 comments on commit 6e8aa1a

Please sign in to comment.