|
2 | 2 |
|
3 | 3 | <script lang="ts"> |
4 | 4 | import { base } from '$app/paths'; |
| 5 | + import { Label, Select } from '@nasa-jpl/stellar-svelte'; |
5 | 6 | import type { ICellRendererParams, ValueGetterParams } from 'ag-grid-community'; |
6 | 7 | import { X } from 'lucide-svelte'; |
7 | 8 | import ExternalEventIcon from '../../assets/external-event-box-with-arrow.svg?component'; |
|
10 | 11 | createDerivationGroupError, |
11 | 12 | createExternalSourceError, |
12 | 13 | creatingExternalSource, |
| 14 | + derivationGroups, |
13 | 15 | externalSources, |
14 | 16 | externalSourceTypes, |
15 | 17 | planDerivationGroupLinks, |
| 18 | + planDerivationGroupLinksByPlan, |
16 | 19 | } from '../../stores/external-source'; |
17 | 20 | import { field } from '../../stores/form'; |
18 | 21 | import { plans } from '../../stores/plans'; |
|
131 | 134 | let selectedSourceTypeParametersMap: ParametersMap = {}; |
132 | 135 | let selectedSourceId: string | null = null; |
133 | 136 | let selectedSourceEventTypes: ExternalEventType[] = []; |
| 137 | + let selectedSourceDerivationGroup: string | undefined; |
| 138 | + let selectedSourceTypeDerivationGroups: string[]; |
134 | 139 |
|
135 | 140 | // Selected element variables |
136 | 141 | let selectedEvent: ExternalEvent | null = null; |
|
167 | 172 | ]); |
168 | 173 | } |
169 | 174 |
|
| 175 | + $: selectedSourceDerivationGroup = selectedSource?.derivation_group_name; |
| 176 | +
|
| 177 | + $: selectedSourceTypeDerivationGroups = $derivationGroups |
| 178 | + .filter(derivationGroup => derivationGroup.source_type_name === selectedSource?.source_type_name) |
| 179 | + .map(derivationGroup => derivationGroup.name); |
| 180 | +
|
170 | 181 | $: if (selectedSource !== null && Object.keys(selectedSource.attributes).length > 0) { |
171 | 182 | // Create an ArgumentsMap for the External Source |
172 | 183 | selectedSourceAttributes = translateJsonSchemaArgumentsToValueSchema(selectedSource.attributes); |
|
309 | 320 | ) |
310 | 321 | .then(fetched => (selectedSourceEventTypes = fetched)); |
311 | 322 |
|
312 | | - $: selectedSourceLinkedDerivationGroupsPlans = $planDerivationGroupLinks.filter(planDerivationGroupLink => { |
| 323 | + $: selectedSourceLinkedDerivationGroupsPlans = $planDerivationGroupLinksByPlan.filter(planDerivationGroupLink => { |
313 | 324 | return planDerivationGroupLink.derivation_group_name === selectedSource?.derivation_group_name; |
314 | 325 | }); |
315 | 326 |
|
|
318 | 329 | // Permissions |
319 | 330 | $: hasCreatePermission = featurePermissions.externalSource.canCreate(user); |
320 | 331 |
|
| 332 | + async function changeDerivationGroup(newDerivationGroup: string | undefined) { |
| 333 | + if (!selectedSource || !newDerivationGroup) { |
| 334 | + return; |
| 335 | + } |
| 336 | + await effects.updateSourceDerivationGroup(selectedSource, newDerivationGroup, $planDerivationGroupLinks, user); |
| 337 | + deselectSource(); // Would actually like this to stay selected, but the table un-selects due to data change |
| 338 | + } |
| 339 | +
|
321 | 340 | async function onDeleteExternalSource(selectedSources: ExternalSourceSlim[] | null | undefined) { |
322 | 341 | if (selectedSources !== null && selectedSources !== undefined) { |
323 | 342 | const deleteExternalSourceResult = await effects.deleteExternalSource( |
324 | 343 | selectedSources, |
325 | | - $planDerivationGroupLinks, |
| 344 | + $planDerivationGroupLinksByPlan, |
326 | 345 | user, |
327 | 346 | ); |
328 | 347 | if (deleteExternalSourceResult !== undefined && deleteExternalSourceResult !== null) { |
|
449 | 468 | value={selectedSource.source_type_name} |
450 | 469 | /> |
451 | 470 | </Input> |
452 | | - |
453 | | - <Input layout="inline"> |
454 | | - Derivation Group |
455 | | - <input |
456 | | - class="st-input w-full" |
457 | | - disabled={true} |
458 | | - name="derivation-group" |
459 | | - value={selectedSource.derivation_group_name} |
460 | | - /> |
461 | | - </Input> |
| 471 | + <div class="grid"> |
| 472 | + <Field field={derivationGroupField}> |
| 473 | + <Label size="sm" for="derivationGroup">Derivation Group</Label> |
| 474 | + <div> |
| 475 | + <Select.Root |
| 476 | + selected={{ label: selectedSourceDerivationGroup, value: selectedSourceDerivationGroup }} |
| 477 | + disabled={false} |
| 478 | + onSelectedChange={value => { |
| 479 | + if (value) { |
| 480 | + changeDerivationGroup(value.value); |
| 481 | + } |
| 482 | + }} |
| 483 | + > |
| 484 | + <Select.Trigger |
| 485 | + value={selectedSourceDerivationGroup} |
| 486 | + size="xs" |
| 487 | + aria-label="Change Derivation Group" |
| 488 | + aria-labelledby={null} |
| 489 | + id="derivationGroup" |
| 490 | + > |
| 491 | + <Select.Value placeholder="Change derivation group" /> |
| 492 | + </Select.Trigger> |
| 493 | + <Select.Content |
| 494 | + class="min-w-[240px] overflow-auto p-0" |
| 495 | + sameWidth={false} |
| 496 | + align="start" |
| 497 | + datatype="text" |
| 498 | + fitViewport |
| 499 | + > |
| 500 | + {#each selectedSourceTypeDerivationGroups as derivationGroup} |
| 501 | + <Select.Item size="xs" value={derivationGroup} label={derivationGroup} class="flex gap-1"> |
| 502 | + {derivationGroup} |
| 503 | + </Select.Item> |
| 504 | + {/each} |
| 505 | + </Select.Content> |
| 506 | + <Select.Input |
| 507 | + type="text" |
| 508 | + name="derivationGroup" |
| 509 | + aria-label="Change Derivation Group hidden input" |
| 510 | + /> |
| 511 | + </Select.Root> |
| 512 | + </div> |
| 513 | + </Field> |
| 514 | + </div> |
462 | 515 |
|
463 | 516 | <Input layout="inline"> |
464 | 517 | Owner |
|
0 commit comments