Skip to content

Commit

Permalink
improving code structure
Browse files Browse the repository at this point in the history
  • Loading branch information
ktuite committed Nov 20, 2024
1 parent ca76b56 commit aae3d68
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 25 deletions.
38 changes: 16 additions & 22 deletions src/components/form/new.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,22 @@ 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: getWarningValue(warning) }) }}
<template v-if="warning.type === 'oldEntityVersion'">
<a :href="externalLinks.oldEntityVersion" target="_blank">{{ $t('moreInfo.learnMore') }}</a>
<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>
<doc-link :to="documentLinks[warning.type]">{{ $t('moreInfo.learnMore') }}</doc-link>
<template v-else-if="warning.type === 'structureChanged'">
{{ $t('warningsText[3].structureChanged') }}
<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>
<span v-if="warning.type === 'structureChanged'">
<br>
<strong>{{ $t('fields') }}</strong> {{ warning.details.join(', ') }}
</span>
</li>
</ul>
</p>
Expand Down Expand Up @@ -148,14 +153,7 @@ export default {
data() {
return {
file: null,
warnings: null,
documentLinks: {
deletedFormExists: 'central-forms/#deleting-a-form',
structureChanged: 'central-forms/#central-forms-updates'
},
externalLinks: {
oldEntityVersion: 'https://getodk.github.io/xforms-spec/entities'
}
warnings: null
};
},
computed: {
Expand Down Expand Up @@ -249,10 +247,6 @@ 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 @@ -331,7 +325,7 @@ export default {
{
"deletedFormExists": "There is a form with ID \"{value}\" in the Trash. If you upload this Form, you wont 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.",
"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."
},
"Please correct the problems and try again.",
{
Expand Down
4 changes: 2 additions & 2 deletions test/components/form/new.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ 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].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 @@ -572,7 +572,7 @@ 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].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
2 changes: 1 addition & 1 deletion transifex/strings_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -3144,7 +3144,7 @@
"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."
"string": "Entities specification version {value} is not compatible with Offline Entities. Please use version 2024.1.0 or later."
}
},
"4": {
Expand Down

0 comments on commit aae3d68

Please sign in to comment.