Skip to content
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

[FC-0059] Components tab #1109

Merged
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
311a7a3
feat: Initial structure of ComponentCard
ChrisChV Jun 13, 2024
aaed74b
feat: Connect TagCount, Colors and Icons with library components card
ChrisChV Jun 17, 2024
caab4b3
feat: Infinite scroll implemented on Components tab
ChrisChV Jun 18, 2024
9490963
style: Style nits on card component
ChrisChV Jun 19, 2024
286d7bf
style: Add fetchNextPage to infinite scroll useEffect
ChrisChV Jun 20, 2024
08667c5
feat: Variant added to LibraryComponents to show full components or a…
ChrisChV Jun 20, 2024
6536902
style: Nits on lints and code
ChrisChV Jun 20, 2024
e2ae342
refactor: Create block-type-utils with block type constants
ChrisChV Jun 20, 2024
cb2aa94
fix: Issues on course-unit tests
ChrisChV Jun 21, 2024
44228e1
refactor: Calculate tagCount in LibraryComponents instead on serach i…
ChrisChV Jun 21, 2024
9014f99
test: Added for LibraryComponents
ChrisChV Jun 24, 2024
94432b4
refactor: Migrate block-type-utils to TS
ChrisChV Jul 1, 2024
bafe651
test: Fixt LibraryAuthoringPage test
ChrisChV Jul 1, 2024
edea059
fix: Delete src/search-modal/index.js to fix lint
ChrisChV Jul 10, 2024
feda1bd
fix: Error with types on Icons
ChrisChV Jul 10, 2024
32838a3
chore: Rebase to clear branch
ChrisChV Jul 11, 2024
7f3444e
refactor: Migrate index and messages files of library components to TS
ChrisChV Jul 11, 2024
7a2e82b
fix: LibraryAuthoringPage.test.tsx
ChrisChV Jul 11, 2024
1346542
chore: Fix merge conflicts
ChrisChV Jul 15, 2024
e5fe05d
refactor: Styles of components depending of type
ChrisChV Jul 16, 2024
0d5e52e
refactor: Add Truncate instead of css code in ComponentCard
ChrisChV Jul 16, 2024
3d09535
refactor: Tag count calculation moved from LibraryComponents to Compo…
ChrisChV Jul 16, 2024
4fe14c0
refactor: ComponentCardLoading deleted
ChrisChV Jul 16, 2024
bb9cbf3
refactor: Unit icons map rename on generic/block-type-utils
ChrisChV Jul 17, 2024
166ab04
refactor: Component card to Highlight the title and body when search
ChrisChV Jul 19, 2024
1ebe818
chore: Fix merge conflicts
ChrisChV Jul 19, 2024
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
2 changes: 1 addition & 1 deletion src/course-unit/add-component/AddComponent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useIntl } from '@edx/frontend-platform/i18n';
import { useToggle } from '@openedx/paragon';

import { getCourseSectionVertical } from '../data/selectors';
import { COMPONENT_TYPES } from '../constants';
import { COMPONENT_TYPES } from '../../generic/block-type-utils/constants';
import ComponentModalView from './add-component-modals/ComponentModalView';
import AddComponentButton from './add-component-btn';
import messages from './messages';
Expand Down
2 changes: 1 addition & 1 deletion src/course-unit/add-component/AddComponent.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { executeThunk } from '../../utils';
import { fetchCourseSectionVerticalData } from '../data/thunk';
import { getCourseSectionVerticalApiUrl } from '../data/api';
import { courseSectionVerticalMock } from '../__mocks__';
import { COMPONENT_TYPES } from '../constants';
import { COMPONENT_TYPES } from '../../generic/block-type-utils/constants';
import AddComponent from './AddComponent';
import messages from './messages';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import PropTypes from 'prop-types';
import { Icon } from '@openedx/paragon';
import { EditNote as EditNoteIcon } from '@openedx/paragon/icons';

import { COMPONENT_TYPES, COMPONENT_TYPE_ICON_MAP } from '../../constants';
import { COMPONENT_TYPES, COMPONENT_TYPE_ICON_MAP } from '../../../generic/block-type-utils/constants';

