Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,16 @@ describe('StatCard', () => {
});

it('applies variant styling for warning', async () => {
render(<StatCard value={5} label="Offline" variant="warning" onClick={() => { /* force this to be a button */ }} />);
render(
<StatCard
value={5}
label="Offline"
variant="warning"
onClick={() => {
/* force this to be a button */
}}
/>,
);

const card = screen.getByRole('button');
expect(card).toBeInTheDocument();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ const Label = styled.div(
);

const StatCard = ({ value, label, variant = 'default', onClick = undefined }: Props) => (
<StyledCard as={onClick ? 'button' : 'div'}
$variant={variant}
$clickable={!!onClick}
onClick={onClick}
type={onClick ? 'button' : undefined}
>
<StyledCard
as={onClick ? 'button' : 'div'}
$variant={variant}
$clickable={!!onClick}
onClick={onClick}
type={onClick ? 'button' : undefined}>
<Value>{value}</Value>
<Label>{label}</Label>
</StyledCard>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ jest.mock('components/common/EntityDataTable/hooks/useSelectedEntities');
jest.mock('../hooks/useCollectorsMutations');

const setSelectedEntitiesMock = jest.fn();
const bulkDeleteEnrollmentTokensMock = jest.fn(() => Promise.resolve({ successfully_performed: 0, failures: [], errors: [] }));
const bulkDeleteEnrollmentTokensMock = jest.fn(() =>
Promise.resolve({ successfully_performed: 0, failures: [], errors: [] }),
);

const useSelectedEntitiesResponse = {
selectedEntities: [],
Expand All @@ -50,9 +52,11 @@ describe('BulkActions', () => {
beforeEach(() => {
jest.clearAllMocks();
asMock(useSelectedEntities).mockReturnValue(useSelectedEntitiesResponse);
asMock(useCollectorsMutations).mockReturnValue(mockCollectorsMutations({
bulkDeleteEnrollmentTokens: bulkDeleteEnrollmentTokensMock,
}));
asMock(useCollectorsMutations).mockReturnValue(
mockCollectorsMutations({
bulkDeleteEnrollmentTokens: bulkDeleteEnrollmentTokensMock,
}),
);
});

it('renders bulk actions dropdown', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ const BulkActions = () => {
show
onConfirm={handleConfirm}
onCancel={() => setShowConfirm(false)}>
Are you sure you want to delete {selectedEntities.length} enrollment tokens?
New collectors will not be able to enroll using the deleted tokens.
Are you sure you want to delete {selectedEntities.length} enrollment tokens? New collectors will not be able
to enroll using the deleted tokens.
</ConfirmDialog>
)}
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,11 @@ describe('EnrollmentTokenList', () => {
isLoading: false,
});

asMock(useCollectorsMutations).mockReturnValue(mockCollectorsMutations({
deleteEnrollmentToken: deleteEnrollmentTokenMock,
}));
asMock(useCollectorsMutations).mockReturnValue(
mockCollectorsMutations({
deleteEnrollmentToken: deleteEnrollmentTokenMock,
}),
);

asMock(fetchPaginatedEnrollmentTokens).mockResolvedValue(mockPaginatedResponse([mockToken()]));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,24 @@ import Routes from 'routing/Routes';
import type { ColumnRenderers } from 'components/common/EntityDataTable';
import type { Sort } from 'stores/PaginationTypes';

import BulkActions from './BulkActions';

import { fetchPaginatedEnrollmentTokens, enrollmentTokensKeyFn, useCollectorsMutations, useFleets } from '../hooks';
import type { EnrollmentTokenMetadata } from '../types';
import BulkActions from './BulkActions';

const DEFAULT_LAYOUT = {
entityTableId: 'enrollment-tokens',
defaultPageSize: 20,
defaultSort: { attributeId: 'created_at', direction: 'desc' } as Sort,
defaultDisplayedAttributes: ['name', 'fleet_id', 'created_by', 'created_at', 'expires_at', 'usage_count', 'last_used_at'],
defaultDisplayedAttributes: [
'name',
'fleet_id',
'created_by',
'created_at',
'expires_at',
'usage_count',
'last_used_at',
],
defaultColumnOrder: ['name', 'fleet_id', 'created_by', 'created_at', 'expires_at', 'usage_count', 'last_used_at'],
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ const CollectorsFleets = () => {
entityActions={() => null}
/>

{showFleetModal && (
<FleetFormModal onClose={closeCreateModal} onSave={handleSaveFleet} />
)}
{showFleetModal && <FleetFormModal onClose={closeCreateModal} onSave={handleSaveFleet} />}
</>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,7 @@ const FleetDetail = ({ fleetId }: Props) => {
const { data: stats, isLoading: statsLoading } = useFleetStats(fleetId);
const defaultInstanceFilters = useDefaultInstanceFilters();
const { data: sources } = useSources(fleetId);
const {
createSource,
updateSource,
deleteSource,
updateFleet,
deleteFleet,
} = useCollectorsMutations();
const { createSource, updateSource, deleteSource, updateFleet, deleteFleet } = useCollectorsMutations();
const [showSourceModal, setShowSourceModal] = useState(false);
const [editingSource, setEditingSource] = useState<Source | null>(null);
const [deletingSource, setDeletingSource] = useState<Source | null>(null);
Expand Down Expand Up @@ -215,7 +209,9 @@ const FleetDetail = ({ fleetId }: Props) => {
return (
<div>
<Header>
<h2>{fleet.name} <BetaBadge /></h2>
<h2>
{fleet.name} <BetaBadge />
</h2>
{fleet.target_version && <Label bsStyle="info">v{fleet.target_version}</Label>}
</Header>

Expand Down Expand Up @@ -288,11 +284,7 @@ const FleetDetail = ({ fleetId }: Props) => {
)}

{showSourceModal && (
<SourceFormModal
fleetId={fleetId}
onClose={() => setShowSourceModal(false)}
onSave={handleSaveSource}
/>
<SourceFormModal fleetId={fleetId} onClose={() => setShowSourceModal(false)} onSave={handleSaveSource} />
)}

{editingSource && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,7 @@ const FleetFormModal = ({ fleet = undefined, onClose, onSave }: Props) => {
<Modal.Title>{isEdit ? 'Edit Fleet' : 'New Fleet'}</Modal.Title>
</Modal.Header>
<Modal.Body>
<FormikInput
id="fleet-name"
label="Name"
name="name"
help="A unique name for this fleet"
required
/>
<FormikInput id="fleet-name" label="Name" name="name" help="A unique name for this fleet" required />
<FormikInput
id="fleet-description"
label="Description"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,8 @@ const FleetSettings = ({ fleet, onSave, onDelete = undefined }: Props) => {
<Section>
<SectionTitle>General Settings</SectionTitle>
<Form>
<FormikInput
id="fleet-name"
label="Fleet Name"
name="name"
required
/>
<FormikInput
id="fleet-description"
type="textarea"
label="Description"
name="description"
/>
<FormikInput id="fleet-name" label="Fleet Name" name="name" required />
<FormikInput id="fleet-description" type="textarea" label="Description" name="description" />
<FormikInput
id="fleet-target-version"
label="Target Version"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ const useCollectorsMutations = () => {

// Enrollment token mutations
const createEnrollmentTokenMutation = useMutation({
mutationFn: (input: { name: string, fleetId: string; expiresIn: string | null }) =>
mutationFn: (input: { name: string; fleetId: string; expiresIn: string | null }) =>
OpAMPEnrollment.createToken({
name: input.name,
fleet_id: input.fleetId,
Expand All @@ -157,8 +157,7 @@ const useCollectorsMutations = () => {
});

const bulkDeleteEnrollmentTokensMutation = useMutation({
mutationFn: (entityIds: string[]) =>
OpAMPEnrollment.bulkDelete({ entity_ids: entityIds }),
mutationFn: (entityIds: string[]) => OpAMPEnrollment.bulkDelete({ entity_ids: entityIds }),
onError: onMutationError('Deleting enrollment tokens'),
onSuccess: onSuccess('Enrollment tokens have been deleted.'),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import asMock from 'helpers/mocking/AsMock';

import useDefaultInstanceFilters from './useDefaultInstanceFilters';
import { useCollectorsConfig } from './useCollectorsConfig';

import type { CollectorsConfig } from '../types';

jest.mock('./useCollectorsConfig');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import FiltersForQueryParams from 'components/common/EntityFilters/FiltersForQue
import { defaultOnError } from 'util/conditional/onError';
import type { PaginatedResponse } from 'components/common/PaginatedEntityTable/useFetchEntities';


import type { EnrollmentTokenMetadata } from '../types';

export const ENROLLMENT_TOKENS_KEY_PREFIX = ['collectors', 'enrollment-tokens'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { useState, useMemo, useCallback } from 'react';

import PaginatedEntityTable from 'components/common/PaginatedEntityTable';


import customColumnRenderers from './ColumnRenderers';
import InstanceActions from './InstanceActions';
import BulkActions from './BulkActions';
Expand All @@ -35,10 +34,7 @@ const CollectorsInstances = () => {
const { data: sources } = useSources(selectedInstance?.fleet_id);
const defaultFilters = useDefaultInstanceFilters();

const fleetNames = useMemo(
() => Object.fromEntries((fleets ?? []).map(fleet => [fleet.id, fleet.name])),
[fleets],
);
const fleetNames = useMemo(() => Object.fromEntries((fleets ?? []).map((fleet) => [fleet.id, fleet.name])), [fleets]);

const columnRenderers = useMemo(() => customColumnRenderers({ fleetNames }), [fleetNames]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ const OsIcon = ({ os }: { os: string | null }) => {
if (os === 'windows') return <span title="Windows">Windows</span>;
if (os === 'darwin') return <span title="macOS">macOS</span>;

return <span title="Unknown"><i>Unknown</i></span>;
return (
<span title="Unknown">
<i>Unknown</i>
</span>
);
};

type Props = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,12 @@ describe('InstanceActions', () => {
beforeEach(() => {
jest.clearAllMocks();

asMock(useCollectorsMutations).mockReturnValue(mockCollectorsMutations({
deleteInstance: deleteInstanceMock,
isDeletingInstance: false,
}));
asMock(useCollectorsMutations).mockReturnValue(
mockCollectorsMutations({
deleteInstance: deleteInstanceMock,
isDeletingInstance: false,
}),
);
});

it('renders View Logs and Details buttons', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import collectorLogsUrl from '../common/collectorLogsUrl';
import { useCollectorsMutations } from '../hooks';
import type { CollectorInstanceView } from '../types';


type Props = {
instance: CollectorInstanceView;
onDetailsClick: (instance: CollectorInstanceView) => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,12 @@ describe('ReassignFleetModal', () => {
isLoading: false,
});

asMock(useCollectorsMutations).mockReturnValue(mockCollectorsMutations({
reassignInstances: reassignInstancesMock,
isReassigningInstances: false,
}));
asMock(useCollectorsMutations).mockReturnValue(
mockCollectorsMutations({
reassignInstances: reassignInstancesMock,
isReassigningInstances: false,
}),
);
});

it('renders modal title with instance count', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ const RecentActivity = () => {

{isLoading && <Spinner />}

{!isLoading && (!data?.activities || data.activities.length === 0) && <NoEntitiesExist>No recent activity.</NoEntitiesExist>}
{!isLoading && (!data?.activities || data.activities.length === 0) && (
<NoEntitiesExist>No recent activity.</NoEntitiesExist>
)}

{!isLoading && data?.activities && data.activities.length > 0 && (
<ActivityList>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,12 @@ describe('CollectorsSettings', () => {
data: config,
isLoading: false,
});
asMock(useCollectorsMutations).mockReturnValue(mockCollectorsMutations({
updateConfig,
isUpdatingConfig: false,
}));
asMock(useCollectorsMutations).mockReturnValue(
mockCollectorsMutations({
updateConfig,
isUpdatingConfig: false,
}),
);
asMock(useInput).mockReturnValue({
data: { id: 'input-1' },
} as ReturnType<typeof useInput>);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,7 @@ const CollectorsSettings = () => {
<h2>Ingest Endpoints</h2>

<h3>HTTP</h3>
<FormikInput
id="http-enabled"
type="checkbox"
label="Enabled"
name="http_enabled"
/>
<FormikInput id="http-enabled" type="checkbox" label="Enabled" name="http_enabled" />
<FormikInput
id="http-hostname"
type="text"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import { SOURCE_TYPE_LABELS } from './Constants';

import type { Source } from '../types';


const customColumnRenderers = (): ColumnRenderers<Source> => ({
attributes: {
name: {
Expand Down
Loading
Loading