Skip to content

Commit 00c3201

Browse files
authored
fix: use AddNewCheckButton for check list empty state (#1485)
* fix: use addnewcheck button for check list empty state * fix: empty state test
1 parent 6f90a89 commit 00c3201

6 files changed

Lines changed: 50 additions & 55 deletions

File tree

docs/analytics/analytics-events.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ Tracks when the "Add New Check" button is clicked.
1414

1515
##### Properties
1616

17-
| name | type | description |
18-
| ------ | ---------------------------- | ------------------------------------------ |
19-
| source | `"check-list" \| "homepage"` | What location the button was clicked from. |
17+
| name | type | description |
18+
| ------ | -------------------------------------------------------- | ------------------------------------------ |
19+
| source | `"check-list-empty-state" \| "check-list" \| "homepage"` | What location the button was clicked from. |
2020

2121
#### synthetic-monitoring_check_creation_add_check_type_group_button_clicked
2222

scripts/terraform-validation/generate-test-configs.ts

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,23 @@
22

33
import fs from 'fs';
44
import path from 'path';
5-
import type { TFCheckConfig, TFProbeConfig, TFCheckAlertsConfig, TFConfig } from '../../src/components/TerraformConfig/terraformTypes';
5+
import type {
6+
TFCheckConfig,
7+
TFProbeConfig,
8+
TFCheckAlertsConfig,
9+
TFConfig,
10+
} from '../../src/components/TerraformConfig/terraformTypes';
611

712
async function generateConfigs() {
813
try {
914
console.log('Loading test fixtures...');
1015
const fixtures = await import('../../src/test/fixtures/checks');
1116
const probeFixtures = await import('../../src/test/fixtures/probes');
12-
17+
1318
console.log('Loading REAL production terraform utilities...');
14-
const { checkToTF, probeToTF, sanitizeName } = await import('../../src/components/TerraformConfig/terraformConfigUtils');
19+
const { checkToTF, probeToTF, sanitizeName } = await import(
20+
'../../src/components/TerraformConfig/terraformConfigUtils'
21+
);
1522

1623
// Comprehensive test cases covering all check types and probe types
1724
const testCases = [
@@ -50,18 +57,18 @@ async function generateConfigs() {
5057
check: fixtures.BASIC_MULTIHTTP_CHECK,
5158
probe: probeFixtures.ONLINE_PROBE,
5259
},
53-
// Scripted Check
54-
{
55-
name: 'basic-scripted',
56-
check: fixtures.BASIC_SCRIPTED_CHECK,
57-
probe: probeFixtures.SCRIPTED_DISABLED_PROBE,
58-
},
59-
// Browser Check with template literals
60-
{
61-
name: 'complex-browser',
62-
check: fixtures.COMPLEX_BROWSER_CHECK,
63-
probe: probeFixtures.PRIVATE_PROBE,
64-
},
60+
// Scripted Check
61+
{
62+
name: 'basic-scripted',
63+
check: fixtures.BASIC_SCRIPTED_CHECK,
64+
probe: probeFixtures.SCRIPTED_DISABLED_PROBE,
65+
},
66+
// Browser Check with template literals
67+
{
68+
name: 'complex-browser',
69+
check: fixtures.COMPLEX_BROWSER_CHECK,
70+
probe: probeFixtures.PRIVATE_PROBE,
71+
},
6572
// Traceroute Check
6673
{
6774
name: 'basic-traceroute',
@@ -71,7 +78,7 @@ async function generateConfigs() {
7178
];
7279

7380
const outputDir = 'artifacts/terraform-validation';
74-
81+
7582
// Ensure output directory exists
7683
if (!fs.existsSync(outputDir)) {
7784
fs.mkdirSync(outputDir, { recursive: true });
@@ -81,13 +88,13 @@ async function generateConfigs() {
8188
const allChecks: TFCheckConfig = {};
8289
const allProbes: TFProbeConfig = {};
8390
const allCheckAlerts: TFCheckAlertsConfig = {};
84-
91+
8592
for (const testCase of testCases) {
8693
console.log(`Transforming ${testCase.name} using REAL production checkToTF and probeToTF...`);
87-
94+
8895
const checkTF = checkToTF(testCase.check);
8996
const probeTF = probeToTF(testCase.probe);
90-
97+
9198
// Add to comprehensive config
9299
allChecks[testCase.name.replace('-', '_')] = checkTF;
93100
allProbes[`${testCase.name.replace('-', '_')}_probe`] = probeTF;
@@ -101,7 +108,7 @@ async function generateConfigs() {
101108
name: alert.name,
102109
threshold: alert.threshold,
103110
period: alert.period,
104-
runbook_url: alert.runbookUrl || "",
111+
runbook_url: alert.runbookUrl || '',
105112
})),
106113
};
107114
console.log(` → Added alerts for ${testCase.name}: ${testCase.check.alerts.length} alert(s)`);
@@ -113,15 +120,15 @@ async function generateConfigs() {
113120
terraform: {
114121
required_providers: {
115122
grafana: {
116-
source: "grafana/grafana",
117-
version: ">= 4.3.0"
118-
}
119-
}
123+
source: 'grafana/grafana',
124+
version: '>= 4.3.0',
125+
},
126+
},
120127
},
121128
resource: {
122129
grafana_synthetic_monitoring_check: allChecks,
123-
grafana_synthetic_monitoring_probe: allProbes
124-
}
130+
grafana_synthetic_monitoring_probe: allProbes,
131+
},
125132
};
126133

127134
// Add alerts resource if any checks have alerts
@@ -152,11 +159,10 @@ async function generateConfigs() {
152159
console.log('\n🧪 To validate:');
153160
console.log(' cd artifacts/terraform-validation');
154161
console.log(' terraform validate');
155-
156162
} catch (error) {
157163
console.error('❌ Error generating configurations:', error);
158164
process.exit(1);
159165
}
160166
}
161167

162-
generateConfigs();
168+
generateConfigs();

src/components/AddNewCheckButton/AddNewCheckButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { generateRoutePath } from 'routing/utils';
88
import { getUserPermissions } from 'data/permissions';
99

1010
interface AddNewCheckButtonProps {
11-
source: 'check-list' | 'homepage';
11+
source: 'check-list-empty-state' | 'check-list' | 'homepage';
1212
}
1313

1414
export function AddNewCheckButton({ source }: AddNewCheckButtonProps) {

src/components/ChecksEmptyState.test.tsx

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,23 @@ async function renderComponent() {
1515
describe('ChecksEmptyState', () => {
1616
it('should render all components correctly', async () => {
1717
const { container } = await renderComponent();
18-
18+
1919
// Verify container renders
2020
expect(container).toBeInTheDocument();
21-
21+
2222
// Verify correct message
2323
expect(await screen.findByText("You haven't created any checks yet")).toBeInTheDocument();
24-
24+
2525
// Verify correct button
26-
expect(await screen.findByText('Create check')).toBeInTheDocument();
27-
26+
expect(await screen.findByText('Add new check')).toBeInTheDocument();
27+
2828
// Verify correct link text
2929
const docsLink = await screen.findByText('Synthetic Monitoring docs');
3030
expect(docsLink).toBeInTheDocument();
31-
31+
3232
// Verify link href
33-
expect(docsLink).toHaveAttribute(
34-
'href',
35-
'https://grafana.com/docs/grafana-cloud/synthetic-monitoring/'
36-
);
37-
33+
expect(docsLink).toHaveAttribute('href', 'https://grafana.com/docs/grafana-cloud/synthetic-monitoring/');
34+
3835
// Verify link target
3936
expect(docsLink).toHaveAttribute('target', '_blank');
4037
});

src/components/ChecksEmptyState.tsx

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,20 @@
11
import React from 'react';
2-
import { Button, EmptyState, TextLink } from '@grafana/ui';
2+
import { EmptyState, TextLink } from '@grafana/ui';
33
import { DataTestIds } from 'test/dataTestIds';
44

5-
import { AppRoutes } from 'routing/types';
6-
import { useNavigation } from 'hooks/useNavigation';
5+
import { AddNewCheckButton } from 'components/AddNewCheckButton';
76

87
interface ChecksEmptyStatePageProps {
98
className?: string;
109
}
1110

1211
export function ChecksEmptyState({ className }: ChecksEmptyStatePageProps) {
13-
const navigate = useNavigation();
14-
const handleCallToAction = () => navigate(AppRoutes.ChooseCheckGroup);
15-
1612
return (
1713
<div className={className} data-testid={DataTestIds.CHECKS_EMPTY_STATE}>
1814
<EmptyState
1915
variant="call-to-action"
2016
message="You haven't created any checks yet"
21-
button={
22-
<Button onClick={handleCallToAction} icon="plus">
23-
Create check
24-
</Button>
25-
}
17+
button={<AddNewCheckButton source="check-list-empty-state" />}
2618
>
2719
<p>
2820
Create a check to start monitoring your services with Grafana Cloud, or check out the{' '}

src/features/tracking/checkCreationEvents.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const checkCreationEvents = createSMEventFactory('check_creation');
66

77
interface AddNewCheckButtonClicked extends TrackingEventProps {
88
/** What location the button was clicked from. */
9-
source: 'check-list' | 'homepage';
9+
source: 'check-list-empty-state' | 'check-list' | 'homepage';
1010
}
1111

1212
/** Tracks when the "Add New Check" button is clicked. */

0 commit comments

Comments
 (0)