Skip to content

Commit

Permalink
Deep link to a specific time window on the timeline (#907)
Browse files Browse the repository at this point in the history
* Deep link to a specific time window on the timeline

* fixed prettier changes to quotes

* PR feedback and fixed issue with activity selection

* Include more info in tooltip

---------

Co-authored-by: Chet Joswig <[email protected]>
  • Loading branch information
2 people authored and JosephVolosin committed Oct 21, 2024
1 parent 3973765 commit 9232d10
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 5 deletions.
41 changes: 41 additions & 0 deletions src/components/timeline/TimelineViewControls.svelte
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
<script lang="ts">
import ArrowLeftIcon from '@nasa-jpl/stellar/icons/arrow_left.svg?component';
import ArrowRightIcon from '@nasa-jpl/stellar/icons/arrow_right.svg?component';
import LinkIcon from '@nasa-jpl/stellar/icons/link.svg?component';
import MinusIcon from '@nasa-jpl/stellar/icons/minus.svg?component';
import PlusIcon from '@nasa-jpl/stellar/icons/plus.svg?component';
import RotateCounterClockwiseIcon from '@nasa-jpl/stellar/icons/rotate_counter_clockwise.svg?component';
import { createEventDispatcher } from 'svelte';
import { SearchParameters } from '../../enums/searchParameters';
import { selectedActivityDirective } from '../../stores/activities';
import { selectedSpan, simulationDatasetId } from '../../stores/simulation';
import { viewIsModified } from '../../stores/views';
import type { DirectiveVisibilityToggleMap, TimeRange } from '../../types/timeline';
import { showFailureToast, showSuccessToast } from '../../utilities/toast';
import { tooltip } from '../../utilities/tooltip';
import TimelineViewDirectiveControls from './TimelineViewDirectiveControls.svelte';
Expand Down Expand Up @@ -106,6 +112,28 @@
function onToggleDirectiveVisibility() {
dispatch('toggleDirectiveVisibility', !allDirectivesVisible);
}
async function onCopyViewportURL() {
const targetUrl = new URL(window.location.href);
targetUrl.searchParams.set(SearchParameters.START_TIME, new Date(viewTimeRange.start).toISOString());
targetUrl.searchParams.set(SearchParameters.END_TIME, new Date(viewTimeRange.end).toISOString());
if ($selectedActivityDirective) {
targetUrl.searchParams.set(SearchParameters.ACTIVITY_ID, $selectedActivityDirective.id.toFixed());
}
if ($selectedSpan) {
targetUrl.searchParams.set(SearchParameters.SPAN_ID, $selectedSpan.id.toFixed());
}
if ($simulationDatasetId) {
targetUrl.searchParams.set(SearchParameters.SIMULATION_DATASET_ID, $simulationDatasetId.toFixed());
}
try {
await navigator.clipboard.writeText(targetUrl.href);
showSuccessToast('URL of plan and view copied to clipboard');
} catch {
showFailureToast('Error copying URL to clipboard');
}
}
</script>

<svelte:window on:keydown={onKeydown} />
Expand Down Expand Up @@ -160,6 +188,19 @@
/>
{/if}

<button
class="st-button icon"
on:click={onCopyViewportURL}
use:tooltip={{
content: `Copy URL including plan, visible time window, selection, and simulation dataset to clipboard.${
$viewIsModified ? ' View has unsaved changes.' : ''
}`,
placement: 'bottom',
}}
>
<LinkIcon />
</button>

<style>
.st-button {
border: 1px solid var(--st-gray-30);
Expand Down
3 changes: 3 additions & 0 deletions src/enums/searchParameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ export enum SearchParameters {
REASON = 'reason',
SIMULATION_DATASET_ID = 'simulationDatasetId',
SNAPSHOT_ID = 'snapshotId',
SPAN_ID = 'spanId',
SPEC_ID = 'specId',
VIEW_ID = 'viewId',
START_TIME = 'startTime',
END_TIME = 'endTime',
}
29 changes: 24 additions & 5 deletions src/routes/plans/[id]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
resetSimulationStores,
resourceTypes,
resources,
selectedSpanId,
simulationDataset,
simulationDatasetId,
simulationDatasetLatest,
Expand Down Expand Up @@ -151,13 +150,33 @@
$simulationDatasetId = data.initialPlan.simulations[0]?.simulation_datasets[0]?.id ?? -1;
}
const queryActivityId = $page.url.searchParams.get(SearchParameters.ACTIVITY_ID);
if (queryActivityId) {
$selectedSpanId = parseInt(queryActivityId);
const queryActivityId = getSearchParameterNumber(SearchParameters.ACTIVITY_ID, $page.url.searchParams);
const querySpanId = getSearchParameterNumber(SearchParameters.SPAN_ID, $page.url.searchParams);
if (queryActivityId !== null || querySpanId !== null) {
setTimeout(() => selectActivity(queryActivityId, querySpanId));
removeQueryParam(SearchParameters.ACTIVITY_ID);
removeQueryParam(SearchParameters.SPAN_ID);
}
$viewTimeRange = $maxTimeRange;
let start = NaN;
const startTimeStr = $page.url.searchParams.get(SearchParameters.START_TIME);
if (startTimeStr) {
start = new Date(startTimeStr).getTime();
removeQueryParam(SearchParameters.START_TIME);
}
let end = NaN;
const endTimeStr = $page.url.searchParams.get(SearchParameters.END_TIME);
if (endTimeStr) {
end = new Date(endTimeStr).getTime();
removeQueryParam(SearchParameters.END_TIME);
}
viewTimeRange.set({
end: !isNaN(end) ? end : $maxTimeRange.end,
start: !isNaN(start) ? start : $maxTimeRange.start,
});
activityTypes.updateValue(() => data.initialActivityTypes);
planTags.updateValue(() => data.initialPlanTags);
Expand Down

0 comments on commit 9232d10

Please sign in to comment.