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

[Interactive Graph Editor] Add the ability to reorder locked figure settings #1360

Merged
merged 5 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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/neat-carrots-guess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@khanacademy/perseus": minor
"@khanacademy/perseus-editor": minor
---

[Interactive Graph Editor] Add the ability to reorder locked figure settings
6 changes: 6 additions & 0 deletions .changeset/wild-gifts-grow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@khanacademy/perseus": minor
"@khanacademy/perseus-editor": minor
---

[Interactive Graph Editor] UI for adding/editing/deleting a locked polygon
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@ export const Default = (args): React.ReactElement => {
return <LockedEllipseSettings {...args} />;
};

type StoryComponentType = StoryObj<typeof LockedEllipseSettings>;

// Set the default values in the control panel.
Default.args = {
const defaultProps = {
...getDefaultFigureForType("ellipse"),
onChangeProps: () => {},
onMove: () => {},
onRemove: () => {},
};

type StoryComponentType = StoryObj<typeof LockedEllipseSettings>;

// Set the default values in the control panel.
Default.args = defaultProps;

export const Controlled: StoryComponentType = {
render: function Render() {
const [props, setProps] = React.useState({
...getDefaultFigureForType("ellipse"),
onRemove: () => {},
});
const [props, setProps] = React.useState(defaultProps);

const handlePropsUpdate = (newProps) => {
setProps({
Expand Down Expand Up @@ -57,10 +57,7 @@ Controlled.parameters = {
export const Expanded: StoryComponentType = {
render: function Render() {
const [expanded, setExpanded] = React.useState(true);
const [props, setProps] = React.useState({
...getDefaultFigureForType("ellipse"),
onRemove: () => {},
});
const [props, setProps] = React.useState(defaultProps);

const handlePropsUpdate = (newProps) => {
setProps({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@ export const Default = (args): React.ReactElement => {
return <LockedLineSettings {...args} />;
};

type StoryComponentType = StoryObj<typeof LockedLineSettings>;

// Set the default values in the control panel.
Default.args = {
const defaultProps = {
...getDefaultFigureForType("line"),
onChangeProps: () => {},
onMove: () => {},
onRemove: () => {},
};

type StoryComponentType = StoryObj<typeof LockedLineSettings>;

// Set the default values in the control panel.
Default.args = defaultProps;

export const Controlled: StoryComponentType = {
render: function Render() {
const [props, setProps] = React.useState({
...getDefaultFigureForType("line"),
onRemove: () => {},
});
const [props, setProps] = React.useState(defaultProps);

const handlePropsUpdate = (newProps) => {
setProps({
Expand Down Expand Up @@ -57,10 +57,7 @@ Controlled.parameters = {
*/
export const WithInvalidPoints: StoryComponentType = {
render: function Render() {
const [props, setProps] = React.useState({
...getDefaultFigureForType("line"),
onRemove: () => {},
});
const [props, setProps] = React.useState(defaultProps);

const handlePropsUpdate = (newProps) => {
setProps({
Expand All @@ -87,10 +84,7 @@ export const WithInvalidPoints: StoryComponentType = {
export const Expanded: StoryComponentType = {
render: function Render() {
const [expanded, setExpanded] = React.useState(true);
const [props, setProps] = React.useState({
...getDefaultFigureForType("line"),
onRemove: () => {},
});
const [props, setProps] = React.useState(defaultProps);

const handlePropsUpdate = (newProps) => {
setProps({
Expand All @@ -115,8 +109,7 @@ export const ExpandedNondefaultProps: StoryComponentType = {
render: function Render() {
const [expanded, setExpanded] = React.useState(true);
const [props, setProps] = React.useState({
...getDefaultFigureForType("line"),
onRemove: () => {},
...defaultProps,
kind: "segment" as const,
color: "green" as const,
lineStyle: "dashed" as const,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@ export const Default = (args): React.ReactElement => {
return <LockedPointSettings {...args} />;
};

type StoryComponentType = StoryObj<typeof LockedPointSettings>;

// Set the default values in the control panel.
Default.args = {
const defaultProps = {
...getDefaultFigureForType("point"),
onChangeProps: () => {},
onMove: () => {},
onRemove: () => {},
};

type StoryComponentType = StoryObj<typeof LockedPointSettings>;

// Set the default values in the control panel.
Default.args = defaultProps;

export const Controlled: StoryComponentType = {
render: function Render() {
const [props, setProps] = React.useState({
...getDefaultFigureForType("point"),
onRemove: () => {},
});
const [props, setProps] = React.useState(defaultProps);

const handlePropsUpdate = (newProps) => {
setProps({
Expand All @@ -54,10 +54,7 @@ Controlled.parameters = {
export const Expanded: StoryComponentType = {
render: function Render() {
const [expanded, setExpanded] = React.useState(true);
const [props, setProps] = React.useState({
...getDefaultFigureForType("point"),
onRemove: () => {},
});
const [props, setProps] = React.useState(defaultProps);

const handlePropsUpdate = (newProps) => {
setProps({
Expand All @@ -81,12 +78,7 @@ export const Expanded: StoryComponentType = {
export const ExpandedNondefaultProps: StoryComponentType = {
render: function Render() {
const [expanded, setExpanded] = React.useState(true);
const [props, setProps] = React.useState({
...getDefaultFigureForType("point"),
onRemove: () => {},
color: "green" as const,
filled: false,
});
const [props, setProps] = React.useState(defaultProps);

const handlePropsUpdate = (newProps) => {
setProps({
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import * as React from "react";

import LockedPolygonSettings from "../locked-polygon-settings";
import {getDefaultFigureForType} from "../util";

import type {Meta, StoryObj} from "@storybook/react";

export default {
title: "PerseusEditor/Components/Locked Polygon Settings",
component: LockedPolygonSettings,
} as Meta<typeof LockedPolygonSettings>;

export const Default = (args): React.ReactElement => {
return <LockedPolygonSettings {...args} />;
};

const defaultProps = {
...getDefaultFigureForType("polygon"),
onChangeProps: () => {},
onMove: () => {},
onRemove: () => {},
};

type StoryComponentType = StoryObj<typeof LockedPolygonSettings>;

// Set the default values in the control panel.
Default.args = defaultProps;

export const Controlled: StoryComponentType = {
render: function Render() {
const [props, setProps] = React.useState(defaultProps);

const handlePropsUpdate = (newProps) => {
setProps({
...props,
...newProps,
});
};

return (
<LockedPolygonSettings
{...props}
onChangeProps={handlePropsUpdate}
/>
);
},
};

Controlled.parameters = {
chromatic: {
// Disabling because this is testing behavior, not visuals.
disableSnapshot: true,
},
};

// Fully expanded view of the locked ellipse settings to allow snapshot testing.
export const Expanded: StoryComponentType = {
render: function Render() {
const [expanded, setExpanded] = React.useState(true);
const [props, setProps] = React.useState(defaultProps);

const handlePropsUpdate = (newProps) => {
setProps({
...props,
...newProps,
});
};

return (
<LockedPolygonSettings
{...props}
expanded={expanded}
onToggle={setExpanded}
onChangeProps={handlePropsUpdate}
/>
);
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@ export const Default = (args): React.ReactElement => {
return <LockedVectorSettings {...args} />;
};

type StoryComponentType = StoryObj<typeof LockedVectorSettings>;

// Set the default values in the control panel.
Default.args = {
const defaultProps = {
...getDefaultFigureForType("vector"),
onChangeProps: () => {},
onMove: () => {},
onRemove: () => {},
};

type StoryComponentType = StoryObj<typeof LockedVectorSettings>;

// Set the default values in the control panel.
Default.args = defaultProps;

export const Expanded: StoryComponentType = {
render: function Render() {
const [props, setProps] = React.useState({
...getDefaultFigureForType("vector"),
onRemove: () => {},
});
const [props, setProps] = React.useState(defaultProps);

const handlePropsUpdate = (newProps) => {
setProps({
Expand All @@ -54,10 +54,7 @@ export const Expanded: StoryComponentType = {
*/
export const WithInvalidPoints: StoryComponentType = {
render: function Render() {
const [props, setProps] = React.useState({
...getDefaultFigureForType("vector"),
onRemove: () => {},
});
const [props, setProps] = React.useState(defaultProps);

const handlePropsUpdate = (newProps) => {
setProps({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type {UserEvent} from "@testing-library/user-event";
const defaultProps = {
...getDefaultFigureForType("ellipse"),
onChangeProps: () => {},
onMove: () => {},
onRemove: () => {},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type {UserEvent} from "@testing-library/user-event";
const defaultProps = {
...getDefaultFigureForType("line"),
onChangeProps: () => {},
onMove: () => {},
onRemove: () => {},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type {UserEvent} from "@testing-library/user-event";
const defaultProps = {
...getDefaultFigureForType("point"),
onRemove: () => {},
onMove: () => {},
onChangeProps: () => {},
};

Expand Down
Loading
Loading