Skip to content

Commit 280d869

Browse files
authored
Add FormatSetSelector, FormatSetPanel, make UI more consistent (#1456)
1 parent 5ce3b8b commit 280d869

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+2139
-485
lines changed

apps/learning-snippets/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"dependencies": {
1818
"@itwin/tree-widget-react": "workspace:*",
1919
"@itwin/property-grid-react": "workspace:*",
20+
"@itwin/quantity-formatting-react": "workspace:*",
2021
"@itwin/itwinui-react": "^3.19.3",
2122
"@itwin/appui-abstract": "^5.1.1",
2223
"@itwin/appui-react": "^5.13.0",

apps/learning-snippets/pnpm-lock.yaml

Lines changed: 25 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/learning-snippets/scripts/linkWorkspaceDeps.cjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ const packages = [
1515
name: "@itwin/property-grid-react",
1616
dir: "property-grid",
1717
},
18+
{
19+
name: "@itwin/quantity-formatting-react",
20+
dir: "quantity-formatting",
21+
},
1822
];
1923

2024
linkPackages();
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3+
* See LICENSE.md in the project root for license terms and full copyright notice.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import { expect } from "chai";
7+
import { render, screen } from "@testing-library/react";
8+
// __PUBLISH_EXTRACT_START__ QuantityFormat.FormatSelectorExampleImports
9+
import { FormatSelector } from "@itwin/quantity-formatting-react";
10+
import type { FormatDefinition } from "@itwin/core-quantity";
11+
import type { FormatSet } from "@itwin/ecschema-metadata";
12+
// __PUBLISH_EXTRACT_END__
13+
import { QuantityFormattingTestUtils } from "../../utils/QuantityFormattingTestUtils.js";
14+
15+
describe("Quantity formatting", () => {
16+
describe("Learning snippets", () => {
17+
describe("FormatSelector", () => {
18+
before(async function () {
19+
await QuantityFormattingTestUtils.initialize();
20+
});
21+
22+
after(async function () {
23+
await QuantityFormattingTestUtils.terminate();
24+
});
25+
26+
it("renders FormatSelector", async function () {
27+
// __PUBLISH_EXTRACT_START__ QuantityFormat.FormatSelectorExample
28+
const formatSet: FormatSet = {
29+
name: "TestSet",
30+
label: "Test Format Set",
31+
unitSystem: "metric",
32+
formats: {
33+
"test-format": {
34+
name: "test-format",
35+
label: "Test Format",
36+
type: "Decimal",
37+
precision: 2,
38+
composite: { units: [{ name: "Units.M", label: "m" }] },
39+
},
40+
},
41+
} as FormatSet;
42+
43+
const handleFormatSelection = (_formatDef: FormatDefinition, _key: string) => {
44+
// Handle format selection
45+
};
46+
47+
render(<FormatSelector activeFormatSet={formatSet} activeFormatDefinitionKey={undefined} onListItemChange={handleFormatSelection} />);
48+
// __PUBLISH_EXTRACT_END__
49+
50+
expect(screen.getByPlaceholderText("labels.searchFormats")).to.exist;
51+
});
52+
});
53+
});
54+
});
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3+
* See LICENSE.md in the project root for license terms and full copyright notice.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import { expect } from "chai";
7+
import { render, screen } from "@testing-library/react";
8+
// __PUBLISH_EXTRACT_START__ QuantityFormat.FormatSetPanelExampleImports
9+
import { FormatSetPanel } from "@itwin/quantity-formatting-react";
10+
import type { FormatSet } from "@itwin/ecschema-metadata";
11+
// __PUBLISH_EXTRACT_END__
12+
import { QuantityFormattingTestUtils } from "../../utils/QuantityFormattingTestUtils.js";
13+
14+
describe("Quantity formatting", () => {
15+
describe("Learning snippets", () => {
16+
describe("FormatSetPanel", () => {
17+
before(async function () {
18+
await QuantityFormattingTestUtils.initialize();
19+
});
20+
21+
after(async function () {
22+
await QuantityFormattingTestUtils.terminate();
23+
});
24+
25+
it("renders FormatSetPanel in editable mode", async function () {
26+
// __PUBLISH_EXTRACT_START__ QuantityFormat.FormatSetPanelEditableExample
27+
const formatSet: FormatSet = {
28+
name: "CustomSet",
29+
label: "Custom Format Set",
30+
unitSystem: "metric",
31+
description: "A custom format set",
32+
formats: {},
33+
} as FormatSet;
34+
35+
const handleFormatSetChange = (_updatedFormatSet: FormatSet) => {
36+
// Handle format set change
37+
};
38+
39+
render(<FormatSetPanel formatSet={formatSet} editable={true} onFormatSetChange={handleFormatSetChange} />);
40+
// __PUBLISH_EXTRACT_END__
41+
42+
expect(screen.getByText("labels.formatSetDetails")).to.exist;
43+
});
44+
45+
it("renders FormatSetPanel in read-only mode", async function () {
46+
// __PUBLISH_EXTRACT_START__ QuantityFormat.FormatSetPanelReadOnlyExample
47+
const formatSet: FormatSet = {
48+
name: "ReadOnlySet",
49+
label: "Read-Only Format Set",
50+
unitSystem: "imperial",
51+
description: "A read-only format set",
52+
formats: {},
53+
} as FormatSet;
54+
55+
render(<FormatSetPanel formatSet={formatSet} editable={false} />);
56+
// __PUBLISH_EXTRACT_END__
57+
58+
expect(screen.getByText("labels.formatSetDetails")).to.exist;
59+
const labelInput = screen.getByLabelText("labels.description");
60+
expect((labelInput as HTMLInputElement).disabled).to.be.true;
61+
});
62+
});
63+
});
64+
});
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3+
* See LICENSE.md in the project root for license terms and full copyright notice.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import { expect } from "chai";
7+
import { render, screen } from "@testing-library/react";
8+
// __PUBLISH_EXTRACT_START__ QuantityFormat.FormatSetSelectorExampleImports
9+
import { FormatSetSelector } from "@itwin/quantity-formatting-react";
10+
import type { FormatSet } from "@itwin/ecschema-metadata";
11+
// __PUBLISH_EXTRACT_END__
12+
import { QuantityFormattingTestUtils } from "../../utils/QuantityFormattingTestUtils.js";
13+
14+
describe("Quantity formatting", () => {
15+
describe("Learning snippets", () => {
16+
describe("FormatSetSelector", () => {
17+
before(async function () {
18+
await QuantityFormattingTestUtils.initialize();
19+
});
20+
21+
after(async function () {
22+
await QuantityFormattingTestUtils.terminate();
23+
});
24+
25+
it("renders FormatSetSelector", async function () {
26+
// __PUBLISH_EXTRACT_START__ QuantityFormat.FormatSetSelectorExample
27+
const formatSets: FormatSet[] = [
28+
{
29+
name: "MetricSet",
30+
label: "Metric Formats",
31+
unitSystem: "metric",
32+
description: "Standard metric unit formats",
33+
formats: {},
34+
} as FormatSet,
35+
{
36+
name: "ImperialSet",
37+
label: "Imperial Formats",
38+
unitSystem: "imperial",
39+
description: "Imperial unit formats",
40+
formats: {},
41+
} as FormatSet,
42+
];
43+
44+
const handleFormatSetChange = (_formatSet: FormatSet, _key: string) => {
45+
// Handle format set change
46+
};
47+
48+
render(<FormatSetSelector formatSets={formatSets} selectedFormatSetKey={undefined} onFormatSetChange={handleFormatSetChange} />);
49+
// __PUBLISH_EXTRACT_END__
50+
51+
expect(screen.getByPlaceholderText("labels.searchFormatSets")).to.exist;
52+
});
53+
});
54+
});
55+
});
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3+
* See LICENSE.md in the project root for license terms and full copyright notice.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import { expect } from "chai";
7+
import { render, screen } from "@testing-library/react";
8+
// __PUBLISH_EXTRACT_START__ QuantityFormat.QuantityFormatPanelExampleImports
9+
import { QuantityFormatPanel } from "@itwin/quantity-formatting-react";
10+
import { IModelApp } from "@itwin/core-frontend";
11+
import type { FormatDefinition } from "@itwin/core-quantity";
12+
// __PUBLISH_EXTRACT_END__
13+
import { QuantityFormattingTestUtils } from "../../utils/QuantityFormattingTestUtils.js";
14+
15+
describe("Quantity formatting", () => {
16+
describe("Learning snippets", () => {
17+
describe("QuantityFormatPanel", () => {
18+
before(async function () {
19+
await QuantityFormattingTestUtils.initialize();
20+
});
21+
22+
after(async function () {
23+
await QuantityFormattingTestUtils.terminate();
24+
});
25+
26+
it("renders QuantityFormatPanel", async function () {
27+
// __PUBLISH_EXTRACT_START__ QuantityFormat.QuantityFormatPanelExample
28+
const formatDefinition: FormatDefinition = {
29+
precision: 4,
30+
type: "Decimal",
31+
composite: {
32+
units: [{ name: "Units.M", label: "m" }],
33+
},
34+
};
35+
36+
const handleFormatChange = (_newFormat: FormatDefinition) => {
37+
// Handle format change
38+
};
39+
40+
render(
41+
<QuantityFormatPanel
42+
formatDefinition={formatDefinition}
43+
unitsProvider={IModelApp.quantityFormatter.unitsProvider}
44+
onFormatChange={handleFormatChange}
45+
initialMagnitude={123.456}
46+
/>,
47+
);
48+
// __PUBLISH_EXTRACT_END__
49+
50+
expect(screen.getByText("labels.type")).to.exist;
51+
});
52+
});
53+
});
54+
});
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3+
* See LICENSE.md in the project root for license terms and full copyright notice.
4+
*--------------------------------------------------------------------------------------------*/
5+
/* eslint-disable import/no-duplicates */
6+
import { IModelApp, NoRenderApp } from "@itwin/core-frontend";
7+
// __PUBLISH_EXTRACT_START__ QuantityFormat.QuantityFormattingInitializeImports
8+
import { QuantityFormatting } from "@itwin/quantity-formatting-react";
9+
10+
// __PUBLISH_EXTRACT_END__
11+
12+
export class QuantityFormattingTestUtils {
13+
private static _initialized = false;
14+
15+
public static async initialize() {
16+
if (QuantityFormattingTestUtils._initialized) {
17+
return;
18+
}
19+
20+
await NoRenderApp.startup();
21+
// __PUBLISH_EXTRACT_START__ QuantityFormat.QuantityFormattingInitialize
22+
await QuantityFormatting.startup({ localization: IModelApp.localization });
23+
// __PUBLISH_EXTRACT_END__
24+
QuantityFormattingTestUtils._initialized = true;
25+
}
26+
27+
public static async terminate() {
28+
QuantityFormatting.terminate();
29+
await IModelApp.shutdown();
30+
QuantityFormattingTestUtils._initialized = false;
31+
}
32+
}

apps/test-viewer/pnpm-lock.yaml

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)