Skip to content

Commit

Permalink
Add hideDefaultDescription to CatalogMemberMixin (#6951)
Browse files Browse the repository at this point in the history
  • Loading branch information
nf-s authored Oct 26, 2023
1 parent 59e658a commit 2f0cec5
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- Fix bug in mismatched GeoJSON Feature `_id_` and TableMixin `rowId` - this was causing incorrect styling when using `filterByProperties` or features had `null` geometry
- Fix splitter for `GeoJsonMixin` (lines and polygon features only)
- Fix share links with picked features from `ProtomapsImageryProvider`
- Add `hideDefaultDescription` to `CatalogMemberTraits` - if true, then no generic default description will be shown when `description` is empty.
- [The next improvement]

#### 8.3.6 - 2023-10-03
Expand Down
6 changes: 5 additions & 1 deletion lib/ReactViews/Preview/Description.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ class Description extends React.Component {
</If>

<If
condition={!catalogItem.hasLocalData && !catalogItem.hasDescription}
condition={
!catalogItem.hasLocalData &&
!catalogItem.hasDescription &&
!catalogItem.hideDefaultDescription
}
>
<p>{t("description.dataNotLocal")}</p>
</If>
Expand Down
8 changes: 8 additions & 0 deletions lib/Traits/TraitsClasses/CatalogMemberTraits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ class CatalogMemberTraits extends ModelTraits {
})
description?: string;

@primitiveTrait({
type: "boolean",
name: "Hide default description",
description:
"If true, then no generic default description will be displayed if `description` is undefined."
})
hideDefaultDescription: boolean = false;

@primitiveTrait({
type: "string",
name: "Name in catalog",
Expand Down
55 changes: 53 additions & 2 deletions test/ReactViews/Preview/DescriptionSpec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import React from "react";
import { act } from "react-dom/test-utils";
import { create, ReactTestRenderer } from "react-test-renderer";
import { ThemeProvider } from "styled-components";
import Terria from "../../../lib/Models/Terria";
import updateModelFromJson from "../../../lib/Models/Definition/updateModelFromJson";
import GeoJsonCatalogItem from "../../../lib/Models/Catalog/CatalogItems/GeoJsonCatalogItem";
import WebMapServiceCatalogItem from "../../../lib/Models/Catalog/Ows/WebMapServiceCatalogItem";
import CommonStrata from "../../../lib/Models/Definition/CommonStrata";
import updateModelFromJson from "../../../lib/Models/Definition/updateModelFromJson";
import Terria from "../../../lib/Models/Terria";
import Description from "../../../lib/ReactViews/Preview/Description";
import { terriaTheme } from "../../../lib/ReactViews/StandardUserInterface";

Expand Down Expand Up @@ -142,4 +144,53 @@ describe("DescriptionSpec", function () {

expect(child.props.children).toBe("some link");
});

it("respects hideDefaultDescription", function () {
const geoJsonItem = new GeoJsonCatalogItem("test-geojson", terria);
runInAction(() => {
geoJsonItem.setTrait(CommonStrata.definition, "description", "test");
});

act(() => {
testRenderer = create(
<ThemeProvider theme={terriaTheme}>
<Description item={geoJsonItem} />
</ThemeProvider>
);
});

const showDescription = testRenderer.root.findAll(
(node) => node.type === "p"
);

expect(showDescription.length).toEqual(1);
expect(showDescription[0].children[0]).toBe("test");

runInAction(() => {
geoJsonItem.setTrait(CommonStrata.definition, "description", "");
});

const showDefaultDescription = testRenderer.root.findAll(
(node) => node.type === "p"
);

expect(showDefaultDescription.length).toEqual(1);
expect(showDefaultDescription[0].children[0]).toBe(
"description.dataNotLocal"
);

runInAction(() => {
geoJsonItem.setTrait(
CommonStrata.definition,
"hideDefaultDescription",
true
);
});

const showNoDescription = testRenderer.root.findAll(
(node) => node.type === "p"
);

expect(showNoDescription.length).toEqual(0);
});
});

0 comments on commit 2f0cec5

Please sign in to comment.