Skip to content

Commit

Permalink
Merge pull request #332 from kbss-cvut/enable-wizard-forward
Browse files Browse the repository at this point in the history
Changed default behavior to allow skip of wizard step
  • Loading branch information
blcham committed Apr 19, 2024
2 parents 6216dd6 + f4fd276 commit b76add4
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 45 deletions.
1 change: 0 additions & 1 deletion .storybook/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ const options = {
modalView: false,
horizontalWizardNav: false,
wizardStepButtons: true,
enableForwardSkip: true,
startingStep: 1,
debugMode: false,
users: [
Expand Down
1 change: 0 additions & 1 deletion src/components/HelpIcon.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { useState } from "react";
import PropTypes from "prop-types";
import { Tooltip } from "react-bootstrap";
import { QuestionCircle } from "../styles/icons";
import IconOverlay from "./IconOverlay.jsx";

Expand Down
6 changes: 5 additions & 1 deletion src/components/IconOverlay.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ const IconOverlay = (props) => {
} else setOverlayPlacement("right");
};

const tooltip = (
const tooltip = props.show ? (
<Tooltip className="tooltip-content" id={props.id}>
{props.tooltipContent}
</Tooltip>
) : (
<span />
);

return (
Expand All @@ -39,12 +41,14 @@ IconOverlay.propTypes = {
id: PropTypes.string.isRequired,
overlayPlacement: PropTypes.string,
absolutePosition: PropTypes.bool,
show: PropTypes.bool,
};

IconOverlay.defaultProps = {
iconClassContainer: "",
iconClass: "",
absolutePosition: true,
show: true,
};

export default IconOverlay;
46 changes: 28 additions & 18 deletions src/components/wizard/HorizontalWizardNav.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ import FormUtils from "../../util/FormUtils";
import { ConfigurationContext } from "../../contexts/ConfigurationContext";
import Question from "../Question";
import classNames from "classnames";
import IconOverlay from "../IconOverlay.jsx";
import { useIntl } from "react-intl";

const HorizontalWizardNav = ({ steps, onNavigate, currentStep }) => {
const { options } = useContext(ConfigurationContext);
const intl = useIntl();

return (
<Card.Header>
Expand All @@ -18,24 +21,31 @@ const HorizontalWizardNav = ({ steps, onNavigate, currentStep }) => {
onSelect={(key) => onNavigate(parseInt(key))}
>
{steps.map((step, index) => (
<NavItem key={"nav" + index} id={"wizard-nav-" + index}>
<NavLink
eventKey={index}
active={index === currentStep ? "active" : ""}
hidden={options.debugMode ? false : !FormUtils.isRelevant(step)}
className={classNames([
options.debugMode && !FormUtils.isRelevant(step)
? "show-irrelevant"
: Question.getEmphasizedClass(step),
"wizard-nav",
])}
>
{JsonLdUtils.getLocalized(
step[JsonLdUtils.RDFS_LABEL],
options.intl
)}
</NavLink>
</NavItem>
<IconOverlay
id="step-disabled"
tooltipContent={intl.formatMessage({ id: "wizard.nav.tooltip" })}
show={!options.enableWizardStepSkip}
>
<NavItem key={"nav" + index} id={"wizard-nav-" + index}>
<NavLink
eventKey={index}
active={index === currentStep ? "active" : ""}
hidden={options.debugMode ? false : !FormUtils.isRelevant(step)}
disabled={!options.enableWizardStepSkip}
className={classNames([
options.debugMode && !FormUtils.isRelevant(step)
? "show-irrelevant"
: Question.getEmphasizedClass(step),
"wizard-nav",
])}
>
{JsonLdUtils.getLocalized(
step[JsonLdUtils.RDFS_LABEL],
options.intl
)}
</NavLink>
</NavItem>
</IconOverlay>
))}
</Nav>
</Card.Header>
Expand Down
48 changes: 29 additions & 19 deletions src/components/wizard/VerticalWizardNav.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,44 @@ import { ConfigurationContext } from "../../contexts/ConfigurationContext";
import FormUtils from "../../util/FormUtils";
import Question from "../Question";
import classNames from "classnames";
import IconOverlay from "../IconOverlay.jsx";
import { useIntl } from "react-intl";

const VerticalWizardNav = ({ steps, onNavigate, currentStep }) => {
const { options } = useContext(ConfigurationContext);
const intl = useIntl();

return (
<div className="wizard-nav col-2 p-0">
<ListGroup>
{steps.map((step, index) => (
<ListGroupItem
hidden={options.debugMode ? false : !FormUtils.isRelevant(step)}
key={"nav" + index}
onClick={() => onNavigate(index)}
id={"wizard-nav-" + index}
action={true}
active={index === currentStep ? "active" : ""}
variant={"default"}
className={classNames([
options.debugMode && !FormUtils.isRelevant(step)
? "show-irrelevant"
: Question.getEmphasizedClass(step),
"wizard-nav",
])}
<IconOverlay
id="step-disabled"
tooltipContent={intl.formatMessage({ id: "wizard.nav.tooltip" })}
show={!options.enableWizardStepSkip}
>
{JsonLdUtils.getLocalized(
step[JsonLdUtils.RDFS_LABEL],
options.intl
)}
</ListGroupItem>
<ListGroupItem
hidden={options.debugMode ? false : !FormUtils.isRelevant(step)}
key={"nav" + index}
onClick={() => onNavigate(index)}
id={"wizard-nav-" + index}
action={true}
active={index === currentStep ? "active" : ""}
disabled={!options.enableWizardStepSkip}
variant={"default"}
className={classNames([
options.debugMode && !FormUtils.isRelevant(step)
? "show-irrelevant"
: Question.getEmphasizedClass(step),
"wizard-nav",
])}
>
{JsonLdUtils.getLocalized(
step[JsonLdUtils.RDFS_LABEL],
options.intl
)}
</ListGroupItem>
</IconOverlay>
))}
</ListGroup>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/components/wizard/Wizard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const Wizard = () => {
if (
stepIndex > currentStep &&
!stepData[stepIndex].visited &&
!options.enableForwardSkip
!options.enableWizardStepSkip
) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/contexts/ConfigurationContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const defaultProps = {
modalProps: {},
horizontalWizardNav: true,
wizardStepButtons: true,
enableForwardSkip: false,
enableWizardStepSkip: true,
startingStep: 0,
},
};
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/cs.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"comment.form.placeholder": "Sem napište své komentáře (Ctrl+Enter pro potvrzení)"
"comment.form.placeholder": "Sem napište své komentáře (Ctrl+Enter pro potvrzení)",
"wizard.nav.tooltip": "Navigace na této kartě je zakázána, aby nedošlo k přehlédnutí důležitých otázek. K navigaci na tuto kartu použijte tlačítka související s formulářem."
}
3 changes: 2 additions & 1 deletion src/i18n/en.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"comment.form.placeholder": "Write your comments here (Ctrl+Enter to confirm, Esc to cancel)"
"comment.form.placeholder": "Write your comments here (Ctrl+Enter to confirm, Esc to cancel)",
"wizard.nav.tooltip": "Navigation to this tab is disabled to prevent overlooking important questions. Use form-related buttons to navigate to this tab instead."
}
1 change: 0 additions & 1 deletion src/stories/SForms.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ const Template: ComponentStory<typeof SForms> = (
modalProps,
horizontalWizardNav: horizontalNavBar,
wizardStepButtons: true,
enableForwardSkip: true,
...getP("startingQuestionId", "layout-options-65"),
startingStep: 1,
debugMode: debugMode,
Expand Down

0 comments on commit b76add4

Please sign in to comment.