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

Use FormLink in DatasetOverview #1096

Merged
merged 1 commit into from
Dec 13, 2024
Merged

Conversation

matthew-white
Copy link
Member

@matthew-white matthew-white commented Dec 12, 2024

This PR is in response to getodk/central#670 (comment). It adds hover cards for the forms shown on the entity list overview.

What has been done to verify that this works as intended?

I tried it out locally. I also updated tests.

Why is this the best possible solution? Were any other approaches considered?

FormLink expects the form passed to it to have a projectId property. However, the forms listed in the entity list don't have a projectId. I think they just have an xmlFormId and name. I ended up thinking that the easiest thing was to add a projectId to these forms when the response for the entity list is received. That way, components don't have to do extra legwork and can just pass each form to FormLink as-is.

I've also added some explanatory comments below.

Before submitting this PR, please make sure you have:

  • run npm run test and npm run lint and confirmed all checks still pass OR confirm CircleCI build passes
  • verified that any code or assets from external sources are properly credited in comments or that everything is internally sourced

Copy link
Member Author

@matthew-white matthew-white left a comment

Choose a reason for hiding this comment

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

Notes for async review

type: Array,
required: true
},
projectId: {
Copy link
Member Author

Choose a reason for hiding this comment

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

Now that projectId is added to each form, we don't need to pass it in as a prop. I went ahead and removed that prop, but then there was an issue in the tests of the component. The component now expects the forms to have a projectId property, but in the tests of the component, they didn't. The easiest way to solve that was to specify a dataset for requestData. Doing so automatically transforms the dataset object, adding projectId. Once I was passing the dataset to the test, I felt like it didn't make sense to also pass properties and sourceForms as props, since those are accessible from the dataset.

@@ -21,7 +21,9 @@ except according to the terms contained in the LICENSE file.
<expandable-row v-for="(form) in propertiesByForm" :key="form.xmlFormId">
<template #title>
<div class="form-name">
<router-link :to="publishedFormPath(projectId, form.xmlFormId)" v-tooltip.text>{{ form.name }}</router-link>
<form-link :form="form"
:to="publishedFormPath(form.projectId, form.xmlFormId)"
Copy link
Member Author

Choose a reason for hiding this comment

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

We need to specify :to in this case. FormLink defaults to primaryFormPath(), but primaryFormPath() doesn't work super well in this case. That's because it expects the form object to have a publishedAt property.

Copy link
Contributor

Choose a reason for hiding this comment

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

Just as projectId is set, we could also set publishedAt to something not null, but this is also fine.

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree that that would have been a reasonable approach as well. 👍

},
propertiesByForm() {
const formMap = new Map(this.sourceForms.map(f => ([f.xmlFormId, { ...f, projectId: this.projectId, properties: [] }])));
Copy link
Member Author

@matthew-white matthew-white Dec 12, 2024

Choose a reason for hiding this comment

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

We were adding projectId to the forms in formMap, but it actually didn't seem like we ever accessed projectId from formMap. We were used the projectId prop directly instead. Either way, forms will now have a projectId property automatically.

@@ -1,33 +1,18 @@
/*
Copyright 2023 ODK Central Developers
Copy link
Member Author

Choose a reason for hiding this comment

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

We don't need a file header in test files.

@@ -21,7 +21,9 @@ except according to the terms contained in the LICENSE file.
<expandable-row v-for="(form) in propertiesByForm" :key="form.xmlFormId">
<template #title>
<div class="form-name">
<router-link :to="publishedFormPath(projectId, form.xmlFormId)" v-tooltip.text>{{ form.name }}</router-link>
<form-link :form="form"
:to="publishedFormPath(form.projectId, form.xmlFormId)"
Copy link
Contributor

Choose a reason for hiding this comment

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

Just as projectId is set, we could also set publishedAt to something not null, but this is also fine.

@matthew-white matthew-white merged commit cd5c4f9 into master Dec 13, 2024
1 check passed
@matthew-white matthew-white deleted the dataset-overview-form-links branch December 13, 2024 05:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants