Files
baserow/web-frontend/modules/database/components/row/RowEditFieldRichText.vue
Davide Silvestri 23f328cb19 feat(database): assign identities to rows and mention them in comments (#6619)
* feat(database): assign and mention identities behind a field option

- Collaborator fields get `include_identities` and long text fields
  `long_text_include_identities`, both off by default.
- With the option on, active identities of the workspace can be assigned
  or suggested as mentions; they are shown with their icon and renamed
  in realtime, and they never receive notifications.
- Turning the collaborator option off backs up the column, deletes the
  identity assignments and strips identities from the view defaults, so
  the update can be undone.
- Identities can author row comments and be mentioned in them.
- Exports write an identity as `Name <identity>`.

* refactor: hide internal emails in collaborator exports through one check

* fix: import a personal view only for a person, without a query per owner

* fix: show collaborator identities with the icon of the user subject type

* refactor: drop a redundant local import of the core handler

* fix: unify identity icons and space field options

* fix: keep identity field menus and saved mentions readable

* fix: limit identity mention suggestions to row comments

* perf: prefetch available collaborators once per workspace

* fix: use workspace members as authors of generated rows

* fix: resolve linked collaborator values by member email

* fix: use workspace collaborators for field pickers and paste

* refactor: move identity avatar styles to the avatar stylesheet

* fix: address review feedback on identity collaborators
2026-11-18 22:53:44 +01:00

124 lines
3.6 KiB
Vue

<template>
<div class="control__elements">
<RichTextEditor
ref="input"
v-model="richCopy"
class="form-input field-rich-text"
:class="{
'form-input--error': touched && !isValid(),
active: editing,
}"
:disabled="readOnly"
:editable="!readOnly"
:enable-rich-text-formatting="true"
:enable-images="enableImages"
:mentionable-users="mentionableUsers"
:allow-identity-suggestions="false"
:menu-container="getMenuContainer"
:scrollable-area-element="getScrollableAreaElement"
:clipboard-markdown-resolver="resolveClipboardMarkdown"
:upload-file="
readOnly || !allowImageUpload || !enableImages ? null : uploadUserFile
"
@focus="select()"
@blur="unselect()"
@upload-settled="saveSettledUpload()"
></RichTextEditor>
<div v-show="touched && !isValid()" class="error">
{{ getError() }}
</div>
</div>
</template>
<script>
import RichTextEditor from '@baserow/modules/core/components/editor/RichTextEditor.vue'
import UserFileService from '@baserow/modules/core/services/userFile'
import { stripImageUrls } from '@baserow/modules/core/editor/richTextImageUtils'
import rowEditField from '@baserow/modules/database/mixins/rowEditField'
import rowEditFieldInput from '@baserow/modules/database/mixins/rowEditFieldInput'
import { getRichTextClipboardContent } from '@baserow/modules/database/utils/clipboard'
export default {
components: { RichTextEditor },
mixins: [rowEditField, rowEditFieldInput],
props: {
allowImageUpload: {
type: Boolean,
required: false,
default: true,
},
enableMentions: {
type: Boolean,
default: true,
},
enableImages: {
type: Boolean,
default: true,
},
},
data() {
return {
// local copy of the value storing the JSON representation of the rich text editor
richCopy: '',
}
},
computed: {
workspace() {
return this.$store.getters['workspace/get'](this.workspaceId)
},
mentionableUsers() {
return this.enableMentions && this.workspace
? this.$store.getters['workspace/getCollaborators'](this.workspace.id)
: null
},
},
watch: {
value: {
handler(value) {
// A value of the field's previous type would be taken for JSON content.
this.richCopy = typeof value === 'string' ? value : ''
},
immediate: true,
},
},
methods: {
resolveClipboardMarkdown: getRichTextClipboardContent,
async uploadUserFile(file) {
return await UserFileService(this.$client).uploadFile(file)
},
getError() {
// The backend strips resolved image URLs before checking max_length, so
// measure the same string or a valid value is rejected.
return this.getValidationError(
stripImageUrls(this.$refs.input?.serializeToMarkdown())
)
},
unselect() {
this.$super(rowEditFieldInput).unselect()
this.editing = false
},
saveSettledUpload() {
// While editing, the blur saves it; after the blur, nothing else would.
if (!this.editing && this.isValid()) {
this.save()
}
},
getMenuContainer() {
// Body-level so floating-ui's fixed strategy anchors to the viewport, not a modal ancestor.
return document.body
},
getScrollableAreaElement() {
return this.$el?.closest('.modal__box-content') ?? null
},
beforeSave() {
// No ref (modal teardown) or an unchanged value means nothing to reserialize.
if (!this.$refs.input?.isDirty()) {
return this.value
}
return this.$refs.input.serializeToMarkdown()
},
},
}
</script>