Skip to content

Commit

Permalink
feat: use new Data view toggle in datatable ENT-5242 (#180)
Browse files Browse the repository at this point in the history
* feat: use new Data view toggle in datatable

wip since it requires new Paragon release

ENT-5242

* feat: remove feature flag cardViewEnabled

* feat: upgrade to paragon 17.3.0

* feat: test fix
  • Loading branch information
binodpant committed Jan 5, 2022
1 parent 8c0659a commit 6ad8b53
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 26 deletions.
18 changes: 9 additions & 9 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"@edx/frontend-component-header": "2.4.1",
"@edx/frontend-enterprise-catalog-search": "2.2.5",
"@edx/frontend-platform": "1.14.3",
"@edx/paragon": "^17.2.0",
"@edx/paragon": "^17.3.0",
"@fortawesome/fontawesome-svg-core": "1.2.35",
"@fortawesome/free-brands-svg-icons": "5.15.3",
"@fortawesome/free-regular-svg-icons": "5.15.3",
Expand Down
19 changes: 11 additions & 8 deletions src/components/catalogSearchResults/CatalogSearchResults.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
import { SearchContext, SearchPagination } from '@edx/frontend-enterprise-catalog-search';
import { FormattedMessage, injectIntl, intlShape } from '@edx/frontend-platform/i18n';

import { getConfig } from '@edx/frontend-platform';
import { GridView, ListView } from '@edx/paragon/icons';

import CourseCard from '../courseCard/CourseCard';
Expand Down Expand Up @@ -163,10 +162,7 @@ export const BaseCatalogSearchResults = ({
const [upcomingRuns, setUpcomingRuns] = useState();
const [skillNames, setSkillNames] = useState([]);

// TODO: Feature control for Card view. Remove once cards are finalized
const config = getConfig();
const cardViewEnabled = config.FEATURE_CARD_VIEW_ENABLED === 'True';
const [cardView, setCardView] = useState(cardViewEnabled);
const [cardView, setCardView] = useState(true);

const rowClicked = (row) => {
const rowPrice = row.original.first_enrollable_paid_seat_price;
Expand Down Expand Up @@ -283,8 +279,13 @@ export const BaseCatalogSearchResults = ({
upcomingRuns={upcomingRuns}
skillNames={skillNames}
/>
{ cardViewEnabled && <ViewToggle cardView={cardView} setCardView={setCardView} /> }
<DataTable
dataViewToggleOptions={{
isDataViewToggleEnabled: true,
onDataViewToggle: val => setCardView(val === 'card'),
togglePlacement: 'left',
defaultActiveStateValue: 'card',
}}
columns={columns}
data={tableData}
itemCount={searchResults?.nbHits}
Expand All @@ -299,7 +300,7 @@ export const BaseCatalogSearchResults = ({
)}
>
<DataTable.TableControlBar />
{ cardViewEnabled && cardView ? (
{ cardView && (
<CardView
columnSizes={{
xs: 12,
Expand All @@ -310,7 +311,9 @@ export const BaseCatalogSearchResults = ({
}}
CardComponent={(props) => <CourseCard {...props} onClick={cardClicked} />}
/>
) : <DataTable.Table /> }
)}
{ !cardView && <DataTable.Table /> }

<DataTable.TableFooter>
<DataTable.RowStatus />
<PaginationComponent defaultRefinement={page} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ describe('Main Catalogs view works as expected', () => {
</SearchDataWrapper>,
);

// switch to table view instead of card
const listViewToggleButton = screen.getByLabelText('List view');
// Card view should be default
const listViewToggleButton = screen.getByLabelText('Card');
userEvent.click(listViewToggleButton);

// course 1
Expand All @@ -128,8 +128,8 @@ describe('Main Catalogs view works as expected', () => {
);

// view selection toggle buttons
expect(screen.getByLabelText('Card view')).toBeVisible();
expect(screen.getByLabelText('List view')).toBeVisible();
expect(screen.getByLabelText('Card')).toBeVisible();
expect(screen.getByLabelText('List')).toBeVisible();

// since card view feature is on, card view should be the default!
const table = screen.queryByRole('table');
Expand Down Expand Up @@ -206,7 +206,7 @@ describe('Main Catalogs view works as expected', () => {
);

// switch to table view instead of card
const listViewToggleButton = screen.getByLabelText('List view');
const listViewToggleButton = screen.getByLabelText('List');
userEvent.click(listViewToggleButton);

expect(screen.queryByText(messages['catalogSearchResults.table.courseName'].defaultMessage)).toBeInTheDocument();
Expand All @@ -227,7 +227,7 @@ describe('Main Catalogs view works as expected', () => {
/>
</SearchDataWrapper>,
);
const listViewToggleButton = screen.getByLabelText('List view');
const listViewToggleButton = screen.getByLabelText('List');
userEvent.click(listViewToggleButton);

expect(screen.queryByText(messages['catalogSearchResults.table.courseName'].defaultMessage)).toBeInTheDocument();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const DownloadCsvButton = ({ facets, query }) => {
)}
<StatefulButton
state={buttonState}
className="download-button"
className="ml-2 download-button"
labels={{
default: 'Download results',
pending: 'Downloading',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.download-button{
.download-button {
background-color: $primary-500;
}

0 comments on commit 6ad8b53

Please sign in to comment.