Skip to content

Commit

Permalink
Merge pull request #330 from acelaya-forks/feature/server-orphan-visi…
Browse files Browse the repository at this point in the history
…ts-filter

Send orphan visits type to server when listing
  • Loading branch information
acelaya authored Apr 17, 2024
2 parents 8025f30 + 30c1827 commit 98efc82
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org).

## [Unreleased]
## [0.6.2] - 2024-04.17
### Added
* *Nothing*

Expand All @@ -20,6 +20,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
### Fixed
* Make sure project dependencies are not bundled with package.
* [#244](https://github.com/shlinkio/shlink-web-component/issues/244) Display `visitedUrl` in visits table if the visit object has it, regardless of it being an orphan visit or not.
* [#327](https://github.com/shlinkio/shlink-web-component/issues/327) Ensure orphan visits type is sent to the server, to enable server-side filtering when consumed Shlink supports it.


## [0.6.1] - 2024-04-10
Expand Down
6 changes: 5 additions & 1 deletion src/visits/reducers/orphanVisits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ export const getOrphanVisits = (apiClientFactory: () => ShlinkApiClient) => crea
const apiClient = apiClientFactory();
const { doIntervalFallback = false } = options;

const visitsLoader = async (query: ShlinkVisitsParams) => apiClient.getOrphanVisits(query).then(
const visitsLoader = async (query: ShlinkVisitsParams) => apiClient.getOrphanVisits({
...query,
type: orphanVisitsType, // Send type to the server, in case it supports filtering by type
}).then(
// We still try to filter locally, for Shlink older than 4.0.0
(resp) => filterOrphanVisitsByType(resp, orphanVisitsType),
);
const lastVisitLoader = lastVisitLoaderForLoader(doIntervalFallback, (q) => apiClient.getOrphanVisits(q));
Expand Down
19 changes: 14 additions & 5 deletions test/visits/reducers/orphanVisits.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,24 +204,28 @@ describe('orphanVisitsReducer', () => {
dateRange: { startDate: subDays(now, 1), endDate: addDays(now, 1) },
loadPrevInterval: true,
expectsPrevVisits: true,
orphanVisitsType: 'base_url' as const,
},
// Undefined date range and loadPrevInterval: true -> prev visits are NOT loaded
{
dateRange: undefined,
loadPrevInterval: true,
expectsPrevVisits: false,
orphanVisitsType: 'regular_404' as const,
},
// Empty date range and loadPrevInterval: true -> prev visits are NOT loaded
{
dateRange: {},
loadPrevInterval: true,
expectsPrevVisits: false,
orphanVisitsType: 'invalid_short_url' as const,
},
// Start date only and loadPrevInterval: true -> prev visits are NOT loaded
{
dateRange: { startDate: subDays(now, 2) },
loadPrevInterval: true,
expectsPrevVisits: true,
orphanVisitsType: 'invalid_short_url' as const,
},
// End date only and loadPrevInterval: true -> prev visits are NOT loaded
{
Expand All @@ -236,18 +240,22 @@ describe('orphanVisitsReducer', () => {
expectsPrevVisits: false,
},
])('returns visits from prev interval when requested and possible', async (
{ dateRange, loadPrevInterval, expectsPrevVisits },
{ dateRange, loadPrevInterval, expectsPrevVisits, orphanVisitsType },
) => {
const getVisitsParam: LoadOrphanVisits = {
params: { dateRange },
options: { loadPrevInterval },
orphanVisitsType,
};
const prevVisits = expectsPrevVisits ? visitsMocks.map(
({ date, ...rest }, index) => ({ ...rest, date: dateForVisit(index + 1 + visitsMocks.length) }),
const expectedVisits = visitsMocks.map(
(visit) => (orphanVisitsType ? { ...visit, type: orphanVisitsType } : visit),
);
const prevVisits = expectsPrevVisits ? expectedVisits.map(
({ date, ...rest }, index) => ({ ...rest, date: dateForVisit(index + 1 + expectedVisits.length) }),
) : undefined;

getOrphanVisitsCall.mockResolvedValue({
data: visitsMocks,
data: expectedVisits,
pagination: {
currentPage: 1,
pagesCount: 1,
Expand All @@ -259,9 +267,10 @@ describe('orphanVisitsReducer', () => {

expect(dispatchMock).toHaveBeenCalledTimes(2);
expect(dispatchMock).toHaveBeenLastCalledWith(expect.objectContaining({
payload: { visits: visitsMocks, prevVisits, ...getVisitsParam },
payload: { visits: expectedVisits, prevVisits, ...getVisitsParam },
}));
expect(getOrphanVisitsCall).toHaveBeenCalledTimes(expectsPrevVisits ? 2 : 1);
expect(getOrphanVisitsCall).toHaveBeenCalledWith(expect.objectContaining({ type: orphanVisitsType }));
});
});
});

0 comments on commit 98efc82

Please sign in to comment.