Skip to content

Commit

Permalink
Fix plan metadata name input reset on snapshot preview (#1358)
Browse files Browse the repository at this point in the history
* fix table action icons staying disabled when no longer in snapshot preview
* make table components less plan specific
  • Loading branch information
duranb authored Jul 3, 2024
1 parent c9dbcdb commit d6e0663
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
5 changes: 3 additions & 2 deletions src/components/activity/ActivityDirectivesTable.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<script lang="ts">
import type { ColDef, ColumnState, ICellRendererParams } from 'ag-grid-community';
import { PlanStatusMessages } from '../../enums/planStatusMessages';
import type { ActivityDirective, ActivityDirectiveId } from '../../types/activity';
import type { User } from '../../types/app';
import type { DataGridColumnDef } from '../../types/data-grid';
Expand Down Expand Up @@ -58,7 +59,7 @@
placement: 'bottom',
},
hasDeletePermission,
planReadOnly,
hasDeletePermissionError: planReadOnly ? PlanStatusMessages.READ_ONLY : undefined,
rowData: params.data,
},
target: actionsDiv,
Expand Down Expand Up @@ -137,8 +138,8 @@
columnDefs={completeColumnDefs}
{columnStates}
{getRowId}
{planReadOnly}
{hasDeletePermission}
hasDeletePermissionError={planReadOnly ? PlanStatusMessages.READ_ONLY : undefined}
items={activityDirectivesWithErrorCounts}
pluralItemDisplayText="Activity Directives"
scrollToSelection={true}
Expand Down
3 changes: 3 additions & 0 deletions src/components/plan/PlanForm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@
),
]);
}
$: if (plan) {
planNameField.validateAndSet(plan?.name ?? '');
}
async function onTagsInputChange(event: TagsChangeEvent) {
const {
Expand Down
12 changes: 7 additions & 5 deletions src/components/ui/DataGrid/BulkActionDataGrid.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import type { ColDef, ColumnState, IRowNode, RedrawRowsParams } from 'ag-grid-community';
import { keyBy } from 'lodash-es';
import { createEventDispatcher, onDestroy, type ComponentEvents } from 'svelte';
import { PlanStatusMessages } from '../../../enums/planStatusMessages';
import type { User } from '../../../types/app';
import type { Dispatcher } from '../../../types/component';
import type { RowId, TRowData } from '../../../types/data-grid';
Expand All @@ -28,7 +27,7 @@
export let columnsToForceRefreshOnDataUpdate: (keyof RowData)[] = [];
export let dataGrid: DataGrid<RowData> | undefined = undefined;
export let hasDeletePermission: PermissionCheck<RowData> | boolean = true;
export let planReadOnly: boolean = false;
export let hasDeletePermissionError: string = 'You do not have permission to delete.';
export let idKey: keyof RowData = 'id';
export let items: RowData[];
export let pluralItemDisplayText: string = '';
Expand All @@ -55,12 +54,12 @@
const selectedItem = items.find(item => item.id === selectedItemId) ?? null;
if (selectedItem) {
if (typeof hasDeletePermission === 'function') {
deletePermission = hasDeletePermission(user, selectedItem) && !planReadOnly;
deletePermission = hasDeletePermission(user, selectedItem);
}
}
}
$: if (typeof hasDeletePermission === 'boolean') {
deletePermission = hasDeletePermission && !planReadOnly;
deletePermission = hasDeletePermission;
}
$: if (selectedItemId != null && !selectedItemIds.includes(selectedItemId)) {
selectedItemIds = [selectedItemId];
Expand All @@ -70,6 +69,9 @@
$: if (user !== undefined) {
redrawRows?.();
}
$: if (deletePermission != null) {
redrawRows?.();
}
onDestroy(() => onBlur());
Expand Down Expand Up @@ -167,7 +169,7 @@
permissionHandler,
{
hasPermission: deletePermission,
permissionError: planReadOnly ? PlanStatusMessages.READ_ONLY : 'You do not have permission to delete.',
permissionError: hasDeletePermissionError,
},
],
]}
Expand Down
12 changes: 3 additions & 9 deletions src/components/ui/DataGrid/DataGridActions.svelte
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<svelte:options immutable={true} />

<script lang="ts">
import { PlanStatusMessages } from '../../../enums/planStatusMessages';
import { permissionHandler } from '../../../utilities/permissionHandler';
import DownloadIcon from '@nasa-jpl/stellar/icons/download.svg?component';
Expand All @@ -28,7 +26,6 @@
export let hasDeletePermissionError: string | undefined = undefined;
export let hasEditPermission: boolean = true;
export let hasEditPermissionError: string | undefined = undefined;
export let planReadOnly: boolean = false;
export let viewTooltip: Tooltip | undefined = undefined;
export let editCallback: ((data: RowData) => void) | undefined = undefined;
Expand Down Expand Up @@ -74,9 +71,7 @@
use:tooltip={hasEditPermission ? editTooltip : undefined}
use:permissionHandler={{
hasPermission: hasEditPermission,
permissionError: planReadOnly
? PlanStatusMessages.READ_ONLY
: hasEditPermissionError || `You do not have permission to ${editTooltip?.content ?? 'edit'}.`,
permissionError: hasEditPermissionError || `You do not have permission to ${editTooltip?.content ?? 'edit'}.`,
}}
>
<PenIcon />
Expand All @@ -93,9 +88,8 @@
use:tooltip={hasDeletePermission ? deleteTooltip : undefined}
use:permissionHandler={{
hasPermission: hasDeletePermission,
permissionError: planReadOnly
? PlanStatusMessages.READ_ONLY
: hasDeletePermissionError || `You do not have permission to ${deleteTooltip?.content ?? 'delete'}.`,
permissionError:
hasDeletePermissionError || `You do not have permission to ${deleteTooltip?.content ?? 'delete'}.`,
}}
>
<TrashIcon />
Expand Down

0 comments on commit d6e0663

Please sign in to comment.