Skip to content

Commit

Permalink
Revert "Prescriptions: Shrink discontinued prescriptions + Flip MAR t…
Browse files Browse the repository at this point in the history
…imeline + Freeze primary columns in horizontal scroll (#6282)" (#6386)

This reverts commit 5009a86.
  • Loading branch information
rithviknishad committed Oct 3, 2023
1 parent e87de4f commit b7fc53c
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 180 deletions.
32 changes: 12 additions & 20 deletions src/Common/hooks/useRangePagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,17 @@ interface Props {
bounds: DateRange;
perPage: number;
slots?: number;
snapToLatest?: boolean;
reverse?: boolean;
defaultEnd?: boolean;
}

const useRangePagination = ({ bounds, perPage, ...props }: Props) => {
const [currentRange, setCurrentRange] = useState(
getInitialBounds(bounds, perPage, props.snapToLatest)
getInitialBounds(bounds, perPage, props.defaultEnd)
);

useEffect(() => {
setCurrentRange(getInitialBounds(bounds, perPage, props.snapToLatest));
}, [bounds, perPage, props.snapToLatest]);
setCurrentRange(getInitialBounds(bounds, perPage, props.defaultEnd));
}, [bounds, perPage, props.defaultEnd]);

const next = () => {
const { end } = currentRange;
Expand Down Expand Up @@ -63,24 +62,17 @@ const useRangePagination = ({ bounds, perPage, ...props }: Props) => {
}

const slots: DateRange[] = [];
const { start, end } = currentRange;
const { start } = currentRange;
const delta = perPage / props.slots;

for (let i = 0; i < props.slots; i++) {
if (props.snapToLatest) {
slots.push({
start: new Date(end.valueOf() - delta * (i - 1)),
end: new Date(end.valueOf() - delta * i),
});
} else {
slots.push({
start: new Date(start.valueOf() + delta * i),
end: new Date(start.valueOf() + delta * (i + 1)),
});
}
slots.push({
start: new Date(start.valueOf() + delta * i),
end: new Date(start.valueOf() + delta * (i + 1)),
});
}

return props.reverse ? slots.reverse() : slots;
return slots;
}, [currentRange, props.slots, perPage]);

return {
Expand All @@ -98,15 +90,15 @@ export default useRangePagination;
const getInitialBounds = (
bounds: DateRange,
perPage: number,
snapToLatest?: boolean
defaultEnd?: boolean
) => {
const deltaBounds = bounds.end.valueOf() - bounds.start.valueOf();

if (deltaBounds < perPage) {
return bounds;
}

if (snapToLatest) {
if (defaultEnd) {
return {
start: new Date(bounds.end.valueOf() - perPage),
end: bounds.end,
Expand Down
Loading

0 comments on commit b7fc53c

Please sign in to comment.