-
Notifications
You must be signed in to change notification settings - Fork 1
PR Template, button bugfix and restructure 'navigator' component #43
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| # Pull Request | ||
|
|
||
| ## Description | ||
|
|
||
| Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. | ||
|
|
||
| Fixes # (issue) | ||
|
|
||
| ## Type of change | ||
|
|
||
| Please select all relevant options, then delete those which are irrelevant. | ||
|
|
||
| - [ ] Bug fix | ||
| - [ ] New feature | ||
| - [ ] Documentation update | ||
| - [ ] Page content update. | ||
|
|
||
| ## Validation | ||
|
|
||
| Please describe how you validate your proposed changes. Provide instructions so we can reproduce this result. | ||
|
|
||
| - [ ] Test A | ||
|
|
||
| ## Checklist | ||
|
|
||
| - [ ] My code follows proposed/requested changes to the related issues. | ||
| - [ ] The [coding guidelines](https://github.com/S7-OpenLearning-Individual/DesignPatternPedia?tab=readme-ov-file#coding-standards) have been applied correctly and thoroughly. | ||
| - [ ] `npm run lint:mdx` passes without errors. | ||
| - [ ] I have performed a self-review of my own code and corrected any misspellings or grammatical errors. | ||
| - [ ] I have tested the changes locally and ensured there are no errors or functional problems. | ||
|
|
||
| ## Screenshots (if applicable) | ||
|
|
||
| Please add screenshots to demonstrate the changes made (if applicable). |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,6 +1,7 @@ | ||||||||||||||||||||||||||||||
| import React from "react"; | ||||||||||||||||||||||||||||||
| import QuestionCard, { YesOrNo } from "./QuestionCard"; | ||||||||||||||||||||||||||||||
| import QuestionCard from "./QuestionCard"; | ||||||||||||||||||||||||||||||
| import styles from "./navigator.module.css"; | ||||||||||||||||||||||||||||||
| import { YesOrNo } from "@site/src/models/yes-or-no"; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| interface AnsweredQuestionProps { | ||||||||||||||||||||||||||||||
| question: string; | ||||||||||||||||||||||||||||||
|
|
@@ -22,11 +23,13 @@ const AnsweredQuestion: React.FC<AnsweredQuestionProps> = ({ | |||||||||||||||||||||||||||||
| question={question} | ||||||||||||||||||||||||||||||
| selectedAnswer={answer} | ||||||||||||||||||||||||||||||
| onAnswerYes={() => { | ||||||||||||||||||||||||||||||
| //Only call if the answer changed | ||||||||||||||||||||||||||||||
| if (answer !== "yes") { | ||||||||||||||||||||||||||||||
| onChangeAnswer("yes"); | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| }} | ||||||||||||||||||||||||||||||
| onAnswerNo={() => { | ||||||||||||||||||||||||||||||
| //Only call if the answer changed | ||||||||||||||||||||||||||||||
|
Comment on lines
+26
to
+32
|
||||||||||||||||||||||||||||||
| //Only call if the answer changed | |
| if (answer !== "yes") { | |
| onChangeAnswer("yes"); | |
| } | |
| }} | |
| onAnswerNo={() => { | |
| //Only call if the answer changed | |
| // Only call if the answer changed | |
| if (answer !== "yes") { | |
| onChangeAnswer("yes"); | |
| } | |
| }} | |
| onAnswerNo={() => { | |
| // Only call if the answer changed |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,19 +1,15 @@ | ||||||
| import React, { useState } from "react"; | ||||||
| import { | ||||||
| decisionTree, | ||||||
| getNode, | ||||||
| getNextNode, | ||||||
| isPatternNode, | ||||||
| } from "@site/src/data/decision-tree"; | ||||||
| import QuestionCard from "./QuestionCard"; | ||||||
| import PatternResult from "./PatternResult"; | ||||||
| import AnsweredQuestion from "./AnsweredQuestion"; | ||||||
| import styles from "./navigator.module.css"; | ||||||
|
|
||||||
| export interface Answer { | ||||||
| nodeId: string; | ||||||
| answer: "yes" | "no"; | ||||||
| } | ||||||
| import { | ||||||
| getNextNode, | ||||||
| getNode, | ||||||
| isPatternNode, | ||||||
| } from "@site/src/utils/decision-tree-helper"; | ||||||
| import { YesOrNo } from "@site/src/models/yes-or-no"; | ||||||
| import { Answer } from "@site/src/models/answer"; | ||||||
|
|
||||||
| const NavigatorContainer: React.FC = () => { | ||||||
| const [answers, setAnswers] = useState<Answer[]>([]); | ||||||
|
|
@@ -30,11 +26,11 @@ const NavigatorContainer: React.FC = () => { | |||||
| return <div>Error: Node not found</div>; | ||||||
| } | ||||||
|
|
||||||
| const handleAnswer = (answer: "yes" | "no") => { | ||||||
| const handleAnswer = (answer: YesOrNo) => { | ||||||
| setAnswers([...answers, { nodeId: currentNodeId, answer }]); | ||||||
| }; | ||||||
|
|
||||||
| const handleGoBack = (index: number, newAnswer?: "yes" | "no") => { | ||||||
| const handleGoBack = (index: number, newAnswer?: YesOrNo) => { | ||||||
| const targetAnswer = newAnswer || answers[index].answer; | ||||||
| setAnswers( | ||||||
| answers | ||||||
|
|
@@ -54,7 +50,10 @@ const NavigatorContainer: React.FC = () => { | |||||
| {/* Show all previous questions with their selected answers */} | ||||||
| {answers.map((answer, index) => { | ||||||
| const node = getNode(answer.nodeId); | ||||||
| if (!node) return null; | ||||||
|
|
||||||
| if (!node) { | ||||||
| return null; | ||||||
| } | ||||||
|
|
||||||
| // Check if the next node after this answer is a pattern (not a question) | ||||||
| const nextNodeId = getNextNode(answer.nodeId, answer.answer); | ||||||
|
|
@@ -65,7 +64,7 @@ const NavigatorContainer: React.FC = () => { | |||||
| return ( | ||||||
| <AnsweredQuestion | ||||||
| key={index} | ||||||
| question={node.question || ""} | ||||||
| question={node.question} | ||||||
|
||||||
| question={node.question} | |
| question={node.question || ""} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -179,10 +179,6 @@ | |
| } | ||
|
|
||
| .answerBtn { | ||
| min-width: 100%; | ||
| } | ||
|
|
||
| .answerButtons { | ||
| flex-direction: column; | ||
| min-width: 30vw; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import { YesOrNo } from "./yes-or-no"; | ||
|
|
||
| export interface Answer { | ||
| nodeId: string; | ||
| answer: YesOrNo; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import { NodeType } from "./node-type"; | ||
|
|
||
| export interface DecisionNode { | ||
| id: string; | ||
| type: NodeType; | ||
| question?: string; | ||
| title?: string; | ||
| description?: string; | ||
| icon?: string; | ||
| yesPath?: string; | ||
| noPath?: string; | ||
| pattern?: { | ||
| name: string; | ||
| description: string; | ||
| path: string; | ||
| }; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import { DecisionNode } from "./decision-node"; | ||
|
|
||
| export interface DecisionTree { | ||
| [nodeId: string]: DecisionNode; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export type NodeType = "question" | "pattern"; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export type YesOrNo = "yes" | "no"; |
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,36 @@ | ||||||||
| import { YesOrNo } from "../components/navigator/QuestionCard"; | ||||||||
|
||||||||
| import { YesOrNo } from "../components/navigator/QuestionCard"; | |
| import { YesOrNo } from "@site/src/models/yes-or-no"; |
Copilot
AI
Dec 18, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The import path is incorrect. DecisionNode has been moved to the models directory and should be imported from "@site/src/models/decision-node" instead of from the data/decision-tree file which no longer exports it.
| import { DecisionNode, decisionTree } from "../data/decision-tree"; | |
| import { DecisionNode } from "@site/src/models/decision-node"; | |
| import { decisionTree } from "../data/decision-tree"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comments should have a space after the double slashes for better readability. Change "//Only" to "// Only".