Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Synthetics] Remove buffer usage #131319

Merged
merged 2 commits into from
May 3, 2022
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 @@ -65,7 +65,7 @@ export const ActionBar = ({
}
return setMonitor({
monitor,
id: monitorId ? Buffer.from(monitorId, 'base64').toString('utf8') : undefined,
id: monitorId,
});
}, [monitor, monitorId, isValid, isSaving]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,16 @@ import { defaultCore, WrappedHelper } from '../../../lib/helper/rtl_helpers';
import { renderHook } from '@testing-library/react-hooks';
import { useMonitorName } from './use_monitor_name';

import * as hooks from '../../../hooks/use_monitor';
import * as reactRouter from 'react-router-dom';

const mockRouter = {
...reactRouter,
};

jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
useParams: jest.fn().mockReturnValue({}),
}));

describe('useMonitorName', () => {
it('returns expected results', () => {
Expand Down Expand Up @@ -56,7 +65,7 @@ describe('useMonitorName', () => {
},
});

jest.spyOn(hooks, 'useMonitorId').mockReturnValue('test-id');
jest.spyOn(mockRouter, 'useParams').mockReturnValue({ monitorId: 'test-id' });

const { result, waitForNextUpdate } = renderHook(() => useMonitorName({ search: 'Test' }), {
wrapper: WrappedHelper,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import { useEffect, useState } from 'react';
import { useFetcher } from '@kbn/observability-plugin/public';
import { useKibana } from '@kbn/kibana-react-plugin/public';
import { useParams } from 'react-router-dom';
import { syntheticsMonitorType } from '../../../../../common/types/saved_objects';
import { useMonitorId } from '../../../hooks';

interface AggsResponse {
monitorNames: {
Expand All @@ -22,7 +22,7 @@ interface AggsResponse {
export const useMonitorName = ({ search = '' }: { search?: string }) => {
const [values, setValues] = useState<string[]>([]);

const monitorId = useMonitorId();
const { monitorId } = useParams<{ monitorId: string }>();

const { savedObjects } = useKibana().services;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('<Actions />', () => {

expect(screen.getByLabelText('Edit monitor')).toHaveAttribute(
'href',
'/app/uptime/edit-monitor/dGVzdC1pZA=='
'/app/uptime/edit-monitor/test-id'
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const Actions = ({ id, name, onUpdate, isDisabled, errorSummaries, monito
<EuiButtonIcon
isDisabled={isDisabled}
iconType="pencil"
href={`${basePath}/app/uptime/edit-monitor/${Buffer.from(id, 'utf8').toString('base64')}`}
href={`${basePath}/app/uptime/edit-monitor/${id}`}
aria-label={EDIT_MONITOR_LABEL}
data-test-subj="monitorManagementEditMonitor"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,7 @@ export const MonitorManagementList = ({
}),
sortable: true,
render: (name: string, { id }: EncryptedSyntheticsMonitorWithId) => (
<EuiLink
href={`${basePath}/app/uptime/monitor/${Buffer.from(id, 'utf8').toString('base64')}`}
>
{name}
</EuiLink>
<EuiLink href={`${basePath}/app/uptime/monitor/${btoa(id)}`}>{name}</EuiLink>
),
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const EditMonitorPage: React.FC = () => {
const { data, status } = useFetcher<
Promise<DecryptedSyntheticsMonitorSavedObject | undefined>
>(() => {
return getMonitor({ id: Buffer.from(monitorId, 'base64').toString('utf8') });
return getMonitor({ id: monitorId });
}, [monitorId]);

const monitor = data?.attributes as MonitorFields;
Expand Down