diff --git a/src/components/graphqlFormGenerator/FormGenerator.vue b/src/components/graphqlFormGenerator/FormGenerator.vue
index 3aeea4f7f..3929da847 100644
--- a/src/components/graphqlFormGenerator/FormGenerator.vue
+++ b/src/components/graphqlFormGenerator/FormGenerator.vue
@@ -31,13 +31,13 @@ along with this program. If not, see .
.
/>
@@ -108,7 +108,11 @@ import cloneDeep from 'lodash/cloneDeep'
import { mdiHelpCircleOutline } from '@mdi/js'
import FormInput from '@/components/graphqlFormGenerator/FormInput'
-import { getNullValue } from '@/utils/aotf'
+import {
+ getNullValue,
+ getMutationShortDesc,
+ getMutationExtendedDesc
+} from '@/utils/aotf'
export default {
name: 'form-generator',
@@ -163,11 +167,11 @@ export default {
/* Return the first line of the description. */
shortDescription () {
- return this.mutation.description?.split('\n\n', 1)[0] || ''
+ return getMutationShortDesc(this.mutation.description)
},
/* Return the subsequent lines of the description */
- longDescription () {
- return this.mutation.description?.split('\n\n').slice(1).join('\n\n')
+ extendedDescription () {
+ return getMutationExtendedDesc(this.mutation.description)
}
},
diff --git a/src/utils/aotf.js b/src/utils/aotf.js
index aa45708f1..f32794ee1 100644
--- a/src/utils/aotf.js
+++ b/src/utils/aotf.js
@@ -269,17 +269,37 @@ export function camelToWords (camel) {
* @param {object} types - Types as returned by introspection query.
*/
export function processMutations (mutations, types) {
- let descLines = null
for (const mutation of mutations) {
- descLines = mutation.description.split(/\n+/)
mutation._title = camelToWords(mutation.name)
mutation._icon = mutationIcons[mutation.name] || mutationIcons['']
- mutation._shortDescription = descLines[0]
- mutation._help = descLines.slice(1).join('\n')
+ mutation._shortDescription = getMutationShortDesc(mutation.description)
+ mutation._help = getMutationExtendedDesc(mutation.description)
processArguments(mutation, types)
}
}
+/**
+ * Get the first part of a mutation description (up to the first double newline).
+ *
+ * @export
+ * @param {str|undefined} text - Full mutation description.
+ * @return {str}
+ */
+export function getMutationShortDesc (text) {
+ return text?.split('\n\n', 1)[0] || ''
+}
+
+/**
+ * Get the rest of a mutation description (after the first double newline).
+ *
+ * @export
+ * @param {str|undefined} text - Full mutation description.
+ * @return {str|undefined}
+ */
+export function getMutationExtendedDesc (text) {
+ return text?.split('\n\n').slice(1).join('\n\n')
+}
+
/* Add special fields to mutations args from a GraphQL introspection query. */
/**
* Process mutation arguments from an introspection query.
diff --git a/tests/unit/components/graphqlFormGenerator/formgenerator.vue.spec.js b/tests/unit/components/graphqlFormGenerator/formgenerator.vue.spec.js
index 95859b7c7..f44794083 100644
--- a/tests/unit/components/graphqlFormGenerator/formgenerator.vue.spec.js
+++ b/tests/unit/components/graphqlFormGenerator/formgenerator.vue.spec.js
@@ -293,25 +293,25 @@ describe('FormGenerator Component', () => {
expect(wrapper.vm.shortDescription).to.equal(desc)
})
})
- describe('.longDescription', () => {
+ describe('.extendedDescription', () => {
it('should be empty', () => {
- expect(wrapper.vm.longDescription).to.equal('')
+ expect(wrapper.vm.extendedDescription).to.equal('')
})
})
})
describe('For a multiline description', () => {
const shortDesc = 'Darmok and Jalad at\nTanagra.'
- const longDesc = 'Shaka when the\nwalls fell.\n\nTemba, his arms wide.'
- const desc = `${shortDesc}\n\n${longDesc}`
+ const extendedDesc = 'Shaka when the\nwalls fell.\n\nTemba, his arms wide.'
+ const desc = `${shortDesc}\n\n${extendedDesc}`
const wrapper = mountWithDescription(desc)
describe('.shortDescription', () => {
it('should be the bit before the first double newline', () => {
expect(wrapper.vm.shortDescription).to.equal(shortDesc)
})
})
- describe('.longDescription', () => {
+ describe('.extendedDescription', () => {
it('should be everything after the first double newline', () => {
- expect(wrapper.vm.longDescription).to.equal(longDesc)
+ expect(wrapper.vm.extendedDescription).to.equal(extendedDesc)
})
})
})