-
Notifications
You must be signed in to change notification settings - Fork 148
fix: Replace custom language names list with standard Intl DisplayNames API #2332 #2371
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -12,8 +12,8 @@ import { Check } from '@openedx/paragon/icons'; | |||||
import { connect, useDispatch } from 'react-redux'; | ||||||
import { useIntl } from '@edx/frontend-platform/i18n'; | ||||||
import { thunkActions, selectors } from '../../../../../../data/redux'; | ||||||
import { videoTranscriptLanguages } from '../../../../../../data/constants/video'; | ||||||
import { FileInput, fileInput } from '../../../../../../sharedComponents/FileInput'; | ||||||
import { getLanguageName } from '../../../../../../data/constants/video'; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
This is simpler - see the best practices checklist in the PR description. |
||||||
import messages from './messages'; | ||||||
|
||||||
export const hooks = { | ||||||
|
@@ -45,27 +45,27 @@ export const hooks = { | |||||
}; | ||||||
|
||||||
const LanguageSelector = ({ | ||||||
index, // For a unique id for the form control | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please leave this comment in place; I think it's helpful. |
||||||
index, | ||||||
language, | ||||||
// Redux | ||||||
openLanguages, // Only allow those languages not already associated with a transcript to be selected | ||||||
openLanguages, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add back a comment to explain this parameter. |
||||||
}) => { | ||||||
const intl = useIntl(); | ||||||
const dispatch = useDispatch(); | ||||||
|
||||||
const [localLang, setLocalLang] = React.useState(language); | ||||||
const input = fileInput({ onAddFile: hooks.addFileCallback({ dispatch: useDispatch(), localLang }) }); | ||||||
const input = fileInput({ onAddFile: hooks.addFileCallback({ dispatch, localLang }) }); | ||||||
const onLanguageChange = hooks.onSelectLanguage({ | ||||||
dispatch: useDispatch(), languageBeforeChange: localLang, setLocalLang, triggerupload: input.click, | ||||||
dispatch, languageBeforeChange: localLang, setLocalLang, triggerupload: input.click, | ||||||
}); | ||||||
|
||||||
const getTitle = () => { | ||||||
if (Object.prototype.hasOwnProperty.call(videoTranscriptLanguages, language)) { | ||||||
if (language) { | ||||||
return ( | ||||||
<ActionRow> | ||||||
{videoTranscriptLanguages[language]} | ||||||
{getLanguageName(language)} | ||||||
<ActionRow.Spacer /> | ||||||
<Icon className="text-primary-500" src={Check} /> | ||||||
</ActionRow> | ||||||
|
||||||
); | ||||||
} | ||||||
return ( | ||||||
|
@@ -78,10 +78,7 @@ const LanguageSelector = ({ | |||||
|
||||||
return ( | ||||||
<> | ||||||
|
||||||
<Dropdown | ||||||
className="w-100 mb-2" | ||||||
> | ||||||
<Dropdown className="w-100 mb-2"> | ||||||
<Dropdown.Toggle | ||||||
iconAs={Button} | ||||||
aria-label={intl.formatMessage(messages.languageSelectLabel)} | ||||||
|
@@ -93,14 +90,25 @@ const LanguageSelector = ({ | |||||
{getTitle()} | ||||||
</Dropdown.Toggle> | ||||||
<Dropdown.Menu> | ||||||
{Object.entries(videoTranscriptLanguages).map(([lang, text]) => { | ||||||
{openLanguages.map(lang => { | ||||||
const name = getLanguageName(lang); | ||||||
|
||||||
if (language === lang) { | ||||||
return (<Dropdown.Item>{text}<Icon className="text-primary-500" src={Check} /></Dropdown.Item>); | ||||||
} | ||||||
if (openLanguages.some(row => row.includes(lang))) { | ||||||
return (<Dropdown.Item onClick={() => onLanguageChange({ newLang: lang })}>{text}</Dropdown.Item>); | ||||||
return ( | ||||||
<Dropdown.Item key={lang}> | ||||||
{name} | ||||||
<Icon className="text-primary-500" src={Check} /> | ||||||
</Dropdown.Item> | ||||||
); | ||||||
} | ||||||
return (<Dropdown.Item className="disabled">{text}</Dropdown.Item>); | ||||||
return ( | ||||||
<Dropdown.Item | ||||||
key={lang} | ||||||
onClick={() => onLanguageChange({ newLang: lang })} | ||||||
> | ||||||
{name} | ||||||
</Dropdown.Item> | ||||||
); | ||||||
})} | ||||||
</Dropdown.Menu> | ||||||
</Dropdown> | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import React from 'react'; | ||
import { | ||
render, screen, initializeMocks, fireEvent, | ||
render, screen, initializeMocks, | ||
} from '@src/testUtils'; | ||
import LanguageSelector from './LanguageSelector'; | ||
import { selectors } from '../../../../../../data/redux'; | ||
|
@@ -13,19 +13,22 @@ const lang3 = 'sImLisH'; | |
const lang3Code = 'sl'; | ||
|
||
jest.mock('../../../../../../data/constants/video', () => ({ | ||
videoTranscriptLanguages: { | ||
[lang1Code]: lang1, | ||
[lang2Code]: lang2, | ||
[lang3Code]: lang3, | ||
}, | ||
getLanguageName: jest.fn((code) => { | ||
const mockMap = { | ||
kl: lang1, | ||
el: lang2, | ||
sl: lang3, | ||
}; | ||
return mockMap[code] || code; | ||
}), | ||
})); | ||
|
||
describe('LanguageSelector', () => { | ||
const props = { | ||
onSelect: jest.fn().mockName('props.OnSelect'), | ||
index: 1, | ||
language: lang1Code, | ||
openLanguages: [[lang2Code, lang2], [lang3Code, lang3]], | ||
openLanguages: [lang2Code, lang3Code, lang1Code], | ||
}; | ||
beforeEach(() => { | ||
initializeMocks(); | ||
|
@@ -46,13 +49,4 @@ describe('LanguageSelector', () => { | |
render(<LanguageSelector {...props} language="" />); | ||
expect(screen.getByText('Select Language')).toBeInTheDocument(); | ||
}); | ||
|
||
test('transcripts no Open Languages, all dropdown items should be disabled', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this test no longer needed? |
||
const { video } = selectors; | ||
jest.spyOn(video, 'openLanguages').mockReturnValue([]); | ||
const { container } = render(<LanguageSelector {...props} language="" />); | ||
fireEvent.click(screen.getByRole('button', { name: 'Languages' })); | ||
const disabledItems = container.querySelectorAll('.disabled.dropdown-item'); | ||
expect(disabledItems.length).toBe(3); | ||
}); | ||
}); |
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.
I think you committed this accidentally? I find the
--coverage
check here to be annoying as well, but we can't just change it without a dedicated PR and a bit more discussion.