Skip to content
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

fix: ensure "no flag" band always displays if no flags are present #3899

Merged
merged 1 commit into from
Nov 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import { Link } from "react-navi";

import { useStore } from "../../../lib/store";
import { DataField } from "./DataField";
import { FlagBand, NoFlagBand } from "./FlagBand";
import Hanger from "./Hanger";
import Node from "./Node";
import { Thumbnail } from "./Thumbnail";
import { FlagBand, NoFlagBand } from "./FlagBand";

const Option: React.FC<any> = (props) => {
const childNodes = useStore((state) => state.childNodesOf(props.id));
Expand All @@ -20,7 +20,9 @@ const Option: React.FC<any> = (props) => {
// Question & Checklist Options set zero or many flag values under "data.flag"
if (props.data?.flag) {
if (Array.isArray(props.data?.flag)) {
flags = flatFlags.filter(({ value }) => props.data?.flag?.includes(value));
flags = flatFlags.filter(
({ value }) => props.data?.flag?.includes(value),
);
} else {
flags = flatFlags.filter(({ value }) => props.data?.flag === value);
}
Expand All @@ -46,9 +48,17 @@ const Option: React.FC<any> = (props) => {
imageAltText={props.data.text}
/>
)}
{flags ? flags.map((flag) => <FlagBand key={`${props.id}-${flag.value}`} flag={flag} />) : <NoFlagBand />}
{flags && flags.length > 0 ? (
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is the only logical change, otherwise linting !

flags.map((flag) => (
<FlagBand key={`${props.id}-${flag.value}`} flag={flag} />
))
) : (
<NoFlagBand />
)}
<div className="text">{props.data.text}</div>
{props.data?.val && <DataField value={props.data.val} variant="child" />}
{props.data?.val && (
<DataField value={props.data.val} variant="child" />
)}
</Link>
<ol className="decisions">
{childNodes.map((child: any) => (
Expand Down
Loading