Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"file-saver": "^2.0.5",
"formik": "2.4.6",
"frontend-components-tinymce-advanced-plugins": "^1.0.3",
"iso-639-1": "^3.1.5",
"jszip": "^3.10.1",
"lodash": "4.17.21",
"meilisearch": "^0.41.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import {
import { Check } from '@openedx/paragon/icons';
import { connect, useDispatch } from 'react-redux';
import { useIntl } from '@edx/frontend-platform/i18n';
import { getLanguageName } from '@src/editors/data/constants/video';
import { thunkActions, selectors } from '../../../../../../data/redux';
import { videoTranscriptLanguages } from '../../../../../../data/constants/video';
import { FileInput, fileInput } from '../../../../../../sharedComponents/FileInput';
import messages from './messages';

Expand Down Expand Up @@ -47,25 +47,25 @@ export const hooks = {
const LanguageSelector = ({
index, // For a unique id for the form control
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please leave this comment in place; I think it's helpful.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

language,
// Redux
openLanguages, // Only allow those languages not already associated with a transcript to be selected
}) => {
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 (
Expand All @@ -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)}
Expand All @@ -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>
Expand Down
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';
Expand All @@ -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();
Expand All @@ -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', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this test no longer needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is reason we dont have disable option in our current implementation that is reason I have removed it

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);
});
});
Loading