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

Show warning for old entity spec version #1059

Merged
merged 3 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
19 changes: 16 additions & 3 deletions src/components/form/new.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,13 @@ definition for an existing form -->
<ul>
<!-- eslint-disable-next-line vue/require-v-for-key -->
<li v-for="warning of warnings.workflowWarnings">
{{ $t('warningsText[3].' + warning.type, { value: warning.details.xmlFormId }) }}
<doc-link :to="documentLinks[warning.type]">{{ $t('moreInfo.learnMore') }}</doc-link>
{{ $t('warningsText[3].' + warning.type, { value: getWarningValue(warning) }) }}
<template v-if="warning.type === 'oldEntityVersion'">
<a :href="externalLinks.oldEntityVersion" target="_blank">{{ $t('moreInfo.learnMore') }}</a>
</template>
<template v-else>
<doc-link :to="documentLinks[warning.type]">{{ $t('moreInfo.learnMore') }}</doc-link>
</template>
Copy link
Member

Choose a reason for hiding this comment

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

I think this predated your changes, but I feel like we're trying to impose a structure on these warnings that doesn't necessarily exist. We have three warnings, and we render each differently. Instead of trying to use computed properties and methods, could we use v-if/v-else? I think that'd be clearer overall. I'm thinking of something like:

<template v-if="warning.type === 'deletedFormExists'">
  {{ $t('warningsText[3].deletedFormExists, { value: warning.details.xmlFormId }) }}
  <doc-link to="central-forms/#deleting-a-form">{{ $t('moreInfo.learnMore') }}</doc-link>
</template>
<template v-else-if="warning.type === 'structureChanged'">
  {{ $t('warningsText[3].structuredChanged') }}
  <doc-link to="central-forms/#central-forms-updates">{{ $t('moreInfo.learnMore') }}</doc-link>
  <span>
    <br>
    <strong>{{ $t('fields') }}</strong> {{ warning.details.join(', ') }}
  </span>
</template>
<template v-else-if="warning.type === 'oldEntityVersion'">
  {{ $t('warningsText[3].oldEntityVersion, { value: warning.details.version }) }}
  <a href="https://getodk.github.io/xforms-spec/entities" target="_blank">{{ $t('moreInfo.learnMore') }}</a>
</template>

For example, I think it's easier to see here that while each warning shows an i18n message, they all work a little differently. deletedFormExists shows details.xmlFormId, oldEntityVersion shows details.version, and structureChanged only shows static text. Its details is actually an array of fields, which are shown in a separate <span>.

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 like this a lot better, I was struggling with how to manage these different, yet in some ways similar, cases.

<span v-if="warning.type === 'structureChanged'">
<br>
<strong>{{ $t('fields') }}</strong> {{ warning.details.join(', ') }}
Expand Down Expand Up @@ -147,6 +152,9 @@ export default {
documentLinks: {
deletedFormExists: 'central-forms/#deleting-a-form',
structureChanged: 'central-forms/#central-forms-updates'
},
externalLinks: {
oldEntityVersion: 'https://getodk.github.io/xforms-spec/entities'
}
};
},
Expand Down Expand Up @@ -241,6 +249,10 @@ export default {
},
getLearnMoreLink(value) {
return value.match(/Learn more: (https?:\/\/xlsform\.org[^.]*)\.?/)[1];
},
getWarningValue(warning) {
if (warning.type === 'oldEntityVersion') return warning.details.version;
return warning.details.xmlFormId;
}
}
};
Expand Down Expand Up @@ -318,7 +330,8 @@ export default {
"Workflow warnings:",
{
"deletedFormExists": "There is a form with ID \"{value}\" in the Trash. If you upload this Form, you won’t be able to undelete the other one with the matching ID.",
"structureChanged": "The following fields have been deleted, renamed or are now in different groups or repeats. These fields will not be visible in the Submission table or included in exports by default."
"structureChanged": "The following fields have been deleted, renamed or are now in different groups or repeats. These fields will not be visible in the Submission table or included in exports by default.",
"oldEntityVersion": "Entities specification version \"{value}\" is not compatible with Offline Entities. Please use version 2024.1.0 or later."
Copy link
Member

Choose a reason for hiding this comment

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

I think curly quotes are usually a nice touch:

Suggested change
"oldEntityVersion": "Entities specification version \"{value}\" is not compatible with Offline Entities. Please use version 2024.1.0 or later."
"oldEntityVersion": "Entities specification version {value} is not compatible with Offline Entities. Please use version 2024.1.0 or later."

Copy link
Member Author

Choose a reason for hiding this comment

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

Should I change it for the deletedFormExists string above, too, or would that require it to get re-translated (so maybe I should just leave it as is)?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I think it's not worth it getting re-translated. It'll be nice to have curly quotes in the new warning though.

},
"Please correct the problems and try again.",
{
Expand Down
9 changes: 8 additions & 1 deletion test/components/form/new.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,8 @@ describe('FormNew', () => {
xlsFormWarnings: ['warning 1', 'warning 2'],
workflowWarnings: [
{ type: 'structureChanged', details: ['Name', 'Age'] },
{ type: 'deletedFormExists', details: { xmlFormId: 'simple' } }
{ type: 'deletedFormExists', details: { xmlFormId: 'simple' } },
{ type: 'oldEntityVersion', details: { version: '2022.1.0' } }
]
}
}
Expand Down Expand Up @@ -545,6 +546,9 @@ describe('FormNew', () => {

items[1].text().should.startWith('There is a form with ID "simple" in the Trash');
items[1].find('span').exists().should.be.false;

items[2].text().should.startWith('Entities specification version "2022.1.0" is not compatible with Offline Entities');
items[2].find('span').exists().should.be.false;
});
});

Expand All @@ -567,6 +571,9 @@ describe('FormNew', () => {

items[3].text().should.startWith('There is a form with ID "simple" in the Trash');
items[3].find('span').exists().should.be.false;

items[4].text().should.startWith('Entities specification version "2022.1.0" is not compatible with Offline Entities');
items[4].find('span').exists().should.be.false;
});
});

Expand Down
3 changes: 3 additions & 0 deletions transifex/strings_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -3142,6 +3142,9 @@
},
"structureChanged": {
"string": "The following fields have been deleted, renamed or are now in different groups or repeats. These fields will not be visible in the Submission table or included in exports by default."
},
"oldEntityVersion": {
"string": "Entities specification version \"{value}\" is not compatible with Offline Entities. Please use version 2024.1.0 or later."
}
},
"4": {
Expand Down