Skip to content

Commit

Permalink
PR feedback and fixed issue with activity selection
Browse files Browse the repository at this point in the history
  • Loading branch information
Chet Joswig authored and joswig committed Oct 9, 2023
1 parent 22a5b0a commit 1df4e14
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
15 changes: 12 additions & 3 deletions src/components/timeline/TimelineViewControls.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
import { createEventDispatcher } from 'svelte';
import { SearchParameters } from '../../enums/searchParameters';
import { selectedActivityDirective } from '../../stores/activities';
import { simulationDatasetId } from '../../stores/simulation';
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 @@ -112,18 +113,26 @@
dispatch('toggleDirectiveVisibility', !allDirectivesVisible);
}
function onCopyViewportURL() {
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());
}
navigator.clipboard.writeText(targetUrl.href);
try {
await navigator.clipboard.writeText(targetUrl.href);
showSuccessToast('URL of plan and view copied to clipboard');
} catch {
showFailureToast('Error copying URL to clipboard');
}
}
</script>

Expand Down
1 change: 1 addition & 0 deletions src/enums/searchParameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export enum SearchParameters {
REASON = 'reason',
SIMULATION_DATASET_ID = 'simulationDatasetId',
SNAPSHOT_ID = 'snapshotId',
SPAN_ID = 'spanId',
SPEC_ID = 'specId',
VIEW_ID = 'viewId',
START_TIME = 'startTime',
Expand Down
24 changes: 10 additions & 14 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,10 +142,12 @@
$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);
}
let start = NaN;
Expand All @@ -163,15 +164,10 @@
removeQueryParam(SearchParameters.END_TIME);
}
if (isNaN(start) && isNaN(end)) {
$viewTimeRange = $maxTimeRange;
} else if (!isNaN(start) && !isNaN(end)) {
viewTimeRange.set({ end, start });
} else if (!isNaN(start)) {
viewTimeRange.set({ ...$maxTimeRange, start });
} else if (!isNaN(end)) {
viewTimeRange.set({ ...$maxTimeRange, end });
}
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 1df4e14

Please sign in to comment.