Removed non-needed components which were just wrapping another component that could directly be used instead

This commit is contained in:
Alejandro Celaya 2022-04-30 11:00:12 +02:00
parent 368f7acd2d
commit ddb08f4d2e
8 changed files with 10 additions and 80 deletions

View file

@ -7,7 +7,7 @@ import VisitsStats from './VisitsStats';
import { NormalizedVisit, VisitsInfo, VisitsParams } from './types'; import { NormalizedVisit, VisitsInfo, VisitsParams } from './types';
import { CommonVisitsProps } from './types/CommonVisitsProps'; import { CommonVisitsProps } from './types/CommonVisitsProps';
import { toApiParams } from './types/helpers'; import { toApiParams } from './types/helpers';
import { NonOrphanVisitsHeader } from './NonOrphanVisitsHeader'; import VisitsHeader from './VisitsHeader';
export interface NonOrphanVisitsProps extends CommonVisitsProps { export interface NonOrphanVisitsProps extends CommonVisitsProps {
getNonOrphanVisits: (params?: ShlinkVisitsParams, doIntervalFallback?: boolean) => void; getNonOrphanVisits: (params?: ShlinkVisitsParams, doIntervalFallback?: boolean) => void;
@ -36,7 +36,7 @@ export const NonOrphanVisits = ({ exportVisits }: ReportExporter) => boundToMerc
exportCsv={exportCsv} exportCsv={exportCsv}
selectedServer={selectedServer} selectedServer={selectedServer}
> >
<NonOrphanVisitsHeader nonOrphanVisits={nonOrphanVisits} goBack={goBack} /> <VisitsHeader title="Non-orphan visits" goBack={goBack} visits={nonOrphanVisits.visits} />
</VisitsStats> </VisitsStats>
); );
}, () => [Topics.visits]); }, () => [Topics.visits]);

View file

@ -1,14 +0,0 @@
import VisitsHeader from './VisitsHeader';
import { VisitsInfo } from './types';
import './ShortUrlVisitsHeader.scss';
interface NonOrphanVisitsHeaderProps {
nonOrphanVisits: VisitsInfo;
goBack: () => void;
}
export const NonOrphanVisitsHeader = ({ nonOrphanVisits, goBack }: NonOrphanVisitsHeaderProps) => {
const { visits } = nonOrphanVisits;
return <VisitsHeader title="Non-orphan visits" goBack={goBack} visits={visits} />;
};

View file

@ -4,10 +4,10 @@ import { Topics } from '../mercure/helpers/Topics';
import { useGoBack } from '../utils/helpers/hooks'; import { useGoBack } from '../utils/helpers/hooks';
import { ReportExporter } from '../common/services/ReportExporter'; import { ReportExporter } from '../common/services/ReportExporter';
import VisitsStats from './VisitsStats'; import VisitsStats from './VisitsStats';
import { OrphanVisitsHeader } from './OrphanVisitsHeader';
import { NormalizedVisit, OrphanVisitType, VisitsInfo, VisitsParams } from './types'; import { NormalizedVisit, OrphanVisitType, VisitsInfo, VisitsParams } from './types';
import { CommonVisitsProps } from './types/CommonVisitsProps'; import { CommonVisitsProps } from './types/CommonVisitsProps';
import { toApiParams } from './types/helpers'; import { toApiParams } from './types/helpers';
import VisitsHeader from './VisitsHeader';
export interface OrphanVisitsProps extends CommonVisitsProps { export interface OrphanVisitsProps extends CommonVisitsProps {
getOrphanVisits: ( getOrphanVisits: (
@ -41,7 +41,7 @@ export const OrphanVisits = ({ exportVisits }: ReportExporter) => boundToMercure
selectedServer={selectedServer} selectedServer={selectedServer}
isOrphanVisits isOrphanVisits
> >
<OrphanVisitsHeader orphanVisits={orphanVisits} goBack={goBack} /> <VisitsHeader title="Orphan visits" goBack={goBack} visits={orphanVisits.visits} />
</VisitsStats> </VisitsStats>
); );
}, () => [Topics.orphanVisits]); }, () => [Topics.orphanVisits]);

