-
Notifications
You must be signed in to change notification settings - Fork 310
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
Right to left mode #611
Right to left mode #611
Conversation
WalkthroughThe pull request introduces a new boolean validation rule for the Changes
Possibly related PRs
Poem
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: 2
🧹 Outside diff range and nitpick comments (9)
client/composables/forms/initForm.js (1)
Line range hint
89-116
: Addlayout_rtl
to default values.The
setFormDefaults
function should include the newlayout_rtl
property to maintain consistency with the initialization defaults.Apply this diff:
const defaultValues = { title: 'Untitled Form', visibility: 'public', theme: 'default', width: 'centered', size: 'md', border_radius: 'small', dark_mode: 'light', color: '#3B82F6', hide_title: false, uppercase_labels: false, no_branding: false, transparent_background: false, submit_button_text: 'Submit', confetti_on_submission: false, show_progress_bar: false, bypass_success_page: false, can_be_indexed: true, use_captcha: false, + layout_rtl: false, properties: [], }
api/app/Http/Resources/FormResource.php (2)
Line range hint
11-11
: Add PHPDoc for the cleanings property.Consider adding documentation to explain the purpose and expected structure of the cleanings array.
+ /** + * Array of cleaning operations for the form. + * + * @var array + */ private array $cleanings = [];
77-77
: Consider grouping related layout properties together.For better code organization, consider grouping the
layout_rtl
field with other layout-related properties likewidth
andtheme
.'theme' => $this->theme, 'width' => 'centered', + 'layout_rtl' => $this->layout_rtl, 'is_password_protected' => true, 'has_password' => $this->has_password, - 'layout_rtl' => $this->layout_rtl, 'no_branding' => $this->no_branding,api/app/Http/Requests/UserFormRequest.php (2)
36-36
: Consider enhancing the layout_rtl validation rule.While the boolean validation is appropriate, consider these improvements to maintain consistency with other UI-related fields:
- Add the 'required' rule like other UI customization fields
- Use
Rule::in([true, false])
for stricter validation- Add a PHPDoc comment describing the field's purpose
- 'layout_rtl' => 'boolean', + // Controls the form's text direction (right-to-left mode) + 'layout_rtl' => ['required', 'boolean', Rule::in([true, false])],
Line range hint
10-13
: Consider updating class documentation.The class documentation could be enhanced to mention the RTL layout support as part of the form customization features.
/** * Abstract class to validate create/update forms + * Supports form customization including themes, layouts (including RTL), and styling * * Class UserFormRequest */
client/components/open/forms/components/form-components/FormCustomization.vue (1)
116-123
: Implementation looks good, with some UX enhancement opportunities.The RTL toggle switch implementation is clean and follows the established patterns. The placement in the Layout & Sizing section is appropriate, and the help text is clear.
Consider these UX enhancements:
- Add a visual indicator (like ←/→) to help users quickly identify the current text direction
- Consider previewing the RTL layout change in real-time within the form editor
Example enhancement:
<ToggleSwitchInput name="layout_rtl" :form="form" class="mt-4" - label="Right-to-Left Layout" + label="Right-to-Left Layout (←)" help="Adjusts form layout for right-to-left languages." + @update:model-value="previewRTLLayout" />client/pages/forms/[slug]/index.vue (1)
23-23
: LGTM! Consider extracting the RTL direction logic to a computed property.The RTL style binding is correctly implemented. However, since this RTL logic might be reused elsewhere in the component, consider extracting it to a computed property for better maintainability and reusability.
+ const getDirection = computed(() => form.value?.layout_rtl ? 'rtl' : 'ltr') - :style="{ 'direction': form?.layout_rtl ? 'rtl' : 'ltr' }" + :style="{ direction: getDirection }"client/components/open/forms/OpenCompleteForm.vue (2)
5-5
: Simplify the RTL direction binding.The optional chaining operator (
?.
) is redundant since the parent div already hasv-if="form"
. Consider simplifying and adding a default value:- :style="{ '--font-family': form.font_family, 'direction': form?.layout_rtl ? 'rtl' : 'ltr' }" + :style="{ '--font-family': form.font_family, 'direction': form.layout_rtl || false ? 'rtl' : 'ltr' }"
Line range hint
1-400
: Consider comprehensive RTL testing and accessibility.The RTL implementation looks good, but please ensure:
- Testing with various RTL languages (Arabic, Hebrew, Persian, etc.)
- Verification of form elements alignment in RTL mode
- Testing with screen readers and RTL text-to-speech
- Validation of bidirectional text rendering
Consider adding RTL-specific test cases to your end-to-end testing suite.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (9)
api/app/Http/Requests/UserFormRequest.php
(1 hunks)api/app/Http/Resources/FormResource.php
(1 hunks)api/app/Models/Forms/Form.php
(1 hunks)api/database/migrations/2024_11_08_091638_add_layout_rtl_to_forms_table.php
(1 hunks)client/components/open/forms/OpenCompleteForm.vue
(2 hunks)client/components/open/forms/components/form-components/FormCustomization.vue
(1 hunks)client/components/open/forms/components/form-components/FormEditorPreview.vue
(1 hunks)client/composables/forms/initForm.js
(1 hunks)client/pages/forms/[slug]/index.vue
(1 hunks)
🔇 Additional comments (12)
api/database/migrations/2024_11_08_091638_add_layout_rtl_to_forms_table.php (4)
1-6
: LGTM! File structure and imports are correct.
The necessary Laravel migration classes are properly imported.
7-7
: LGTM! Migration class is properly defined.
The anonymous class extending Migration follows Laravel's recommended structure.
21-26
: LGTM! Rollback functionality is properly implemented.
The down method correctly drops the layout_rtl column, providing a clean rollback path.
11-16
: Consider performance implications of the new column.
The implementation is correct, but consider these architectural points:
- If this column will be frequently queried (e.g., filtering forms by RTL mode), consider adding an index.
- Since this is a boolean column with a default value, ensure that any existing queries in the codebase properly handle this new column.
Let's check for existing queries that might be affected:
✅ Verification successful
No performance concerns with the new layout_rtl
boolean column
Based on the codebase analysis:
- The
layout_rtl
column is a simple boolean with a default value, similar to other boolean flags in the forms table likeno_branding
,hide_title
, etc. - There are no existing queries that filter or sort by boolean columns in the forms table, suggesting this column won't impact query performance.
- The Form model and controllers don't show any complex querying patterns that would require indexing of boolean columns.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Search for existing form queries that might need updating
rg -l "select.*from\s+forms" --type php
Length of output: 41
Script:
#!/bin/bash
# Let's try a more comprehensive search for form queries using different patterns
rg -l "forms.*where|from\s+forms|join\s+forms" --type php
# Also search for Eloquent query usage
rg -l "Form::where|Form::select|Form::find" --type php
# Check for model definition to understand query patterns
fd Form.php
# Look for repository or service classes that might handle form queries
fd -e php -E "migrations" | grep -i "form"
Length of output: 5683
Script:
#!/bin/bash
# Let's examine the Form model and any existing queries that might need to consider the new column
cat api/app/Models/Forms/Form.php
# Check form-related controllers for query patterns
cat api/app/Http/Controllers/Forms/FormController.php
# Look for any existing boolean column filtering in forms
rg "where\(['\"]forms['\"].*true|false" --type php
Length of output: 45248
client/composables/forms/initForm.js (2)
16-16
: LGTM: RTL property addition looks good.
The layout_rtl
property is appropriately placed in the customization section with other layout-related properties.
Line range hint 1-116
: Verify RTL implementation across components.
The changes look good, but let's verify the RTL implementation in related components mentioned in the summary.
✅ Verification successful
Let me try a different search strategy to locate the relevant files and RTL implementation.
Let me search specifically in the identified form components for RTL implementation.
RTL implementation is properly integrated across components
The RTL implementation is correctly handled across the form components:
- FormCustomization.vue has the RTL toggle control with
layout_rtl
binding - FormEditorPreview.vue properly applies RTL direction using conditional styling
- The
layout_rtl
property in initForm.js is appropriately consumed by these components
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify RTL implementation in related Vue components
# Expected: Find RTL-related bindings and logic in the components
echo "Checking OpenCompleteForm.vue for RTL text direction..."
rg -A 3 "layout_rtl" "client/components/forms/OpenCompleteForm.vue" || echo "File not found or no matches"
echo -e "\nChecking FormCustomization.vue for RTL toggle..."
rg -A 3 "layout_rtl" "client/components/forms/FormCustomization.vue" || echo "File not found or no matches"
echo -e "\nChecking FormEditorPreview.vue for RTL styles..."
rg -A 3 "layout_rtl" "client/components/forms/FormEditorPreview.vue" || echo "File not found or no matches"
Length of output: 1004
Script:
#!/bin/bash
# First, let's find all Vue files that might contain RTL-related code
echo "Finding Vue files with RTL-related code..."
rg -l "layout_rtl|direction.*rtl" --type vue
echo -e "\nChecking for RTL-related imports and usage..."
rg -A 3 "layout_rtl" --type vue
echo -e "\nFinding all form-related Vue components..."
fd ".vue$" --type f | grep -i "form"
Length of output: 6285
Script:
#!/bin/bash
# Search for RTL implementation in the identified form components
echo "Checking FormCustomization.vue for RTL implementation..."
rg -A 3 "layout_rtl|direction.*rtl" "client/components/open/forms/components/form-components/FormCustomization.vue"
echo -e "\nChecking FormEditorPreview.vue for RTL implementation..."
rg -A 3 "layout_rtl|direction.*rtl" "client/components/open/forms/components/form-components/FormEditorPreview.vue"
echo -e "\nChecking OpenForm.vue for RTL implementation..."
rg -A 3 "layout_rtl|direction.*rtl" "client/components/open/forms/OpenForm.vue"
echo -e "\nChecking VForm.vue for RTL implementation..."
rg -A 3 "layout_rtl|direction.*rtl" "client/components/forms/VForm.vue"
Length of output: 1089
api/app/Http/Resources/FormResource.php (1)
Line range hint 108-111
: Fix typo in method name: getCleanigns
→ getCleanings
The method name contains a spelling error which should be corrected for better code maintainability.
- private function getCleanigns()
+ private function getCleanings()
{
return $this->extra?->cleanings ?? $this->cleanings;
}
Let's verify if this method is called elsewhere in the codebase:
✅ Verification successful
Fix typo in method name and its usage
api/app/Http/Resources/FormResource.php
: Rename method fromgetCleanigns
togetCleanings
and update its invocation in the same file
- 'cleanings' => $this->getCleanigns(),
+ 'cleanings' => $this->getCleanings(),
- private function getCleanigns()
+ private function getCleanings()
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Search for any references to the misspelled method
rg "getCleanigns"
Length of output: 183
client/components/open/forms/components/form-components/FormEditorPreview.vue (2)
80-80
: Verify logo positioning in RTL mode.
The logo uses absolute positioning without explicit left/right properties. In RTL mode, this might cause unexpected positioning. Consider adding appropriate positioning classes that respect the RTL direction.
Let's check for any existing RTL-specific positioning classes:
#!/bin/bash
# Search for RTL-specific positioning in styles or classes
rg -t vue "right-\d+|left-\d+.*rtl" client/
Consider updating the class binding to handle RTL positioning:
-class="max-w-60 h-20 object-contain absolute transition-all"
+:class="[
+ 'max-w-60 h-20 object-contain absolute transition-all',
+ form?.layout_rtl ? 'right-0' : 'left-0'
+]"
74-74
: Consider implementing RTL support at a higher level.
While the RTL direction binding works, applying it only to the logo container might not provide complete RTL support. Consider moving this binding to a higher-level container to ensure consistent RTL behavior across all form elements.
Let's check if other components implement RTL at a higher level:
client/components/open/forms/components/form-components/FormCustomization.vue (1)
116-123
: Verify RTL compatibility with auto-focus feature.
Since the form has an auto-focus feature (line 186), ensure that the focus handling works correctly in RTL mode, especially for the first input field on each page.
✅ Verification successful
Let me try searching without the file type filter since the Vue file type might not be recognized in the sandbox environment. This will help us find focus-related logic in the client directory.
Let's examine the actual focus-related code to understand how it's implemented and its interaction with RTL layout.
I want to see how the auto_focus setting is implemented in the actual form rendering and if there's any specific RTL-focus interaction logic.
I want to see how the first element focus is implemented and understand if there's any RTL-specific layout handling that might affect focus behavior.
Based on the gathered information, I can now provide the final response:
RTL layout implementation is CSS-based and independent of focus handling
The RTL layout is implemented through CSS direction property and doesn't interfere with the focus handling mechanism. The auto-focus feature is controlled by focusOnFirstFormElement()
which is triggered independently of the RTL setting. Since:
- RTL layout is applied via CSS
direction: rtl
property - Focus handling is managed separately through JavaScript
- There's no direct interaction between RTL and focus mechanisms
The auto-focus feature should work correctly regardless of the RTL setting.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Search for focus-related logic that might need RTL consideration
rg -l 'focus|autofocus' --type vue
Length of output: 64
Script:
#!/bin/bash
# Search for focus-related logic with ripgrep, without file type filter
rg -l 'focus|autofocus' client/
Length of output: 984
Script:
#!/bin/bash
# Let's examine the focus-related code in FormCustomization.vue and related form components
rg 'focus|autofocus' -A 3 -B 3 client/components/open/forms/components/form-components/FormCustomization.vue
# Also check the form initialization logic
rg 'focus|autofocus' -A 3 -B 3 client/composables/forms/initForm.js
Length of output: 581
Script:
#!/bin/bash
# Let's check how the auto_focus setting is actually used in the form rendering
rg 'auto_focus' -A 5 -B 5 client/pages/forms/[slug]/index.vue
# Also check if there's any RTL-specific focus handling
rg 'rtl.*focus|focus.*rtl' client/
Length of output: 353
Script:
#!/bin/bash
# Let's examine the focusOnFirstFormElement function implementation
rg -A 10 'function focusOnFirstFormElement' client/pages/forms/[slug]/index.vue
# Also check for any RTL-related layout code
rg -A 3 'layout_rtl' client/
Length of output: 1848
api/app/Models/Forms/Form.php (1)
61-61
: LGTM! The layout_rtl property is correctly added to fillable attributes.
The property is appropriately placed with other layout-related attributes in the customization section.
client/components/open/forms/OpenCompleteForm.vue (1)
Line range hint 150-157
: Verify RTL text rendering in TextBlock component.
The TextBlock component will inherit RTL direction from its parent. Please ensure that:
- The submitted text renders correctly in RTL mode
- Mixed RTL/LTR content (if supported) displays properly
✅ Verification successful
RTL text rendering is properly handled by parent component
The TextBlock component inherits RTL/LTR direction correctly from its parent OpenCompleteForm.vue
, which explicitly sets the direction based on the form's layout_rtl
property:
<div :style="{ '--font-family': form.font_family, 'direction': form?.layout_rtl ? 'rtl' : 'ltr' }">
The TextBlock component is a simple wrapper that processes content through useParseMention
and renders it with v-html
, allowing it to naturally inherit the text direction from its parent container. No additional RTL-specific handling is needed in the TextBlock component itself.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Check if TextBlock component has any explicit direction styles that might conflict with RTL
# Test: Search for direction-related styles in TextBlock component
rg -t vue "direction|rtl|ltr" --glob "TextBlock.vue"
Length of output: 80
Script:
#!/bin/bash
# Search for TextBlock component file first
fd "TextBlock.vue"
# Then search for direction-related styles in the found files
rg "direction|rtl|ltr" $(fd "TextBlock.vue")
# Also check for any CSS classes that might affect text direction
rg "class=.*(?:direction|rtl|ltr)" $(fd "TextBlock.vue")
# Look for any v-bind directives that might set direction
rg ":style|:class" $(fd "TextBlock.vue")
Length of output: 313
Script:
#!/bin/bash
# Let's examine the TextBlock component content
cat client/components/forms/TextBlock.vue
# Also check parent component for any RTL-related styles or classes
cat client/components/open/forms/OpenCompleteForm.vue
Length of output: 11537
> | ||
<img | ||
alt="Logo Picture" | ||
:src="form.logo_picture" | ||
:class="{'top-5':!form.cover_picture, '-top-10':form.cover_picture}" | ||
class="w-20 h-20 object-contain absolute left-5 transition-all" | ||
class="w-20 h-20 object-contain absolute transition-all" |
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
Logo positioning change needs to be reverted
The search results show that the logo positioning was previously handled with dynamic classes based on the cover picture presence:
:class="{'top-5':!form.cover_picture, '-top-10':form.cover_picture}"
This conditional positioning has been removed in favor of a static positioning, which will break the layout in different scenarios. The logo needs different vertical positions (top-5
vs -top-10
) depending on whether a cover picture is present.
- Revert the change and restore the conditional classes for proper logo positioning
- Keep the other utility classes (
w-20 h-20 object-contain absolute transition-all
)
🔗 Analysis chain
Verify logo positioning in all scenarios.
The class binding has been simplified, but please verify that the logo positioning still works correctly in these scenarios:
- With cover picture
- Without cover picture
- With RTL mode enabled/disabled
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Search for related logo positioning styles and tests
echo "Searching for related logo positioning styles..."
rg -t vue "logo.*position|position.*logo" --glob "client/**/*.vue"
echo "Searching for related logo tests..."
rg -t js -t vue "logo.*test|test.*logo" --glob "client/**/*.{spec,test}.{js,ts,vue}"
Length of output: 399
Script:
#!/bin/bash
# Let's try a different approach to search for logo-related styles and layout
echo "Searching for logo-related styles in Vue files..."
rg "class=.*logo|class=.*w-20.*h-20" --type-add 'vue:*.vue' -t vue
echo -e "\nSearching for cover picture related code..."
rg "coverPicture|cover-picture" --type-add 'vue:*.vue' -t vue
echo -e "\nChecking RTL-related styles..."
rg "rtl|direction.*rtl|dir=.*rtl" --type-add 'vue:*.vue' -t vue
echo -e "\nLooking for the form component structure..."
rg -A 5 -B 5 "w-20.*h-20" --type-add 'vue:*.vue' -t vue
Length of output: 2656
@@ -58,6 +58,7 @@ class Form extends Model implements CachableAttributes | |||
'border_radius', | |||
'theme', | |||
'width', | |||
'layout_rtl', |
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 boolean casting for the layout_rtl property.
For better data integrity and consistent type handling, consider adding the layout_rtl property to the casts array.
Add this to the casts array in the casts() method:
protected function casts(): array
{
return [
'properties' => 'array',
'database_fields_update' => 'array',
'closes_at' => 'datetime',
'tags' => 'array',
'removed_properties' => 'array',
- 'seo_meta' => 'object'
+ 'seo_meta' => 'object',
+ 'layout_rtl' => 'boolean'
];
}
Committable suggestion skipped: line range outside the PR's diff.
Summary by CodeRabbit
Release Notes
New Features
Improvements
layout_rtl
property.These changes improve user experience by providing flexible layout options for diverse language needs.