Skip to content

Commit

Permalink
PagesEditor: implement WorkflowHeaderTabs
Browse files Browse the repository at this point in the history
  • Loading branch information
shaunanoordin committed Jan 8, 2025
1 parent 4d513c8 commit 8acccb1
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 83 deletions.
18 changes: 5 additions & 13 deletions app/pages/lab-pages-editor/PagesEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { StrictMode, useState } from 'react';
import PropTypes from 'prop-types';

import DataManager from './DataManager.jsx';
import WorkflowTabs from './components/WorkflowTabs.jsx';
import WorkflowHeaderTabs from './components/WorkflowHeaderTabs.jsx';
import WorkflowTopLinks from './components/WorkflowTopLinks.jsx';
import TasksPage from './components/TasksPage';
import WorkflowSettingsPage from './components/WorkflowSettingsPage';
Expand All @@ -32,11 +32,11 @@ function PagesEditor({ params }) {
const tabs = [
{
id: 'pages-editor_workflow-header-tab-button_task',
label: strings.PagesEditor.components.WorkflowTabs.tasks,
label: strings.PagesEditor.components.WorkflowHeaderTabs.tasks,
targetPanel: 'pages-editor_tab-panel_task'
}, {
id: 'pages-editor_workflow-header-tab-button_settings',
label: strings.PagesEditor.components.WorkflowTabs.workflow_settings,
label: strings.PagesEditor.components.WorkflowHeaderTabs.workflow_settings,
targetPanel: 'pages-editor_tab-panel_settings'
}
];
Expand All @@ -49,20 +49,12 @@ function PagesEditor({ params }) {
projectId={projectId}
workflowId={workflowId}
>
<WorkflowTopLinks
<WorkflowTopLinks />
<WorkflowHeaderTabs
currentTab={currentTab}
projectId={projectId}
setCurrentTab={setCurrentTab}
tabs={tabs}
/>
{/*
<WorkflowTabs
currentTab={currentTab}
projectId={projectId}
setCurrentTab={setCurrentTab}
tabs={tabs}
/>
*/}
{(currentTab === 0) && (
<div
aria-labelledby={tabs[0].id}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
import PropTypes from 'prop-types';

import getPreviewEnv from '../helpers/getPreviewEnv.js';
import ExternalLinkIcon from '../icons/ExternalLinkIcon.jsx';
import ReturnIcon from '../icons/ReturnIcon.jsx';
import { useWorkflowContext } from '../context.js';
import strings from '../strings.json';

const DEFAULT_HANDLER = () => {};

export default function WorkflowHeader({
currentTab = 0,
projectId = '',
setCurrentTab = DEFAULT_HANDLER,
tabs = []
}) {
const { project, workflow } = useWorkflowContext();
const returnUrl = `/lab/${projectId}/workflows`;
const previewEnv = getPreviewEnv();
const previewUrl = `https://frontend.preview.zooniverse.org/projects/${project?.slug}/classify/workflow/${workflow?.id}${previewEnv}`;

const { workflow } = useWorkflowContext();

// When clicking a tab button, make that tab active. This is pretty straightforward.
function onClick(e) {
const { tab } = e?.target?.dataset || {};
Expand Down Expand Up @@ -47,46 +38,29 @@ export default function WorkflowHeader({
if (!workflow) return null;

return (
<div className="workflow-header">
<div className="workflow-header-top">
<a href={returnUrl}> {/* Formerly <Link> from 'react-router', but React was throwing Legacy Context errors. */}
<ReturnIcon />
{strings.PagesEditor.components.WorkflowHeader.return}
</a>
<span className="flex-item" />
<a
className="button-link"
href={previewUrl}
rel="noopener noreferrer"
target='_blank'
>
Preview Workflow <ExternalLinkIcon />
</a>
</div>
<div
role="tablist"
className="workflow-header-tabs flex-row flex-item justify-around"
>
{tabs.map((tab, index) => (
<TabButton
id={tab.id}
index={index}
key={`${tab.id}`}
label={tab.label}
onClick={onClick}
onKeyUp={onKeyUp}
selected={(currentTab === index)}
targetPanel={tab.targetPanel}
/>
))}
</div>

<div
role="tablist"
className="workflow-header-tabs"
>
{tabs.map((tab, index) => (
<TabButton
id={tab.id}
index={index}
key={`${tab.id}`}
label={tab.label}
onClick={onClick}
onKeyUp={onKeyUp}
selected={(currentTab === index)}
targetPanel={tab.targetPanel}
/>
))}
</div>
);
}

WorkflowHeader.propTypes = {
currentTab: PropTypes.number,
projectId: PropTypes.string,
setCurrentTab: PropTypes.func,
tabs: PropTypes.arrayOf(
PropTypes.shape({
Expand Down
2 changes: 1 addition & 1 deletion app/pages/lab-pages-editor/strings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"PagesEditor": {
"components": {
"WorkflowTabs": {
"WorkflowHeaderTabs": {
"tasks": "Tasks",
"workflow_settings": "Workflow Settings"
},
Expand Down
43 changes: 19 additions & 24 deletions css/lab-pages-editor.styl
Original file line number Diff line number Diff line change
Expand Up @@ -210,32 +210,27 @@ $fontWeightBoldPlus = 700
.zooniverse-logo
max-width: 160px

.workflow-header
margin-bottom: $sizeXL

a
min-width: 40%

.workflow-header-tabs
main-content()
gap: $sizeXL
justify-content: center
border-bottom: 0.5px solid $grey1
.workflow-header-tabs
main-content()
flex-row()
justify-content: center
gap: $sizeXL
border-bottom: 0.5px solid $grey1

button
background: none
border: none
cursor: pointer
font-size: $fontSizeL
font-weight: $fontWeightBoldPlus
text-transform: uppercase
button
background: none
border: none
cursor: pointer
font-size: $fontSizeL
font-weight: $fontWeightBoldPlus
text-transform: uppercase

&[aria-selected=true]
border-bottom: 4px solid $teal
&[aria-selected=false]
color: $grey1
border-bottom: 4px solid transparent
&[aria-selected=true]
border-bottom: 4px solid $teal

&[aria-selected=false]
color: $grey1
border-bottom: 4px solid transparent

// Component: Workflow Settings Page
// ---------------------------------------------------------------------------
Expand Down

0 comments on commit 8acccb1

Please sign in to comment.