trotl-table 1.0.21 → 1.0.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +78 -3
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +78 -3
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -9771,6 +9771,8 @@ function TableInner({
|
|
|
9771
9771
|
|
|
9772
9772
|
// Option to read search param from URL
|
|
9773
9773
|
const [searchTerm, setSearchTerm] = React.useState(extraSearchTerm);
|
|
9774
|
+
// Track current URL search so date filters rerun when params change
|
|
9775
|
+
const [urlSearchString, setUrlSearchString] = React.useState(() => window.location.search);
|
|
9774
9776
|
|
|
9775
9777
|
// Listen to URL changes via popstate (back/forward) and custom events
|
|
9776
9778
|
React.useEffect(() => {
|
|
@@ -9843,15 +9845,88 @@ function TableInner({
|
|
|
9843
9845
|
const normalizedGroups = React.useMemo(() => {
|
|
9844
9846
|
return normalizeData(isGrouped ? localData : [], isGrouped ? [] : localData);
|
|
9845
9847
|
}, [localData, isGrouped]);
|
|
9848
|
+
|
|
9849
|
+
// Listen for changes to date-related URL params and update searchTerm to trigger re-filter
|
|
9850
|
+
React.useEffect(() => {
|
|
9851
|
+
const handleDateParamChange = () => {
|
|
9852
|
+
setUrlSearchString(window.location.search);
|
|
9853
|
+
};
|
|
9854
|
+
|
|
9855
|
+
// Listen for popstate (back/forward navigation)
|
|
9856
|
+
window.addEventListener('popstate', handleDateParamChange);
|
|
9857
|
+
|
|
9858
|
+
// Listen for programmatic URL changes
|
|
9859
|
+
const originalPushState = window.history.pushState;
|
|
9860
|
+
const originalReplaceState = window.history.replaceState;
|
|
9861
|
+
window.history.pushState = function (...args) {
|
|
9862
|
+
originalPushState.apply(this, args);
|
|
9863
|
+
handleDateParamChange();
|
|
9864
|
+
};
|
|
9865
|
+
window.history.replaceState = function (...args) {
|
|
9866
|
+
originalReplaceState.apply(this, args);
|
|
9867
|
+
handleDateParamChange();
|
|
9868
|
+
};
|
|
9869
|
+
|
|
9870
|
+
// Listen for hashchange (in case date params are in hash)
|
|
9871
|
+
window.addEventListener('hashchange', handleDateParamChange);
|
|
9872
|
+
return () => {
|
|
9873
|
+
window.removeEventListener('popstate', handleDateParamChange);
|
|
9874
|
+
window.removeEventListener('hashchange', handleDateParamChange);
|
|
9875
|
+
window.history.pushState = originalPushState;
|
|
9876
|
+
window.history.replaceState = originalReplaceState;
|
|
9877
|
+
};
|
|
9878
|
+
}, []);
|
|
9846
9879
|
const filterRows = React.useCallback(rows => {
|
|
9847
|
-
|
|
9880
|
+
console.log(urlSearchString);
|
|
9881
|
+
// Check for date-related URL params first
|
|
9882
|
+
const urlParams = new URLSearchParams(urlSearchString);
|
|
9883
|
+
const dateParams = ['startDate', 'endDate', 'date'];
|
|
9884
|
+
let dateFiltered = rows;
|
|
9885
|
+
for (const paramKey of dateParams) {
|
|
9886
|
+
const paramValue = urlParams.get(paramKey);
|
|
9887
|
+
if (!paramValue) continue;
|
|
9888
|
+
|
|
9889
|
+
// Check if it's a range (contains ~)
|
|
9890
|
+
if (paramValue.includes('~')) {
|
|
9891
|
+
const [startTs, endTs] = paramValue.split('~').map(Number);
|
|
9892
|
+
if (isNaN(startTs) || isNaN(endTs)) continue;
|
|
9893
|
+
dateFiltered = dateFiltered.filter(row => {
|
|
9894
|
+
// Check if any date field in the row falls within the range
|
|
9895
|
+
const itemStartDate = row.startDate ? new Date(row.startDate).getTime() : null;
|
|
9896
|
+
const itemEndDate = row.endDate ? new Date(row.endDate).getTime() : null;
|
|
9897
|
+
const itemDate = row.date ? new Date(row.date).getTime() : null;
|
|
9898
|
+
|
|
9899
|
+
// Match if any date field overlaps with the range
|
|
9900
|
+
return itemStartDate && itemStartDate >= startTs && itemStartDate <= endTs || itemEndDate && itemEndDate >= startTs && itemEndDate <= endTs || itemDate && itemDate >= startTs && itemDate <= endTs ||
|
|
9901
|
+
// Check if event spans the entire range
|
|
9902
|
+
itemStartDate && itemEndDate && itemStartDate <= startTs && itemEndDate >= endTs;
|
|
9903
|
+
});
|
|
9904
|
+
} else {
|
|
9905
|
+
// Single timestamp
|
|
9906
|
+
const timestamp = Number(paramValue);
|
|
9907
|
+
if (isNaN(timestamp)) continue;
|
|
9908
|
+
dateFiltered = dateFiltered.filter(row => {
|
|
9909
|
+
const itemStartDate = row.startDate ? new Date(row.startDate).getTime() : null;
|
|
9910
|
+
const itemEndDate = row.endDate ? new Date(row.endDate).getTime() : null;
|
|
9911
|
+
const itemDate = row.date ? new Date(row.date).getTime() : null;
|
|
9912
|
+
|
|
9913
|
+
// Match if the timestamp falls within the event's date range or matches the date
|
|
9914
|
+
return itemDate && Math.abs(itemDate - timestamp) < 86400000 ||
|
|
9915
|
+
// Same day (within 24h)
|
|
9916
|
+
itemStartDate && itemEndDate && itemStartDate <= timestamp && itemEndDate >= timestamp || itemStartDate && Math.abs(itemStartDate - timestamp) < 86400000 || itemEndDate && Math.abs(itemEndDate - timestamp) < 86400000;
|
|
9917
|
+
});
|
|
9918
|
+
}
|
|
9919
|
+
}
|
|
9920
|
+
|
|
9921
|
+
// Then apply text search filter
|
|
9922
|
+
if (!searchTerm) return dateFiltered;
|
|
9848
9923
|
const query = searchTerm.toLowerCase();
|
|
9849
|
-
return
|
|
9924
|
+
return dateFiltered.filter(row => columns.some(col => {
|
|
9850
9925
|
const val = row[col.accessor];
|
|
9851
9926
|
if (val == null) return false;
|
|
9852
9927
|
return String(val).toLowerCase().includes(query);
|
|
9853
9928
|
}));
|
|
9854
|
-
}, [searchTerm, columns]);
|
|
9929
|
+
}, [searchTerm, columns, urlSearchString]);
|
|
9855
9930
|
|
|
9856
9931
|
// Natural-ish comparator: handles nulls, numbers, strings, ISO dates
|
|
9857
9932
|
const compare = (x, y, dir = "asc") => {
|