View file

@ -1,14 +0,0 @@
import VisitsHeader from './VisitsHeader';
import { VisitsInfo } from './types';
import './ShortUrlVisitsHeader.scss';
interface OrphanVisitsHeaderProps {
orphanVisits: VisitsInfo;
goBack: () => void;
}
export const OrphanVisitsHeader = ({ orphanVisits, goBack }: OrphanVisitsHeaderProps) => {
const { visits } = orphanVisits;
return <VisitsHeader title="Orphan visits" goBack={goBack} visits={visits} />;
};

View file

@ -4,10 +4,10 @@ import { NonOrphanVisits as createNonOrphanVisits } from '../../src/visits/NonOr
import { MercureBoundProps } from '../../src/mercure/helpers/boundToMercureHub'; import { MercureBoundProps } from '../../src/mercure/helpers/boundToMercureHub';
import { VisitsInfo } from '../../src/visits/types'; import { VisitsInfo } from '../../src/visits/types';
import VisitsStats from '../../src/visits/VisitsStats'; import VisitsStats from '../../src/visits/VisitsStats';
import { NonOrphanVisitsHeader } from '../../src/visits/NonOrphanVisitsHeader';
import { Settings } from '../../src/settings/reducers/settings'; import { Settings } from '../../src/settings/reducers/settings';
import { ReportExporter } from '../../src/common/services/ReportExporter'; import { ReportExporter } from '../../src/common/services/ReportExporter';
import { SelectedServer } from '../../src/servers/data'; import { SelectedServer } from '../../src/servers/data';
import VisitsHeader from '../../src/visits/VisitsHeader';
jest.mock('react-router-dom', () => ({ jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'), ...jest.requireActual('react-router-dom'),
@ -33,14 +33,14 @@ describe('<NonOrphanVisits />', () => {
/>, />,
).dive(); ).dive();
const stats = wrapper.find(VisitsStats); const stats = wrapper.find(VisitsStats);
const header = wrapper.find(NonOrphanVisitsHeader); const header = wrapper.find(VisitsHeader);
expect(stats).toHaveLength(1); expect(stats).toHaveLength(1);
expect(header).toHaveLength(1); expect(header).toHaveLength(1);
expect(stats.prop('cancelGetVisits')).toEqual(cancelGetNonOrphanVisits); expect(stats.prop('cancelGetVisits')).toEqual(cancelGetNonOrphanVisits);
expect(stats.prop('visitsInfo')).toEqual(nonOrphanVisits); expect(stats.prop('visitsInfo')).toEqual(nonOrphanVisits);
expect(stats.prop('isOrphanVisits')).not.toBeDefined(); expect(stats.prop('isOrphanVisits')).not.toBeDefined();
expect(header.prop('nonOrphanVisits')).toEqual(nonOrphanVisits); expect(header.prop('visits')).toEqual(nonOrphanVisits.visits);
expect(header.prop('goBack')).toEqual(expect.any(Function)); expect(header.prop('goBack')).toEqual(expect.any(Function));
}); });
}); });

View file

@ -1,21 +0,0 @@
import { shallow } from 'enzyme';
import { Mock } from 'ts-mockery';
import { NonOrphanVisitsHeader } from '../../src/visits/NonOrphanVisitsHeader';
import VisitsHeader from '../../src/visits/VisitsHeader';
import { Visit, VisitsInfo } from '../../src/visits/types';
describe('<NonOrphanVisitsHeader />', () => {
it('wraps a VisitsHeader with provided data', () => {
const visits: Visit[] = [];
const orphanVisits = Mock.of<VisitsInfo>({ visits });
const goBack = jest.fn();
const wrapper = shallow(<NonOrphanVisitsHeader nonOrphanVisits={orphanVisits} goBack={goBack} />);
const visitsHeader = wrapper.find(VisitsHeader);
expect(visitsHeader).toHaveLength(1);
expect(visitsHeader.prop('visits')).toEqual(visits);
expect(visitsHeader.prop('goBack')).toEqual(goBack);
expect(visitsHeader.prop('title')).toEqual('Non-orphan visits');
});
});

