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

Fix locals config option #13

Merged
merged 3 commits into from
Dec 14, 2024
Merged

Fix locals config option #13

merged 3 commits into from
Dec 14, 2024

Conversation

pschilly
Copy link
Contributor

@pschilly pschilly commented Dec 8, 2024

In the current build the "locals" config item does nothing.

This PR fixes that functionality so that one can dynamically assign the preferred locales.

Changes the default config item to: NULL so as to maintain the existing options of "Arabic, English" but one can change it simply to an array of ['en'] or others to change those options out.

Summary by CodeRabbit

  • Documentation

    • Added a new section "Config Locales" in the README for localization instructions.
    • Updated the "Auto Caching" section for clarity and added supported cache stores.
    • Revised the "Use Type Component" section for improved formatting.
  • Configuration Changes

    • Updated the 'locals' setting in the configuration to be NULL, clarifying language options.
  • Functionality Updates

    • Modified the locals method to retrieve localization settings dynamically rather than through a parameter.

Copy link

coderabbitai bot commented Dec 8, 2024

Walkthrough

The pull request introduces updates to the documentation and configuration files related to localization settings in the filament-types package. A new section titled "Config Locales" has been added to the README.md, detailing how to adjust localization settings. The config/filament-types.php file has modified the locals variable to NULL and included comments for clarity. Additionally, the locals method in the FilamentTypesPlugin class has been refactored to retrieve localization settings dynamically from the configuration instead of accepting an array.

Changes

File Change Summary
README.md Added "Config Locales" section; modified "Auto Caching" and "Use Type Component" sections; minor formatting changes.
config/filament-types.php Updated locals from an associative array to NULL; added comments regarding language options.
src/FilamentTypesPlugin.php Changed locals method signature from accepting an array to no parameters; updated getLocals implementation.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant FilamentTypesPlugin
    participant Config

    User->>FilamentTypesPlugin: Call locals()
    FilamentTypesPlugin->>Config: Retrieve filament-types.locals
    Config-->>FilamentTypesPlugin: Return locals value
    FilamentTypesPlugin-->>User: Return locals or defaults
Loading

🐇 "In the meadow, changes abound,
Config locales now can be found.
With clearer docs and settings bright,
Our plugin hops to new delight!
In code we trust, with joy we sing,
Localization's a wondrous thing!" 🌼


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between b8bc7a6 and b20b240.

📒 Files selected for processing (1)
  • src/FilamentTypesPlugin.php (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/FilamentTypesPlugin.php

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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a 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 (3)
src/FilamentTypesPlugin.php (1)

Line range hint 12-12: Consider updating default static locals to match config.

The static $locals property defaults to ['ar', 'en'] while the config defaults to NULL. Consider aligning these defaults for consistency.

-    protected static array $locals = ['ar', 'en'];
+    protected static array $locals = [];
README.md (2)

91-93: Fix typos and grammar in documentation.

There are a few minor issues in the text:

  • "applys" should be "applies"
  • Remove the forward slash after "file"
-- Publish the config file/
-- Modify the `locals` array to include the two character language code that applys to the language you wish to offer. EG:
+- Publish the config file
+- Modify the `locals` array to include the two-character language code that applies to the language you wish to offer. For example:

94-96: Add language specifier to code block.

The code block should specify the language for proper syntax highlighting.

-```
+'```php
 'locals' = ['en'],

<details>
<summary>🧰 Tools</summary>

<details>
<summary>🪛 Markdownlint (0.35.0)</summary>

94-94: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)

</details>

</details>

</blockquote></details>

</blockquote></details>

<details>
<summary>📜 Review details</summary>

**Configuration used: CodeRabbit UI**
**Review profile: CHILL**

<details>
<summary>📥 Commits</summary>

Reviewing files that changed from the base of the PR and between 0a283a68b731220bbde61a18b4e7b9704e116842 and b8bc7a69bbe3969933a66677549a652c76712b22.

</details>

<details>
<summary>📒 Files selected for processing (3)</summary>

* `README.md` (5 hunks)
* `config/filament-types.php` (1 hunks)
* `src/FilamentTypesPlugin.php` (1 hunks)

</details>

<details>
<summary>🧰 Additional context used</summary>

<details>
<summary>🪛 Markdownlint (0.35.0)</summary>

<details>
<summary>README.md</summary>

