Skip to content

Commit

Permalink
refactor: add layout
Browse files Browse the repository at this point in the history
  • Loading branch information
rpenido committed Oct 25, 2023
1 parent bfa0953 commit 87808bb
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 159 deletions.
4 changes: 2 additions & 2 deletions src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import CourseAuthoringRoutes from './CourseAuthoringRoutes';
import Head from './head/Head';
import { StudioHome } from './studio-home';
import CourseRerun from './course-rerun';
import { TaxonomyDetailPage, TaxonomyListPage } from './taxonomy';
import { TaxonomyLayout, TaxonomyDetailPage, TaxonomyListPage } from './taxonomy';

import 'react-datepicker/dist/react-datepicker.css';
import './index.scss';
Expand Down Expand Up @@ -53,7 +53,7 @@ const App = () => {
<Route path="/course/:courseId/*" element={<CourseAuthoringRoutes />} />
<Route path="/course_rerun/:courseId" element={<CourseRerun />} />
{process.env.ENABLE_TAGGING_TAXONOMY_PAGES === 'true' && (
<Route path="/taxonomy-list">
<Route path="/taxonomy-list" element={<TaxonomyLayout />}>
<Route index element={<TaxonomyListPage />} />
<Route path="/taxonomy-list/:taxonomyId" element={<TaxonomyDetailPage />} />
</Route>
Expand Down
21 changes: 21 additions & 0 deletions src/taxonomy/TaxonomyLayout.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { StudioFooter } from '@edx/frontend-component-footer';
import { Outlet } from 'react-router-dom';

import Header from '../header';

const TaxonomyLayout = () => (
<>
<style>
{`
body {
background-color: #E9E6E4; /* light-400 */
}
`}
</style>
<Header isHiddenMainMenu />
<Outlet />
<StudioFooter />
</>
);

export default TaxonomyLayout;
11 changes: 0 additions & 11 deletions src/taxonomy/TaxonomyListPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import {
Spinner,
} from '@edx/paragon';
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';
import { StudioFooter } from '@edx/frontend-component-footer';
import Header from '../header';
import SubHeader from '../generic/sub-header/SubHeader';
import messages from './messages';
import TaxonomyCard from './taxonomy-card/TaxonomyCard';
Expand Down Expand Up @@ -36,14 +34,6 @@ const TaxonomyListPage = ({ intl }) => {

return (
<>
<style>
{`
body {
background-color: #E9E6E4; /* light-400 */
}
`}
</style>
<Header isHiddenMainMenu />
<div className="pt-4.5 pr-4.5 pl-4.5 pb-2 bg-light-100 box-shadow-down-2">
<Container size="xl">
<SubHeader
Expand Down Expand Up @@ -92,7 +82,6 @@ const TaxonomyListPage = ({ intl }) => {
)}
</Container>
</div>
<StudioFooter />
</>
);
};
Expand Down
1 change: 1 addition & 0 deletions src/taxonomy/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { default as TaxonomyListPage } from './TaxonomyListPage';
export { default as TaxonomyLayout } from './TaxonomyLayout';
export { default as TaxonomyDetailPage } from './taxonomy-detail/TaxonomyDetailPage';
127 changes: 0 additions & 127 deletions src/taxonomy/taxonomy-detail/TaxonomyDetailContent.jsx

This file was deleted.

145 changes: 126 additions & 19 deletions src/taxonomy/taxonomy-detail/TaxonomyDetailPage.jsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,128 @@
import { StudioFooter } from '@edx/frontend-component-footer';

import Header from '../../header';
import TaxonomyDetailContent from './TaxonomyDetailContent';

const TaxonomyDetailPage = () => (
<>
<style>
{`
body {
background-color: #E9E6E4; /* light-400 */
}
`}
</style>
<Header isHiddenMainMenu />
<TaxonomyDetailContent />
<StudioFooter />
</>
);
import React, { useState } from 'react';
import {
Breadcrumb,
Container,
Layout,
} from '@edx/paragon';
import { Link, useParams } from 'react-router-dom';

import PermissionDeniedAlert from '../../generic/PermissionDeniedAlert';
import Loading from '../../generic/Loading';
import SubHeader from '../../generic/sub-header/SubHeader';
import TaxonomyDetailMenu from './TaxonomyDetailMenu';
import TaxonomyDetailSideCard from './TaxonomyDetailSideCard';
import TagListTable from './TagListTable';
import ExportModal from '../modals/ExportModal';
import { useTaxonomyDetailDataResponse, useTaxonomyDetailDataStatus } from '../api/hooks/selectors';

const TaxonomyDetailPage = () => {
const { taxonomyId } = useParams();

const useTaxonomyDetailData = () => {
const { isError, isFetched } = useTaxonomyDetailDataStatus(taxonomyId);
const taxonomy = useTaxonomyDetailDataResponse(taxonomyId);
return { isError, isFetched, taxonomy };
};

const { isError, isFetched, taxonomy } = useTaxonomyDetailData(taxonomyId);

const [isExportModalOpen, setIsExportModalOpen] = useState(false);

if (isError) {
return (
<PermissionDeniedAlert />
);
}

if (!isFetched) {
return (
<Loading />
);
}

const renderModals = () => (
// eslint-disable-next-line react/jsx-no-useless-fragment
<>
{isExportModalOpen && (
<ExportModal
isOpen={isExportModalOpen}
onClose={() => setIsExportModalOpen(false)}
taxonomyId={taxonomyId}
taxonomyName={taxonomy.name}
/>
)}
</>
);

const onClickMenuItem = (menuName) => {
switch (menuName) {
case 'export':
setIsExportModalOpen(true);
break;
default:
break;
}
};

const getHeaderActions = () => (
<TaxonomyDetailMenu
id={taxonomy.id}
name={taxonomy.name}
disabled={
// We don't show the export menu, because the system-taxonomies
// can't be exported. The API returns and error.
// The entire menu has been disabled because currently only
// the export menu exists.
// ToDo: When adding more menus, change this logic to hide only the export menu.
taxonomy.systemDefined
}
onClickMenuItem={onClickMenuItem}
/>
);

if (taxonomy) {
return (
<>
<div className="pt-4.5 pr-4.5 pl-4.5 pb-2 bg-light-100 box-shadow-down-2">
<Container size="xl">
<Breadcrumb
links={[
{ label: 'Taxonomies', to: '/taxonomy-list/' },
]}
activeLabel={taxonomy.name}
linkAs={Link}
/>
<SubHeader
title={taxonomy.name}
hideBorder
headerActions={getHeaderActions()}
/>
</Container>
</div>
<div className="bg-light-400 m-4">
<Container size="xl">
<Layout
lg={[{ span: 9 }, { span: 3 }]}
md={[{ span: 9 }, { span: 3 }]}
sm={[{ span: 9 }, { span: 3 }]}
xs={[{ span: 9 }, { span: 3 }]}
xl={[{ span: 9 }, { span: 3 }]}
>
<Layout.Element>
<TagListTable taxonomyId={taxonomyId} />
</Layout.Element>
<Layout.Element>
<TaxonomyDetailSideCard taxonomy={taxonomy} />
</Layout.Element>
</Layout>
</Container>
</div>
{renderModals()}
</>
);
}

return undefined;
};

export default TaxonomyDetailPage;

0 comments on commit 87808bb

Please sign in to comment.