Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

View Definition Auto Migration #1504

Merged
merged 15 commits into from
Oct 22, 2024
Merged
1 change: 0 additions & 1 deletion e2e-tests/data/valid-view.json
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,6 @@
"layers": [
{
"activityColor": "#283593",
"activityHeight": 20,
"chartType": "activity",
"filter": {
"activity": {
Expand Down
1 change: 1 addition & 0 deletions e2e-tests/fixtures/View.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export class View {
navButtonViewSaveAsMenuButton: Locator;
navButtonViewSavedViewsMenuButton: Locator;
navButtonViewUploadViewMenuButton: Locator;
outOfDateViewFilePath: string = 'src/tests/mocks/view/v0/view.json';
renameViewMenuSaveViewButton: Locator;
saveAsMenuSaveAsButton: Locator;
table: Locator;
Expand Down
11 changes: 11 additions & 0 deletions e2e-tests/tests/view.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,15 @@ test.describe.serial('View', () => {
await page.locator('.modal .st-button:has-text("Upload View")').click();
await expect(page.locator('.modal')).not.toBeVisible();
});

test(`Selecting an out of date view file should not display an error and not prevent the file from being uploaded`, async () => {
await view.openViewMenu();
await expect(view.navButtonViewUploadViewMenuButton).toBeVisible();
await view.navButtonViewUploadViewMenuButton.click();
await view.fillViewInputName();
await view.fillViewInputFile(view.outOfDateViewFilePath);
await expect(page.locator('.modal-content .error')).not.toBeVisible();
await page.locator('.modal .st-button:has-text("Upload View")').click();
await expect(page.locator('.modal')).not.toBeVisible();
});
});
6 changes: 3 additions & 3 deletions src/components/modals/SavedViewsModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@
}
}

async function getFullView(viewId: number): Promise<View | null> {
async function getFullView(viewId: number, migrate: boolean = true): Promise<View | null> {
const query = new URLSearchParams(`?${SearchParameters.VIEW_ID}=${viewId}`);
return await effects.getView(query, user);
return await effects.getView(query, user, migrate);
}

async function openView({ detail: viewId }: CustomEvent<number>) {
Expand All @@ -78,7 +78,7 @@
}

async function downloadView({ detail: viewId }: CustomEvent<number>) {
const view = await getFullView(viewId);
const view = await getFullView(viewId, false);
if (view !== null) {
downloadViewUtil(view);
dispatch('close');
Expand Down
1 change: 1 addition & 0 deletions src/components/modals/UploadViewModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
name="file"
required
type="file"
accept="application/json"
bind:files
on:click={onClick}
on:change={onChange}
Expand Down
4 changes: 4 additions & 0 deletions src/constants/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,7 @@ export const ViewXRangeLayerSchemePresets: Record<XRangeLayerColorScheme, readon
schemeSet3,
schemeTableau10,
};

export const viewSchemaVersion = 1;

export const viewSchemaVersionName = `v${viewSchemaVersion}`;
2 changes: 1 addition & 1 deletion src/routes/plans/[id]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@
const { detail } = event;
const { definition, id, name, owner } = detail;
if (id != null && hasUpdateViewPermission) {
const success = await effects.updateView(id, { definition, name, owner }, data.user);
const success = await effects.updateView(id, { definition, name, owner }, null, data.user);
if (success) {
resetOriginalView();
}
Expand Down
1 change: 1 addition & 0 deletions src/routes/plans/[id]/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export const load: PageLoad = async ({ parent, params, url }) => {
const initialView = await effects.getView(
url.searchParams,
user,
true,
initialActivityTypes,
initialResourceTypes,
initialExternalEventTypes,
Expand Down
7 changes: 7 additions & 0 deletions src/schemas/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import * as v0 from './ui-view-schema-v0.json';
import * as v1 from './ui-view-schema-v1.json';

export default {
v0,
v1,
};
Loading
Loading