Skip to content

Commit 0e1fa9b

Browse files
authored
chore: cleanup constant naming convention (#1596)
* chore: cleanup constant naming convention * chore: update some more naming * fix: add additional probe API server mapping
1 parent 7900328 commit 0e1fa9b

59 files changed

Lines changed: 201 additions & 195 deletions

Some content is hidden

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

src/components/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { MetaContextProvider } from 'contexts/MetaContext';
1313
import { PermissionsContextProvider } from 'contexts/PermissionsContext';
1414
import { SMDatasourceProvider } from 'contexts/SMDatasourceContext';
1515
import { queryClient } from 'data/queryClient';
16-
import { queryKeys as alertingQueryKeys } from 'data/useAlerts';
16+
import { QUERY_KEYS as alertingQueryKeys } from 'data/useAlerts';
1717

1818
import { DevTools } from './DevTools';
1919
import { FeatureFlagProvider } from './FeatureFlagProvider';

src/components/CheckUsage.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Check, CheckType } from 'types';
77

88
import { ChecksterProvider } from './Checkster/contexts/ChecksterContext';
99
import { CheckUsage } from './CheckUsage';
10-
import { fallbackCheckMap } from './constants';
10+
import { FALLBACK_CHECK_MAP } from './constants';
1111

1212
function RenderWrapper() {
1313
return (
@@ -26,7 +26,7 @@ async function renderComponent(check?: Check) {
2626

2727
describe('CheckUsage', () => {
2828
describe('existing check', () => {
29-
const mockedCheck = fallbackCheckMap[CheckType.Http];
29+
const mockedCheck = FALLBACK_CHECK_MAP[CheckType.Http];
3030
it('should render', async () => {
3131
const { container } = await renderComponent(mockedCheck);
3232
expect(container).toBeInTheDocument();

src/components/CheckUsage.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ const getStyles = (theme: GrafanaTheme2) => ({
3232
}),
3333
});
3434

35-
const hideTelemetryForTypes = [CheckType.Scripted, CheckType.MultiHttp, CheckType.Browser];
35+
const HIDE_TELEMETRY_FOR_TYPES = [CheckType.Scripted, CheckType.MultiHttp, CheckType.Browser];
3636

3737
export const CheckUsage = ({ checkType }: { checkType: CheckType }) => {
3838
const styles = useStyles2(getStyles);
3939
const { watch } = useFormContext<CheckFormValues>();
4040
const checkFormValues = watch();
4141
const usage = useUsageCalc([checkFormValuesToUsageCalcValues(checkFormValues)]);
4242

43-
const hideTelemetry = hideTelemetryForTypes.includes(checkType);
43+
const hideTelemetry = HIDE_TELEMETRY_FOR_TYPES.includes(checkType);
4444

4545
if (!usage) {
4646
return null;

src/components/Checkster/components/form/FormDnsRegExpValidationField.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const newItem: RegexpItem = {
3333
inverted: false,
3434
};
3535

36-
const selectInputWidth = 13; // times theme.spacing
36+
const SELECT_INPUT_WIDTH = 13; // times theme.spacing
3737

3838
export function FormDnsRegExpValidationField({
3939
field,
@@ -65,7 +65,7 @@ export function FormDnsRegExpValidationField({
6565
return (
6666
<Fragment key={fieldArray.id}>
6767
<GenericInputSelectField
68-
width={selectInputWidth}
68+
width={SELECT_INPUT_WIDTH}
6969
field={createPath(field, index, 'responseMatch')}
7070
aria-label={`Match subject for validation ${index + 1}`}
7171
options={DNS_RESPONSE_MATCH_OPTIONS}
@@ -110,7 +110,7 @@ function getStyles(theme: GrafanaTheme2) {
110110
return {
111111
inputGrid: css`
112112
display: grid;
113-
grid-template-columns: minmax(auto, ${theme.spacing(selectInputWidth)}) auto minmax(auto, 60px) minmax(auto, 30px);
113+
grid-template-columns: minmax(auto, ${theme.spacing(SELECT_INPUT_WIDTH)}) auto minmax(auto, 60px) minmax(auto, 30px);
114114
gap: ${theme.spacing(1)};
115115
`,
116116
centeredCell: css`

src/components/Checkster/components/form/FormMultiHttpVariablesField.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ interface FormMultiHttpVariablesFieldProps {
1515
field: `settings.multihttp.entries.${number}.variables`;
1616
}
1717

18-
const expressionFieldPropsMap: Record<
18+
const EXPRESSION_FIELD_PROPS_MAP: Record<
1919
MultiHttpVariableType,
2020
Pick<ComponentProps<typeof GenericInputField>, 'label' | 'description' | 'placeholder'>
2121
> = {
@@ -49,7 +49,7 @@ const expressionFieldPropsMap: Record<
4949
};
5050

5151
function getExpressionFieldProps(variableType: MultiHttpVariableType) {
52-
return expressionFieldPropsMap[variableType];
52+
return EXPRESSION_FIELD_PROPS_MAP[variableType];
5353
}
5454

5555
export function FormMultiHttpVariablesField({ field }: FormMultiHttpVariablesFieldProps) {

src/components/Checkster/components/form/FormTcpQueryAndResponseField.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ interface FormTcpQueryAndResponseFieldProps {
2020
addButtonText?: string;
2121
}
2222

23-
const newOption = { expect: '', send: '', startTLS: false };
23+
const NEW_OPTION = { expect: '', send: '', startTLS: false };
2424

2525
export function FormTcpQueryAndResponseField({
2626
field,
@@ -92,7 +92,7 @@ export function FormTcpQueryAndResponseField({
9292
align-self: flex-start; // Stops button from being 100% width
9393
`}
9494
icon="plus"
95-
onClick={() => append(newOption)}
95+
onClick={() => append(NEW_OPTION)}
9696
variant="secondary"
9797
size="sm"
9898
type="button"

src/components/Checkster/components/form/sections/AlertingSection.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import { FormSectionName } from '../../../types';
55
import { FormSection } from '../FormSection';
66
import { GenericAlertingContent } from '../layouts/GenericAlertingContent';
77

8-
const defaultAlertingFields = ['alerts'];
8+
const DEFAULT_ALERTING_FIELDS = ['alerts'];
99

1010
export function AlertingSection() {
1111
return (
12-
<FormSection sectionName={FormSectionName.Alerting} fields={defaultAlertingFields}>
12+
<FormSection sectionName={FormSectionName.Alerting} fields={DEFAULT_ALERTING_FIELDS}>
1313
<GenericAlertingContent />
1414
</FormSection>
1515
);

src/components/Checkster/components/form/sections/CheckSection.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { SCRIPTED_CHECK_FIELDS,ScriptedCheckContent } from '../layouts/ScriptedC
1515
import { TCP_REQUEST_OPTIONS_FIELDS,TcpCheckContent } from '../layouts/TcpCheckContent';
1616
import { TRACEROUTE_CHECK_FIELDS,TracerouteCheckContent } from '../layouts/TracerouteCheckContent';
1717

18-
const defaultCheckFields = ['job', 'target'];
18+
const DEFAULT_CHECK_FIELDS = ['job', 'target'];
1919

2020
function getCheckTypeFields(checkType: CheckType) {
2121
switch (checkType) {
@@ -36,11 +36,11 @@ function getCheckTypeFields(checkType: CheckType) {
3636
case CheckType.Browser:
3737
return BROWSER_CHECK_FIELDS;
3838
default:
39-
return defaultCheckFields;
39+
return DEFAULT_CHECK_FIELDS;
4040
}
4141
}
4242

43-
const checkTypeLayoutMap: Record<CheckType, ComponentType> = {
43+
const CHECK_TYPE_LAYOUT_MAP: Record<CheckType, ComponentType> = {
4444
/* Protocol checks (blackbox exporter)*/
4545
[CheckType.Http]: HttpCheckContent,
4646
[CheckType.Ping]: PingCheckContent,
@@ -69,7 +69,7 @@ function getNavLabel(checkType: CheckType) {
6969
export function CheckSection() {
7070
const { checkType } = useChecksterContext();
7171

72-
const SectionComponent = checkTypeLayoutMap[checkType] ?? null;
72+
const SectionComponent = CHECK_TYPE_LAYOUT_MAP[checkType] ?? null;
7373
const fields = getCheckTypeFields(checkType);
7474

7575
return (

src/components/Checkster/components/form/sections/ExecutionSection.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ import { useChecksterContext } from '../../../contexts/ChecksterContext';
66
import { FormSection } from '../FormSection';
77
import { GenericExecutionContent } from '../layouts/GenericExecutionContent';
88

9-
const defaultExecutionFields = ['probes', 'frequency'];
9+
const DEFAULT_EXECUTION_FIELDS = ['probes', 'frequency'];
1010

1111
export function ExecutionSection() {
1212
const { isK6Check } = useChecksterContext();
1313

1414
return (
15-
<FormSection sectionName={FormSectionName.Execution} fields={defaultExecutionFields}>
15+
<FormSection sectionName={FormSectionName.Execution} fields={DEFAULT_EXECUTION_FIELDS}>
1616
<GenericExecutionContent publishAdvancedMetrics={!isK6Check} />
1717
</FormSection>
1818
);

src/components/Checkster/components/form/sections/UptimeSection.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { ScriptedUptimeContent } from '../layouts/ScriptedUptimeContent';
1616
import { TcpUptimeContent } from '../layouts/TcpUptimeContent';
1717
import { TracerouteUptimeContent } from '../layouts/TracerouteUptimeContent';
1818

19-
const checkTypeLayoutMap: Record<CheckType, ComponentType> = {
19+
const CHECK_TYPE_LAYOUT_MAP: Record<CheckType, ComponentType> = {
2020
/* Protocol checks (blackbox exporter)*/
2121
[CheckType.Http]: HttpUptimeContent,
2222
[CheckType.Ping]: PingUptimeContent,
@@ -30,7 +30,7 @@ const checkTypeLayoutMap: Record<CheckType, ComponentType> = {
3030
[CheckType.Browser]: BrowserUptimeContent,
3131
};
3232

33-
const defaultUptimeFields = ['timeout'];
33+
const DEFAULT_UPTIME_FIELDS = ['timeout'];
3434

3535
function getCheckTypeFields(checkType: CheckType) {
3636
switch (checkType) {
@@ -39,14 +39,14 @@ function getCheckTypeFields(checkType: CheckType) {
3939
case CheckType.Http:
4040
return HTTP_UPTIME_FIELDS;
4141
default:
42-
return defaultUptimeFields;
42+
return DEFAULT_UPTIME_FIELDS;
4343
}
4444
}
4545

4646
export function UptimeSection() {
4747
const { checkType } = useChecksterContext();
4848

49-
const SectionComponent = checkTypeLayoutMap[checkType] ?? null;
49+
const SectionComponent = CHECK_TYPE_LAYOUT_MAP[checkType] ?? null;
5050
const fields = getCheckTypeFields(checkType);
5151

5252
return (

0 commit comments

Comments
 (0)