View file

@ -4,10 +4,10 @@ import { OrphanVisits as createOrphanVisits } from '../../src/visits/OrphanVisit
import { MercureBoundProps } from '../../src/mercure/helpers/boundToMercureHub'; import { MercureBoundProps } from '../../src/mercure/helpers/boundToMercureHub';
import { VisitsInfo } from '../../src/visits/types'; import { VisitsInfo } from '../../src/visits/types';
import VisitsStats from '../../src/visits/VisitsStats'; import VisitsStats from '../../src/visits/VisitsStats';
import { OrphanVisitsHeader } from '../../src/visits/OrphanVisitsHeader';
import { Settings } from '../../src/settings/reducers/settings'; import { Settings } from '../../src/settings/reducers/settings';
import { ReportExporter } from '../../src/common/services/ReportExporter'; import { ReportExporter } from '../../src/common/services/ReportExporter';
import { SelectedServer } from '../../src/servers/data'; import { SelectedServer } from '../../src/servers/data';
import VisitsHeader from '../../src/visits/VisitsHeader';
jest.mock('react-router-dom', () => ({ jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'), ...jest.requireActual('react-router-dom'),
@ -33,14 +33,14 @@ describe('<OrphanVisits />', () => {
/>, />,
).dive(); ).dive();
const stats = wrapper.find(VisitsStats); const stats = wrapper.find(VisitsStats);
const header = wrapper.find(OrphanVisitsHeader); const header = wrapper.find(VisitsHeader);
expect(stats).toHaveLength(1); expect(stats).toHaveLength(1);
expect(header).toHaveLength(1); expect(header).toHaveLength(1);
expect(stats.prop('cancelGetVisits')).toEqual(cancelGetOrphanVisits); expect(stats.prop('cancelGetVisits')).toEqual(cancelGetOrphanVisits);
expect(stats.prop('visitsInfo')).toEqual(orphanVisits); expect(stats.prop('visitsInfo')).toEqual(orphanVisits);
expect(stats.prop('isOrphanVisits')).toEqual(true); expect(stats.prop('isOrphanVisits')).toEqual(true);
expect(header.prop('orphanVisits')).toEqual(orphanVisits); expect(header.prop('visits')).toEqual(orphanVisits.visits);
expect(header.prop('goBack')).toEqual(expect.any(Function)); expect(header.prop('goBack')).toEqual(expect.any(Function));
}); });
}); });

View file

@ -1,21 +0,0 @@
import { shallow } from 'enzyme';
import { Mock } from 'ts-mockery';
import { OrphanVisitsHeader } from '../../src/visits/OrphanVisitsHeader';
import VisitsHeader from '../../src/visits/VisitsHeader';
import { Visit, VisitsInfo } from '../../src/visits/types';
describe('<OrphanVisitsHeader />', () => {
it('wraps a VisitsHeader with provided data', () => {
const visits: Visit[] = [];
const orphanVisits = Mock.of<VisitsInfo>({ visits });
const goBack = jest.fn();
const wrapper = shallow(<OrphanVisitsHeader orphanVisits={orphanVisits} goBack={goBack} />);
const visitsHeader = wrapper.find(VisitsHeader);
expect(visitsHeader).toHaveLength(1);
expect(visitsHeader.prop('visits')).toEqual(visits);
expect(visitsHeader.prop('goBack')).toEqual(goBack);
expect(visitsHeader.prop('title')).toEqual('Orphan visits');
});
});