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
55import { toast } from "sonner" ;
66import { Toaster } from "@/components/ui/sonner" ;
77
88// For routing / querying
99import { useNavigate , useSearch } from "@tanstack/react-router" ;
10- // import { TELESCOPES } from "@/components/parameters";
1110
1211// UI components
1312import { 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";
3533import 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
6866function 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