const AddComponentIcon = ({ type }) => {
const icon = COMPONENT_TYPE_ICON_MAP[type] || EditNoteIcon;
Expand Down
47 changes: 0 additions & 47 deletions src/course-unit/constants.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,6 @@
import {
BackHand as BackHandIcon,
BookOpen as BookOpenIcon,
Edit as EditIcon,
EditNote as EditNoteIcon,
FormatListBulleted as FormatListBulletedIcon,
HelpOutline as HelpOutlineIcon,
LibraryAdd as LibraryIcon,
Lock as LockIcon,
QuestionAnswerOutline as QuestionAnswerOutlineIcon,
Science as ScienceIcon,
TextFields as TextFieldsIcon,
VideoCamera as VideoCameraIcon,
} from '@openedx/paragon/icons';

import messages from './sidebar/messages';
import addComponentMessages from './add-component/messages';

export const UNIT_ICON_TYPES = ['video', 'other', 'vertical', 'problem', 'lock'];

export const COMPONENT_TYPES = {
advanced: 'advanced',
discussion: 'discussion',
library: 'library',
html: 'html',
openassessment: 'openassessment',
problem: 'problem',
video: 'video',
dragAndDrop: 'drag-and-drop-v2',
};

export const TYPE_ICONS_MAP = {
video: VideoCameraIcon,
other: BookOpenIcon,
vertical: FormatListBulletedIcon,
problem: EditIcon,
lock: LockIcon,
};

export const COMPONENT_TYPE_ICON_MAP = {
[COMPONENT_TYPES.advanced]: ScienceIcon,
[COMPONENT_TYPES.discussion]: QuestionAnswerOutlineIcon,
[COMPONENT_TYPES.library]: LibraryIcon,
[COMPONENT_TYPES.html]: TextFieldsIcon,
[COMPONENT_TYPES.openassessment]: EditNoteIcon,
[COMPONENT_TYPES.problem]: HelpOutlineIcon,
[COMPONENT_TYPES.video]: VideoCameraIcon,
[COMPONENT_TYPES.dragAndDrop]: BackHandIcon,
};

export const getUnitReleaseStatus = (intl) => ({
release: intl.formatMessage(messages.releaseStatusTitle),
released: intl.formatMessage(messages.releasedStatusTitle),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import PropTypes from 'prop-types';
import { Icon } from '@openedx/paragon';
import { BookOpen as BookOpenIcon } from '@openedx/paragon/icons';

import { TYPE_ICONS_MAP, UNIT_ICON_TYPES } from '../../constants';
import { TYPE_ICONS_MAP, UNIT_ICON_TYPES } from '../../../generic/block-type-utils/constants';

const UnitIcon = ({ type }) => {
const icon = TYPE_ICONS_MAP[type] || BookOpenIcon;
Expand Down
2 changes: 1 addition & 1 deletion src/course-unit/course-xblock/CourseXBlock.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import SortableItem from '../../generic/drag-helper/SortableItem';
import { scrollToElement } from '../../course-outline/utils';
import { COURSE_BLOCK_NAMES } from '../../constants';
import { copyToClipboard } from '../../generic/data/thunks';
import { COMPONENT_TYPES } from '../constants';
import { COMPONENT_TYPES } from '../../generic/block-type-utils/constants';
import XBlockMessages from './xblock-messages/XBlockMessages';
import messages from './messages';

Expand Down
3 changes: 2 additions & 1 deletion src/course-unit/course-xblock/CourseXBlock.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import { getCourseSectionVerticalApiUrl, getXBlockBaseApiUrl } from '../data/api
import { fetchCourseSectionVerticalData } from '../data/thunk';
import { executeThunk } from '../../utils';
import { getCourseId } from '../data/selectors';
import { PUBLISH_TYPES, COMPONENT_TYPES } from '../constants';
import { PUBLISH_TYPES } from '../constants';
import { COMPONENT_TYPES } from '../../generic/block-type-utils/constants';
import { courseSectionVerticalMock, courseVerticalChildrenMock } from '../__mocks__';
import CourseXBlock from './CourseXBlock';
import messages from './messages';
Expand Down
69 changes: 69 additions & 0 deletions src/generic/block-type-utils/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import React from 'react';
import {
BackHand as BackHandIcon,
BookOpen as BookOpenIcon,
Edit as EditIcon,
EditNote as EditNoteIcon,
FormatListBulleted as FormatListBulletedIcon,
HelpOutline as HelpOutlineIcon,
LibraryAdd as LibraryIcon,
Lock as LockIcon,
QuestionAnswerOutline as QuestionAnswerOutlineIcon,
Science as ScienceIcon,
TextFields as TextFieldsIcon,
VideoCamera as VideoCameraIcon,
Folder,
} from '@openedx/paragon/icons';

export const UNIT_ICON_TYPES = ['video', 'other', 'vertical', 'problem', 'lock'];

export const COMPONENT_TYPES = {
advanced: 'advanced',
discussion: 'discussion',
library: 'library',
html: 'html',
openassessment: 'openassessment',
problem: 'problem',
video: 'video',
dragAndDrop: 'drag-and-drop-v2',
};

export const TYPE_ICONS_MAP: Record<string, React.ComponentType> = {
ChrisChV marked this conversation as resolved.
Show resolved Hide resolved
video: VideoCameraIcon,
other: BookOpenIcon,
vertical: FormatListBulletedIcon,
problem: EditIcon,
lock: LockIcon,
};

export const COMPONENT_TYPE_ICON_MAP: Record<string, React.ComponentType> = {
[COMPONENT_TYPES.advanced]: ScienceIcon,
[COMPONENT_TYPES.discussion]: QuestionAnswerOutlineIcon,
[COMPONENT_TYPES.library]: LibraryIcon,
[COMPONENT_TYPES.html]: TextFieldsIcon,
[COMPONENT_TYPES.openassessment]: EditNoteIcon,
[COMPONENT_TYPES.problem]: HelpOutlineIcon,
[COMPONENT_TYPES.video]: VideoCameraIcon,
[COMPONENT_TYPES.dragAndDrop]: BackHandIcon,
};

export const STRUCTURAL_TYPE_ICONS: Record<string, React.ComponentType> = {
vertical: TYPE_ICONS_MAP.vertical,
sequential: Folder,
chapter: Folder,
};

export const COMPONENT_TYPE_COLOR_MAP = {
[COMPONENT_TYPES.advanced]: 'bg-other',
[COMPONENT_TYPES.discussion]: 'bg-component',
[COMPONENT_TYPES.library]: 'bg-component',
[COMPONENT_TYPES.html]: 'bg-html',
[COMPONENT_TYPES.openassessment]: 'bg-component',
[COMPONENT_TYPES.problem]: 'bg-component',
[COMPONENT_TYPES.video]: 'bg-video',
[COMPONENT_TYPES.dragAndDrop]: 'bg-component',
vertical: 'bg-vertical',
sequential: 'bg-component',
chapter: 'bg-component',
collection: 'bg-collection',
};
15 changes: 15 additions & 0 deletions src/generic/block-type-utils/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react';
import { Article } from '@openedx/paragon/icons';
import {
COMPONENT_TYPE_ICON_MAP,
STRUCTURAL_TYPE_ICONS,
COMPONENT_TYPE_COLOR_MAP,
} from './constants';

export function getItemIcon(blockType: string): React.ComponentType {
return STRUCTURAL_TYPE_ICONS[blockType] ?? COMPONENT_TYPE_ICON_MAP[blockType] ?? Article;
}

export function getComponentColor(blockType: string): string {
return COMPONENT_TYPE_COLOR_MAP[blockType] ?? 'bg-component';
}
1 change: 1 addition & 0 deletions src/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
@import "search-modal/SearchModal";
@import "certificates/scss/Certificates";
@import "group-configurations/GroupConfigurations";
@import "library-authoring";

// To apply the glow effect to the selected Section/Subsection, in the Course Outline
div.row:has(> div > div.highlight) {
Expand Down
6 changes: 2 additions & 4 deletions src/library-authoring/LibraryAuthoringPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ describe('<LibraryAuthoringPage />', () => {
axiosMock.onGet(getContentLibraryApiUrl(libraryData.id)).reply(200, libraryData);

const {
getByRole, getByText, queryByText,
getByRole, getByText, queryByText, findByText,
} = render(<RootWrapper />);

// Ensure the search endpoint is called
Expand All @@ -163,14 +163,13 @@ describe('<LibraryAuthoringPage />', () => {
expect(getByText('Recently Modified')).toBeInTheDocument();
expect(getByText('Collections (0)')).toBeInTheDocument();
expect(getByText('Components (6)')).toBeInTheDocument();
expect(getByText('There are 6 components in this library')).toBeInTheDocument();
expect(await findByText('Test HTML Block')).toBeInTheDocument();

// Navigate to the components tab
fireEvent.click(getByRole('tab', { name: 'Components' }));
expect(queryByText('Recently Modified')).not.toBeInTheDocument();
expect(queryByText('Collections (0)')).not.toBeInTheDocument();
expect(queryByText('Components (6)')).not.toBeInTheDocument();
expect(getByText('There are 6 components in this library')).toBeInTheDocument();

// Navigate to the collections tab
fireEvent.click(getByRole('tab', { name: 'Collections' }));
Expand All @@ -186,7 +185,6 @@ describe('<LibraryAuthoringPage />', () => {
expect(getByText('Recently Modified')).toBeInTheDocument();
expect(getByText('Collections (0)')).toBeInTheDocument();
expect(getByText('Components (6)')).toBeInTheDocument();
expect(getByText('There are 6 components in this library')).toBeInTheDocument();
});

it('show library without components', async () => {
Expand Down
4 changes: 2 additions & 2 deletions src/library-authoring/LibraryAuthoringPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Loading from '../generic/Loading';
import SubHeader from '../generic/sub-header/SubHeader';
import Header from '../header';
import NotFoundAlert from '../generic/NotFoundAlert';
import LibraryComponents from './LibraryComponents';
import LibraryComponents from './components/LibraryComponents';
import LibraryCollections from './LibraryCollections';
import LibraryHome from './LibraryHome';
import { useContentLibrary } from './data/apiHook';
Expand Down Expand Up @@ -104,7 +104,7 @@ const LibraryAuthoringPage = () => {
/>
<Route
path={TabList.components}
element={<LibraryComponents libraryId={libraryId} filter={{ searchKeywords }} />}
element={<LibraryComponents libraryId={libraryId} filter={{ searchKeywords }} variant="full" />}
/>
<Route
path={TabList.collections}
Expand Down
6 changes: 3 additions & 3 deletions src/library-authoring/LibraryHome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {

import { NoComponents, NoSearchResults } from './EmptyStates';
import LibraryCollections from './LibraryCollections';
import LibraryComponents from './LibraryComponents';
import LibraryComponents from './components/LibraryComponents';
import { useLibraryComponentCount } from './data/apiHook';
import messages from './messages';

Expand Down Expand Up @@ -45,8 +45,8 @@ const LibraryHome = ({ libraryId, filter } : LibraryHomeProps) => {
<Section title={intl.formatMessage(messages.collectionsTitle, { collectionCount })}>
<LibraryCollections />
</Section>
<Section title={intl.formatMessage(messages.componentsTitle, { componentCount })}>
<LibraryComponents libraryId={libraryId} filter={filter} />
<Section title={`Components (${componentCount})`}>
<LibraryComponents libraryId={libraryId} filter={filter} variant="preview" />
</Section>
</Stack>
);
Expand Down
2 changes: 2 additions & 0 deletions src/library-authoring/__mocks__/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// eslint-disable-next-line import/prefer-default-export
export { default as libraryComponentsMock } from './libraryComponentsMock';
74 changes: 74 additions & 0 deletions src/library-authoring/__mocks__/libraryComponentsMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
module.exports = [
{
id: '1',
displayName: 'Text',
formatted: {
content: {
htmlContent: 'This is a text: ID=1',
},
},
tags: {
level0: ['1', '2', '3'],
},
blockType: 'text',
},
{
id: '2',
displayName: 'Text',
formatted: {
content: {
htmlContent: 'This is a text: ID=2',
},
},
tags: {
level0: ['1', '2', '3'],
},
blockType: 'text',
},
{
id: '3',
displayName: 'Video',
formatted: {
content: {
htmlContent: 'This is a video: ID=3',
},
},
tags: {
level0: ['1', '2'],
},
blockType: 'video',
},
{
id: '4',
displayName: 'Video',
formatted: {
content: {
htmlContent: 'This is a video: ID=4',
},
},
tags: {
level0: ['1', '2'],
},
blockType: 'text',
},
{
id: '5',
displayName: 'Problem',
formatted: {
content: {
htmlContent: 'This is a problem: ID=5',
},
},
blockType: 'problem',
},
{
id: '6',
displayName: 'Problem',
formatted: {
content: {
htmlContent: 'This is a problem: ID=6',
},
},
blockType: 'problem',
},
];
Loading
Loading