Skip to content

Commit

Permalink
Fix truncated mutation description in menu
Browse files Browse the repository at this point in the history
  • Loading branch information
MetRonnie committed Jan 28, 2022
1 parent 4acef2f commit 0c99038
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 18 deletions.
20 changes: 12 additions & 8 deletions src/components/graphqlFormGenerator/FormGenerator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<v-expansion-panels
accordion
flat
v-bind="longDescription ? { hover: true } : { readonly: true }"
v-bind="extendedDescription ? { hover: true } : { readonly: true }"
>
<v-expansion-panel
class="mutation-desc"
>
<v-expansion-panel-header
v-bind="longDescription ? {} : {
v-bind="extendedDescription ? {} : {
expandIcon: null,
style: {
cursor: 'default'
Expand All @@ -50,10 +50,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
/>
</v-expansion-panel-header>
<v-expansion-panel-content
v-if="longDescription"
v-if="extendedDescription"
>
<vue-markdown
:source="longDescription"
:source="extendedDescription"
:breaks="false"
/>
</v-expansion-panel-content>
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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)
}
},

Expand Down
28 changes: 24 additions & 4 deletions src/utils/aotf.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})
})
Expand Down

0 comments on commit 0c99038

Please sign in to comment.