-
Notifications
You must be signed in to change notification settings - Fork 2
juho/enhancement/548-move-hardcoded-heroes-to-directus-CMS-and-implement-endpoints #578
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
Draft
patinen
wants to merge
9
commits into
dev
Choose a base branch
from
juho/enhancement/548-move-hardcoded-heroes-to-directus-CMS-and-implement-endpoints
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
639ae8c
fix: hero page after merge
patinen 1a22b7c
fix: break circular dependency;
patinen 4392862
refactor: update hero page data fetching logic to prioritize Directusβ¦
patinen 9b0ecd6
refactor: extract groupHeroesByGroup function to improve code organizβ¦
patinen 5143494
feat(heroes): migrate hero data fetching to Directus with static fallβ¦
patinen 773368b
Follow-up commit to include changes that were prepared locally but miβ¦
patinen 48444d2
fix(hero) from last push: fetch hero rarityClass from heroes;
patinen 1e35229
fix(heroes): i18n hero rarity labels + restore per-stat rarityClass fβ¦
patinen 2e84c80
normalize locale codes for Directus API
patinen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
frontend-next-migration/src/entities/Hero/model/buildHeroQueryParams.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| import type { Locale } from './heroApi'; | ||
|
|
||
| /** Relation field keys (O2M translations) */ | ||
| const HERO_TR_KEYS = ['translations'] as const; | ||
| const GROUP_TR_KEYS = ['translations'] as const; | ||
|
|
||
| /** File field keys */ | ||
| const HERO_IMG_KEYS = ['srcImg'] as const; | ||
| const HERO_GIF_KEYS = ['srcGif'] as const; | ||
| const GROUP_IMG_KEYS = ['srcImg'] as const; | ||
| const GROUP_LABEL_KEYS = ['label'] as const; | ||
|
|
||
| /** Stats relation key */ | ||
| const STATS_KEYS = ['stats'] as const; | ||
|
|
||
| /** Normalized languages_code in Directus */ | ||
| const languageCode = (locale: Locale): string => locale; | ||
|
|
||
| /** Fields requested from Directus */ | ||
| export const FIELDS = [ | ||
| 'id', | ||
| 'slug', | ||
| 'order', | ||
| ...HERO_IMG_KEYS.flatMap((key) => [`${key}.id`, `${key}.width`, `${key}.height`]), | ||
| ...HERO_GIF_KEYS.flatMap((key) => [`${key}.id`, `${key}.width`, `${key}.height`]), | ||
| ...HERO_TR_KEYS.flatMap((key) => [ | ||
| `${key}.languages_code`, | ||
| `${key}.title`, | ||
| `${key}.description`, | ||
| `${key}.alt`, | ||
| `${key}.altGif`, | ||
| ]), | ||
| 'rarityClass', | ||
| 'group.id', | ||
| 'group.key', | ||
| 'group.bgColour', | ||
| ...GROUP_IMG_KEYS.flatMap((key) => [ | ||
| `group.${key}.id`, | ||
| `group.${key}.width`, | ||
| `group.${key}.height`, | ||
| ]), | ||
| ...GROUP_LABEL_KEYS.flatMap((key) => [ | ||
| `group.${key}.id`, | ||
| `group.${key}.width`, | ||
| `group.${key}.height`, | ||
| ]), | ||
| ...GROUP_TR_KEYS.flatMap((key) => [ | ||
| `group.${key}.languages_code`, | ||
| `group.${key}.name`, | ||
| `group.${key}.description`, | ||
| ]), | ||
| ...STATS_KEYS.flatMap((key) => [ | ||
| `${key}.name`, | ||
| `${key}.rarityClass`, | ||
| `${key}.defaultLevel`, | ||
| `${key}.developmentLevel`, | ||
| `${key}.order`, | ||
| ]), | ||
| ].join(','); | ||
|
|
||
| /** | ||
| * Build query parameters for Directus hero API calls | ||
| */ | ||
| export function buildHeroQueryParams( | ||
| locale: Locale, | ||
| options?: { slug?: string; limit?: string }, | ||
| ): URLSearchParams { | ||
| const params = new URLSearchParams(); | ||
| if (options?.slug) params.set('filter[slug][_eq]', options.slug); | ||
| if (options?.limit) params.set('limit', options.limit); | ||
| params.set('fields', FIELDS); | ||
| params.set('sort', 'order'); | ||
| for (const key of HERO_TR_KEYS) { | ||
| params.set(`deep[${key}][filter][languages_code][_eq]`, languageCode(locale)); | ||
| } | ||
| for (const key of GROUP_TR_KEYS) { | ||
| params.set(`deep[group][${key}][filter][languages_code][_eq]`, languageCode(locale)); | ||
| } | ||
| return params; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.