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

feat(refs T31492): refactor editor #104

Merged
merged 12 commits into from
Mar 1, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
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
4 changes: 0 additions & 4 deletions src/components/core/DpEditor/DpBoilerPlate.stories.mdx

This file was deleted.

126 changes: 0 additions & 126 deletions src/components/core/DpEditor/DpBoilerPlate.vue

This file was deleted.

6 changes: 0 additions & 6 deletions src/components/core/DpEditor/DpBoilerPlateModal.stories.mdx

This file was deleted.

147 changes: 0 additions & 147 deletions src/components/core/DpEditor/DpBoilerPlateModal.vue
Original file line number Diff line number Diff line change
@@ -1,147 +0,0 @@
<template>
<dp-modal
ref="boilerPlateModal"
content-classes="u-1-of-2">
<template>
<h3>{{ Translator.trans('boilerplate.insert') }}</h3>
<dp-boiler-plate
:title="Translator.trans('boilerplates.category', { category: Translator.trans(boilerPlateType) })"
:boiler-plates="displayedBoilerplates"
ref="boilerplateDropdown"
group-values="boilerplates"
group-label="groupName"
:group-select="false"
@boilerplate-text-added="addBoilerplateText" />
<div class="flex flex-items-center u-mt">
<a
v-if="boilerplateEditViewRoute"
class="weight--bold font-size-small"
:href="boilerplateEditViewRoute">
{{ Translator.trans('boilerplates.edit') }} ({{ Translator.trans('view.leave.hint') }})
</a>
<dp-button-row
class="flex-item-end"
primary
:primary-text="Translator.trans('insert')"
secondary
@primary-action="insertBoilerPlate"
@secondary-action="resetAndClose" />
</div>
</template>
</dp-modal>
</template>

<script>
import { mapActions, mapGetters, mapState } from 'vuex'
import DpBoilerPlate from './DpBoilerPlate'
import DpButtonRow from '../../DpButtonRow/DpButtonRow'
import DpModal from '../DpModal'
import { hasOwnProp } from '../../../utils'

export default {
name: 'DpBoilerPlateModal',

components: {
DpBoilerPlate,
DpButtonRow,
DpModal
},

props: {
// Needed to get boilerplates from BE via store
procedureId: {
required: true,
type: String
},

boilerPlateType: {
required: false,
type: String,
default: ''
},

/**
* Route to a view that allows editing the available boilerplates
* Displayed as a link at the bottom of the modal
*/
boilerplateEditViewRoute: {
required: false,
type: String,
default: ''
},

editorId: {
required: false,
type: String,
default: ''
}
},

data () {
return {
// Needed to make sure boilerplates are loaded from the BE before <dp-boiler-plate> component is mounted
boilerPlatesLoaded: false,
// The boilerplate text emitted from dp-boiler-plate, then emitted to TipTapTextEditor.vue on click of 'insert' button
textToBeAdded: ''
}
},

computed: {
...mapState('boilerplates', ['getBoilerplatesRequestFired', 'moduleRegistered']),
...mapGetters('boilerplates', ['getGroupedBoilerplates']),

displayedBoilerplates () {
const displayed = JSON.parse(JSON.stringify(this.getGroupedBoilerplates))
displayed.forEach(group => {
if (this.boilerPlateType !== '') {
if (typeof this.boilerPlateType === 'string') {
group.boilerplates = group.boilerplates.filter(bp => bp.category.includes(this.boilerPlateType))
} else if (Array.isArray(this.boilerPlateType)) {
group.boilerplates = group.boilerplates.filter(bp => this.boilerPlateType.some(el => bp.category.includes(el)))
}
}
})

return displayed
},

displayedBoilerplateType () {
let boilerplateString = ''
if (typeof this.boilerPlateType === 'string') {
boilerplateString = Translator.trans(this.boilerPlateType)
} else if (Array.isArray(this.boilerPlateType)) {
boilerplateString = this.boilerPlateType.map(bp => Translator.trans(bp)).join(', ')
}
return boilerplateString
}
},

methods: {
...mapActions('boilerplates', ['getBoilerPlates']),

addBoilerplateText (textFromTextArea) {
this.textToBeAdded = textFromTextArea
},

insertBoilerPlate () {
this.$emit('insertBoilerPlate', this.textToBeAdded)
this.resetAndClose()
},

resetAndClose () {
this.$refs.boilerplateDropdown.resetBoilerPlateMultiSelect()
this.toggleModal()
},

toggleModal () {
this.$refs.boilerPlateModal.toggle()
}
},

created () {
if (this.getBoilerplatesRequestFired === false) {
this.getBoilerPlates(this.procedureId)
}
}
}
</script>
Loading