Skip to content

Commit 3d09d03

Browse files
author
Eugene Cheung
authored
feat(dashboards): expose anyDashboardCreated from DefaultDashboardFactory (#171)
This is useful if you want to conditionally create any constructs based on the existence of dashboards without necessarily checking the input props. --- _By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license_
1 parent 6a7e91c commit 3d09d03

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

API.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,7 @@ Any object.
633633
| **Name** | **Type** | **Description** |
634634
| --- | --- | --- |
635635
| <code><a href="#cdk-monitoring-constructs.DefaultDashboardFactory.property.node">node</a></code> | <code>constructs.Node</code> | The tree node. |
636+
| <code><a href="#cdk-monitoring-constructs.DefaultDashboardFactory.property.anyDashboardCreated">anyDashboardCreated</a></code> | <code>boolean</code> | *No description.* |
636637
| <code><a href="#cdk-monitoring-constructs.DefaultDashboardFactory.property.alarmDashboard">alarmDashboard</a></code> | <code>aws-cdk-lib.aws_cloudwatch.Dashboard</code> | *No description.* |
637638
| <code><a href="#cdk-monitoring-constructs.DefaultDashboardFactory.property.dashboard">dashboard</a></code> | <code>aws-cdk-lib.aws_cloudwatch.Dashboard</code> | *No description.* |
638639
| <code><a href="#cdk-monitoring-constructs.DefaultDashboardFactory.property.summaryDashboard">summaryDashboard</a></code> | <code>aws-cdk-lib.aws_cloudwatch.Dashboard</code> | *No description.* |
@@ -651,6 +652,16 @@ The tree node.
651652

652653
---
653654

655+
##### `anyDashboardCreated`<sup>Required</sup> <a name="anyDashboardCreated" id="cdk-monitoring-constructs.DefaultDashboardFactory.property.anyDashboardCreated"></a>
656+
657+
```typescript
658+
public readonly anyDashboardCreated: boolean;
659+
```
660+
661+
- *Type:* boolean
662+
663+
---
664+
654665
##### `alarmDashboard`<sup>Optional</sup> <a name="alarmDashboard" id="cdk-monitoring-constructs.DefaultDashboardFactory.property.alarmDashboard"></a>
655666

656667
```typescript

lib/dashboard/DefaultDashboardFactory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export class DefaultDashboardFactory
9191
readonly dashboard?: Dashboard;
9292
readonly summaryDashboard?: Dashboard;
9393
readonly alarmDashboard?: Dashboard;
94-
protected readonly anyDashboardCreated: boolean;
94+
readonly anyDashboardCreated: boolean;
9595

9696
constructor(scope: Construct, id: string, props: MonitoringDashboardsProps) {
9797
super(scope, id);

test/dashboard/DefaultDashboardFactory.test.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,45 +11,48 @@ import {
1111
test("default dashboards created", () => {
1212
const stack = new Stack();
1313

14-
new DefaultDashboardFactory(stack, "Dashboards", {
14+
const factory = new DefaultDashboardFactory(stack, "Dashboards", {
1515
dashboardNamePrefix: "DummyDashboard",
1616
renderingPreference: DashboardRenderingPreference.INTERACTIVE_ONLY,
1717
});
1818

19+
expect(factory.anyDashboardCreated).toEqual(true);
1920
expect(Template.fromStack(stack)).toMatchSnapshot();
2021
});
2122

2223
test("all dashboards created", () => {
2324
const stack = new Stack();
2425

25-
new DefaultDashboardFactory(stack, "Dashboards", {
26+
const factory = new DefaultDashboardFactory(stack, "Dashboards", {
2627
dashboardNamePrefix: "DummyDashboard",
2728
createDashboard: true,
2829
createSummaryDashboard: true,
2930
createAlarmDashboard: true,
3031
renderingPreference: DashboardRenderingPreference.INTERACTIVE_ONLY,
3132
});
3233

34+
expect(factory.anyDashboardCreated).toEqual(true);
3335
expect(Template.fromStack(stack)).toMatchSnapshot();
3436
});
3537

3638
test("no dashboards created", () => {
3739
const stack = new Stack();
3840

39-
const dashboards = new DefaultDashboardFactory(stack, "Dashboards", {
41+
const factory = new DefaultDashboardFactory(stack, "Dashboards", {
4042
dashboardNamePrefix: "DummyDashboard",
4143
createDashboard: false,
4244
createSummaryDashboard: false,
4345
createAlarmDashboard: false,
4446
renderingPreference: DashboardRenderingPreference.INTERACTIVE_ONLY,
4547
});
4648

47-
dashboards.addSegment({
49+
factory.addSegment({
4850
segment: new SingleWidgetDashboardSegment(
4951
new TextWidget({ markdown: "Hello world!" })
5052
),
5153
});
5254

55+
expect(factory.anyDashboardCreated).toEqual(false);
5356
expect(Template.fromStack(stack)).toMatchSnapshot();
5457
});
5558

0 commit comments

Comments
 (0)