Skip to content

Commit

Permalink
Fetch full view when downloading from SavedViewsModel
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronPlave committed Dec 11, 2023
1 parent c264172 commit b9c758d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
28 changes: 22 additions & 6 deletions src/components/modals/SavedViewsModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
import { SearchParameters } from '../../enums/searchParameters';
import { initializeView, view, views } from '../../stores/views';
import type { User } from '../../types/app';
import type { ViewSlim } from '../../types/view';
import type { View, ViewSlim } from '../../types/view';
import effects from '../../utilities/effects';
import { setQueryParam } from '../../utilities/generic';
import { downloadView as downloadViewUtil } from '../../utilities/view';
import Tab from '../ui/Tabs/Tab.svelte';
import TabPanel from '../ui/Tabs/TabPanel.svelte';
import Tabs from '../ui/Tabs/Tabs.svelte';
Expand Down Expand Up @@ -58,13 +59,26 @@
}
}
async function openView({ detail: viewId }: CustomEvent<number>) {
async function getFullView(viewId: number): Promise<View | null> {
const query = new URLSearchParams(`?${SearchParameters.VIEW_ID}=${viewId}`);
const newView = await effects.getView(query, user);
return await effects.getView(query, user);
}
async function openView({ detail: viewId }: CustomEvent<number>) {
const view = await getFullView(viewId);
if (view !== null) {
initializeView({ ...view });
setQueryParam(SearchParameters.VIEW_ID, `${view.id}`);
dispatch('close');
} else {
console.log(`No view found for ID: ${viewId}`);
}
}
if (view !== null && newView !== null) {
initializeView({ ...newView });
setQueryParam(SearchParameters.VIEW_ID, `${newView.id}`);
async function downloadView({ detail: viewId }: CustomEvent<number>) {
const view = await getFullView(viewId);
if (view !== null) {
downloadViewUtil(view);
dispatch('close');
} else {
console.log(`No view found for ID: ${viewId}`);
Expand All @@ -87,6 +101,7 @@
on:deleteView={deleteView}
on:deleteViews={deleteViews}
on:openView={openView}
on:downloadView={downloadView}
/>
</TabPanel>
<TabPanel>
Expand All @@ -96,6 +111,7 @@
on:deleteView={deleteView}
on:deleteViews={deleteViews}
on:openView={openView}
on:downloadView={downloadView}
/>
</TabPanel>
</Tabs>
Expand Down
7 changes: 5 additions & 2 deletions src/components/view/ViewsTable.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import type { DataGridColumnDef } from '../../types/data-grid';
import type { View, ViewSlim } from '../../types/view';
import { featurePermissions } from '../../utilities/permissions';
import { downloadView as downloadViewUtil } from '../../utilities/view';
import BulkActionDataGrid from '../ui/DataGrid/BulkActionDataGrid.svelte';
import DataGridActions from '../ui/DataGrid/DataGridActions.svelte';
Expand Down Expand Up @@ -91,7 +90,7 @@
},
cellRendererParams: {
deleteView,
downloadView: downloadViewUtil,
downloadView,
openView,
} as CellRendererParams,
field: 'actions',
Expand All @@ -108,6 +107,10 @@
dispatch('deleteView', viewId);
}
function downloadView({ id: viewId }: ViewSlim) {
dispatch('downloadView', viewId);
}
function deleteViews({ detail: views }: CustomEvent<ViewSlim[]>) {
const viewIds = views.map(({ id }) => id);
dispatch('deleteViews', viewIds);
Expand Down

0 comments on commit b9c758d

Please sign in to comment.