Skip to content

Fix fallback interval not causing new visits to be loaded #528

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

Merged
merged 1 commit into from
Nov 30, 2024
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
4 changes: 2 additions & 2 deletions 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.11.0] - 2024-11-30
### Added
* [#491](https://github.com/shlinkio/shlink-web-component/issues/491) Add support for colors in QR code configurator.
* [#515](https://github.com/shlinkio/shlink-web-component/issues/515) Add support for geolocation redirect conditions, when using Shlink 4.3 or newer.
Expand All @@ -23,7 +23,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
* *Nothing*

### Fixed
* *Nothing*
* [#504](https://github.com/shlinkio/shlink-web-component/issues/504) Fix fallback interval not causing new visits to be loaded.


## [0.10.1] - 2024-10-19
Expand Down
16 changes: 8 additions & 8 deletions src/visits/VisitsStats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@
},
[updateQuery],
);
const initialInterval = useRef<DateRange | DateInterval>(
dateRange ?? fallbackInterval ?? visitsSettings?.defaultInterval ?? 'last30Days',
const [currentFallbackInterval, setCurrentFallbackInterval] = useState<DateInterval>(
fallbackInterval ?? visitsSettings?.defaultInterval ?? 'last30Days',
);
const [highlightedVisits, setHighlightedVisits] = useState<NormalizedVisit[]>([]);
const [highlightedLabel, setHighlightedLabel] = useState<string | undefined>();
Expand Down Expand Up @@ -158,7 +158,7 @@

useEffect(() => cancelGetVisits, [cancelGetVisits]);
useEffect(() => {
const resolvedDateRange = dateRange ?? toDateRange(initialInterval.current);
const resolvedDateRange = dateRange ?? toDateRange(currentFallbackInterval);
const { loadPrevInterval: doLoadPrevInterval, ...filter } = resolvedFilter;
const options: GetVisitsOptions = {
doIntervalFallback: isFirstLoad.current,
Expand All @@ -169,13 +169,13 @@

setSelectedVisits([]); // Reset selected visits every time we load visits
isFirstLoad.current = false;
}, [dateRange, visitsFilter, getVisits, resolvedFilter, setSelectedVisits]);
}, [currentFallbackInterval, dateRange, getVisits, resolvedFilter, setSelectedVisits]);
useEffect(() => {
// As soon as the fallback is loaded, if the initial interval used the settings one, we do fall back
if (fallbackInterval && initialInterval.current === (visitsSettings?.defaultInterval ?? 'last30Days')) {
initialInterval.current = fallbackInterval;
if (fallbackInterval && currentFallbackInterval === (visitsSettings?.defaultInterval ?? 'last30Days')) {
setCurrentFallbackInterval(fallbackInterval);

Check warning on line 176 in src/visits/VisitsStats.tsx

View check run for this annotation

Codecov / codecov/patch

src/visits/VisitsStats.tsx#L176

Added line #L176 was not covered by tests
}
}, [fallbackInterval, visitsSettings?.defaultInterval]);
}, [currentFallbackInterval, fallbackInterval, visitsSettings?.defaultInterval]);

return (
<>
Expand All @@ -188,7 +188,7 @@
<div className="flex-grow-1">
<DateRangeSelector
disabled={loading}
dateRangeOrInterval={activeInterval ?? dateRange ?? initialInterval.current}
dateRangeOrInterval={activeInterval ?? dateRange ?? currentFallbackInterval}
defaultText="All visits"
onDatesChange={setDates}
/>
Expand Down