Changed way of disabling sidebar button; Disabled API button before building.

This commit is contained in:
Lucas Oliveira 2023-07-26 15:36:35 -03:00
commit eb0883231b
7 changed files with 30 additions and 9 deletions

View file

@ -12,9 +12,8 @@ import { NodeType } from "../../types/flow";
export default function Chat({ flow }: ChatType) { export default function Chat({ flow }: ChatType) {
const [open, setOpen] = useState(false); const [open, setOpen] = useState(false);
const [isBuilt, setIsBuilt] = useState(false);
const [canOpen, setCanOpen] = useState(false); const [canOpen, setCanOpen] = useState(false);
const { tabsState } = useContext(TabsContext); const { tabsState, isBuilt, setIsBuilt } = useContext(TabsContext);
useEffect(() => { useEffect(() => {
const handleKeyDown = (event: KeyboardEvent) => { const handleKeyDown = (event: KeyboardEvent) => {

View file

@ -40,6 +40,8 @@ const TabsContextInitialValue: TabsContextType = {
downloadFlows: () => {}, downloadFlows: () => {},
uploadFlows: () => {}, uploadFlows: () => {},
uploadFlow: () => {}, uploadFlow: () => {},
isBuilt: false,
setIsBuilt: (state: boolean) => {},
hardReset: () => {}, hardReset: () => {},
saveFlow: async (flow: FlowType) => {}, saveFlow: async (flow: FlowType) => {},
lastCopiedSelection: null, lastCopiedSelection: null,
@ -583,10 +585,14 @@ export function TabsProvider({ children }: { children: ReactNode }) {
} }
} }
const [isBuilt, setIsBuilt] = useState(false);
return ( return (
<TabsContext.Provider <TabsContext.Provider
value={{ value={{
saveFlow, saveFlow,
isBuilt,
setIsBuilt,
lastCopiedSelection, lastCopiedSelection,
setLastCopiedSelection, setLastCopiedSelection,
hardReset, hardReset,

View file

@ -30,9 +30,11 @@ const ApiModal = forwardRef(
{ {
flow, flow,
children, children,
disable,
}: { }: {
flow: FlowType; flow: FlowType;
children: ReactNode; children: ReactNode;
disable: boolean;
}, },
ref ref
) => { ) => {
@ -278,7 +280,7 @@ const ApiModal = forwardRef(
} }
return ( return (
<BaseModal open={open} setOpen={setOpen}> <BaseModal open={open} setOpen={setOpen} disable={disable}>
<BaseModal.Trigger>{children}</BaseModal.Trigger> <BaseModal.Trigger>{children}</BaseModal.Trigger>
<BaseModal.Header description={EXPORT_CODE_DIALOG}> <BaseModal.Header description={EXPORT_CODE_DIALOG}>
<span className="pr-2">Code</span> <span className="pr-2">Code</span>

View file

@ -46,11 +46,13 @@ interface BaseModalProps {
]; ];
open?: boolean; open?: boolean;
setOpen?: (open: boolean) => void; setOpen?: (open: boolean) => void;
disable?: boolean;
size?: "smaller" | "small" | "medium" | "large" | "large-h-full"; size?: "smaller" | "small" | "medium" | "large" | "large-h-full";
} }
function BaseModal({ function BaseModal({
open, open,
setOpen, setOpen,
disable = false,
children, children,
size = "large", size = "large",
}: BaseModalProps) { }: BaseModalProps) {
@ -99,7 +101,10 @@ function BaseModal({
//UPDATE COLORS AND STYLE CLASSSES //UPDATE COLORS AND STYLE CLASSSES
return ( return (
<Dialog open={open} onOpenChange={setOpen}> <Dialog open={open} onOpenChange={setOpen}>
<DialogTrigger className="w-full" hidden={triggerChild ? false : true}> <DialogTrigger
className={"w-full " + (disable ? "button-disable" : "")}
hidden={triggerChild ? false : true}
>
{triggerChild} {triggerChild}
</DialogTrigger> </DialogTrigger>
<DialogContent className={minWidth}> <DialogContent className={minWidth}>

View file

@ -19,7 +19,7 @@ import DisclosureComponent from "../DisclosureComponent";
export default function ExtraSidebar() { export default function ExtraSidebar() {
const { data } = useContext(typesContext); const { data } = useContext(typesContext);
const { flows, tabId, uploadFlow, tabsState, saveFlow } = const { flows, tabId, uploadFlow, tabsState, saveFlow, isBuilt } =
useContext(TabsContext); useContext(TabsContext);
const { setSuccessData, setErrorData } = useContext(alertContext); const { setSuccessData, setErrorData } = useContext(alertContext);
const [dataFilter, setFilterData] = useState(data); const [dataFilter, setFilterData] = useState(data);
@ -88,11 +88,14 @@ export default function ExtraSidebar() {
<div className="side-bar-button"> <div className="side-bar-button">
<ShadTooltip content="Code" side="top"> <ShadTooltip content="Code" side="top">
{flow && flow.data && ( {flow && flow.data && (
<ApiModal flow={flow}> <ApiModal flow={flow} disable={!isBuilt}>
<div className={classNames("extra-side-bar-buttons")}> <div className={classNames("extra-side-bar-buttons")}>
<IconComponent <IconComponent
name="Code2" name="Code2"
className="side-bar-button-size" className={
"side-bar-button-size" +
(isBuilt ? " " : " extra-side-bar-save-disable")
}
/> />
</div> </div>
</ApiModal> </ApiModal>
@ -102,12 +105,13 @@ export default function ExtraSidebar() {
<div className="side-bar-button"> <div className="side-bar-button">
<ShadTooltip content="Save" side="top"> <ShadTooltip content="Save" side="top">
<button <button
className="extra-side-bar-buttons" className={
"extra-side-bar-buttons " + (isPending ? "" : "button-disable")
}
onClick={(event) => { onClick={(event) => {
saveFlow(flow); saveFlow(flow);
setSuccessData({ title: "Changes saved successfully" }); setSuccessData({ title: "Changes saved successfully" });
}} }}
disabled={!isPending}
> >
<IconComponent <IconComponent
name="Save" name="Save"

View file

@ -81,6 +81,9 @@
.side-bar-button { .side-bar-button {
@apply flex w-full @apply flex w-full
} }
.button-disable {
@apply pointer-events-none
}
.extra-side-bar-buttons { .extra-side-bar-buttons {
@apply relative inline-flex w-full items-center justify-center rounded-md bg-background px-2 py-2 text-foreground shadow-sm ring-1 ring-inset ring-input transition-all duration-500 ease-in-out @apply relative inline-flex w-full items-center justify-center rounded-md bg-background px-2 py-2 text-foreground shadow-sm ring-1 ring-inset ring-input transition-all duration-500 ease-in-out
} }

View file

@ -18,6 +18,8 @@ export type TabsContextType = {
) => void; ) => void;
downloadFlows: () => void; downloadFlows: () => void;
uploadFlows: () => void; uploadFlows: () => void;
isBuilt: boolean;
setIsBuilt: (state: boolean) => void;
uploadFlow: (newFlow?: boolean, file?: File) => void; uploadFlow: (newFlow?: boolean, file?: File) => void;
hardReset: () => void; hardReset: () => void;
getNodeId: (nodeType: string) => string; getNodeId: (nodeType: string) => string;