Skip to content

Commit

Permalink
[GEN-1973]: fix empty labels for "unknown" instr. rules (ron note) (#…
Browse files Browse the repository at this point in the history
…1966)

This pull request includes changes to the `frontend/webapp` to handle
unknown instrumentation rule types more gracefully. The most important
changes include adding a new enumeration value and updating a utility
function to return this new value instead of `undefined`.

Enumeration update:

*
[`frontend/webapp/types/instrumentation-rules.ts`](diffhunk://#diff-66b962d2cc49488445ed7154565b752e0aa1b146265ed64309349a8d01ca24ddR3):
Added `UNKNOWN_TYPE` to the `InstrumentationRuleType` enum.

Utility function update:

*
[`frontend/webapp/utils/functions/strings/derive-type-from-rule/index.ts`](diffhunk://#diff-bf9d9f843b6a752fac1a44af59ce489d0cf7595ac1c40147741c4a1de8c2a1f0L8-R8):
Modified the `deriveTypeFromRule` function to return
`InstrumentationRuleType.UNKNOWN_TYPE` instead of `undefined` for
unrecognized rule types.
  • Loading branch information
BenElferink authored Dec 10, 2024
1 parent 99cdc01 commit 646befd
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import buildCard from './build-card';
import { RuleFormBody } from '../';
import styled from 'styled-components';
import { useDrawerStore } from '@/store';
import { ACTION, DATA_CARDS, getRuleIcon } from '@/utils';
import { DataCard } from '@/reuseable-components';
import buildDrawerItem from './build-drawer-item';
import { RULE_OPTIONS } from '../rule-modal/rule-options';
import OverviewDrawer from '../../overview/overview-drawer';
import { OVERVIEW_ENTITY_TYPES, type InstrumentationRuleSpec } from '@/types';
import { useInstrumentationRuleCRUD, useInstrumentationRuleFormData } from '@/hooks';
import { ACTION, DATA_CARDS, FORM_ALERTS, getRuleIcon, NOTIFICATION } from '@/utils';
import { useInstrumentationRuleCRUD, useInstrumentationRuleFormData, useNotify } from '@/hooks';
import { InstrumentationRuleType, OVERVIEW_ENTITY_TYPES, type InstrumentationRuleSpec } from '@/types';

interface Props {}

Expand All @@ -22,6 +22,7 @@ const FormContainer = styled.div`
`;

export const RuleDrawer: React.FC<Props> = () => {
const notify = useNotify();
const { selectedItem, setSelectedItem } = useDrawerStore();
const { formData, formErrors, handleFormChange, resetFormData, validateForm, loadFormWithDrawerItem } = useInstrumentationRuleFormData();

Expand Down Expand Up @@ -72,7 +73,11 @@ export const RuleDrawer: React.FC<Props> = () => {
const { id, item } = selectedItem as { id: string; item: InstrumentationRuleSpec };

const handleEdit = (bool?: boolean) => {
setIsEditing(typeof bool === 'boolean' ? bool : true);
if (item.type === InstrumentationRuleType.UNKNOWN_TYPE) {
notify({ type: NOTIFICATION.WARNING, title: FORM_ALERTS.FORBIDDEN, message: FORM_ALERTS.CANNOT_EDIT_RULE, crdType: OVERVIEW_ENTITY_TYPES.RULE, target: id });
} else {
setIsEditing(typeof bool === 'boolean' ? bool : true);
}
};

const handleCancel = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type ComponentType = React.FC<ComponentProps> | null;

const componentsMap: Record<InstrumentationRuleType, ComponentType> = {
[InstrumentationRuleType.PAYLOAD_COLLECTION]: PayloadCollection,
[InstrumentationRuleType.UNKNOWN_TYPE]: null,
};

const RuleCustomFields: React.FC<Props> = ({ ruleType, value, setValue, formErrors }) => {
Expand Down
1 change: 1 addition & 0 deletions frontend/webapp/types/instrumentation-rules.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Enumeration of possible Instrumentation Rule Types
export enum InstrumentationRuleType {
UNKNOWN_TYPE = 'UnknownType',
PAYLOAD_COLLECTION = 'PayloadCollection',
}

Expand Down
2 changes: 2 additions & 0 deletions frontend/webapp/utils/constants/string.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export const ACTION = {
export const FORM_ALERTS = {
REQUIRED_FIELDS: 'Required fields are missing',
FIELD_IS_REQUIRED: 'This field is required',
FORBIDDEN: 'Forbidden',
CANNOT_EDIT_RULE: 'Cannot edit instrumentation rule of this type',
};

export const NOTIFICATION: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ export const deriveTypeFromRule = (rule: InstrumentationRuleInput | Instrumentat
return InstrumentationRuleType.PAYLOAD_COLLECTION;
}

return undefined;
return InstrumentationRuleType.UNKNOWN_TYPE;
};

0 comments on commit 646befd

Please sign in to comment.