Skip to content

Commit c19b9f5

Browse files
authored
Merge pull request #630 from citation-file-format/619-message-type-fields
Update message field based on type
2 parents c83054f + 902835b commit c19b9f5

File tree

3 files changed

+25
-47
lines changed

3 files changed

+25
-47
lines changed

src/components/ScreenStart.vue

Lines changed: 20 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@
1212
</div>
1313

1414
<div id="form-content">
15+
<h2 class="question">
16+
What type of work does this CITATION.cff describe?
17+
<SchemaGuideLink anchor="#type" />
18+
</h2>
19+
<q-option-group
20+
type="radio"
21+
v-bind:model-value="type"
22+
v-bind:options="typeOptions"
23+
v-on:update:modelValue="[setType, setMessagePlaceHolder]"
24+
/>
1525
<h2 class="question">
1626
What is the title of the work?
1727
<SchemaGuideLink anchor="#title" />
@@ -35,46 +45,14 @@
3545
bg-color="white"
3646
label="message"
3747
outlined
48+
standout
3849
v-bind:class="[messageErrors.length > 0 ? 'has-error' : '']"
3950
v-bind:model-value="message"
4051
v-bind:error="messageErrors.length > 0"
4152
v-bind:error-message="messageErrors.join(', ')"
42-
v-on:new-value="setMessage"
4353
v-on:update:modelValue="setMessage"
44-
>
45-
<template v-slot:append>
46-
<q-btn-dropdown
47-
class="dropdown"
48-
flat
49-
>
50-
<q-list>
51-
<q-item
52-
clickable
53-
v-bind:key="messageOption"
54-
v-close-popup
55-
v-for="messageOption in messageOptions"
56-
v-on:click="setMessage(messageOption)"
57-
>
58-
<q-item-section>
59-
<q-item-label>{{ messageOption }}</q-item-label>
60-
</q-item-section>
61-
</q-item>
62-
</q-list>
63-
</q-btn-dropdown>
64-
</template>
65-
</q-input>
66-
<h2 class="question">
67-
What type of work does this CITATION.cff describe?
68-
<SchemaGuideLink anchor="#type" />
69-
</h2>
70-
<q-option-group
71-
type="radio"
72-
v-bind:model-value="type"
73-
v-bind:options="typeOptions"
74-
v-on:update:modelValue="setType"
7554
/>
7655
</div>
77-
7856
<div id="form-button-bar">
7957
<StepperActions />
8058
</div>
@@ -105,14 +83,6 @@ export default defineComponent({
10583
})
10684
const { message, title, type, setMessage, setTitle, setType } = useCff()
10785
const { errors } = useValidation()
108-
const messageOptions = [
109-
'If you use this software, please cite it using the metadata from this file.',
110-
'Please cite this software using these metadata.',
111-
'Please cite this software using the metadata from \'preferred-citation\'.',
112-
'If you use this dataset, please cite it using the metadata from this file.',
113-
'Please cite this dataset using these metadata.',
114-
'Please cite this dataset using the metadata from \'preferred-citation\'.'
115-
]
11686
const messageErrors = computed(() => {
11787
return messageQueries
11888
.filter(byError(errors.value))
@@ -123,10 +93,17 @@ export default defineComponent({
12393
.filter(byError(errors.value))
12494
.map(query => query.replace.message)
12595
})
96+
const setMessagePlaceHolder = () => {
97+
const messagePlaceHolderRegex = /(software|dataset)/igm
98+
const matches = messagePlaceHolderRegex.exec(message.value)
99+
if (matches) {
100+
// search and replace all occurrences
101+
setMessage(message.value.split(matches[0]).join(type.value))
102+
}
103+
}
126104
return {
127105
message,
128106
messageErrors,
129-
messageOptions,
130107
title,
131108
titleErrors,
132109
type,
@@ -135,6 +112,7 @@ export default defineComponent({
135112
{ label: 'Dataset', value: 'dataset' }
136113
],
137114
setMessage,
115+
setMessagePlaceHolder,
138116
setTitle,
139117
setType
140118
}

src/store/cff.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const getInitialData = () => {
1111
identifiers: undefined,
1212
keywords: undefined,
1313
license: undefined,
14-
message: '',
14+
message: 'If you use this software, please cite it using the metadata from this file.',
1515
repository: undefined,
1616
repositoryArtifact: undefined,
1717
repositoryCode: undefined,

test/jest/__tests__/store/cffstr.jest.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe('useCffstr', () => {
1212
})
1313
describe('initial content', () => {
1414
it('should only have fields with defaults', () => {
15-
const expected = generatedBy + "cff-version: 1.2.0\ntitle: ''\nmessage: ''\ntype: software\nauthors: []\n"
15+
const expected = generatedBy + "cff-version: 1.2.0\ntitle: ''\nmessage: >-\n If you use this software, please cite it using the\n metadata from this file.\ntype: software\nauthors: []\n"
1616
expect(cffstr.value).toEqual(expected)
1717
})
1818
})
@@ -23,7 +23,7 @@ describe('useCffstr', () => {
2323
})
2424

2525
it('should have title', () => {
26-
const expected = generatedBy + "cff-version: 1.2.0\ntitle: sometitle\nmessage: ''\ntype: software\nauthors: []\n"
26+
const expected = generatedBy + "cff-version: 1.2.0\ntitle: sometitle\nmessage: >-\n If you use this software, please cite it using the\n metadata from this file.\ntype: software\nauthors: []\n"
2727
expect(cffstr.value).toEqual(expected)
2828
})
2929
})
@@ -34,7 +34,7 @@ describe('useCffstr', () => {
3434
})
3535

3636
it('should have a keyword', () => {
37-
const expected = generatedBy + "cff-version: 1.2.0\ntitle: ''\nmessage: ''\ntype: software\nauthors: []\nkeywords:\n - keyword1\n"
37+
const expected = generatedBy + "cff-version: 1.2.0\ntitle: ''\nmessage: >-\n If you use this software, please cite it using the\n metadata from this file.\ntype: software\nauthors: []\nkeywords:\n - keyword1\n"
3838
expect(cffstr.value).toEqual(expected)
3939
})
4040
})
@@ -45,7 +45,7 @@ describe('useCffstr', () => {
4545
})
4646

4747
it('should have a identifier', () => {
48-
const expected = generatedBy + "cff-version: 1.2.0\ntitle: ''\nmessage: ''\ntype: software\nauthors: []\nidentifiers:\n - type: doi\n value: 10.5281/zenodo.5171937\n"
48+
const expected = generatedBy + "cff-version: 1.2.0\ntitle: ''\nmessage: >-\n If you use this software, please cite it using the\n metadata from this file.\ntype: software\nauthors: []\nidentifiers:\n - type: doi\n value: 10.5281/zenodo.5171937\n"
4949
expect(cffstr.value).toEqual(expected)
5050
})
5151
})

0 commit comments

Comments
 (0)