Skip to content

Commit

Permalink
[JN-682] add tabs to site content editor (#610)
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewBemis authored Oct 30, 2023
1 parent 7255f7a commit 912f623
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 9 deletions.
14 changes: 14 additions & 0 deletions ui-admin/src/portal/siteContent/SiteContentEditor.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,17 @@ test('readOnly hides save button', async () => {
expect(screen.getByText('Landing page')).toBeInTheDocument()
expect(screen.queryByText('Save')).not.toBeInTheDocument()
})

test('clicking on the Preview tab shows full page preview', async () => {
const siteContent = mockSiteContent()
const { RoutedComponent } = setupRouterTest(
<SiteContentEditor siteContent={siteContent} previewApi={emptyApi} readOnly={false}
loadSiteContent={jest.fn()} createNewVersion={jest.fn()} portalShortcode="foo"
switchToVersion={jest.fn()}
portalEnv={mockPortalEnvironment('sandbox')}/>)
render(RoutedComponent)

await userEvent.click(screen.getByText('Preview'))
expect(screen.queryByText('Insert section')).not.toBeInTheDocument()
expect(screen.queryByText('we are the best')).toBeInTheDocument()
})
50 changes: 41 additions & 9 deletions ui-admin/src/portal/siteContent/SiteContentEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import React, { useState } from 'react'
import { NavbarItemInternal, PortalEnvironment } from 'api/api'
import { HtmlSection, NavbarItemInternal, PortalEnvironment } from 'api/api'
import Select from 'react-select'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { faClockRotateLeft, faImage, faPlus } from '@fortawesome/free-solid-svg-icons'
import HtmlPageEditView from './HtmlPageEditView'
import { HtmlPage, LocalSiteContent, ApiProvider, SiteContent, ApiContextT } from '@juniper/ui-core'
import { HtmlPage, LocalSiteContent, ApiProvider, SiteContent, ApiContextT, HtmlSectionView } from '@juniper/ui-core'
import { Link } from 'react-router-dom'
import SiteContentVersionSelector from './SiteContentVersionSelector'
import { Button } from '../../components/forms/Button'
import { Button } from 'components/forms/Button'
import AddPageModal from './AddPageModal'
import ErrorBoundary from 'util/ErrorBoundary'
import { Tab, Tabs } from 'react-bootstrap'

type NavbarOption = {label: string, value: string}
const landingPageOption = { label: 'Landing page', value: 'Landing page' }
Expand All @@ -31,6 +33,7 @@ const SiteContentEditor = (props: InitializedSiteContentViewProps) => {
portalEnv, loadSiteContent, switchToVersion, createNewVersion, readOnly
} = props
const selectedLanguage = 'en'
const [activeTab, setActiveTab] = useState<string | null>('designer')
const [selectedNavOpt, setSelectedNavOpt] = useState<NavbarOption>(landingPageOption)
const [workingContent, setWorkingContent] = useState<SiteContent>(siteContent)
const [showVersionSelector, setShowVersionSelector] = useState(false)
Expand Down Expand Up @@ -160,12 +163,41 @@ const SiteContentEditor = (props: InitializedSiteContentViewProps) => {
</div>

</div>
<div>
{pageToRender &&
<ApiProvider api={previewApi}>
<HtmlPageEditView htmlPage={pageToRender} readOnly={readOnly}
updatePage={page => updatePage(page, currentNavBarItem?.text)}/>
</ApiProvider>}
<div className="d-flex flex-column flex-grow-1 mt-2">
<Tabs
activeKey={activeTab ?? undefined}
className="mb-1"
mountOnEnter
unmountOnExit
onSelect={setActiveTab}
>
<Tab
eventKey="designer"
title="Designer"
>
<ErrorBoundary>
<div>
{pageToRender &&
<ApiProvider api={previewApi}>
<HtmlPageEditView htmlPage={pageToRender} readOnly={readOnly}
updatePage={page => updatePage(page, currentNavBarItem?.text)}/>
</ApiProvider>}
</div>
</ErrorBoundary>
</Tab>
<Tab
eventKey="preview"
title="Preview"
>
<ErrorBoundary>
<ApiProvider api={previewApi}>
{ pageToRender.sections.map((section: HtmlSection) =>
<HtmlSectionView section={section} key={section.id}/>)
}
</ApiProvider>
</ErrorBoundary>
</Tab>
</Tabs>
</div>
</div>
{ showVersionSelector &&
Expand Down

0 comments on commit 912f623

Please sign in to comment.