Added sorting by date on langflow my collection

This commit is contained in:
Lucas Oliveira 2023-11-21 21:29:31 -03:00
commit 6f709dc3ee
5 changed files with 24 additions and 5 deletions

View file

@ -58,6 +58,7 @@ const FlowsContextInitialValue: FlowsContextType = {
setTabId: (index: string) => {}, setTabId: (index: string) => {},
isLoading: true, isLoading: true,
flows: [], flows: [],
refreshFlows: () => {},
removeFlow: (id: string) => {}, removeFlow: (id: string) => {},
addFlow: async (newProject: boolean, flowData?: FlowType) => "", addFlow: async (newProject: boolean, flowData?: FlowType) => "",
updateFlow: (newFlow: FlowType) => {}, updateFlow: (newFlow: FlowType) => {},
@ -760,6 +761,7 @@ export function FlowsProvider({ children }: { children: ReactNode }) {
tabId, tabId,
setTabId, setTabId,
flows, flows,
refreshFlows,
incrementNodeId, incrementNodeId,
removeFlow, removeFlow,
addFlow, addFlow,

View file

@ -27,6 +27,7 @@ export default function ComponentsComponent({
useEffect(() => { useEffect(() => {
setAllData(flows.filter((f) => f.is_component === is_component)); setAllData(flows.filter((f) => f.is_component === is_component));
console.log(allData);
}, [flows]); }, [flows]);
useEffect(() => { useEffect(() => {
@ -80,11 +81,23 @@ export default function ComponentsComponent({
<div className="grid w-full gap-4 md:grid-cols-2 lg:grid-cols-2"> <div className="grid w-full gap-4 md:grid-cols-2 lg:grid-cols-2">
{!isLoading || data?.length > 0 ? ( {!isLoading || data?.length > 0 ? (
data data
?.sort( ?.sort((a, b) => {
(a, b) => if (a?.updated_at && b?.updated_at) {
new Date(b?.date_created!).getTime() - return (
new Date(a?.date_created!).getTime() new Date(b?.updated_at!).getTime() -
) new Date(a?.updated_at!).getTime()
);
} else if (a?.updated_at && !b?.updated_at) {
return -1;
} else if (!a?.updated_at && b?.updated_at) {
return 1;
} else {
return (
new Date(b?.date_created!).getTime() -
new Date(a?.date_created!).getTime()
);
}
})
.map((item, idx) => ( .map((item, idx) => (
<CollectionCardComponent <CollectionCardComponent
onDelete={() => { onDelete={() => {

View file

@ -17,6 +17,7 @@ export default function HomePage(): JSX.Element {
addFlow, addFlow,
removeFlow, removeFlow,
uploadFlow, uploadFlow,
refreshFlows,
isLoading, isLoading,
} = useContext(FlowsContext); } = useContext(FlowsContext);
const { setErrorData, setSuccessData } = useContext(alertContext); const { setErrorData, setSuccessData } = useContext(alertContext);
@ -62,6 +63,7 @@ export default function HomePage(): JSX.Element {
// Set a null id // Set a null id
useEffect(() => { useEffect(() => {
setTabId(""); setTabId("");
refreshFlows();
}, []); }, []);
const navigate = useNavigate(); const navigate = useNavigate();

View file

@ -10,6 +10,7 @@ export type FlowType = {
is_component: boolean; is_component: boolean;
parent?: string; parent?: string;
date_created?: string; date_created?: string;
updated_at?: string;
last_tested_version?: string; last_tested_version?: string;
}; };
export type NodeType = { export type NodeType = {

View file

@ -7,6 +7,7 @@ export type FlowsContextType = {
isLoading: boolean; isLoading: boolean;
setTabId: (index: string) => void; setTabId: (index: string) => void;
flows: Array<FlowType>; flows: Array<FlowType>;
refreshFlows: () => void;
removeFlow: (id: string) => void; removeFlow: (id: string) => void;
addFlow: ( addFlow: (
newProject: boolean, newProject: boolean,