chore(flowsContext.tsx): remove unused imports and variables for better code cleanliness
feat(flowsContext.tsx): add support for creating a new flow with a default name if no flow is provided feat(flowsContext.tsx): add support for adding a version number to duplicate flow names feat(flowsContext.tsx): add support for saving a flow to the database and updating its id feat(flowsContext.tsx): add support for deleting a component flow feat(extraSidebarComponent/index.tsx): add support for disabling save button when there are no nodes in the flow
This commit is contained in:
parent
51ff8eb032
commit
eb8ff52ac2
2 changed files with 14 additions and 16 deletions
|
|
@ -43,8 +43,6 @@ import {
|
||||||
createRandomKey,
|
createRandomKey,
|
||||||
getRandomDescription,
|
getRandomDescription,
|
||||||
getRandomName,
|
getRandomName,
|
||||||
getSetFromObject,
|
|
||||||
removeCountFromString,
|
|
||||||
} from "../utils/utils";
|
} from "../utils/utils";
|
||||||
import { alertContext } from "./alertContext";
|
import { alertContext } from "./alertContext";
|
||||||
import { AuthContext } from "./authContext";
|
import { AuthContext } from "./authContext";
|
||||||
|
|
@ -504,27 +502,22 @@ export function FlowsProvider({ children }: { children: ReactNode }) {
|
||||||
let flowData = flow
|
let flowData = flow
|
||||||
? processDataFromFlow(flow)
|
? processDataFromFlow(flow)
|
||||||
: { nodes: [], edges: [], viewport: { zoom: 1, x: 0, y: 0 } };
|
: { nodes: [], edges: [], viewport: { zoom: 1, x: 0, y: 0 } };
|
||||||
|
|
||||||
|
|
||||||
// Create a new flow with a default name if no flow is provided.
|
// Create a new flow with a default name if no flow is provided.
|
||||||
|
|
||||||
const newFlow = createNewFlow(flowData, flow!);
|
const newFlow = createNewFlow(flowData, flow!);
|
||||||
|
|
||||||
|
|
||||||
const newName = addVersionToDuplicates(newFlow, flows);
|
const newName = addVersionToDuplicates(newFlow, flows);
|
||||||
|
|
||||||
|
|
||||||
newFlow.name = newName;
|
newFlow.name = newName;
|
||||||
try {
|
try {
|
||||||
const { id } = await saveFlowToDatabase(newFlow);
|
const { id } = await saveFlowToDatabase(newFlow);
|
||||||
// Change the id to the new id.
|
// Change the id to the new id.
|
||||||
newFlow.id = id;
|
newFlow.id = id;
|
||||||
|
|
||||||
|
|
||||||
// Add the new flow to the list of flows.
|
// Add the new flow to the list of flows.
|
||||||
addFlowToLocalState(newFlow);
|
addFlowToLocalState(newFlow);
|
||||||
|
|
||||||
|
|
||||||
// Return the id
|
// Return the id
|
||||||
return id;
|
return id;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
@ -607,6 +600,7 @@ export function FlowsProvider({ children }: { children: ReactNode }) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function saveFlow(newFlow: FlowType, silent?: boolean) {
|
async function saveFlow(newFlow: FlowType, silent?: boolean) {
|
||||||
|
if (newFlow?.data?.nodes?.length === 0) return;
|
||||||
try {
|
try {
|
||||||
// updates flow in db
|
// updates flow in db
|
||||||
const updatedFlow = await updateFlowInDatabase(newFlow);
|
const updatedFlow = await updateFlowInDatabase(newFlow);
|
||||||
|
|
@ -652,8 +646,7 @@ export function FlowsProvider({ children }: { children: ReactNode }) {
|
||||||
function deleteComponent(key: string) {
|
function deleteComponent(key: string) {
|
||||||
let componentFlow = flows.find(
|
let componentFlow = flows.find(
|
||||||
(componentFlow) =>
|
(componentFlow) =>
|
||||||
componentFlow.is_component &&
|
componentFlow.is_component && componentFlow.name === key
|
||||||
componentFlow.name === key
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if (componentFlow) {
|
if (componentFlow) {
|
||||||
|
|
|
||||||
|
|
@ -252,9 +252,12 @@ export default function ExtraSidebar(): JSX.Element {
|
||||||
<ShadTooltip content="Save" side="top">
|
<ShadTooltip content="Save" side="top">
|
||||||
<div>
|
<div>
|
||||||
<button
|
<button
|
||||||
|
disabled={flow?.data?.nodes.length === 0}
|
||||||
className={
|
className={
|
||||||
"extra-side-bar-buttons " +
|
"extra-side-bar-buttons " +
|
||||||
(isPending ? "" : "button-disable")
|
(isPending && flow!.data!.nodes?.length > 0
|
||||||
|
? ""
|
||||||
|
: "button-disable")
|
||||||
}
|
}
|
||||||
onClick={(event) => {
|
onClick={(event) => {
|
||||||
saveFlow({ ...flow!, data: reactFlowInstance!.toObject() });
|
saveFlow({ ...flow!, data: reactFlowInstance!.toObject() });
|
||||||
|
|
@ -264,7 +267,9 @@ export default function ExtraSidebar(): JSX.Element {
|
||||||
name="Save"
|
name="Save"
|
||||||
className={
|
className={
|
||||||
"side-bar-button-size" +
|
"side-bar-button-size" +
|
||||||
(isPending ? " " : " extra-side-bar-save-disable")
|
(isPending && flow!.data!.nodes?.length > 0
|
||||||
|
? " "
|
||||||
|
: " extra-side-bar-save-disable")
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
</button>
|
</button>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue