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

Draft: Add auto-sum-to-100 button to multi choice questions #87

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

slowSort
Copy link
Contributor

@slowSort slowSort commented Dec 22, 2024

Pull Request: Add auto-sum-to-100 button to multi choice questions

Related Issue

Closes [#82] – please check for continued discussion in the issue while this is in draft

Changes Made

  • Added "Sum to 100" button for multi-choice questions (behavior captured in issues)
  • Added jest tests for core behavior

Testing

TODO: Once test suite no longer failing

Copy link

vercel bot commented Dec 22, 2024

@slowSort is attempting to deploy a commit to the Sage Team on Vercel.

A member of the Team first needs to authorize it.

import MultiChoiceQuestion from "./MultiChoiceQuestion"
import { PredictProvider } from "../PredictProvider"

describe("MultiChoiceQuestion", () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will add more tests when test setup is fixed

@@ -60,24 +77,34 @@ export default function MultiChoiceQuestion({
/>
))}

{fields.length < MAX_OPTIONS && (
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Might be wrong, but I think this is now handled by the addOption callback, decided to remove but let me know if I've missed something

Add option
</button>

{
<button
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Github has diffed this very strangely but if you take a look at the code I'm just adding a new button here along with some styling

@@ -0,0 +1,41 @@
import { OptionType } from "../components/predict-form/PredictProvider"

export function normalizeOptionsToHundred(options: OptionType[]) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

considered naming getNormalizeOptionsToHundred to make it clearer we're not mutating – let me know what you think. I'm usually a big "get prefixer" but I can see the good in both approaches

const optionsCopy = [...options]
const optionsWithForecasts = optionsCopy.filter(
({ forecast }) => forecast !== undefined && !Number.isNaN(forecast),
) as Array<OptionType & { forecast: number }>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Typing forecast here means that I don't have to assert it to be a value in each of my filters

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alternatively, I see in PredictProvider.tsx that optionSchema can be NaN. Any reason why? If we could get rid of that then we could at least get rid of the isNaN check – not urgent though

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant