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

[Hint Mode: Start Coords] Add separate flags for graph types #1465

Merged
merged 4 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions .changeset/slow-taxis-give.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@khanacademy/perseus": patch
"@khanacademy/perseus-editor": patch
---

[Hint Mode: Start Coords] Add separate flags for graph types
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@ export const flags = {
linear: true,
"linear-system": true,
ray: true,
"start-coords-ui": true,

// Locked figures flags
"interactive-graph-locked-features-m2": true,
"interactive-graph-locked-features-m2b": true,

// Start coords UI flags
// TODO(LEMS-2228): Remove flags once this is fully released
"start-coords-ui-phase-1": true,
},
} satisfies APIOptions["flags"];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ export const MafsWithLockedFiguresCurrent = (): React.ReactElement => {
flags: {
mafs: {
...flags.mafs,
"start-coords-ui": false,
"interactive-graph-locked-features-m2": false,
"interactive-graph-locked-features-m2b": false,
},
Expand All @@ -149,7 +148,6 @@ export const MafsWithLockedFiguresM2Flag = (): React.ReactElement => {
flags: {
mafs: {
...flags.mafs,
"start-coords-ui": false,
"interactive-graph-locked-features-m2": true,
"interactive-graph-locked-features-m2b": false,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -672,4 +672,60 @@ describe("InteractiveGraphEditor", () => {
}),
);
});

test.each`
type | shouldRender
${"linear"} | ${true}
${"ray"} | ${true}
${"linear-system"} | ${true}
${"segment"} | ${true}
${"circle"} | ${true}
${"quadratic"} | ${false}
${"sinusoid"} | ${false}
${"polygon"} | ${false}
${"angle"} | ${false}
${"point"} | ${false}
`(
"should render for $type graphs if phase1 flag is on: $shouldRender",
async ({type, shouldRender}) => {
// Arrange

// Act
render(
<InteractiveGraphEditor
{...baseProps}
apiOptions={{
...ApiOptions.defaults,
flags: {
...flags,
mafs: {
...flags.mafs,
"start-coords-ui-phase-1": shouldRender,
},
},
}}
graph={{type}}
correct={{type}}
/>,
{
wrapper: RenderStateRoot,
},
);

// Assert
if (shouldRender) {
expect(
await screen.findByRole("button", {
name: "Use default start coordinates",
}),
).toBeInTheDocument();
} else {
expect(
screen.queryByRole("button", {
name: "Use default start coordinates",
}),
).toBeNull();
}
},
);
});
17 changes: 16 additions & 1 deletion packages/perseus-editor/src/widgets/interactive-graph-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ const POLYGON_SIDES = _.map(_.range(3, 13), function (value) {
);
});

// TODO(LEMS-2228): Remove flags once this is fully released
const startCoordsUiPhase1Types = [
"linear",
"linear-system",
"ray",
"segment",
"circle",
];

type Range = [min: number, max: number];

export type Props = {
Expand Down Expand Up @@ -473,7 +482,13 @@ class InteractiveGraphEditor extends React.Component<Props> {
</LabeledRow>
)}
{this.props.graph?.type &&
this.props.apiOptions?.flags?.mafs?.["start-coords-ui"] && (
// TODO(LEMS-2228): Remove flags once this is fully released
this.props.apiOptions?.flags?.mafs?.[
"start-coords-ui-phase-1"
] &&
startCoordsUiPhase1Types.includes(
this.props.graph.type,
) && (
<StartCoordsSettings
{...this.props.graph}
range={this.props.range}
Expand Down
3 changes: 2 additions & 1 deletion packages/perseus/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,9 @@ export const InteractiveGraphLockedFeaturesFlags = [
export const InteractiveGraphEditorFlags = [
/**
* Enables the UI for setting the start coordinates of a graph.
* Includes linear, linear-system, ray, segment, and circle graphs.
*/
"start-coords-ui",
"start-coords-ui-phase-1",
] as const;

/**
Expand Down