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

PADV-1158 - Truncate class/course title with an ellipsis at the end #122

Merged
merged 1 commit into from
Oct 26, 2024
Merged
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
6 changes: 3 additions & 3 deletions src/features/Dashboard/DashboardPage/_test_/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe('DashboardPage component', () => {
);

test('renders components', () => {
const { getByText } = component;
const { getByText, getAllByText } = component;

expect(getByText('This week')).toBeInTheDocument();
expect(getByText('Last month')).toBeInTheDocument();
Expand All @@ -73,8 +73,8 @@ describe('DashboardPage component', () => {
expect(getByText('Classes scheduled')).toBeInTheDocument();
expect(getByText('License inventory')).toBeInTheDocument();
expect(getByText('Instructor assignment')).toBeInTheDocument();
expect(getByText('ccx 1')).toBeInTheDocument();
expect(getByText('Demo Course 1')).toBeInTheDocument();
expect(getAllByText('ccx 1')[0]).toBeInTheDocument();
expect(getAllByText('Demo Course 1')[0]).toBeInTheDocument();
expect(getByText('License Name 1')).toBeInTheDocument();
expect(getByText('Class schedule')).toBeInTheDocument();
expect(getByText('No classes scheduled at this time')).toBeInTheDocument();
Expand Down
12 changes: 12 additions & 0 deletions src/features/Dashboard/DashboardPage/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
min-height: 426px;
}

.responsive {
display: none;
}

.schedule-section {
margin-bottom: 2rem;
}
Expand Down Expand Up @@ -53,4 +57,12 @@
.instructor-assign-section {
min-height: 200px;
}

.no-responsive {
display: none;
}

.responsive {
display: block;
}
}
22 changes: 20 additions & 2 deletions src/features/Dashboard/InstructorAssignSection/ClassCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import { Button } from 'react-paragon-topaz';
import { formatDateRange } from 'helpers';
import { useInstitutionIdQueryParam } from 'hooks';

import EllipsisText from 'features/Dashboard/InstructorAssignSection/EllipsisText';
import { textLength } from 'features/constants';

import 'features/Dashboard/InstructorAssignSection/index.scss';

const ClassCard = ({ data }) => {
Expand All @@ -19,8 +22,23 @@ const ClassCard = ({ data }) => {

return (
<div className="class-card-container">
<h4>{data?.className}</h4>
<p className="course-name">{data?.masterCourseName}</p>
<div className="no-responsive">
{data?.className.length > textLength ? (
<EllipsisText title={data?.className} type="className" />
) : (
<h4>{data?.className}</h4>
)}
{data?.masterCourseName.length > textLength ? (
<EllipsisText title={data?.masterCourseName} type="courseName" />
) : (
<p className="course-name">{data?.masterCourseName}</p>
)}
</div>
<div className="responsive">
<h4>{data?.className}</h4>
<p className="course-name">{data?.masterCourseName}</p>
</div>

<p className="date"><i className="fa-sharp fa-regular fa-calendar-day" />{formatDateRange(data.startDate, data?.endDate)}</p>
<Button variant="outline-primary" size="sm" onClick={handleManageButton}>
<i className="fa-regular fa-chalkboard-user" />
Expand Down
32 changes: 32 additions & 0 deletions src/features/Dashboard/InstructorAssignSection/EllipsisText.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import PropTypes from 'prop-types';
import { Tooltip, OverlayTrigger } from '@edx/paragon';

import { textLength } from 'features/constants';

const EllipsisText = ({ title, type }) => (
<OverlayTrigger
placement={type === 'className' ? 'top' : 'bottom'}
overlay={
(
<Tooltip>
{title}
</Tooltip>
)
}
trigger={['hover', 'focus']}
show={undefined}
>
{type === 'className' ? (
<h4>{title.substring(0, textLength)}...</h4>
) : (
<p className="course-name">{title.substring(0, textLength)}...</p>
)}
</OverlayTrigger>
);

EllipsisText.propTypes = {
title: PropTypes.string.isRequired,
type: PropTypes.string.isRequired,
};

export default EllipsisText;
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ describe('Instructor Assign component', () => {
);

test('renders components', () => {
const { getByText } = component;
const { getByText, getAllByText } = component;

expect(getByText('Instructor assignment')).toBeInTheDocument();
expect(getByText('ccx 1')).toBeInTheDocument();
expect(getByText('Demo Course 1')).toBeInTheDocument();
expect(getByText('Jan 23, 2024')).toBeInTheDocument();
expect(getAllByText('ccx 1')[0]).toBeInTheDocument();
expect(getAllByText('Demo Course 1')[0]).toBeInTheDocument();
expect(getAllByText('Jan 23, 2024')[0]).toBeInTheDocument();
expect(getByText('Manage instructor')).toBeInTheDocument();
});
});
7 changes: 7 additions & 0 deletions src/features/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,10 @@ export const cookieText = 'This website uses cookies to ensure you get the best
* @constant {string}
*/
export const unauthorizedText = 'You do not have access to CertPREP Manager. If you believe you should have access then please contact your sales rep.';

/**
* Constant for text length.
* @readonly
* @number
*/
export const textLength = 20;
Loading