Skip to content

Commit

Permalink
filter modal per section
Browse files Browse the repository at this point in the history
  • Loading branch information
aarron-lee committed Jan 8, 2024
1 parent 88417ab commit 901f616
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/components/HhdComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const HhdComponent: FC<HhdComponentType> = ({
<>
<CardBody style={{ display: "flex", flexDirection: "column" }}>
<Heading as="h1" fontSize="xl" marginBottom="1rem">
{title} <HintsModal />
{title} <HintsModal pluginName={`${childName}`} />
</Heading>
<Stack spacing="3">
{renderChild &&
Expand Down
1 change: 1 addition & 0 deletions src/components/HhdState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const HhdState = () => {
key={`${statePath}${topIdx}${idx}`}
{...plugin}
state={state}
childName={pluginName}
renderChild={renderChild}
statePath={statePath}
updateState={setState}
Expand Down
24 changes: 17 additions & 7 deletions src/components/HintsAccordion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@ import { FC } from "react";

type PropType = {
settings: { [key: string]: any };
settingName: string;
};

const SettingsAccordion: FC<PropType> = ({ settings }) => {
const SettingsAccordion: FC<PropType> = ({ settings, settingName }) => {
return (
<Accordion allowToggle allowMultiple>
{Object.keys(settings).map((topLevelStr, idx) => {
const { title, hint, children } = settings[topLevelStr];
<Accordion defaultIndex={[0]} allowToggle allowMultiple>
{Object.keys(settings).map((pluginName, idx) => {
if (pluginName !== settingName) {
return null;
}
const { title, hint, children } = settings[pluginName];
return (
<AccordionItem key={idx}>
<h2>
Expand Down Expand Up @@ -73,14 +77,20 @@ function renderChild(child: any, key: number) {
);
}

const HintsAccordionContainer = () => {
type ContainerProps = {
pluginName: string;
};

const HintsAccordionContainer: FC<ContainerProps> = ({ pluginName }) => {
const settings = useSelector(selectHhdSettings);

return (
<>
{Object.values(settings).map((s, idx) => {
//@ts-ignore
return <SettingsAccordion settings={s} key={idx} />;
return (
//@ts-ignore
<SettingsAccordion settings={s} settingName={pluginName} key={idx} />
);
})}
</>
);
Expand Down
12 changes: 8 additions & 4 deletions src/components/HintsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ import {
ModalFooter,
} from "@chakra-ui/react";
import { InfoIcon } from "@chakra-ui/icons";
import { useState } from "react";
import { FC, useState } from "react";
import HintsAccordion from "./HintsAccordion";

function HintsModal() {
type Props = {
pluginName: string;
};

const HintsModal: FC<Props> = ({ pluginName }) => {
const [open, setIsOpen] = useState(false);

const onOpen = () => setIsOpen(true);
Expand All @@ -30,7 +34,7 @@ function HintsModal() {
<ModalHeader>More Information</ModalHeader>
<ModalCloseButton />
<ModalBody>
<HintsAccordion />
<HintsAccordion pluginName={pluginName} />
</ModalBody>

<ModalFooter>
Expand All @@ -42,6 +46,6 @@ function HintsModal() {
</Modal>
</>
);
}
};

export default HintsModal;

0 comments on commit 901f616

Please sign in to comment.