-
Notifications
You must be signed in to change notification settings - Fork 2
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
Feature/ Consoles - Extract console tabs into components #2189
Open
xkopenreview
wants to merge
4
commits into
master
Choose a base branch
from
feature/extract-console-tab
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+361
−469
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { useEffect, useState } from 'react' | ||
import { useRouter } from 'next/router' | ||
import { Tab, TabList, TabPanel, TabPanels, Tabs } from '../Tabs' | ||
|
||
const ConsoleTabs = ({ defaultActiveTabId, tabs = [], updateActiveTabId }) => { | ||
const validTabIds = tabs.flatMap((tab) => (tab.visible ? tab.id : [])) | ||
const [activeTabId, setActiveTabId] = useState( | ||
decodeURIComponent(window.location.hash.substring(1)) || | ||
defaultActiveTabId || | ||
validTabIds[0] | ||
) | ||
const router = useRouter() | ||
|
||
useEffect(() => { | ||
if (!validTabIds.includes(activeTabId)) { | ||
setActiveTabId(defaultActiveTabId) | ||
updateActiveTabId?.(`#${defaultActiveTabId}`) | ||
return | ||
} | ||
updateActiveTabId?.(`#${activeTabId}`) | ||
router.replace(`#${activeTabId}`).catch((e) => { | ||
if (!e.cancelled) { | ||
throw e | ||
} | ||
}) | ||
}, [activeTabId]) | ||
|
||
return ( | ||
<Tabs> | ||
<TabList> | ||
{tabs.map((tab) => { | ||
const { id, label, visible } = tab | ||
if (!visible) return null | ||
return ( | ||
<Tab | ||
key={id} | ||
id={id} | ||
active={activeTabId === id ? true : undefined} | ||
onClick={() => setActiveTabId(id)} | ||
> | ||
{label} | ||
</Tab> | ||
) | ||
})} | ||
</TabList> | ||
<TabPanels> | ||
{tabs.map((tab) => { | ||
const { id, content, visible } = tab | ||
if (!visible || activeTabId !== `${id}`) return null | ||
return ( | ||
<TabPanel key={id} id={id}> | ||
{content} | ||
</TabPanel> | ||
) | ||
})} | ||
</TabPanels> | ||
</Tabs> | ||
) | ||
} | ||
|
||
export default ConsoleTabs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
/* globals promptError: false */ | ||
import { useContext, useEffect, useState } from 'react' | ||
import { useContext, useEffect } from 'react' | ||
import { useRouter } from 'next/router' | ||
import useUser from '../../hooks/useUser' | ||
import useQuery from '../../hooks/useQuery' | ||
import { Tab, TabList, TabPanel, TabPanels, Tabs } from '../Tabs' | ||
import { referrerLink, venueHomepageLink } from '../../lib/banner-links' | ||
import WebFieldContext from '../WebFieldContext' | ||
import BasicHeader from './BasicHeader' | ||
|
@@ -12,6 +11,7 @@ import EthicsChairOverview from './EthicsChairConsole/EthicsChairOverview' | |
import PaperStatus from './EthicsChairConsole/EthicsChairPaperStatus' | ||
import EthicsChairTasks from './EthicsChairConsole/EthicsChairTasks' | ||
import { getRoleHashFragment } from '../../lib/utils' | ||
import ConsoleTabs from './ConsoleTabs' | ||
|
||
const EthicsChairConsole = ({ appContext }) => { | ||
const { | ||
|
@@ -31,17 +31,9 @@ const EthicsChairConsole = ({ appContext }) => { | |
const { setBannerContent } = appContext | ||
const router = useRouter() | ||
const query = useQuery() | ||
const [activeTabId, setActiveTabId] = useState( | ||
decodeURIComponent(window.location.hash) || '#overview' | ||
) | ||
const { user, userLoading } = useUser() | ||
|
||
const ethicsChairsUrlFormat = getRoleHashFragment(ethicsChairsName) | ||
const validTabIds = [ | ||
'#overview', | ||
`#${submissionName.toLowerCase()}-status`, | ||
`#${ethicsChairsUrlFormat}-tasks`, | ||
] | ||
|
||
useEffect(() => { | ||
if (!query) return | ||
|
@@ -53,14 +45,6 @@ const EthicsChairConsole = ({ appContext }) => { | |
} | ||
}, [query, venueId]) | ||
|
||
useEffect(() => { | ||
if (!validTabIds.includes(activeTabId)) { | ||
setActiveTabId(validTabIds[0]) | ||
return | ||
} | ||
router.replace(activeTabId) | ||
}, [activeTabId]) | ||
|
||
const missingConfig = Object.entries({ | ||
header, | ||
entity: group, | ||
|
@@ -85,45 +69,29 @@ const EthicsChairConsole = ({ appContext }) => { | |
return ( | ||
<> | ||
<BasicHeader title={header?.title} instructions={header.instructions} /> | ||
<Tabs> | ||
<TabList> | ||
<Tab | ||
id="overview" | ||
active={activeTabId === '#overview' ? true : undefined} | ||
onClick={() => setActiveTabId('#overview')} | ||
> | ||
Overview | ||
</Tab> | ||
<Tab | ||
id={`${submissionName.toLowerCase()}-status`} | ||
active={ | ||
activeTabId === `#${submissionName.toLowerCase()}-status` ? true : undefined | ||
} | ||
onClick={() => setActiveTabId(`#${submissionName.toLowerCase()}-status`)} | ||
> | ||
{submissionName} Status | ||
</Tab> | ||
<Tab | ||
id={`${ethicsChairsUrlFormat}-tasks`} | ||
active={activeTabId === `#${ethicsChairsUrlFormat}-tasks` ? true : undefined} | ||
onClick={() => setActiveTabId(`#${ethicsChairsUrlFormat}-tasks`)} | ||
> | ||
Ethics Chair Tasks | ||
</Tab> | ||
</TabList> | ||
|
||
<TabPanels> | ||
<TabPanel id="overview"> | ||
<EthicsChairOverview /> | ||
</TabPanel> | ||
<TabPanel id={`${submissionName.toLowerCase()}-status`}> | ||
{activeTabId === `#${submissionName.toLowerCase()}-status` && <PaperStatus />} | ||
</TabPanel> | ||
<TabPanel id={`${ethicsChairsUrlFormat}-tasks`}> | ||
{activeTabId === `#${ethicsChairsUrlFormat}-tasks` && <EthicsChairTasks />} | ||
</TabPanel> | ||
</TabPanels> | ||
</Tabs> | ||
<ConsoleTabs | ||
defaultActiveTabId="overview" | ||
tabs={[ | ||
Comment on lines
+72
to
+74
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The AC and Reviewer console have |
||
{ | ||
id: 'overview', | ||
label: 'Overview', | ||
content: <EthicsChairOverview />, | ||
visible: true, | ||
}, | ||
{ | ||
id: `${submissionName.toLowerCase()}-status`, | ||
label: `${submissionName} Status`, | ||
content: <PaperStatus />, | ||
visible: true, | ||
}, | ||
{ | ||
id: `${ethicsChairsUrlFormat}-tasks`, | ||
label: 'Ethics Chair Tasks', | ||
content: <EthicsChairTasks />, | ||
visible: true, | ||
}, | ||
]} | ||
/> | ||
</> | ||
) | ||
} | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to call
updateActiveTabId
here? I think whensetActiveTabId
is called it will trigger useEffect again with a valid (default) tab, so the parent's state would already get updated in line 20 with the default. What do you think?