Skip to content

Commit

Permalink
Populate plugin store with UTC defaults, refactoring, fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronPlave committed Jul 1, 2024
1 parent 0a65548 commit 65a15df
Show file tree
Hide file tree
Showing 18 changed files with 252 additions and 446 deletions.
11 changes: 6 additions & 5 deletions src/components/activity/ActivityDirectiveChangelog.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import HistoryIcon from '@nasa-jpl/stellar/icons/history.svg?component';
import { createEventDispatcher, onMount } from 'svelte';
import { plan } from '../../stores/plan';
import { plugins } from '../../stores/plugins';
import type {
ActivityDirective,
ActivityDirectiveRevision,
Expand Down Expand Up @@ -112,12 +113,12 @@
// Manually check remaining fields that could have changed and require extra formatting
if (current.start_offset !== previous.start_offset) {
const currentStartTimeDoy = getDoyTimeFromInterval(planStartTimeYmd, current.start_offset);
const previousStartTimeDoy = getDoyTimeFromInterval(planStartTimeYmd, previous.start_offset);
const currentStartTime = getDoyTimeFromInterval(planStartTimeYmd, current.start_offset);
const previousStartTime = getDoyTimeFromInterval(planStartTimeYmd, previous.start_offset);
differences['Start Time (UTC)'] = {
currentValue: currentStartTimeDoy,
previousValue: previousStartTimeDoy,
differences[`Start Time (${$plugins.time.primary.label})`] = {
currentValue: currentStartTime,
previousValue: previousStartTime,
};
}
Expand Down
88 changes: 29 additions & 59 deletions src/components/activity/ActivityDirectiveForm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,9 @@
import { permissionHandler } from '../../utilities/permissionHandler';
import { featurePermissions } from '../../utilities/permissions';
import { pluralize } from '../../utilities/text';
import {
getDoyTime,
getDoyTimeFromInterval,
getIntervalFromDoyRange,
getUnixEpochTimeFromInterval,
} from '../../utilities/time';
import { getDoyTime, getIntervalFromDoyRange, getUnixEpochTimeFromInterval } from '../../utilities/time';
import { tooltip } from '../../utilities/tooltip';
import { required, timestamp } from '../../utilities/validators';
import { required } from '../../utilities/validators';
import Collapse from '../Collapse.svelte';
import ActivityMetadataField from '../activityMetadata/ActivityMetadataField.svelte';
import DatePickerField from '../form/DatePickerField.svelte';
Expand Down Expand Up @@ -101,22 +96,14 @@
$: activityType =
(activityTypes ?? []).find(({ name: activityTypeName }) => activityDirective?.type === activityTypeName) ?? null;
$: {
if ($plugins.time?.primary?.format && $plugins.time?.primary?.parse) {
const startTimeMs = getUnixEpochTimeFromInterval(
planStartTimeYmd,
revision ? revision.start_offset : activityDirective.start_offset,
);
startTime = $plugins.time?.primary?.format(new Date(startTimeMs));
} else {
startTime = getDoyTimeFromInterval(
planStartTimeYmd,
revision ? revision.start_offset : activityDirective.start_offset,
);
}
const startTimeMs = getUnixEpochTimeFromInterval(
planStartTimeYmd,
revision ? revision.start_offset : activityDirective.start_offset,
);
startTime = $plugins.time.primary.format(new Date(startTimeMs));
}
$: startTimeFieldValidators = $plugins.time?.primary?.validate || timestamp;
$: startTimeField = field<string>(startTime, [required, startTimeFieldValidators]);
$: startTimeField = field<string>(startTime, [required, $plugins.time.primary.validate]);
$: activityNameField = field<string>(activityDirective.name);
$: if (activityType && activityDirective.arguments) {
Expand Down Expand Up @@ -376,13 +363,10 @@
}
function onUpdateStartTime() {
if ($startTimeField.valid /* && startTime !== $startTimeField.value */) {
console.log('startTimeField.value :>> ', $startTimeField.value);
if ($startTimeField.valid && startTime !== $startTimeField.value) {
const { id } = activityDirective;
const planStartTimeDoy = getDoyTime(new Date(planStartTimeYmd));
const startTimeDoy = $plugins.time?.primary?.parse
? getDoyTime($plugins.time?.primary?.parse($startTimeField.value))
: $startTimeField.value;
const startTimeDoy = getDoyTime($plugins.time.primary.parse($startTimeField.value));
const start_offset = getIntervalFromDoyRange(planStartTimeDoy, startTimeDoy);
if ($plan) {
effects.updateActivityDirective($plan, id, { start_offset }, activityType, user);
Expand Down Expand Up @@ -572,28 +556,11 @@
</Highlight>

<Highlight highlight={highlightKeysMap.start_offset}>
{#if $plugins.time?.primary?.parse}
<div class="start-time-field">
<Field field={startTimeField} on:change={onUpdateStartTime}>
<Input layout="inline">
<label use:tooltip={{ content: 'Start Time', placement: 'top' }} for="start-time">
Start Time ({$plugins.time?.primary.label}) - {$plugins.time?.primary.formatString}
</label>
<input
autocomplete="off"
class="st-input w-100"
name="start-time"
value={activityDirective.type}
on:keyup={onStartTimeKeyUp}
/>
</Input>
</Field>
</div>
{:else}
{#if $plugins.time.enableDatePicker}
<DatePickerField
disabled={!editable || activityDirective.anchor_id !== null}
field={startTimeField}
label="Start Time (UTC) - YYYY-DDDThh:mm:ss"
label={`Start Time (${$plugins.time.primary.label}) - ${$plugins.time.primary.formatString}`}
layout="inline"
name="start-time"
use={[
Expand All @@ -608,23 +575,26 @@
on:change={onUpdateStartTime}
on:keydown={onUpdateStartTime}
/>
{:else}
<div class="start-time-field">
<Field field={startTimeField} on:change={onUpdateStartTime}>
<Input layout="inline">
<label use:tooltip={{ content: 'Start Time', placement: 'top' }} for="start-time">
Start Time ({$plugins.time.primary.label}) - {$plugins.time.primary.formatString}
</label>
<input
autocomplete="off"
class="st-input w-100"
name="start-time"
value={activityDirective.type}
on:keyup={onStartTimeKeyUp}
/>
</Input>
</Field>
</div>
{/if}
</Highlight>

<!-- <Input layout="inline">
<label use:tooltip={{ content: 'Start Time', placement: 'top' }} for="start-time">
Start Time ({$plugins.time?.secondary?.label ?? 'UTC'})
</label>
<input
disabled
autocomplete="off"
class="st-input w-100"
name="start-time"
value={}
on:keyup={onStartTimeKeyUp}
/>
</Input> -->

<ActivityAnchorForm
{activityDirective}
{activityDirectivesMap}
Expand Down
6 changes: 3 additions & 3 deletions src/components/activity/ActivityDirectivesTablePanel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import type { User } from '../../types/app';
import type { AutoSizeColumns, ViewGridSection, ViewTable } from '../../types/view';
import { filterEmpty } from '../../utilities/generic';
import { getDoyTime, getUnixEpochTimeFromInterval } from '../../utilities/time';
import { getUnixEpochTimeFromInterval } from '../../utilities/time';
import { tooltip } from '../../utilities/tooltip';
import GridMenu from '../menus/GridMenu.svelte';
import DataGrid from '../ui/DataGrid/DataGrid.svelte';
Expand Down Expand Up @@ -167,13 +167,13 @@
derived_start_time: {
field: 'start_time_ms',
filter: 'text',
headerName: `Absolute Start Time (${$plugins.time?.primary?.label ?? 'UTC'})`,
headerName: `Absolute Start Time (${$plugins.time.primary.label})`,
hide: false,
resizable: true,
sortable: true,
valueGetter: (params: ValueGetterParams<ActivityDirective>) => {
if ($plan && params && params.data && typeof params.data.start_time_ms === 'number') {
return ($plugins.time?.primary?.format ?? getDoyTime)(new Date(params.data.start_time_ms), false);
return $plugins.time.primary.format(new Date(params.data.start_time_ms));
}
return '';
},
Expand Down
24 changes: 8 additions & 16 deletions src/components/activity/ActivitySpanForm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import { getSpanRootParent } from '../../utilities/activities';
import effects from '../../utilities/effects';
import { getFormParameters } from '../../utilities/parameters';
import { getDoyTimeFromInterval, getUnixEpochTime, getUnixEpochTimeFromInterval } from '../../utilities/time';
import { getUnixEpochTimeFromInterval } from '../../utilities/time';
import { tooltip } from '../../utilities/tooltip';
import Collapse from '../Collapse.svelte';
import Input from '../form/Input.svelte';
Expand Down Expand Up @@ -43,23 +43,15 @@
$: activityType = (activityTypes ?? []).find(({ name: activityTypeName }) => span.type === activityTypeName) ?? null;
$: rootSpan = getSpanRootParent(spansMap, span.id);
$: rootSpanHasChildren = (rootSpan && spanUtilityMaps.spanIdToChildIdsMap[rootSpan.id]?.length > 0) ?? false;
$: {
if ($plugins.time?.primary?.format && $plugins.time?.primary?.parse) {
const startTimeMs = getUnixEpochTimeFromInterval(planStartTimeYmd, span.start_offset);
startTime = $plugins.time?.primary?.format(new Date(startTimeMs));
} else {
startTime = getDoyTimeFromInterval(planStartTimeYmd, span.start_offset);
}
const startTimeMs = getUnixEpochTimeFromInterval(planStartTimeYmd, span.start_offset);
startTime = $plugins.time.primary.format(new Date(startTimeMs));
}
$: if (span.duration) {
if ($plugins.time?.primary?.format && $plugins.time?.primary?.parse) {
const endTimeMs = getUnixEpochTimeFromInterval(planStartTimeYmd, span.duration);
endTime = $plugins.time?.primary?.format(new Date(endTimeMs));
} else {
const startTimeISO = new Date(getUnixEpochTime(startTime)).toISOString();
endTime = getDoyTimeFromInterval(startTimeISO, span.duration);
}
const endTimeMs = getUnixEpochTimeFromInterval(planStartTimeYmd, span.duration);
endTime = $plugins.time.primary.format(new Date(endTimeMs));
} else {
endTime = null;
}
Expand Down Expand Up @@ -182,14 +174,14 @@

<Input layout="inline">
<label use:tooltip={{ content: 'Start Time', placement: 'top' }} for="startTime">
Start Time ({$plugins.time?.primary?.label ?? 'UTC'})
Start Time ({$plugins.time.primary.label})
</label>
<input class="st-input w-100" disabled name="startTime" value={startTime} />
</Input>

<Input layout="inline">
<label use:tooltip={{ content: 'End Time', placement: 'top' }} for="endTime">
End Time ({$plugins.time?.primary?.label ?? 'UTC'})
End Time ({$plugins.time.primary.label})
</label>
<input class="st-input w-100" disabled name="endTime" value={endTime ?? 'None'} />
</Input>
Expand Down
10 changes: 5 additions & 5 deletions src/components/activity/ActivitySpansTablePanel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import type { Span } from '../../types/simulation';
import type { AutoSizeColumns, ViewGridSection, ViewTable } from '../../types/view';
import { filterEmpty } from '../../utilities/generic';
import { getDoyTime } from '../../utilities/time';
import { tooltip } from '../../utilities/tooltip';
import GridMenu from '../menus/GridMenu.svelte';
import type DataGrid from '../ui/DataGrid/DataGrid.svelte';
Expand Down Expand Up @@ -84,13 +83,14 @@
derived_start_time: {
filter: 'text',
field: 'startMs',
headerName: `Absolute End Time (${$plugins.time?.primary?.label ?? 'UTC'})`,
headerName: `Absolute Start Time (${$plugins.time.primary.label})`,
hide: true,
resizable: true,
sortable: true,
valueGetter: params => {
if (params && params.data && typeof params.data.startMs === 'number') {
return ($plugins.time?.primary?.format ?? getDoyTime)(new Date(params.data.startMs), false);
/* TODO could use short format here to skip ms but do we need short(er) format somewhere else? */
return $plugins.time.primary.format(new Date(params.data.startMs));
}
return '';
},
Expand All @@ -99,13 +99,13 @@
derived_end_time: {
filter: 'text',
field: 'endMs',
headerName: 'Absolute End Time (UTC)',
headerName: `Absolute End Time (${$plugins.time.primary.label})`,
hide: true,
resizable: true,
sortable: true,
valueGetter: params => {
if (params && params.data && typeof params.data.endMs === 'number') {
return ($plugins.time?.primary?.format ?? getDoyTime)(new Date(params.data.endMs), false);
return $plugins.time.primary.format(new Date(params.data.endMs));
}
return '';
},
Expand Down
51 changes: 26 additions & 25 deletions src/components/constraints/ConstraintViolationButton.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,9 @@
export let window: TimeRange;
$: ({
doy: startDoy,
hours: startHours,
mins: startMins,
msecs: startMsecs,
secs: startSecs,
year: startYear,
} = getDoyTimeComponents(new Date(window.start)));
let isDoyPattern = false;
$: ({
doy: endDoy,
hours: endHours,
mins: endMins,
msecs: endMsecs,
secs: endSecs,
year: endYear,
} = getDoyTimeComponents(new Date(window.end)));
$: isDoyPattern = new RegExp(/^(\d{4})-(\d{3})T(\d{2}):(\d{2}):(\d{2})(?:\.(\d+))?$/);
function zoomToViolation(window: TimeRange): void {
$viewTimeRange = window;
Expand All @@ -33,21 +19,36 @@

<button class="st-button tertiary violation-button" on:click={() => zoomToViolation(window)}>
<div>
{#if $plugins.time?.primary?.format}
{$plugins.time?.primary?.format(new Date(window.start))}
{:else}
{#if isDoyPattern}
{@const {
doy: startDoy,
hours: startHours,
mins: startMins,
msecs: startMsecs,
secs: startSecs,
year: startYear,
} = getDoyTimeComponents(new Date(window.start))}
{startYear}-<span class="st-typography-bold">{startDoy}</span> T {startHours}:{startMins}:{startSecs}.{startMsecs}
UTC
{$plugins.time.primary.label}
{:else}
{$plugins.time.primary.format(new Date(window.start))}
{/if}
</div>

<div class="separator">–</div>
<div>
<!-- TODO use regex to detect this and make plugin have defaults -->
{#if $plugins.time?.primary?.format}
{$plugins.time?.primary?.format(new Date(window.start))}
{#if isDoyPattern}
{@const {
doy: endDoy,
hours: endHours,
mins: endMins,
msecs: endMsecs,
secs: endSecs,
year: endYear,
} = getDoyTimeComponents(new Date(window.end))}
{endYear}-<span class="st-typography-bold">{endDoy}</span> T {endHours}:{endMins}:{endSecs}.{endMsecs}
{$plugins.time.primary.label}
{:else}
{endYear}-<span class="st-typography-bold">{endDoy}</span> T {endHours}:{endMins}:{endSecs}.{endMsecs} UTC UTC
{$plugins.time.primary.format(new Date(window.start))}
{/if}
</div>
</button>
Expand Down
Loading

0 comments on commit 65a15df

Please sign in to comment.