Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deep link to a specific time window on the timeline #907

Merged
merged 5 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
joswig marked this conversation as resolved.
Show resolved Hide resolved
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',
}
31 changes: 25 additions & 6 deletions src/routes/plans/[id]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
resetSimulationStores,
resourceTypes,
resources,
selectedSpanId,
simulationDataset,
simulationDatasetId,
simulationDatasetLatest,
Expand All @@ -86,7 +85,7 @@
import type { ActivityDirective } from '../../../types/activity';
import type { ViewSaveEvent, ViewToggleEvent } from '../../../types/view';
import effects from '../../../utilities/effects';
import { removeQueryParam } from '../../../utilities/generic';
import { getSearchParameterNumber, removeQueryParam } from '../../../utilities/generic';
import { isSaveEvent } from '../../../utilities/keyboardEvents';
import { closeActiveModal, showPlanLockedModal } from '../../../utilities/modal';
import { featurePermissions } from '../../../utilities/permissions';
Expand Down Expand Up @@ -143,13 +142,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);
AaronPlave marked this conversation as resolved.
Show resolved Hide resolved
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
Loading