Skip to content

Commit 04e5ee8

Browse files
committed
2 parents bfbeb67 + d53c97b commit 04e5ee8

14 files changed

Lines changed: 125 additions & 79 deletions

.github/pull_request_template.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Pull Request
2+
3+
## Description
4+
5+
Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context.
6+
7+
Fixes # (issue)
8+
9+
## Type of change
10+
11+
Please select all relevant options, then delete those which are irrelevant.
12+
13+
- [ ] Bug fix
14+
- [ ] New feature
15+
- [ ] Documentation update
16+
- [ ] Page content update.
17+
18+
## Validation
19+
20+
Please describe how you validate your proposed changes. Provide instructions so we can reproduce this result.
21+
22+
- [ ] Test A
23+
24+
## Checklist
25+
26+
- [ ] My code follows proposed/requested changes to the related issues.
27+
- [ ] The [coding guidelines](https://github.com/S7-OpenLearning-Individual/DesignPatternPedia?tab=readme-ov-file#coding-standards) have been applied correctly and thoroughly.
28+
- [ ] `npm run lint:mdx` passes without errors.
29+
- [ ] I have performed a self-review of my own code and corrected any misspellings or grammatical errors.
30+
- [ ] I have tested the changes locally and ensured there are no errors or functional problems.
31+
32+
## Screenshots (if applicable)
33+
34+
Please add screenshots to demonstrate the changes made (if applicable).

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ This website is built using [Docusaurus](https://docusaurus.io/), a modern stati
1919
2. All images have `alt` texts explaining their purpose and contents.
2020
3. All basic page elements that can be re-used should be turned into components.
2121
4. Code is written in American English.
22-
5. Page content is written in Queens English.
22+
5. Page content is written in Queen's English.
2323
6. Page content is cited, sourced, and referenced where deemed necessary.
2424
7. All docs/pages are `.mdx` files.
2525
8. Code compiles and tests pass.
2626
9. Directories follow the correct pattern structure.
27-
10. Each page is built using the [template](/template.mdx) (validated by `npm run lint:mdx`).
27+
10. Each _pattern_ page is built using the [template](/template.mdx) (validated by `npm run lint:mdx`).
2828
11. Custom components should not implement their own title, they should use the correct heading (#) level in the page itself to ensure proper url based linking.
2929
12. Images need to have padding applied around them, optimally `2rem`.
30-
13. Code has no 'TODO' blocks, only a 'FUTURE_WORK' block may be present with a reference to an issue or task.
30+
13. Source code contains no 'TODO' blocks, only a 'FUTURE_WORK' block may be present with a reference to an issue or task.
3131

3232
## Installation
3333

src/components/navigator/AnsweredQuestion.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from "react";
2-
import QuestionCard, { YesOrNo } from "./QuestionCard";
2+
import QuestionCard from "./QuestionCard";
33
import styles from "./navigator.module.css";
4+
import { YesOrNo } from "@site/src/models/yes-or-no";
45

56
interface AnsweredQuestionProps {
67
question: string;
@@ -22,11 +23,13 @@ const AnsweredQuestion: React.FC<AnsweredQuestionProps> = ({
2223
question={question}
2324
selectedAnswer={answer}
2425
onAnswerYes={() => {
26+
//Only call if the answer changed
2527
if (answer !== "yes") {
2628
onChangeAnswer("yes");
2729
}
2830
}}
2931
onAnswerNo={() => {
32+
//Only call if the answer changed
3033
if (answer !== "no") {
3134
onChangeAnswer("no");
3235
}

src/components/navigator/NavigatorContainer.tsx

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
11
import React, { useState } from "react";
2-
import {
3-
decisionTree,
4-
getNode,
5-
getNextNode,
6-
isPatternNode,
7-
} from "@site/src/data/decision-tree";
82
import QuestionCard from "./QuestionCard";
93
import PatternResult from "./PatternResult";
104
import AnsweredQuestion from "./AnsweredQuestion";
115
import styles from "./navigator.module.css";
12-
13-
export interface Answer {
14-
nodeId: string;
15-
answer: "yes" | "no";
16-
}
6+
import {
7+
getNextNode,
8+
getNode,
9+
isPatternNode,
10+
} from "@site/src/utils/decision-tree-helper";
11+
import { YesOrNo } from "@site/src/models/yes-or-no";
12+
import { Answer } from "@site/src/models/answer";
1713

1814
const NavigatorContainer: React.FC = () => {
1915
const [answers, setAnswers] = useState<Answer[]>([]);
@@ -30,11 +26,11 @@ const NavigatorContainer: React.FC = () => {
3026
return <div>Error: Node not found</div>;
3127
}
3228

33-
const handleAnswer = (answer: "yes" | "no") => {
29+
const handleAnswer = (answer: YesOrNo) => {
3430
setAnswers([...answers, { nodeId: currentNodeId, answer }]);
3531
};
3632

37-
const handleGoBack = (index: number, newAnswer?: "yes" | "no") => {
33+
const handleGoBack = (index: number, newAnswer?: YesOrNo) => {
3834
const targetAnswer = newAnswer || answers[index].answer;
3935
setAnswers(
4036
answers
@@ -54,7 +50,10 @@ const NavigatorContainer: React.FC = () => {
5450
{/* Show all previous questions with their selected answers */}
5551
{answers.map((answer, index) => {
5652
const node = getNode(answer.nodeId);
57-
if (!node) return null;
53+
54+
if (!node) {
55+
return null;
56+
}
5857

5958
// Check if the next node after this answer is a pattern (not a question)
6059
const nextNodeId = getNextNode(answer.nodeId, answer.answer);
@@ -65,7 +64,7 @@ const NavigatorContainer: React.FC = () => {
6564
return (
6665
<AnsweredQuestion
6766
key={index}
68-
question={node.question || ""}
67+
question={node.question}
6968
answer={answer.answer}
7069
onChangeAnswer={(newAnswer) => handleGoBack(index, newAnswer)}
7170
showDivider={!isNextNodePattern}

src/components/navigator/PatternResult.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import React from "react";
22
import styles from "./navigator.module.css";
33
import useDocusaurusContext from "@docusaurus/useDocusaurusContext";
44

5-
const baseURL = "/DesignPatternPedia/docs";
6-
75
interface PatternResultProps {
86
name: string;
97
description: string;

src/components/navigator/QuestionCard.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React from "react";
22
import styles from "./navigator.module.css";
3-
4-
export type YesOrNo = "yes" | "no";
3+
import { YesOrNo } from "@site/src/models/yes-or-no";
54

65
interface QuestionCardProps {
76
question: string;

src/components/navigator/navigator.module.css

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,6 @@
179179
}
180180

181181
.answerBtn {
182-
min-width: 100%;
183-
}
184-
185-
.answerButtons {
186-
flex-direction: column;
182+
min-width: 30vw;
187183
}
188184
}

src/data/decision-tree.ts

Lines changed: 2 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,5 @@
1-
// Decision Tree Node Types
2-
export type NodeType = "question" | "pattern";
3-
4-
export interface DecisionNode {
5-
id: string;
6-
type: NodeType;
7-
question?: string; // For question nodes
8-
title?: string; // For pattern nodes
9-
description?: string; // For pattern nodes
10-
icon?: string; // Optional icon identifier
11-
yesPath?: string; // ID of next node if "Yes"
12-
noPath?: string; // ID of next node if "No"
13-
pattern?: {
14-
name: string;
15-
description: string;
16-
path: string;
17-
};
18-
}
19-
20-
export interface DecisionTree {
21-
[nodeId: string]: DecisionNode;
22-
}
23-
24-
// Decision Tree Structure
1+
import { DecisionTree } from "../models/decision-tree";
2+
253
export const decisionTree: DecisionTree = {
264
// First main decision
275
q1: {
@@ -428,30 +406,3 @@ export const decisionTree: DecisionTree = {
428406
},
429407
},
430408
};
431-
432-
// Helper function to get node by ID
433-
export const getNode = (nodeId: string): DecisionNode | undefined => {
434-
return decisionTree[nodeId];
435-
};
436-
437-
// Helper function to get next node based on answer
438-
export const getNextNode = (
439-
nodeId: string,
440-
answer: "yes" | "no"
441-
): string | undefined => {
442-
const node = getNode(nodeId);
443-
if (!node) return undefined;
444-
return answer === "yes" ? node.yesPath : node.noPath;
445-
};
446-
447-
// Helper function to check if node is a pattern endpoint
448-
export const isPatternNode = (nodeId: string): boolean => {
449-
const node = getNode(nodeId);
450-
return node?.type === "pattern";
451-
};
452-
453-
// Helper function to check if node is a question
454-
export const isQuestionNode = (nodeId: string): boolean => {
455-
const node = getNode(nodeId);
456-
return node?.type === "question";
457-
};

src/models/answer.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { YesOrNo } from "./yes-or-no";
2+
3+
export interface Answer {
4+
nodeId: string;
5+
answer: YesOrNo;
6+
}

src/models/decision-node.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { NodeType } from "./node-type";
2+
3+
export interface DecisionNode {
4+
id: string;
5+
type: NodeType;
6+
question?: string;
7+
title?: string;
8+
description?: string;
9+
icon?: string;
10+
yesPath?: string;
11+
noPath?: string;
12+
pattern?: {
13+
name: string;
14+
description: string;
15+
path: string;
16+
};
17+
}

0 commit comments

Comments
 (0)