94-94: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)

</details>

</details>
<details>
<summary>🪛 LanguageTool</summary>

<details>
<summary>README.md</summary>

[uncategorized] ~126-~126: It appears that a hyphen is missing (if ‘auto’ is not used in the context of ‘cars’).
Context: ...scription()     ->searchable(), ```  ## Auto Caching  on your `.env` add this  ```.env CACHE...

(AUTO_HYPHEN)

---

[grammar] ~195-~195: Consider using either the past participle “appeared” or the present participle “appearing” here.
Context: ...         ];     } } ```  it will be not appear on the navigation menu by default but y...

(BEEN_PART_AGREEMENT)

---

[uncategorized] ~195-~195: Use a comma before ‘but’ if it connects two independent clauses (unless they are closely connected and short).
Context: ...appear on the navigation menu by default but you can change that by just use this me...

(COMMA_COMPOUND_SENTENCE)

</details>

</details>

</details>

<details>
<summary>🔇 Additional comments (1)</summary>

<details>
<summary>config/filament-types.php (1)</summary>

`39-45`: **LGTM! Clear documentation and sensible default.**

The updated configuration with NULL default and clear documentation about the expected format (`['en','ar']`) aligns well with the PR objective of fixing the locals config option.

</details>

</details>

</details>

<!-- This is an auto-generated comment by CodeRabbit for review status -->

src/FilamentTypesPlugin.php Show resolved Hide resolved
}

public function getLocals(): array
{
return self::$locals;
return $this->locals();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Type compatibility issue confirmed - locals() can return null

The locals() method can indeed return null when both config('filament-types.locals') is null and $this->locals is null, which is incompatible with the getLocals(): array return type declaration. This needs to be fixed by either:

  • Adding null check in getLocals()
  • Ensuring $this->locals is always initialized as an array
  • Changing return type to array|null
🔗 Analysis chain

Verify return type compatibility.

The getLocals() method declares : array return type but calls locals() which could return null. Ensure type compatibility is maintained.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for potential type mismatches in method calls
ast-grep --pattern 'getLocals()' -A 5

Length of output: 39


Script:

#!/bin/bash
# Let's check the class implementation and method signatures
ast-grep --pattern 'class FilamentTypesPlugin {
  $$$
}'

# Also check for the locals() method implementation
ast-grep --pattern 'function locals() {
  $$$
}'

Length of output: 109


Script:

#!/bin/bash
# Let's try with ripgrep to find the class and method implementations
rg -l "class FilamentTypesPlugin" --type php

# Find the locals method
rg "function locals\(" --type php -A 5

Length of output: 474

@3x1io
Copy link
Member

3x1io commented Dec 8, 2024

hi @pschilly can you check the comments of Code Rabbit? and run tests locally because you have a problem with testing

────────────────────────────────────────────────────────────────────────────  
   FAILED  Tests\src\TypeColumnTest > it can render type colu…  ViewException   
  Accessing static property TomatoPHP\FilamentTypes\FilamentTypesPlugin::$locals as non static (View: /home/runner/work/filament-types/filament-types/vendor/orchestra/testbench-core/laravel/storage/framework/views/a168b0ebcff266df6b662fc4b6d06e88.blade.php)

  at src/FilamentTypesPlugin.php:21
     17▕      * @return $this
     18▕      */
     19▕     public function locals()
     20▕     {
  ➜  21▕         return (!is_null(config('filament-types.locals'))) ? config('filament-types.locals') : $this->locals;
     22▕     }
     23▕ 
     24▕     public function getLocals(): array
     25▕     {

  1   src/FilamentTypesPlugin.php:26
  2   src/Filament/Resources/TypeResource.php:24

@pschilly
Copy link
Contributor Author

pschilly commented Dec 8, 2024

@3x1io seen - pushed fix.

@pschilly
Copy link
Contributor Author

Not sure how to have the bot redo the tests - but I did push a fix for the bug that you mentioned @3x1io

@3x1io
Copy link
Member

3x1io commented Dec 14, 2024

@coderabbitai

Copy link

coderabbitai bot commented Dec 14, 2024

@3x1io: I see that @pschilly has pushed a fix for the issue. Great job! I will review the updated changes.


If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@3x1io 3x1io merged commit 5c3511c into tomatophp:master Dec 14, 2024
5 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants