Skip to content

Commit

Permalink
Use bulk default activity arguments and remove getEffectiveActivityAr…
Browse files Browse the repository at this point in the history
…guments calls (#1605)

* Use cached default activity args for ActivityDirectiveChangelog
* Use cached default activity args in ActivityDirectiveForm
* Remove extraneous component parameter
* Use cached activity args for ActivitySpanForm
* Remove GET_EFFECTIVE_ACTIVITY_ARGUMENTS query
* Refactor getDefaultActivityArguments to use only list of activity type names instead of full activity types
* Rework plan export to use bulk activity arg defaults and to not be cancelable but still show progress
  • Loading branch information
AaronPlave authored Feb 11, 2025
1 parent 0803e6d commit fb8083f
Show file tree
Hide file tree
Showing 14 changed files with 117 additions and 387 deletions.
13 changes: 3 additions & 10 deletions src/components/activity/ActivityDirectiveChangelog.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<script lang="ts">
import HistoryIcon from '@nasa-jpl/stellar/icons/history.svg?component';
import { createEventDispatcher, onMount } from 'svelte';
import { activityArgumentDefaultsMap } from '../../stores/activities';
import { plan } from '../../stores/plan';
import { plugins } from '../../stores/plugins';
import type {
Expand All @@ -28,7 +29,6 @@
export let activityDirective: ActivityDirective;
export let activityDirectivesMap: ActivityDirectivesMap = {};
export let activityTypes: ActivityType[] = [];
export let modelId: number;
export let planStartTimeYmd: string;
export let user: User | null;
Expand Down Expand Up @@ -192,18 +192,11 @@
const { id: activityId, plan_id: planId } = activityDirective;
activityRevisions = await effects.getActivityDirectiveChangelog(planId, activityId, user);
// Get default set of effective arguments
const effectiveDefaultArguments = await effects.getEffectiveActivityArguments(
modelId,
activityType?.name || '',
{},
user,
);
// Get effective arguments for all revisions by coalescing defaults with args supplied in revision
const defaultArguments = $activityArgumentDefaultsMap[activityType?.name || ''] ?? null;
effectiveRevisionArguments = activityRevisions.map(revision => {
return {
...effectiveDefaultArguments?.arguments,
...defaultArguments?.arguments,
...revision.arguments,
};
});
Expand Down
27 changes: 8 additions & 19 deletions src/components/activity/ActivityDirectiveForm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import { keyBy } from 'lodash-es';
import { createEventDispatcher } from 'svelte';
import { PlanStatusMessages } from '../../enums/planStatusMessages';
import { activityArgumentDefaultsMap } from '../../stores/activities';
import { activityErrorRollupsMap, activityValidationErrors } from '../../stores/errors';
import { field } from '../../stores/form';
import { plan, planReadOnly } from '../../stores/plan';
Expand Down Expand Up @@ -111,25 +112,13 @@
$: activityNameField.validateAndSet(activityDirective.name);
$: if (activityType && activityDirective.arguments) {
effects
.getEffectiveActivityArguments(
modelId,
activityType.name,
revision ? revision.arguments : activityDirective.arguments,
user,
)
.then(effectiveArguments => {
if (effectiveArguments && activityType) {
const { arguments: defaultArgumentsMap } = effectiveArguments;
formParameters = getFormParameters(
activityType.parameters,
revision ? revision.arguments : activityDirective.arguments,
activityType.required_parameters,
revision ? undefined : activityDirective.applied_preset?.preset_applied?.arguments,
defaultArgumentsMap,
);
}
});
formParameters = getFormParameters(
activityType.parameters,
revision ? revision.arguments : activityDirective.arguments,
activityType.required_parameters,
revision ? undefined : activityDirective.applied_preset?.preset_applied?.arguments,
$activityArgumentDefaultsMap[activityType?.name || ''] ?? {},
);
}
$: validateArguments(revision ? revision.arguments : activityDirective.arguments);
$: numOfUserChanges = formParameters.reduce((previousHasChanges: number, formParameter) => {
Expand Down
2 changes: 0 additions & 2 deletions src/components/activity/ActivityFormPanel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@
activityDirective={$selectedActivityDirective}
activityDirectivesMap={$activityDirectivesMap || {}}
activityTypes={$activityTypes}
modelId={$modelId}
planStartTimeYmd={$plan.start_time}
on:closeChangelog={onToggleViewChangelog}
on:previewRevision={onPreviewRevision}
Expand All @@ -231,7 +230,6 @@
<ActivitySpanForm
activityTypes={$activityTypes}
filteredExpansionSequences={$filteredExpansionSequences}
modelId={$modelId}
simulationDatasetId={$simulationDatasetId}
span={$selectedSpan}
spansMap={$spansMap}
Expand Down
28 changes: 11 additions & 17 deletions src/components/activity/ActivitySpanForm.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<svelte:options immutable={true} />

<script lang="ts">
import { activityArgumentDefaultsMap } from '../../stores/activities';
import { plugins } from '../../stores/plugins';
import type { ActivityType } from '../../types/activity';
import type { User } from '../../types/app';
Expand All @@ -20,7 +21,6 @@
export let activityTypes: ActivityType[] = [];
export let filteredExpansionSequences: ExpansionSequence[] = [];
export let modelId: number;
export let simulationDatasetId: number = -1;
export let span: Span;
export let spansMap: SpansMap | null = {};
Expand Down Expand Up @@ -52,22 +52,16 @@
}
$: if (activityType && span.attributes.arguments) {
effects
.getEffectiveActivityArguments(modelId, activityType.name, span.attributes.arguments, user)
.then(activityArguments => {
if (activityArguments !== null && activityType !== null) {
formParameters = getFormParameters(
activityType.parameters,
span.attributes.arguments,
activityType.required_parameters,
{},
activityArguments.arguments,
).map(formParameter => ({
...formParameter,
valueSource: 'none',
}));
}
});
formParameters = getFormParameters(
activityType.parameters,
span.attributes.arguments,
activityType.required_parameters,
{},
$activityArgumentDefaultsMap[activityType?.name || ''] ?? {},
).map(formParameter => ({
...formParameter,
valueSource: 'none',
}));
}
$: if (parameterErrorMap) {
Expand Down
49 changes: 9 additions & 40 deletions src/components/menus/PlanMenu.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import BranchIcon from '@nasa-jpl/stellar/icons/branch.svg?component';
import ChevronDownIcon from '@nasa-jpl/stellar/icons/chevron_down.svg?component';
import { PlanStatusMessages } from '../../enums/planStatusMessages';
import { activityDirectivesMap } from '../../stores/activities';
import { planReadOnly } from '../../stores/plan';
import { initialPlanSnapshotsLoading } from '../../stores/planSnapshots';
import { viewTogglePanel } from '../../stores/views';
Expand All @@ -18,7 +19,6 @@
import { exportPlan } from '../../utilities/plan';
import Menu from '../menus/Menu.svelte';
import MenuItem from '../menus/MenuItem.svelte';
import ProgressRadial from '../ui/ProgressRadial.svelte';
import MenuDivider from './MenuDivider.svelte';
export let plan: Plan;
Expand All @@ -27,9 +27,8 @@
let hasCreateMergeRequestPermission: boolean = false;
let hasCreatePlanBranchPermission: boolean = false;
let hasCreateSnapshotPermission: boolean = false;
let planExporting: boolean = false;
let planMenu: Menu;
let planExportAbortController: AbortController | null = null;
let planExportProgress: number | null = null;
$: hasCreateMergeRequestPermission = plan.parent_plan
? featurePermissions.planBranch.canCreateRequest(
Expand Down Expand Up @@ -62,31 +61,11 @@
}
async function onExportPlan() {
if (planExportAbortController) {
planExportAbortController.abort();
if (!planExporting && $activityDirectivesMap) {
planExporting = true;
await exportPlan(plan, user, Object.values($activityDirectivesMap));
planExporting = false;
}
planExportProgress = 0;
planExportAbortController = new AbortController();
if (planExportAbortController && !planExportAbortController.signal.aborted) {
await exportPlan(
plan,
user,
(progress: number) => {
planExportProgress = progress;
},
undefined,
planExportAbortController.signal,
);
}
planExportProgress = null;
}
function onCancelExportPlan() {
planExportAbortController?.abort();
planExportAbortController = null;
planExportProgress = null;
}
function viewSnapshotHistory() {
Expand Down Expand Up @@ -178,14 +157,11 @@
<div class="column-name">View Snapshot History</div>
</MenuItem>
<MenuDivider />
<MenuItem on:click={planExportProgress === null ? onExportPlan : onCancelExportPlan}>
{#if planExportProgress === null}
<MenuItem on:click={onExportPlan} disabled={planExporting}>
{#if !planExporting}
Export plan as .json
{:else}
<div class="cancel-plan-export">
Cancel plan export
<ProgressRadial progress={planExportProgress} size={16} strokeWidth={1} />
</div>
Exporting...
{/if}
</MenuItem>
</Menu>
Expand Down Expand Up @@ -243,11 +219,4 @@
cursor: pointer;
user-select: none;
}
.cancel-plan-export {
--progress-radial-background: var(--st-gray-20);
align-items: center;
column-gap: 0.25rem;
display: flex;
}
</style>
53 changes: 14 additions & 39 deletions src/components/plan/PlanForm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
import Loading from '../Loading.svelte';
import Field from '../form/Field.svelte';
import Input from '../form/Input.svelte';
import CancellableProgressRadial from '../ui/CancellableProgressRadial.svelte';
import CardList from '../ui/CardList.svelte';
import FilterToggleButton from '../ui/FilterToggleButton.svelte';
import ProgressRadial from '../ui/ProgressRadial.svelte';
import PlanCollaboratorInput from '../ui/Tags/PlanCollaboratorInput.svelte';
import TagsInput from '../ui/Tags/TagsInput.svelte';
import PlanSnapshot from './PlanSnapshot.svelte';
Expand All @@ -53,15 +53,14 @@
let hasCreateSnapshotPermission: boolean = false;
let hasPlanUpdatePermission: boolean = false;
let hasPlanCollaboratorsUpdatePermission: boolean = false;
let planExportAbortController: AbortController | null = null;
let planNameField = field<string>('', [
required,
unique(
($plans || []).filter(p => p.id !== plan?.id).map(p => p.name),
'Plan name already exists',
),
]);
let planExportProgress: number | null = null;
let planExporting: boolean = false;
let planStartTime: string = '';
let planEndTime: string = '';
Expand Down Expand Up @@ -158,50 +157,22 @@
}
async function onExportPlan() {
if (plan && activityDirectivesMap) {
if (planExportAbortController) {
planExportAbortController.abort();
}
planExportAbortController = new AbortController();
if (planExportAbortController && !planExportAbortController.signal.aborted) {
await exportPlan(
plan,
user,
(progress: number) => {
planExportProgress = progress;
},
Object.values(activityDirectivesMap),
planExportAbortController.signal,
);
}
planExportProgress = null;
if (plan && !planExporting && activityDirectivesMap) {
planExporting = true;
await exportPlan(plan, user, Object.values(activityDirectivesMap));
planExporting = false;
}
}
function onCancelExportPlan() {
planExportAbortController?.abort();
planExportAbortController = null;
planExportProgress = null;
}
</script>

<div class="plan-form">
{#if plan}
<fieldset>
<Collapse title="Details">
<svelte:fragment slot="right">
{#if planExportProgress !== null}
<button
class="st-button icon cancel-button"
on:click|stopPropagation={onCancelExportPlan}
use:tooltip={{
content: 'Cancel Plan Export',
placement: 'top',
}}
>
<CancellableProgressRadial progress={planExportProgress} />
{#if planExporting}
<button class="st-button icon progress" on:click|stopPropagation={() => {}}>
<ProgressRadial strokeWidth={1} />
</button>
{:else}
<button
Expand Down Expand Up @@ -424,9 +395,13 @@
width: 28px;
}
.cancel-button {
.progress {
border: 0;
border-radius: 50%;
width: 28px;
--progress-radial-background: var(--st-gray-20);
}
.progress:hover {
background: none;
}
</style>
20 changes: 14 additions & 6 deletions src/components/ui/DataGrid/DataGridActions.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import type { TRowData } from '../../../types/data-grid';
import { tooltip } from '../../../utilities/tooltip';
import CancellableProgressRadial from '../CancellableProgressRadial.svelte';
import ProgressRadial from '../ProgressRadial.svelte';
type RowData = $$Generic<TRowData>;
Expand All @@ -20,7 +21,7 @@
placement: Placement;
};
export let rowData: RowData | undefined;
export let isDownloadCancellable: boolean = true;
export let editButtonClass: string | undefined = undefined;
export let editTooltip: Tooltip | undefined = undefined;
export let deleteButtonClass: string | undefined = undefined;
Expand All @@ -31,6 +32,7 @@
export let hasDeletePermissionError: string | undefined = undefined;
export let hasEditPermission: boolean = true;
export let hasEditPermissionError: string | undefined = undefined;
export let rowData: RowData | undefined;
export let useExportIcon: boolean | undefined = undefined;
export let viewButtonClass: string | undefined = undefined;
export let viewTooltip: Tooltip | undefined = undefined;
Expand Down Expand Up @@ -67,9 +69,11 @@
}
function onCancelDownload() {
downloadAbortController?.abort();
downloadAbortController = null;
downloadProgress = null;
if (isDownloadCancellable) {
downloadAbortController?.abort();
downloadAbortController = null;
downloadProgress = null;
}
}
function progressCallback(progress: number) {
Expand Down Expand Up @@ -116,9 +120,13 @@
class:icon={true}
class={downloadButtonClass}
on:click|stopPropagation={onCancelDownload}
use:tooltip={{ ...downloadTooltip, content: `Cancel ${downloadTooltip?.content}` }}
use:tooltip={{ ...downloadTooltip, content: isDownloadCancellable ? `Cancel ${downloadTooltip?.content}` : '' }}
>
<CancellableProgressRadial progress={downloadProgress} />
{#if isDownloadCancellable}
<CancellableProgressRadial progress={downloadProgress} />
{:else}
<ProgressRadial progress={downloadProgress} strokeWidth={1} />
{/if}
</button>
{/if}
{/if}
Expand Down
Loading

0 comments on commit fb8083f

Please sign in to comment.