|
3 | 3 | <script lang="ts"> |
4 | 4 | import { Badge, Button, Tabs } from '@nasa-jpl/stellar-svelte'; |
5 | 5 | import type { ColDef, ICellRendererParams, ValueFormatterParams } from 'ag-grid-community'; |
6 | | - import { Archive } from 'lucide-svelte'; |
7 | 6 | import { createEventDispatcher, onDestroy } from 'svelte'; |
8 | 7 | import { actionDefinitionsByWorkspace, actionRunsByWorkspace } from '../../../stores/actions'; |
9 | 8 | import { workspaceId } from '../../../stores/workspaces'; |
|
17 | 16 | getLatestRunnableVersion, |
18 | 17 | getStatusForActionRun, |
19 | 18 | getUserSequenceValueSchemaOptions, |
| 19 | + openActionRun, |
20 | 20 | truncateRunParameters, |
21 | 21 | valueSchemaRecordToParametersMap, |
22 | 22 | } from '../../../utilities/actions'; |
23 | 23 | import effects from '../../../utilities/effects'; |
| 24 | + import { isMetaOrCtrlPressed } from '../../../utilities/keyboardEvents'; |
24 | 25 | import { showConfirmModal } from '../../../utilities/modal'; |
25 | 26 | import { getArguments, getFormParameters } from '../../../utilities/parameters'; |
26 | 27 | import { permissionHandler } from '../../../utilities/permissionHandler'; |
|
162 | 163 | const { confirm } = await showConfirmModal( |
163 | 164 | actionDefinition.archived ? 'Unarchive' : 'Archive', |
164 | 165 | `Are you sure you want to ${action} "${actionDefinition.name}"?${action === 'archive' ? ' This operation can only be undone by an admin.' : ''}`, |
165 | | - `${actionDefinition.archived ? 'Unarchive' : 'Archive'} Action`, |
| 166 | + `${actionDefinition.archived ? 'Unarchive' : 'Archive'} action`, |
166 | 167 | true, |
167 | 168 | ); |
168 | 169 | if (!confirm) { |
|
243 | 244 | } |
244 | 245 | } |
245 | 246 |
|
246 | | - function onRowClicked(event: CustomEvent<{ data: ActionRunSlim }>) { |
247 | | - const { data } = event.detail; |
| 247 | + function onRowClicked(event: CustomEvent<{ data: ActionRunSlim; event?: Event | null }>) { |
| 248 | + const { data, event: originalEvent } = event.detail; |
248 | 249 | if (data) { |
249 | | - dispatch('viewRun', { runId: data.id }); |
| 250 | + if (originalEvent && isMetaOrCtrlPressed(originalEvent as MouseEvent)) { |
| 251 | + openActionRun($workspaceId, data.id, true); |
| 252 | + } else { |
| 253 | + dispatch('viewRun', { runId: data.id }); |
| 254 | + } |
250 | 255 | } |
251 | 256 | } |
252 | 257 |
|
|
409 | 414 | permissionError: 'You do not have permission to run an action', |
410 | 415 | }} |
411 | 416 | > |
412 | | - <Button on:click={onRunClick}>Run Action</Button> |
| 417 | + <Button on:click={onRunClick} disabled={actionDefinition.archived}>Run Action</Button> |
413 | 418 | </div> |
414 | 419 | <input bind:this={uploadFileInput} accept=".js" class="hidden" on:change={uploadNewVersion} type="file" /> |
415 | 420 | <div |
|
418 | 423 | permissionError: 'You do not have permission to upload a new version', |
419 | 424 | }} |
420 | 425 | > |
421 | | - <Button variant="outline" on:click={() => uploadFileInput?.click()}>Upload New Version</Button> |
| 426 | + <Button variant="outline" on:click={() => uploadFileInput?.click()} disabled={actionDefinition.archived}> |
| 427 | + Upload New Version |
| 428 | + </Button> |
422 | 429 | </div> |
423 | 430 | <Button on:click={() => dispatch('close')} variant="outline">Close</Button> |
424 | 431 | </div> |
|
454 | 461 | </div> |
455 | 462 | {#if activeTab === 'code'} |
456 | 463 | <div class="flex items-center gap-2 pr-2"> |
| 464 | + <label class="flex shrink-0 cursor-pointer items-center gap-1 text-xs text-muted-foreground"> |
| 465 | + <input type="checkbox" bind:checked={showArchivedVersions} class="h-3.5 w-3.5" /> |
| 466 | + <span>Archived</span> |
| 467 | + </label> |
457 | 468 | <select |
458 | 469 | class="st-input h-6 bg-white !px-1 text-xs" |
459 | 470 | value={selectedVersion?.revision ?? 0} |
|
471 | 482 | </select> |
472 | 483 | {#if selectedVersion} |
473 | 484 | <span class="text-xs text-muted-foreground"> |
474 | | - {selectedVersion.author ?? 'Unknown'} • {new Date(selectedVersion.created_at).toLocaleDateString()} |
| 485 | + Author: |
| 486 | + {selectedVersion.author ?? 'Unknown'} • Created: {new Date( |
| 487 | + selectedVersion.created_at, |
| 488 | + ).toLocaleDateString()} |
475 | 489 | </span> |
476 | 490 | {/if} |
477 | | - <button |
478 | | - class="flex shrink-0 items-center rounded p-0.5 {showArchivedVersions |
479 | | - ? 'bg-accent' |
480 | | - : 'text-muted-foreground hover:text-foreground'}" |
481 | | - title={showArchivedVersions ? 'Hide archived versions' : 'Show archived versions'} |
482 | | - on:click={() => (showArchivedVersions = !showArchivedVersions)} |
483 | | - > |
484 | | - <Archive size={14} /> |
485 | | - </button> |
| 491 | + |
486 | 492 | {#if selectedVersion && (selectedVersion !== actionDefinition.versions[0] || actionDefinition.versions.filter(v => !v.archived && v !== selectedVersion).length > 0)} |
487 | 493 | <Button |
488 | 494 | variant="outline" |
489 | 495 | class="h-6 text-xs" |
490 | 496 | disabled={!hasUpdatePermission} |
491 | 497 | on:click={() => toggleVersionArchive(actionDefinition, selectedVersion, user)} |
492 | 498 | > |
493 | | - {selectedVersion.archived ? 'Unarchive' : 'Archive'} |
| 499 | + {selectedVersion.archived ? 'Unarchive Version' : 'Archive Version'} |
494 | 500 | </Button> |
495 | 501 | {/if} |
496 | 502 | </div> |
|
626 | 632 | {/if} |
627 | 633 | </div> |
628 | 634 |
|
| 635 | + <!-- Versions section --> |
| 636 | + <div class="flex flex-col gap-3 rounded border border-border p-4"> |
| 637 | + <div class="flex items-center justify-between"> |
| 638 | + <h3 class="text-sm font-medium">Versions</h3> |
| 639 | + <label class="flex items-center gap-1.5 text-xs text-muted-foreground"> |
| 640 | + <input type="checkbox" bind:checked={showArchivedVersions} class="h-3.5 w-3.5" /> |
| 641 | + Show archived |
| 642 | + </label> |
| 643 | + </div> |
| 644 | + {#if displayedVersions.length === 0} |
| 645 | + <p class="text-xs italic text-muted-foreground">No versions</p> |
| 646 | + {:else} |
| 647 | + <div class="divide-y divide-border rounded border border-border"> |
| 648 | + {#each displayedVersions as version, i (version.revision)} |
| 649 | + <div |
| 650 | + class="flex items-center justify-between px-3 py-2 text-xs {version.archived ? 'opacity-50' : ''}" |
| 651 | + > |
| 652 | + <div class="flex flex-wrap items-center gap-x-4 gap-y-1"> |
| 653 | + <span class="font-medium"> |
| 654 | + v{version.revision} |
| 655 | + {#if i === 0 && !version.archived} |
| 656 | + <span class="text-muted-foreground">(latest)</span> |
| 657 | + {/if} |
| 658 | + </span> |
| 659 | + <span class="text-muted-foreground"> |
| 660 | + Author: <span class="text-foreground">{version.author ?? 'Unknown'}</span> |
| 661 | + </span> |
| 662 | + <span class="text-muted-foreground"> |
| 663 | + Created: <span class="text-foreground" |
| 664 | + >{new Date(version.created_at).toLocaleDateString()}</span |
| 665 | + > |
| 666 | + </span> |
| 667 | + {#if version.archived} |
| 668 | + <Badge variant="destructive">Archived</Badge> |
| 669 | + {/if} |
| 670 | + </div> |
| 671 | + {#if version !== actionDefinition.versions[0] || actionDefinition.versions.filter(v => !v.archived && v !== version).length > 0} |
| 672 | + <div |
| 673 | + use:permissionHandler={{ |
| 674 | + hasPermission: hasUpdatePermission, |
| 675 | + permissionError: 'You do not have permission to archive a version', |
| 676 | + }} |
| 677 | + > |
| 678 | + <Button |
| 679 | + variant="outline" |
| 680 | + class="h-6 shrink-0 text-xs" |
| 681 | + disabled={!hasUpdatePermission} |
| 682 | + on:click={() => toggleVersionArchive(actionDefinition, version, user)} |
| 683 | + > |
| 684 | + {version.archived ? 'Unarchive Version' : 'Archive Version'} |
| 685 | + </Button> |
| 686 | + </div> |
| 687 | + {/if} |
| 688 | + </div> |
| 689 | + {/each} |
| 690 | + </div> |
| 691 | + {/if} |
| 692 | + </div> |
| 693 | + |
629 | 694 | <div class="flex items-center gap-2"> |
630 | 695 | <div |
631 | 696 | use:permissionHandler={{ |
|
644 | 709 | }} |
645 | 710 | > |
646 | 711 | <Button variant="outline" on:click={toggleArchive}> |
647 | | - {actionDefinition.archived ? 'Unarchive' : 'Archive'} |
| 712 | + {actionDefinition.archived ? 'Unarchive Action' : 'Archive Action'} |
648 | 713 | </Button> |
649 | 714 | </div> |
650 | 715 | </div> |
|
0 commit comments