-
Notifications
You must be signed in to change notification settings - Fork 320
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
Set char limit on rich text #662
base: main
Are you sure you want to change the base?
Conversation
WalkthroughThe pull request introduces character limit functionality for rich text input fields. A new prop Changes
Sequence DiagramsequenceDiagram
participant User
participant RichTextInput
participant CharCounter
User->>RichTextInput: Enters text
RichTextInput->>CharCounter: Calculate current characters
CharCounter-->>RichTextInput: Return character count
RichTextInput->>User: Display character count (X/Max)
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (1)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
🧹 Nitpick comments (2)
client/components/open/forms/fields/components/FieldOptions.vue (1)
844-846
: Default character limit aligns with other field types.The default character limit of 2000 for rich text fields matches the limits set for other text-based fields, maintaining consistency across the application.
However, consider extracting these magic numbers into named constants to improve maintainability.
export default { data() { return { + DEFAULT_CHAR_LIMIT: 2000, typesWithoutPlaceholder: ['date', 'checkbox', 'files'], // ... } }, methods: { setDefaultFieldValues() { const defaultFieldValues = { text: { multi_lines: false, - max_char_limit: 2000 + max_char_limit: this.DEFAULT_CHAR_LIMIT }, rich_text: { - max_char_limit: 2000 + max_char_limit: this.DEFAULT_CHAR_LIMIT }, email: { - max_char_limit: 2000 + max_char_limit: this.DEFAULT_CHAR_LIMIT }, url: { - max_char_limit: 2000 + max_char_limit: this.DEFAULT_CHAR_LIMIT }, // ... } } } }client/components/forms/RichTextAreaInput.client.vue (1)
45-52
: Enhance character count display with visual feedback.Consider adding visual feedback when approaching or exceeding the character limit:
- Color coding (green/yellow/red) based on usage percentage
- Visual indicator when limit is exceeded
<template v-if="maxCharLimit && showCharLimit" #bottom_after_help> <small :class="[ theme.default.help, + { + 'text-red-500': charCount > maxCharLimit, + 'text-yellow-500': charCount >= maxCharLimit * 0.9 && charCount <= maxCharLimit, + 'text-green-500': charCount < maxCharLimit * 0.9 + } ]"> {{ charCount }}/{{ maxCharLimit }} </small> </template>
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
client/components/forms/RichTextAreaInput.client.vue
(3 hunks)client/components/open/forms/fields/components/FieldOptions.vue
(2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Build the Nuxt app
🔇 Additional comments (3)
client/components/open/forms/fields/components/FieldOptions.vue (1)
555-555
: LGTM! Character limit support added for rich text fields.The template correctly includes 'rich_text' in the list of field types that support character limits, maintaining consistency with other text-based field types.
client/components/forms/RichTextAreaInput.client.vue (2)
38-41
: LGTM! Good defensive programming.The conditional checks for slot existence (
v-if="$slots.help"
andv-if="$slots.error"
) prevent rendering empty slots.Also applies to: 54-57
132-134
: 🛠️ Refactor suggestionImprove character counting accuracy and performance.
The current implementation has several potential issues:
- HTML entities (e.g.,
) are counted as multiple characters- Unicode characters and emojis might not be counted correctly
- Regular expression performance might degrade with large content
Consider using DOMParser for more accurate character counting:
const charCount = computed(() => { - return compVal.value ? compVal.value.replace(/<[^>]*>/g, '').trim().length : 0 + if (!compVal.value) return 0; + const parser = new DOMParser(); + const doc = parser.parseFromString(compVal.value, 'text/html'); + return doc.body.textContent.trim().length; })Let's verify the performance impact with different content sizes:
@@ -552,7 +552,7 @@ | |||
@update:model-value="onFieldHelpPositionChange" | |||
/> | |||
|
|||
<template v-if="['text', 'number', 'url', 'email'].includes(field.type)"> | |||
<template v-if="['text', 'rich_text', 'number', 'url', 'email'].includes(field.type)"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
Missing prop definition and character limit enforcement in RichTextAreaInput
showCharLimit
is used in template but not defined as a prop- Character limit is displayed but not enforced through validation or input restriction
🔗 Analysis chain
Verify integration with RichTextAreaInput component.
The changes look good, but we should verify that the RichTextAreaInput
component correctly handles these character limit properties.
Also applies to: 844-846
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify that RichTextAreaInput component handles maxCharLimit and showCharLimit props
# Search for RichTextAreaInput component definition
echo "Searching for RichTextAreaInput component definition..."
ast-grep --pattern 'export default {
name: "RichTextAreaInput",
$$$
}'
# Search for maxCharLimit and showCharLimit prop definitions
echo "Searching for character limit prop definitions..."
rg -A 5 'props.*\{' client/components/**/RichTextAreaInput*.vue
# Search for character limit usage in template
echo "Searching for character limit usage in template..."
rg -A 5 'maxCharLimit|showCharLimit' client/components/**/RichTextAreaInput*.vue
Length of output: 1895
Script:
#!/bin/bash
# Search for showCharLimit prop and charCount implementation
echo "Searching for showCharLimit prop..."
rg -A 2 'showCharLimit.*\{' client/components/forms/RichTextAreaInput.client.vue
echo "Searching for charCount implementation..."
rg -A 5 'charCount' client/components/forms/RichTextAreaInput.client.vue
echo "Searching for validation or restriction logic..."
rg -A 10 'maxCharLimit' client/components/forms/RichTextAreaInput.client.vue
Length of output: 1305
@@ -59,6 +76,7 @@ import registerMentionExtension from '~/lib/quill/quillMentionExtension.js' | |||
|
|||
const props = defineProps({ | |||
...inputProps, | |||
maxCharLimit: { type: Number, required: false, default: null }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add validation for maxCharLimit prop.
The maxCharLimit
prop should validate:
- Non-negative numbers
- Reasonable maximum value to prevent performance issues
- maxCharLimit: { type: Number, required: false, default: null },
+ maxCharLimit: {
+ type: Number,
+ required: false,
+ default: null,
+ validator: (value) => {
+ return value === null || (value > 0 && value <= 100000);
+ }
+ },
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
maxCharLimit: { type: Number, required: false, default: null }, | |
maxCharLimit: { | |
type: Number, | |
required: false, | |
default: null, | |
validator: (value) => { | |
return value === null || (value > 0 && value <= 100000); | |
} | |
}, |
<template | ||
v-if="$slots.help" | ||
#help | ||
> | ||
<slot name="help" /> | ||
</template> | ||
<template #error> | ||
|
||
<template | ||
v-if="maxCharLimit && showCharLimit" | ||
#bottom_after_help | ||
> | ||
<small :class="theme.default.help"> | ||
{{ charCount }}/{{ maxCharLimit }} | ||
</small> | ||
</template> | ||
|
||
<template | ||
v-if="$slots.error" | ||
#error | ||
> | ||
<slot name="error" /> | ||
</template> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Prevent input when character limit is exceeded.
Currently, the component only displays the character count but doesn't prevent users from exceeding the limit. Consider adding an input prevention mechanism:
<QuillyEditor
:id="id ? id : name"
ref="editor"
v-model="compVal"
:options="quillOptions"
:disabled="disabled"
:placeholder="placeholder"
:style="inputStyle"
+ @text-change="handleTextChange"
/>
+const handleTextChange = (delta, oldDelta, source) => {
+ if (source === 'user' && props.maxCharLimit && charCount.value > props.maxCharLimit) {
+ // Revert the change
+ editor.value.quill.history.undo();
+ }
+};
Committable suggestion skipped: line range outside the PR's diff.
Summary by CodeRabbit
New Features
Improvements