fix(exampleComponent): add Link component to wrap Button for navigation

feat(exampleComponent): add Link to navigate to specific flow based on data id

feat(components): add support for setting examples based on STARTER_FOLDER_NAME constant
feat(components): filter out examples from all flows and set them separately
feat(components): log examples and set them using setExamples function

feat(MainPage): add examples state to store and use it to render ExampleCardComponent
feat(MainPage): map over examples to render ExampleCardComponent for each example

feat(flowsManagerStore): add examples array to store state
feat(flowsManagerStore): add setExamples function to set examples in store

feat(flow): add folder and user_id fields to FlowType

feat(zustand): add examples array and setExamples function to FlowsManagerStoreType
This commit is contained in:
anovazzi1 2024-03-05 20:44:11 -03:00
commit f2395aaee1
6 changed files with 23 additions and 5 deletions

View file

@ -19,6 +19,7 @@ import {
CardTitle, CardTitle,
} from "../ui/card"; } from "../ui/card";
import { FlowType } from "../../types/flow"; import { FlowType } from "../../types/flow";
import { Link } from "react-router-dom";
export default function CollectionCardComponent({ export default function CollectionCardComponent({
data, data,
@ -58,6 +59,7 @@ export default function CollectionCardComponent({
<CardFooter> <CardFooter>
<div className="flex w-full items-center justify-between gap-2"> <div className="flex w-full items-center justify-between gap-2">
<div className="flex w-full justify-end flex-wrap gap-2"> <div className="flex w-full justify-end flex-wrap gap-2">
<Link to={"/flow/" + data.id}>
<Button <Button
tabIndex={-1} tabIndex={-1}
variant="outline" variant="outline"
@ -70,6 +72,7 @@ export default function CollectionCardComponent({
/> />
Select Flow Select Flow
</Button> </Button>
</Link>
</div> </div>
</div> </div>
</CardFooter> </CardFooter>

View file

@ -14,6 +14,7 @@ import {
import useAlertStore from "../../../../stores/alertStore"; import useAlertStore from "../../../../stores/alertStore";
import useFlowsManagerStore from "../../../../stores/flowsManagerStore"; import useFlowsManagerStore from "../../../../stores/flowsManagerStore";
import { FlowType } from "../../../../types/flow"; import { FlowType } from "../../../../types/flow";
import { STARTER_FOLDER_NAME } from "../../../../constants/constants";
export default function ComponentsComponent({ export default function ComponentsComponent({
is_component = true, is_component = true,
@ -24,6 +25,7 @@ export default function ComponentsComponent({
const uploadFlow = useFlowsManagerStore((state) => state.uploadFlow); const uploadFlow = useFlowsManagerStore((state) => state.uploadFlow);
const removeFlow = useFlowsManagerStore((state) => state.removeFlow); const removeFlow = useFlowsManagerStore((state) => state.removeFlow);
const isLoading = useFlowsManagerStore((state) => state.isLoading); const isLoading = useFlowsManagerStore((state) => state.isLoading);
const setExamples = useFlowsManagerStore((state) => state.setExamples);
const flows = useFlowsManagerStore((state) => state.flows); const flows = useFlowsManagerStore((state) => state.flows);
const setSuccessData = useAlertStore((state) => state.setSuccessData); const setSuccessData = useAlertStore((state) => state.setSuccessData);
const setErrorData = useAlertStore((state) => state.setErrorData); const setErrorData = useAlertStore((state) => state.setErrorData);
@ -35,7 +37,7 @@ export default function ComponentsComponent({
useEffect(() => { useEffect(() => {
if (isLoading) return; if (isLoading) return;
const all = flows let all = flows
.filter((f) => (f.is_component ?? false) === is_component) .filter((f) => (f.is_component ?? false) === is_component)
.sort((a, b) => { .sort((a, b) => {
if (a?.updated_at && b?.updated_at) { if (a?.updated_at && b?.updated_at) {
@ -56,6 +58,10 @@ export default function ComponentsComponent({
}); });
const start = (pageIndex - 1) * pageSize; const start = (pageIndex - 1) * pageSize;
const end = start + pageSize; const end = start + pageSize;
const examples = all.filter(f=>(f.folder===STARTER_FOLDER_NAME && !f.user_id));
console.log(examples);
setExamples(examples);
all = all.filter(f=>!(f.folder===STARTER_FOLDER_NAME && !f.user_id));;
setData(all.slice(start, end)); setData(all.slice(start, end));
}, [flows, isLoading, pageIndex, pageSize]); }, [flows, isLoading, pageIndex, pageSize]);

View file

@ -29,6 +29,7 @@ export default function HomePage(): JSX.Element {
const location = useLocation(); const location = useLocation();
const pathname = location.pathname; const pathname = location.pathname;
const [openModal, setOpenModal] = useState(false); const [openModal, setOpenModal] = useState(false);
const examples = useFlowsManagerStore((state) => state.examples);
const is_component = pathname === "/components"; const is_component = pathname === "/components";
const dropdownOptions = [ const dropdownOptions = [
{ {
@ -128,10 +129,10 @@ export default function HomePage(): JSX.Element {
</BaseModal.Header> </BaseModal.Header>
<BaseModal.Content> <BaseModal.Content>
<div className="flex flex-wrap w-full h-full p-4 gap-3"> <div className="flex flex-wrap w-full h-full p-4 gap-3">
<ExampleCardComponent data={ {examples.map((example, idx) => {
{ data: { edges: [], nodes: [], viewport: { x: 0, y: 0, zoom: 1 } }, return(
description: "test description",id:"teste",name:"test name",} <ExampleCardComponent data={example} />)
} /> })}
<NewFlowCardComponent/> <NewFlowCardComponent/>
</div> </div>
</BaseModal.Content> </BaseModal.Content>

View file

@ -37,6 +37,10 @@ const past = {};
const future = {}; const future = {};
const useFlowsManagerStore = create<FlowsManagerStoreType>((set, get) => ({ const useFlowsManagerStore = create<FlowsManagerStoreType>((set, get) => ({
examples:[],
setExamples: (examples: FlowType[]) => {
set({ examples });
},
currentFlowId: "", currentFlowId: "",
setCurrentFlowId: (currentFlowId: string) => { setCurrentFlowId: (currentFlowId: string) => {
set((state) => ({ set((state) => ({

View file

@ -13,6 +13,8 @@ export type FlowType = {
updated_at?: string; updated_at?: string;
date_created?: string; date_created?: string;
parent?: string; parent?: string;
folder?: string;
user_id?: string;
}; };
export type NodeType = { export type NodeType = {

View file

@ -44,6 +44,8 @@ export type FlowsManagerStoreType = {
undo: () => void; undo: () => void;
redo: () => void; redo: () => void;
takeSnapshot: () => void; takeSnapshot: () => void;
examples: Array<FlowType>;
setExamples: (examples: FlowType[]) => void;
}; };
export type UseUndoRedoOptions = { export type UseUndoRedoOptions = {