-
Notifications
You must be signed in to change notification settings - Fork 8
refactor(blog): do not use static paths file #450
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
Conversation
WalkthroughThis update refactors how article language and locale are managed and represented across the codebase. It replaces the use of generic language strings with a strongly-typed enum, introduces explicit language-to-locale mappings, removes the generation of language-specific article path JSON assets, and updates component APIs and guards to use the new locale-centric approach. Additionally, a new i18n service is introduced and integrated into the providers. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant ArticleDetailsComponent
participant ArticleShareIconsComponent
User->>ArticleDetailsComponent: Navigates to article
ArticleDetailsComponent->>ArticleDetailsComponent: Compute locale from article.language using articleLangToLocaleMap
ArticleDetailsComponent->>ArticleShareIconsComponent: Passes [locale]=locale()
ArticleShareIconsComponent->>ArticleShareIconsComponent: Uses locale to construct share URLs
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (10)
💤 Files with no reviewable changes (2)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (6)
🧰 Additional context used🧬 Code Graph Analysis (1)libs/blog/i18n/util/src/lib/i18n.service.ts (1)
🔇 Additional comments (2)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. 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 (
|
PR is detected, will deploy to dev environment |
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: 1
🧹 Nitpick comments (2)
libs/blog/articles/feature-article/src/lib/article-share-icons/article-share-icons.component.ts (1)
67-69
: Verify locale mapping consistency.The hardcoded check for
'pl_PL'
should align with the locale values fromdbLangToLocaleMap
. Consider using a constant or the mapping to avoid hardcoded values.Consider importing the locale constants to avoid hardcoding:
+ import { dbLangToLocaleMap, DbLang } from '@angular-love/contracts/articles'; readonly articleUrl = computed(() => - this.locale() === 'pl_PL' + this.locale() === dbLangToLocaleMap[DbLang.Polish] ? `https://angular.love/pl/${this.slug()}` : `https://angular.love/${this.slug()}`, );libs/blog-contracts/articles/src/lib/languages.ts (1)
18-26
: Consider adding helper functions for type safety.While the mapping objects are excellent, consider adding helper functions to ensure type safety and provide better error handling.
Consider adding helper functions for safer usage:
+ export function getLocaleFromDbLang(dbLang: DbLang): string { + const locale = dbLangToLocaleMap[dbLang]; + if (!locale) { + throw new Error(`Unsupported DbLang: ${dbLang}`); + } + return locale; + } + + export function getLangFromDbLang(dbLang: DbLang): string { + const lang = dbLangToLangMap[dbLang]; + if (!lang) { + throw new Error(`Unsupported DbLang: ${dbLang}`); + } + return lang; + }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (7)
apps/blog/scripts/build-routes.mjs
(0 hunks)libs/blog-contracts/articles/src/lib/articles.ts
(2 hunks)libs/blog-contracts/articles/src/lib/languages.ts
(1 hunks)libs/blog/articles/data-access/src/lib/guards/article-exists.guard.ts
(1 hunks)libs/blog/articles/feature-article/src/lib/article-details/article-details.component.html
(2 hunks)libs/blog/articles/feature-article/src/lib/article-details/article-details.component.ts
(3 hunks)libs/blog/articles/feature-article/src/lib/article-share-icons/article-share-icons.component.ts
(1 hunks)
💤 Files with no reviewable changes (1)
- apps/blog/scripts/build-routes.mjs
🔇 Additional comments (11)
libs/blog-contracts/articles/src/lib/articles.ts (2)
3-3
: Excellent type safety improvement!Adding the
DbLang
import enables the use of strongly-typed language enums instead of generic strings.
128-128
:✅ Verification successful
Verify all Article interface consumers are updated.
The change from
lang: string
tolanguage: DbLang
is a breaking change that improves type safety but requires all consumers to be updated.Run the following script to verify all usages of the Article interface are properly updated:
🏁 Script executed:
#!/bin/bash # Description: Find all usages of Article interface and check for old 'lang' property usage # Find all TypeScript files that import Article echo "=== Files importing Article interface ===" rg -l "import.*Article.*from.*articles" --type ts # Search for any remaining usage of 'lang' property on Article objects echo -e "\n=== Potential old 'lang' property usage ===" rg "\.lang\b" --type ts -A 2 -B 2 # Search for any remaining 'lang:' property definitions echo -e "\n=== Property definitions using 'lang:' ===" rg "lang\s*:" --type ts -A 1 -B 1Length of output: 20110
Verification complete: Article interface consumers updated
No lingering
.lang
references were found in any TypeScript files importing theArticle
interface—every consumer now useslanguage: DbLang
. Other occurrences oflang
(in middleware tests, database schema, DTOs, etc.) are unrelated to theArticle
contract and remain valid.All good to merge.
libs/blog/articles/feature-article/src/lib/article-share-icons/article-share-icons.component.ts (1)
62-62
: Good API consistency improvement.Renaming from
language
tolocale
aligns with the new locale-centric approach and makes the component API more semantically correct.libs/blog/articles/feature-article/src/lib/article-details/article-details.component.ts (3)
5-5
: Good addition of computed import.Adding
computed
to support the new reactive locale property.
28-28
: Excellent import of mapping utility.Adding
dbLangToLocaleMap
enables the type-safe conversion fromDbLang
enum to locale string.
63-65
: Well-implemented reactive locale derivation.The computed property provides a clean, reactive way to derive the locale from the article's language using the type-safe mapping.
libs/blog-contracts/articles/src/lib/languages.ts (2)
18-21
: Excellent reverse mapping for language codes.The
dbLangToLangMap
provides a clean reverse lookup fromDbLang
enum to string language codes, completing the bidirectional mapping capability.
23-26
: Perfect locale mapping implementation.The
dbLangToLocaleMap
enables type-safe conversion fromDbLang
enum to locale strings, which is being used effectively in the component layer.libs/blog/articles/data-access/src/lib/guards/article-exists.guard.ts (1)
18-33
: LGTM! Excellent simplification from async to sync validation.The refactoring successfully removes the HTTP dependency and simplifies the guard logic to use in-memory validation. The redirect logic for handling language mismatches is well-implemented.
libs/blog/articles/feature-article/src/lib/article-details/article-details.component.html (2)
35-35
: LGTM! Consistent API update for locale handling.The change from
[language]="articleDetails().lang"
to[locale]="locale()"
is part of the refactoring to use locale-based internationalization. The change is clean and follows the new component API.
86-86
: LGTM! Consistent with the previous change.This maintains consistency with the same property binding change made on line 35, ensuring both instances of the
al-article-share-icons
component use the new locale-based approach.
libs/blog/articles/data-access/src/lib/guards/article-exists.guard.ts
Outdated
Show resolved
Hide resolved
Deployed to dev environment |
cfe2a8f
to
fd50c74
Compare
PR is detected, will deploy to dev environment |
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: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (10)
apps/blog/scripts/build-routes.mjs
(0 hunks)libs/blog-contracts/articles/src/lib/articles.ts
(3 hunks)libs/blog-contracts/articles/src/lib/languages.ts
(0 hunks)libs/blog/articles/data-access/src/lib/guards/article-exists.guard.ts
(1 hunks)libs/blog/articles/feature-article/src/lib/article-details/article-details.component.html
(2 hunks)libs/blog/articles/feature-article/src/lib/article-details/article-details.component.ts
(3 hunks)libs/blog/articles/feature-article/src/lib/article-share-icons/article-share-icons.component.ts
(2 hunks)libs/blog/i18n/data-access/src/lib/providers.ts
(2 hunks)libs/blog/i18n/util/src/index.ts
(1 hunks)libs/blog/i18n/util/src/lib/i18n.service.ts
(1 hunks)
💤 Files with no reviewable changes (2)
- apps/blog/scripts/build-routes.mjs
- libs/blog-contracts/articles/src/lib/languages.ts
🚧 Files skipped from review as they are similar to previous changes (5)
- libs/blog/articles/feature-article/src/lib/article-details/article-details.component.html
- libs/blog/articles/feature-article/src/lib/article-share-icons/article-share-icons.component.ts
- libs/blog/articles/data-access/src/lib/guards/article-exists.guard.ts
- libs/blog/articles/feature-article/src/lib/article-details/article-details.component.ts
- libs/blog-contracts/articles/src/lib/articles.ts
🧰 Additional context used
🧬 Code Graph Analysis (1)
libs/blog/i18n/util/src/lib/i18n.service.ts (1)
libs/blog-contracts/articles/src/lib/languages.ts (1)
Lang
(10-10)
🔇 Additional comments (3)
libs/blog/i18n/util/src/index.ts (1)
3-3
: LGTM! Proper barrel file export.The export addition follows standard barrel file patterns and makes the new service publicly accessible.
libs/blog/i18n/data-access/src/lib/providers.ts (2)
7-7
: LGTM! Correct import addition.The import statement properly includes the new
AlI18nService
alongside the existing service.
34-34
: LGTM! Proper DI registration.The service is correctly added to the providers array for dependency injection.
Deployed to dev environment |
fd50c74
to
25937be
Compare
PR is detected, will deploy to dev environment |
Deployed to dev environment |
Summary by CodeRabbit