-
Notifications
You must be signed in to change notification settings - Fork 655
Angular: Configuration Components Deprecation Warning #31511
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
Open
ajivanyandev
wants to merge
14
commits into
25_2
Choose a base branch
from
angular/deprecation-warning
base: 25_2
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.
Open
Changes from 5 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
12f5284
Add configuration components' deprecation warning
ajivanyandev 4d83b6c
Add todo
ajivanyandev c8eb424
lint fix
ajivanyandev 57617ef
Add angular warning mechanism for warnings with code
ajivanyandev daeed9c
Merge branch '25_2' into angular/deprecation-warning
ajivanyandev 944b9f8
remove unnecessary type casting
ajivanyandev 04f909c
fix lint issue
ajivanyandev 5e5e9ab
Merge branch '25_2' into angular/deprecation-warning
ajivanyandev 0c5de27
Merge branch '25_2' into angular/deprecation-warning
ajivanyandev 94a7146
Merge branch '25_2' into angular/deprecation-warning
ajivanyandev 60e7740
Merge branch '25_2' into angular/deprecation-warning
ajivanyandev 6367232
simplify object key check
ajivanyandev 6385db7
Merge branch '25_2' into angular/deprecation-warning
ajivanyandev 2a00f9f
revert small fix
ajivanyandev 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,4 +2,5 @@ export const knownWarnings = [ | |
| 'W0019 -', | ||
| 'W0022 -', | ||
| 'W2108 -', | ||
| 'W3001 -' | ||
| ]; | ||
1,090 changes: 1,090 additions & 0 deletions
1,090
packages/devextreme-angular/src/core/deprecated-config-map.ts
Large diffs are not rendered by default.
Oops, something went wrong.
81 changes: 81 additions & 0 deletions
81
packages/devextreme-angular/src/core/deprecated-config-warning.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,81 @@ | ||
| import type { BaseNestedOption, INestedOptionContainer } from './nested-option'; | ||
| import { DEPRECATED_CONFIG_COMPONENTS } from './deprecated-config-map'; | ||
| import WARNING_CODES from './warning-codes'; | ||
| import { logWarning } from './warning-helper'; | ||
|
|
||
| const warnedUsages = new Set<string>(); | ||
|
|
||
| const LEGACY_CLASS_NAME_REGEXP = /^Dx([io])([A-Za-z0-9]+)Component$/; | ||
|
|
||
| type DeprecatedConfigEntry = Record<string, string>; | ||
|
|
||
| function getLegacySelector(nestedOption: BaseNestedOption): string | undefined { | ||
| const className = nestedOption?.constructor?.name; | ||
| if (!className) { | ||
| return undefined; | ||
| } | ||
|
|
||
| const match = LEGACY_CLASS_NAME_REGEXP.exec(className); | ||
| if (!match) { | ||
| return undefined; | ||
| } | ||
|
|
||
| const [, type, rest] = match; | ||
| const prefix = type === 'o' ? 'dxo-' : 'dxi-'; | ||
|
|
||
| return `${prefix}${toKebabCase(rest)}`; | ||
| } | ||
|
|
||
| function getHostMapping(host: INestedOptionContainer | undefined): DeprecatedConfigEntry | undefined { | ||
| const visited = new Set<INestedOptionContainer>(); | ||
| let current = host; | ||
|
|
||
| while (current && !visited.has(current)) { | ||
| visited.add(current); | ||
|
|
||
| const ctorName = current.constructor?.name; | ||
| if (ctorName && Object.prototype.hasOwnProperty.call(DEPRECATED_CONFIG_COMPONENTS, ctorName)) { | ||
| return DEPRECATED_CONFIG_COMPONENTS[ctorName] as DeprecatedConfigEntry; | ||
| } | ||
|
|
||
| current = (current as { _host?: INestedOptionContainer })._host; | ||
| } | ||
|
|
||
| return undefined; | ||
| } | ||
|
|
||
| export function warnIfLegacyNestedComponent(nestedOption: BaseNestedOption, host: INestedOptionContainer | undefined): void { | ||
| const legacySelector = getLegacySelector(nestedOption); | ||
| if (!legacySelector) { | ||
| return; | ||
| } | ||
|
|
||
| const mappingEntry = getHostMapping(host); | ||
| if (!mappingEntry) { | ||
| return; | ||
| } | ||
|
|
||
| const replacement = mappingEntry[legacySelector]; | ||
| if (!replacement) { | ||
| return; | ||
| } | ||
|
|
||
| const cacheKey = `${legacySelector}|${replacement}`; | ||
| if (warnedUsages.has(cacheKey)) { | ||
| return; | ||
| } | ||
|
|
||
| warnedUsages.add(cacheKey); | ||
|
|
||
| logWarning( | ||
| WARNING_CODES.LEGACY_CONFIG_COMPONENT_USED, | ||
| { legacySelector, replacement }, | ||
| ); | ||
| } | ||
|
|
||
| function toKebabCase(value: string): string { | ||
| return value | ||
| .replace(/([a-z0-9])([A-Z])/g, '$1-$2') | ||
| .replace(/([A-Z])([A-Z][a-z])/g, '$1-$2') | ||
| .toLowerCase(); | ||
| } | ||
ajivanyandev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| const WARNING_CODES = { | ||
| LEGACY_CONFIG_COMPONENT_USED: { | ||
| code: 'W3001', | ||
| template: 'You are using the legacy {legacySelector} configuration component. We recommend ' | ||
| + 'upgrading to the new {replacement} configuration component.', | ||
| // TODO: link to docs article, when available | ||
| }, | ||
| } as const; | ||
|
|
||
| export type WarningId = keyof typeof WARNING_CODES; | ||
| export type WarningDefinition = typeof WARNING_CODES[WarningId]; | ||
|
|
||
| export default WARNING_CODES; |
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,35 @@ | ||
| import type { WarningDefinition } from './warning-codes'; | ||
|
|
||
| type TemplatePrimitive = string | number | boolean; | ||
| export type TemplateArgs = TemplatePrimitive[] | Record<string, TemplatePrimitive>; | ||
|
|
||
| function formatWarningMessage(template: string, args?: TemplateArgs): string { | ||
| if (!args) { | ||
| return template; | ||
| } | ||
|
|
||
| if (Array.isArray(args)) { | ||
| return args.reduce<string>( | ||
| (message, value, index) => replacePlaceholder(message, `{${index}}`, String(value)), | ||
| template, | ||
| ); | ||
| } | ||
|
|
||
| return (Object.entries(args) as Array<[string, TemplatePrimitive]>).reduce<string>( | ||
| (message, [key, value]) => replacePlaceholder(message, `{${key}}`, String(value)), | ||
| template, | ||
| ); | ||
| } | ||
|
|
||
| export function logWarning(warning: WarningDefinition, args?: TemplateArgs): void { | ||
| if (typeof console === 'undefined' || typeof console.warn !== 'function') { | ||
| return; | ||
| } | ||
|
|
||
| const message = formatWarningMessage(warning.template, args); | ||
| console.warn(`${warning.code} - ${message}`); | ||
| } | ||
|
|
||
| function replacePlaceholder(message: string, placeholder: string, value: string): string { | ||
| return message.split(placeholder).join(value); | ||
| } |
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.