-
Notifications
You must be signed in to change notification settings - Fork 13
Add report for language scope hierarchy issues #652
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
whwan4570
wants to merge
5
commits into
master
Choose a base branch
from
report-language-scope-issues
base: master
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 all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
99e287c
Add report for language scope hierarchy issues.
whwan4570 0073889
Refactor Scope Issues report to use selected language authority.
whwan4570 6e3bec7
Address latest Scope Issues review updates.
whwan4570 6a7f6d7
Rebase on master and fix InteractiveEntityTable import.
whwan4570 efc30c7
Show all scope issues regardless of sidebar scope filter.
whwan4570 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
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,119 @@ | ||
| import React, { useMemo } from 'react'; | ||
|
|
||
| import { useDataContext } from '@features/data/context/useDataContext'; | ||
| import Hoverable from '@features/layers/hovercard/Hoverable'; | ||
| import HoverableObjectName from '@features/layers/hovercard/HoverableObjectName'; | ||
| import InteractiveEntityTable from '@features/table/InteractiveEntityTable'; | ||
| import TableID from '@features/table/TableID'; | ||
| import Field from '@features/transforms/fields/Field'; | ||
|
|
||
| import { LanguageData, LanguageScope } from '@entities/language/LanguageTypes'; | ||
|
|
||
| import { getLanguageScopeLabel } from '@strings/LanguageScopeStrings'; | ||
|
|
||
| import { filterLanguagesWithScopeIssues, getLanguagePath } from './getLanguageScopeIssues'; | ||
|
|
||
| const ReportLanguageScopeIssues: React.FC = () => { | ||
| const { languagesInSelectedSource } = useDataContext(); | ||
|
|
||
| const languagesWithIssues = useMemo( | ||
| () => filterLanguagesWithScopeIssues(languagesInSelectedSource), | ||
| [languagesInSelectedSource], | ||
| ); | ||
|
|
||
| return ( | ||
| <> | ||
| This report flags languages in the current language source whose scope is broader than their | ||
| direct parent's scope, which may indicate a hierarchy inconsistency. Results are shown | ||
| regardless of the sidebar Language Scope filter so dialect and family issues remain visible. | ||
| <InteractiveEntityTable<LanguageData> | ||
| tableID={TableID.LanguageScopeIssues} | ||
| shouldFilterUsingSearchBar={false} | ||
| useScope={false} | ||
| columns={[ | ||
| { | ||
| key: 'Parent Code', | ||
| render: (lang) => lang.parentLanguage?.codeDisplay, | ||
| }, | ||
| { | ||
| key: 'Parent Name', | ||
| render: (lang) => | ||
| lang.parentLanguage != null ? ( | ||
| <HoverableObjectName object={lang.parentLanguage} /> | ||
| ) : null, | ||
| exportValue: (lang) => lang.parentLanguage?.nameDisplay, | ||
| }, | ||
| { | ||
| key: 'Parent Scope', | ||
| render: (lang) => | ||
| lang.parentLanguage?.scope != null | ||
| ? getLanguageScopeLabel(lang.parentLanguage.scope) | ||
| : null, | ||
| }, | ||
| { | ||
| key: 'Child Code', | ||
| render: (lang) => lang.codeDisplay, | ||
| field: Field.Code, | ||
| }, | ||
| { | ||
| key: 'Child Name', | ||
| render: (lang) => <HoverableObjectName object={lang} />, | ||
| exportValue: (lang) => lang.nameDisplay, | ||
| field: Field.Name, | ||
| }, | ||
| { | ||
| key: 'Child Scope', | ||
| render: (lang) => (lang.scope != null ? getLanguageScopeLabel(lang.scope) : null), | ||
| field: Field.LanguageScope, | ||
| }, | ||
|
conradarcturus marked this conversation as resolved.
|
||
| { | ||
| key: 'Full Path', | ||
| render: (lang) => <LanguagePath path={getLanguagePath(lang)} />, | ||
| exportValue: (lang) => formatLanguagePath(getLanguagePath(lang)), | ||
| }, | ||
| ]} | ||
| entities={languagesWithIssues} | ||
| /> | ||
| </> | ||
| ); | ||
| }; | ||
|
|
||
| const LanguagePath: React.FC<{ path: LanguageData[] }> = ({ path }) => { | ||
| const compact = path.map((lang) => getScopeChar(lang.scope)).join('/'); | ||
|
|
||
| return <Hoverable hoverContent={<ExpandedLanguagePath path={path} />}>{compact}</Hoverable>; | ||
| }; | ||
|
|
||
| const ExpandedLanguagePath: React.FC<{ path: LanguageData[] }> = ({ path }) => ( | ||
| <> | ||
| {path.map((lang, index) => ( | ||
| <React.Fragment key={lang.ID}> | ||
| {index > 0 && ' > '} | ||
| <HoverableObjectName object={lang} /> [{lang.codeDisplay}] | ||
| </React.Fragment> | ||
| ))} | ||
| </> | ||
| ); | ||
|
|
||
| function getScopeChar(scope: LanguageScope | undefined): string { | ||
| switch (scope) { | ||
| case LanguageScope.Family: | ||
| return 'F'; | ||
| case LanguageScope.Macrolanguage: | ||
| return 'M'; | ||
| case LanguageScope.Language: | ||
| return 'I'; | ||
| case LanguageScope.Dialect: | ||
| return 'D'; | ||
| case LanguageScope.SpecialCode: | ||
| return 'S'; | ||
| default: | ||
| return '?'; | ||
| } | ||
| } | ||
|
|
||
| function formatLanguagePath(path: LanguageData[]): string { | ||
| return path.map((lang) => `${lang.nameDisplay} [${lang.codeDisplay}]`).join(' > '); | ||
| } | ||
|
|
||
| export default ReportLanguageScopeIssues; | ||
119 changes: 119 additions & 0 deletions
119
src/widgets/reports/__tests__/getLanguageScopeIssues.test.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,119 @@ | ||
| import { describe, expect, it } from 'vitest'; | ||
|
|
||
| import { getBaseLanguageData, LanguageData, LanguageScope } from '@entities/language/LanguageTypes'; | ||
|
|
||
| import { filterLanguagesWithScopeIssues, getLanguagePath } from '../getLanguageScopeIssues'; | ||
|
|
||
| function makeLanguage( | ||
| id: string, | ||
| name: string, | ||
| scope: LanguageScope, | ||
| parentLanguage?: LanguageData, | ||
| ): LanguageData { | ||
| return { | ||
| ...getBaseLanguageData(id, name), | ||
| scope, | ||
| parentLanguage, | ||
| childLanguages: [], | ||
| }; | ||
| } | ||
|
|
||
| describe('filterLanguagesWithScopeIssues', () => { | ||
| it('detects languages whose scope is broader than their parent', () => { | ||
| const dialectParent = makeLanguage('dial1', 'Test Dialect Group', LanguageScope.Dialect); | ||
| const individualChild = makeLanguage( | ||
| 'ind1', | ||
| 'Test Individual', | ||
| LanguageScope.Language, | ||
| dialectParent, | ||
| ); | ||
| const macroChild = makeLanguage( | ||
| 'mac1', | ||
| 'Test Macro', | ||
| LanguageScope.Macrolanguage, | ||
| dialectParent, | ||
| ); | ||
| const macroParent = makeLanguage('mac2', 'Another Macro', LanguageScope.Macrolanguage); | ||
| const familyChild = makeLanguage('fam1', 'Test Family', LanguageScope.Family, macroParent); | ||
| const individualParent = makeLanguage('ind2', 'Parent Individual', LanguageScope.Language); | ||
| const familyChild2 = makeLanguage( | ||
| 'fam2', | ||
| 'Nested Family', | ||
| LanguageScope.Family, | ||
| individualParent, | ||
| ); | ||
|
|
||
| dialectParent.childLanguages = [individualChild, macroChild]; | ||
| macroParent.childLanguages = [familyChild]; | ||
| individualParent.childLanguages = [familyChild2]; | ||
|
|
||
| const issues = filterLanguagesWithScopeIssues([ | ||
| dialectParent, | ||
| individualChild, | ||
| macroChild, | ||
| macroParent, | ||
| familyChild, | ||
| individualParent, | ||
| familyChild2, | ||
| ]); | ||
|
|
||
| expect(issues.map((lang) => lang.ID).sort()).toEqual(['fam1', 'fam2', 'ind1', 'mac1']); | ||
| }); | ||
|
|
||
| it('builds the language path from root to child using parentLanguage', () => { | ||
| const root = makeLanguage('fam-root', 'Root Family', LanguageScope.Family); | ||
| const parent = makeLanguage('mac-root', 'Root Macro', LanguageScope.Macrolanguage, root); | ||
| const child = makeLanguage('ind-root', 'Root Individual', LanguageScope.Language, parent); | ||
|
|
||
| root.childLanguages = [parent]; | ||
| parent.childLanguages = [child]; | ||
|
|
||
| expect(getLanguagePath(child).map((lang) => lang.ID)).toEqual([ | ||
| 'fam-root', | ||
| 'mac-root', | ||
| 'ind-root', | ||
| ]); | ||
| }); | ||
|
|
||
| it('ignores valid parent-child scope pairs', () => { | ||
| const family = makeLanguage('fam-valid', 'Valid Family', LanguageScope.Family); | ||
| const macro = makeLanguage('mac-valid', 'Valid Macro', LanguageScope.Macrolanguage, family); | ||
| family.childLanguages = [macro]; | ||
|
|
||
| expect(filterLanguagesWithScopeIssues([family, macro])).toEqual([]); | ||
| }); | ||
|
|
||
| it('ignores languages without a parent', () => { | ||
| const family = makeLanguage('fam-orphan', 'Root Family', LanguageScope.Family); | ||
|
|
||
| expect(filterLanguagesWithScopeIssues([family])).toEqual([]); | ||
| }); | ||
|
|
||
| it('ignores languages with missing scope', () => { | ||
| const parent = makeLanguage('par1', 'Parent', LanguageScope.Dialect); | ||
| const childWithIssue = makeLanguage('child1', 'Child', LanguageScope.Language, parent); | ||
| const childMissingScope: LanguageData = { | ||
| ...getBaseLanguageData('child2', 'No Scope Child'), | ||
| parentLanguage: parent, | ||
| childLanguages: [], | ||
| }; | ||
|
|
||
| expect(filterLanguagesWithScopeIssues([parent, childWithIssue, childMissingScope])).toEqual([ | ||
| childWithIssue, | ||
| ]); | ||
| }); | ||
|
|
||
| it('uses lang.parentLanguage and lang.scope instead of Combined fields', () => { | ||
| const dialectParent = makeLanguage('par1', 'Parent', LanguageScope.Dialect); | ||
| const child = makeLanguage('child1', 'Child', LanguageScope.Language, dialectParent); | ||
| const validCombinedParent = makeLanguage('valid-par', 'Valid Parent', LanguageScope.Family); | ||
|
|
||
| child.Combined.parentLanguage = validCombinedParent; | ||
| child.Combined.scope = LanguageScope.Language; | ||
| dialectParent.Combined.scope = LanguageScope.Dialect; | ||
|
|
||
| expect(filterLanguagesWithScopeIssues([dialectParent, child, validCombinedParent])).toEqual([ | ||
| child, | ||
| ]); | ||
| }); | ||
| }); |
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,31 @@ | ||
| import { LanguageData } from '@entities/language/LanguageTypes'; | ||
|
|
||
| export function getLanguagePath(child: LanguageData): LanguageData[] { | ||
| const path: LanguageData[] = []; | ||
| const visited = new Set<string>(); | ||
| let current: LanguageData | undefined = child; | ||
|
|
||
| while (current != null) { | ||
| if (visited.has(current.ID)) break; | ||
| visited.add(current.ID); | ||
| path.unshift(current); | ||
| current = current.parentLanguage; | ||
| } | ||
|
|
||
| return path; | ||
| } | ||
|
|
||
| export function filterLanguagesWithScopeIssues(languages: LanguageData[]): LanguageData[] { | ||
| return languages.filter((lang) => { | ||
| const parent = lang.parentLanguage; | ||
| if (parent == null) return false; | ||
|
|
||
| const parentScope = parent.scope; | ||
| const childScope = lang.scope; | ||
| if (parentScope == null || childScope == null) return false; | ||
|
|
||
| // LanguageScope uses higher values for broader scopes (Family=5 > Dialect=2). | ||
| // Flag when the child scope is broader than its parent's scope. | ||
| return childScope > parentScope; | ||
| }); | ||
| } |
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
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.
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.
Instead of forcing a sort, let's use the global sort function.nevermind, the table overrides the sort anyway :)