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

Only allow selecting one license on create dandiset page #1505

Merged
merged 1 commit into from
Feb 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions web/src/views/CreateDandisetView/CreateDandisetView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@
:items="dandiLicenses"
label="License*"
class="my-4"
multiple
outlined
dense
/>
Expand Down Expand Up @@ -114,7 +113,7 @@ import { useDandisetStore } from '@/stores/dandiset';
import { useRouter } from 'vue-router/composables';

import type { ComputedRef } from 'vue';
import type { IdentifierForAnAward, LicenseType, License } from '@/types';
import type { IdentifierForAnAward, LicenseType } from '@/types';

// Regular expression to validate an NIH award number.
// Based on https://era.nih.gov/files/Deciphering_NIH_Application.pdf
Expand All @@ -132,7 +131,7 @@ const store = useDandisetStore();

const name = ref('');
const description = ref('');
const license = ref<License>();
const license = ref<LicenseType>();
const embargoed = ref(false);
const awardNumber = ref('');
const saveDisabled = computed(
Expand All @@ -159,7 +158,14 @@ if (!loggedIn()) {
}

async function registerDandiset() {
const metadata = { name: name.value, description: description.value, license: license.value };
const metadata: Record<string, any> = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be Record<"name" | "description", string>?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing the reason this was done was to prevent the type checker from complaining when the license field is added below.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you do

const metadata: {name: string, description: string, license?: LicenseType} = ...

🤷‍♂️

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you do

const metadata: {name: string, description: string, license?: LicenseType} = ...

man_shrugging

Yeah, that syntax is much better. And my use of any here also inadvertently hid a bug 😞

Screenshot from 2023-02-27 19-49-06

I thought I tested it on the deploy preview and it worked, but clearly I messed something up

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow up on this - #1510

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typechecking for the win!

name: name.value,
description: description.value,
};

if (license.value) {
metadata.license = license.value;
}

const { data } = embargoed.value
? await dandiRest.createEmbargoedDandiset(name.value, metadata, awardNumber.value)
Expand Down