Skip to content

Commit

Permalink
feat: action lists persists in localstorage
Browse files Browse the repository at this point in the history
  • Loading branch information
alberto-abarzua committed Nov 7, 2023
1 parent 6ac8846 commit 4d04234
Show file tree
Hide file tree
Showing 11 changed files with 253 additions and 22 deletions.
29 changes: 29 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"@emotion/styled": "^11.11.0",
"@mui/icons-material": "^5.14.7",
"@radix-ui/react-accordion": "^1.1.2",
"@radix-ui/react-context-menu": "^2.1.5",
"@radix-ui/react-dropdown-menu": "^2.0.6",
"@radix-ui/react-label": "^2.0.2",
"@radix-ui/react-slot": "^1.0.2",
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/actions/ActionSet.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
AccordionItem,
AccordionTrigger,
} from '@/components/ui/accordion';
import { Label } from '@/components/ui/label';
import { actionListActions } from '@/redux/ActionListSlice';
import { ItemTypes } from '@/utils/ItemTypes';
import AddIcon from '@mui/icons-material/Add';
Expand All @@ -21,6 +20,7 @@ const ActionSet = ({ action, ...props }) => {

const id = action.id;
const [isOver, setIsOver] = useState(false);
const name = action.name ? action.name : '';

const actionList = action.value;

Expand Down Expand Up @@ -60,7 +60,7 @@ const ActionSet = ({ action, ...props }) => {
autoComplete="off"
className="focus:border-blue-3 w-2/3 rounded-md border-none bg-slate-300 px-2 py-1 text-lg italic text-gray-900 hover:border-blue-300 "
placeholder="Change Action Set Name"
value={action.name}
value={name}
name="actionsetlabel"
onChange={e =>
dispatch(
Expand Down
10 changes: 5 additions & 5 deletions frontend/src/components/actions/ActionsPanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,26 +52,26 @@ const ActionPanel = () => {
let play_or_stop = {
icon: null,
color: null,
hoverColor: null,
hovercolor: null,
text: null,
};

if (valid) {
if (running) {
play_or_stop.icon = <StopIcon className="text-3xl text-white" />;
play_or_stop.color = 'bg-red-400';
play_or_stop.hoverColor = 'hover:bg-red-500';
play_or_stop.hovercolor = 'hover:bg-red-500';
play_or_stop.text = 'Stop';
} else {
play_or_stop.icon = <PlayArrowIcon className="text-3xl text-white" />;
play_or_stop.color = 'bg-green-400';
play_or_stop.hoverColor = 'hover:bg-green-500';
play_or_stop.hovercolor = 'hover:bg-green-500';
play_or_stop.text = 'Run';
}
} else {
play_or_stop.icon = <ErrorIcon className="text-3xl text-white" />;
play_or_stop.color = 'bg-orange-400';
play_or_stop.hoverColor = 'hover:bg-orange-500';
play_or_stop.hovercolor = 'hover:bg-orange-500';
play_or_stop.text = 'Errors';
}

Expand All @@ -85,7 +85,7 @@ const ActionPanel = () => {
<div className="absolute bottom-10 right-8 z-20">
<Button
color={play_or_stop.color}
hoverColor={play_or_stop.hoverColor}
hovercolor={play_or_stop.hoverColor}
onClick={handleClickPlayStop}
disabled={!valid}
>
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/components/actions/ToolBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const ToolBar = () => {
bgColor: 'bg-action-move',
type: ActionTypes.MOVE,
value: moveValue,
hoverColor: 'hover:bg-action-move-hover',
hovercolor: 'hover:bg-action-move-hover',
helpText: 'Move Addction: Move to a pose',
},
{
Expand All @@ -51,7 +51,7 @@ const ToolBar = () => {
bgColor: 'bg-action-sleep',
type: ActionTypes.SLEEP,
value: { duration: 2 },
hoverColor: 'hover:bg-action-sleep-hover',
hovercolor: 'hover:bg-action-sleep-hover',
helpText: 'Sleep Action: Pause movement',
},
{
Expand All @@ -60,7 +60,7 @@ const ToolBar = () => {
bgColor: 'bg-action-tool',
type: ActionTypes.TOOL,
value: { toolValue: 0 },
hoverColor: 'hover:bg-action-tool-hover',
hovercolor: 'hover:bg-action-tool-hover',
helpText: 'Tool Action: Change tool value',
},
{
Expand All @@ -69,7 +69,7 @@ const ToolBar = () => {
bgColor: 'bg-action-set',
type: ActionTypes.ACTIONSET,
value: [],
hoverColor: 'hover:bg-action-set-hover',
hovercolor: 'hover:bg-action-set-hover',
helpText: 'Action Set: Set of actions',
},
];
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/actions/ToolBarElement.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ ToolBarElement.propTypes = {
icon: PropTypes.object.isRequired,
bgColor: PropTypes.string.isRequired,
value: PropTypes.any.isRequired,
hoverColor: PropTypes.string.isRequired,
hovercolor: PropTypes.string.isRequired,
helpText: PropTypes.string.isRequired,
}).isRequired,
};
Expand Down
3 changes: 0 additions & 3 deletions frontend/src/components/armsimulation/ArmSimulation.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
const ArmSimulation = () => {
// const simulation_url = process.env.NEXT_PUBLIC_ARM_SIMULATION_URL;
// const websocket_port = process.env.NEXT_PUBLIC_ARM_SIMULATION_WEBSOCKET_PORT;
// const websocket_host = process.env.NEXT_PUBLIC_ARM_SIMULATION_WEBSOCKET_HOST;
const simulation_url = import.meta.env.VITE_ARM_SIMULATION_URL;
const websocket_port = import.meta.env.VITE_ARM_SIMULATION_WEBSOCKET_PORT;
const websocket_host = import.meta.env.VITE_ARM_SIMULATION_WEBSOCKET_HOST;
Expand Down
156 changes: 156 additions & 0 deletions frontend/src/components/ui/context-menu.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
import * as React from "react"
import * as ContextMenuPrimitive from "@radix-ui/react-context-menu"
import { Check, ChevronRight, Circle } from "lucide-react"

import { cn } from "@/lib/utils"

const ContextMenu = ContextMenuPrimitive.Root

const ContextMenuTrigger = ContextMenuPrimitive.Trigger

const ContextMenuGroup = ContextMenuPrimitive.Group

const ContextMenuPortal = ContextMenuPrimitive.Portal

const ContextMenuSub = ContextMenuPrimitive.Sub

const ContextMenuRadioGroup = ContextMenuPrimitive.RadioGroup

const ContextMenuSubTrigger = React.forwardRef(({ className, inset, children, ...props }, ref) => (
<ContextMenuPrimitive.SubTrigger
ref={ref}
className={cn(
"flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[state=open]:bg-accent data-[state=open]:text-accent-foreground",
inset && "pl-8",
className
)}
{...props}>
{children}
<ChevronRight className="ml-auto h-4 w-4" />
</ContextMenuPrimitive.SubTrigger>
))
ContextMenuSubTrigger.displayName = ContextMenuPrimitive.SubTrigger.displayName

const ContextMenuSubContent = React.forwardRef(({ className, ...props }, ref) => (
<ContextMenuPrimitive.SubContent
ref={ref}
className={cn(
"z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
className
)}
{...props} />
))
ContextMenuSubContent.displayName = ContextMenuPrimitive.SubContent.displayName

const ContextMenuContent = React.forwardRef(({ className, ...props }, ref) => (
<ContextMenuPrimitive.Portal>
<ContextMenuPrimitive.Content
ref={ref}
className={cn(
"z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md animate-in fade-in-80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
className
)}
{...props} />
</ContextMenuPrimitive.Portal>
))
ContextMenuContent.displayName = ContextMenuPrimitive.Content.displayName

const ContextMenuItem = React.forwardRef(({ className, inset, ...props }, ref) => (
<ContextMenuPrimitive.Item
ref={ref}
className={cn(
"relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
inset && "pl-8",
className
)}
{...props} />
))
ContextMenuItem.displayName = ContextMenuPrimitive.Item.displayName

const ContextMenuCheckboxItem = React.forwardRef(({ className, children, checked, ...props }, ref) => (
<ContextMenuPrimitive.CheckboxItem
ref={ref}
className={cn(
"relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
className
)}
checked={checked}
{...props}>
<span className="absolute left-2 flex h-3.5 w-3.5 items-center justify-center">
<ContextMenuPrimitive.ItemIndicator>
<Check className="h-4 w-4" />
</ContextMenuPrimitive.ItemIndicator>
</span>
{children}
</ContextMenuPrimitive.CheckboxItem>
))
ContextMenuCheckboxItem.displayName =
ContextMenuPrimitive.CheckboxItem.displayName

const ContextMenuRadioItem = React.forwardRef(({ className, children, ...props }, ref) => (
<ContextMenuPrimitive.RadioItem
ref={ref}
className={cn(
"relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
className
)}
{...props}>
<span className="absolute left-2 flex h-3.5 w-3.5 items-center justify-center">
<ContextMenuPrimitive.ItemIndicator>
<Circle className="h-2 w-2 fill-current" />
</ContextMenuPrimitive.ItemIndicator>
</span>
{children}
</ContextMenuPrimitive.RadioItem>
))
ContextMenuRadioItem.displayName = ContextMenuPrimitive.RadioItem.displayName

const ContextMenuLabel = React.forwardRef(({ className, inset, ...props }, ref) => (
<ContextMenuPrimitive.Label
ref={ref}
className={cn(
"px-2 py-1.5 text-sm font-semibold text-foreground",
inset && "pl-8",
className
)}
{...props} />
))
ContextMenuLabel.displayName = ContextMenuPrimitive.Label.displayName

const ContextMenuSeparator = React.forwardRef(({ className, ...props }, ref) => (
<ContextMenuPrimitive.Separator
ref={ref}
className={cn("-mx-1 my-1 h-px bg-border", className)}
{...props} />
))
ContextMenuSeparator.displayName = ContextMenuPrimitive.Separator.displayName

const ContextMenuShortcut = ({
className,
...props
}) => {
return (
(<span
className={cn("ml-auto text-xs tracking-widest text-muted-foreground", className)}
{...props} />)
);
}
ContextMenuShortcut.displayName = "ContextMenuShortcut"

export {
ContextMenu,
ContextMenuTrigger,
ContextMenuContent,
ContextMenuItem,
ContextMenuCheckboxItem,
ContextMenuRadioItem,
ContextMenuLabel,
ContextMenuSeparator,
ContextMenuShortcut,
ContextMenuGroup,
ContextMenuPortal,
ContextMenuSub,
ContextMenuSubContent,
ContextMenuSubTrigger,
ContextMenuRadioGroup,
}
3 changes: 0 additions & 3 deletions frontend/src/redux/ActionListSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,13 @@ const actionListSlice = createSlice({
actionToUpdate.parentId = newParentId;
state.byId[newId] = actionToUpdate;
if (actionToUpdate.type === ActionTypes.ACTIONSET) {
console.log(actionToUpdate);
for (let subactionToUpdate of actionToUpdate.value) {
updateHelper(subactionToUpdate, newId);
}
}
};

updateHelper(newAction, actionToDuplicate.parentId);
console.log(newAction);
console.log(actionToDuplicate);

actionList.splice(actionIndex + 1, 0, newAction);
},
Expand Down
Loading

0 comments on commit 4d04234

Please sign in to comment.