Skip to content

Commit ad64ee7

Browse files
committed
Misc PR review edits.
1 parent 4063c3e commit ad64ee7

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

src/components/ContextFeedColumns.jsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import FullScreenIcon from "../assets/FullScreenIcon.svg";
1919

2020
const columnHelper = createColumnHelper();
2121

22-
// TODO: Move to utils and import to here and dataLogColumns
22+
// TODO: Move to utils and import to here and dataLogColumns (OSW-1118)
2323
// Exact (multiple) match(es) filter function
2424
export const matchValueOrInList = (row, columnId, filterValue) => {
2525
const rowValue = row.getValue(columnId);
@@ -32,14 +32,13 @@ export const matchValueOrInList = (row, columnId, filterValue) => {
3232
};
3333

3434
// Helper function to make time columns more readable
35-
// Luxon only natively supports milisecond precision, not microseconds.
35+
// Luxon only natively supports millisecond precision, not microseconds.
3636
// Will need to extra microseconds if this precision is required.
3737
function formatTimestamp(tsString) {
3838
if (!tsString) return null;
3939
const dt = DateTime.fromISO(tsString, { zone: "utc" });
4040
return dt.isValid ? dt.toFormat("yyyy-LL-dd HH:mm:ss.S") : tsString;
4141
}
42-
// }
4342

4443
export const contextFeedColumns = [
4544
columnHelper.accessor("salIndex", {

src/pages/ContextFeed.jsx

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
// Standard React hooks
2-
import { useEffect, useState } from "react";
2+
import { useEffect, useState, useMemo } from "react";
33

44
// Libraries for the "toast" pop-up messages
55
import { toast } from "sonner";
66
import { Toaster } from "@/components/ui/sonner";
77

88
// For routing / querying
99
import { useNavigate, useSearch } from "@tanstack/react-router";
10-
// import { TELESCOPES } from "@/components/parameters";
1110

1211
// UI components
1312
import { Skeleton } from "@/components/ui/skeleton";
@@ -31,7 +30,6 @@ import {
3130
} from "@/components/ContextFeedDefinitions.jsx";
3231

3332
// Icons
34-
// import InfoIcon from "../assets/InfoIcon.svg";
3533
import DownloadIcon from "../assets/DownloadIcon.svg";
3634

3735
// Utils
@@ -66,7 +64,7 @@ const filterDefaultEventsByTelescope = (telescope) => {
6664
// This is the page that gets rendered
6765
// as the Routing service's <Outlet /> in main.jsx
6866
function ContextFeed() {
69-
// Get params from URL
67+
// Subscribe component to URL params
7068
const { startDayobs, endDayobs, telescope, startTime, endTime } = useSearch({
7169
from: "/context-feed",
7270
});
@@ -77,11 +75,19 @@ function ContextFeed() {
7775
const queryEndDayobs = getDatetimeFromDayobsStr(endDayobs.toString())
7876
.plus({ days: 1 })
7977
.toFormat("yyyyMMdd");
80-
// const instrument = TELESCOPES[telescope];
8178

8279
// Time ranges for timeline
83-
const [selectedTimeRange, setSelectedTimeRange] = useState([null, null]);
84-
const [fullTimeRange, setFullTimeRange] = useState([null, null]);
80+
// fullTimeRange doesn't need to be stored in state because it
81+
// isn't modified by any child components, whereas selectedTimeRange
82+
// is modified by the timeline.
83+
const fullTimeRange = useMemo(
84+
() => [
85+
getDayobsStartUTC(String(startDayobs)),
86+
getDayobsEndUTC(String(endDayobs)),
87+
],
88+
[startDayobs, endDayobs],
89+
);
90+
const [selectedTimeRange, setSelectedTimeRange] = useState(fullTimeRange);
8591

8692
// Storing and setting "state"
8793
// - [variable, setting function]
@@ -127,17 +133,12 @@ function ContextFeed() {
127133
});
128134
}, [telescope]);
129135

130-
// Set time ranges from url params.
136+
// Set selectedTimeRange from url params.
131137
// Must be separate from general url-filter sync to avoid infinite renders.
132138
useEffect(() => {
133139
const startMillis = Number(startTime);
134140
const endMillis = Number(endTime);
135141

136-
// Compute full dayobs range
137-
const startTimeRange = getDayobsStartUTC(String(startDayobs));
138-
const endTimeRange = getDayobsEndUTC(String(endDayobs));
139-
setFullTimeRange([startTimeRange, endTimeRange]);
140-
141142
// Url params are optional; make sure we don't set NaNs
142143
const hasValidTimes =
143144
startMillis != null &&
@@ -152,9 +153,9 @@ function ContextFeed() {
152153
]);
153154
} else {
154155
// Fallback to full dayobs range
155-
setSelectedTimeRange([startTimeRange, endTimeRange]);
156+
setSelectedTimeRange(fullTimeRange);
156157
}
157-
}, [startTime, endTime, startDayobs, endDayobs]);
158+
}, [startTime, endTime, fullTimeRange]);
158159

159160
// Sync url time params with selectedTimeRange
160161
useEffect(() => {
@@ -169,6 +170,7 @@ function ContextFeed() {
169170
const newEnd = selectedTimeRange[1].toMillis();
170171

171172
if (currentStart !== newStart || currentEnd !== newEnd) {
173+
// Mutate browser history with new times
172174
navigate({
173175
to: "/context-feed",
174176
search: {
@@ -268,7 +270,6 @@ function ContextFeed() {
268270

269271
// Fetch the Context Feed data
270272
fetchContextFeed(startDayobs, endDayobs, abortController)
271-
// Just collecting columns for now, until dataframe bug is sorted
272273
.then(([data]) => {
273274
// Prepare data for timeline and table
274275
let currentTask = null;
@@ -281,7 +282,7 @@ function ContextFeed() {
281282
let eventColor = salInfo.color ?? "#ffffff";
282283

283284
// Split Narrative Log into variants
284-
// Narrative Log splitting
285+
// TODO: Adapt when this comes from rubin_nights (OSW-1119)
285286
if (salInfo.label === "Narrative Log") {
286287
if (NARRATIVE_LOG_MAP.AuxTel.includes(entry.name)) {
287288
salInfo = SAL_INDEX_INFO[7];
@@ -296,7 +297,7 @@ function ContextFeed() {
296297
}
297298

298299
if (
299-
// TODO: swap to "Task Change" once changed in rubin_nights
300+
// TODO: swap to "Task Change" (OSW-1119)
300301
entry.finalStatus === "Job Change"
301302
) {
302303
currentTask = entry.name;
@@ -315,8 +316,7 @@ function ContextFeed() {
315316
// Chronological order
316317
.sort((a, b) => a.event_time_millis - b.event_time_millis);
317318

318-
// Set the fetched cols to state.
319-
// setContextFeedCols(cols);
319+
// Set the fetched data to state.
320320
setContextFeedData(preparedData);
321321

322322
// Warn if no data returned but no error
@@ -438,6 +438,7 @@ function ContextFeed() {
438438
{Object.entries(SAL_INDEX_INFO)
439439
.filter(([key]) => key !== "10" && key !== "0") // exclude AUTOLOG & NL
440440
.sort(
441+
// sort on displayIndex
441442
([, aInfo], [, bInfo]) =>
442443
(aInfo.displayIndex ?? 0) - (bInfo.displayIndex ?? 0),
443444
)

0 commit comments

Comments
 (0)