From 2ed4bc825459a01d7f83008149f15e0c9bc39d9a Mon Sep 17 00:00:00 2001 From: Carol Soliman <17387510+carsoli@users.noreply.github.com> Date: Wed, 25 May 2022 11:59:54 +0200 Subject: [PATCH] fix(KtComment): fix/enhance/refact KtComments - fix: stop avatar from getting squished - fix: prefix all class names with `kt-` - fix: stop the inline edit from resizing - feat: add translations to edit/delete options - fix: options not skipping stacking context (by using tippy) - refact: introduce common components for reply button - refact: common component for inline edit - refact: common component for options - refact: migrate to ts where possible - refact: delete dead classes and move style sheets to ..relevant components rather than _comments.scss --- .../pages/usage/components/comment.vue | 48 ++-- .../source/kotti-comment/KtComment.vue | 169 +++++++------- .../source/kotti-comment/KtCommentInput.vue | 75 ++++-- .../components/CommentActions.vue | 58 +++++ .../components/CommentActionsOptions.vue | 32 +++ .../components/CommentActionsReply.vue | 37 +++ .../components/CommentInlineEdit.vue | 96 ++++++++ .../kotti-comment/components/CommentReply.vue | 176 ++++++-------- .../kotti-ui/source/kotti-comment/types.ts | 46 ++-- .../source/kotti-comment/utilities.ts | 3 +- .../kotti-field-text-area/KtFieldTextArea.vue | 26 +-- .../kotti-ui/source/kotti-field/mixins.scss | 28 +++ .../source/kotti-i18n/locales/de-DE.ts | 2 + .../source/kotti-i18n/locales/en-US.ts | 2 + .../source/kotti-i18n/locales/es-ES.ts | 2 + .../source/kotti-i18n/locales/fr-FR.ts | 2 + .../source/kotti-i18n/locales/ja-JP.ts | 2 + .../source/kotti-popover/KtPopover.vue | 4 - .../source/kotti-style/_comments.scss | 216 +----------------- 19 files changed, 539 insertions(+), 485 deletions(-) create mode 100644 packages/kotti-ui/source/kotti-comment/components/CommentActions.vue create mode 100644 packages/kotti-ui/source/kotti-comment/components/CommentActionsOptions.vue create mode 100644 packages/kotti-ui/source/kotti-comment/components/CommentActionsReply.vue create mode 100644 packages/kotti-ui/source/kotti-comment/components/CommentInlineEdit.vue diff --git a/packages/documentation/pages/usage/components/comment.vue b/packages/documentation/pages/usage/components/comment.vue index f2a4478dbd..841f22de8a 100644 --- a/packages/documentation/pages/usage/components/comment.vue +++ b/packages/documentation/pages/usage/components/comment.vue @@ -146,22 +146,6 @@ methods: { /> -### Props - -| Attribute | Description | Type | Accepted values | Default | -| :---------------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :----------------- | :-------------------------------- | :--------------------- | -| `createdTime` | The Time that appears in the comment | string | "20-12-2008" | - | -| `id` | the id to track the comment | number, string | "1" | - | -| `replies` | array of comment props to be nested under the coment | [CommentProps] | [{id: "1", message: "hello"}] | - | -| `userAvatar` | url to image thumbnail | string | "https://someimage.com/image.png" | - | -| `userId` | id of user who made the comment to reply too | number, string | "2" | - | -| `userName` | name of user to display | string | "Jhone Doe" | - | -| `message` | the actual comment | string | "Hello" | - | -| `dangerDefaultParserOverride` | A function that processes and escapes the comment message before it is passed to the div that render it, as the name implies you're responsible for escaping if you use this | (string) => string | Function | lodash escape function | -| `postEscapeParser` | A function that processes the message after is has been escaped use this instead of `dangerDefaultParserOverride` | (string) => string | Function | (_) => _ | -| `isDeletable` | whether this comment is deletable | boolean | true,false | false | -| `isEditable` | whether this comment is editable | boolean | true,false | false | - ### Event | Event Name | Component | Payload | Description | @@ -251,9 +235,35 @@ export default { methods: { dangerouslyOverrideParser: (msg) => escape(msg), postEscapeParser: (msg) => msg.replace(/\n/g, '
'), - handleEdit(payload) { - // eslint-disable-next-line - console.log(payload) + handleEdit({ id, message, parentId }) { + if (parentId === null) { + const commentIndex = this.comments.findIndex( + (comment) => comment.id === id, + ) + + return (this.comments = [ + ...this.comments.slice(0, commentIndex), + { ...this.comments[commentIndex], message }, + ...this.comments.slice(commentIndex + 1), + ]) + } + + const parentCommentIndex = this.comments.findIndex( + (comment) => comment.id === parentId, + ) + const oldReplies = this.comments[parentCommentIndex].replies + const replyIndex = oldReplies.findIndex((reply) => reply.id === id) + const newReplies = [ + ...oldReplies.slice(0, replyIndex), + { ...oldReplies[replyIndex], message }, + ...oldReplies.slice(replyIndex + 1), + ] + + this.comments = [ + ...this.comments.slice(0, parentCommentIndex), + { ...this.comments[parentCommentIndex], replies: newReplies }, + ...this.comments.slice(parentCommentIndex + 1), + ] }, handleSubmit(payload) { const _message = { diff --git a/packages/kotti-ui/source/kotti-comment/KtComment.vue b/packages/kotti-ui/source/kotti-comment/KtComment.vue index 066a6a485c..1042341c1e 100644 --- a/packages/kotti-ui/source/kotti-comment/KtComment.vue +++ b/packages/kotti-ui/source/kotti-comment/KtComment.vue @@ -1,65 +1,39 @@