Fixed sorting
This commit is contained in:
parent
b2c8702db1
commit
103b497328
2 changed files with 53 additions and 53 deletions
|
|
@ -19,15 +19,32 @@ export default function ComponentsComponent({
|
||||||
const { setErrorData, setSuccessData } = useContext(alertContext);
|
const { setErrorData, setSuccessData } = useContext(alertContext);
|
||||||
const [pageSize, setPageSize] = useState(10);
|
const [pageSize, setPageSize] = useState(10);
|
||||||
const [pageIndex, setPageIndex] = useState(1);
|
const [pageIndex, setPageIndex] = useState(1);
|
||||||
const [allData, setAllData] = useState(
|
const [allData, setAllData] = useState(flows);
|
||||||
flows.filter((f) => f.is_component === is_component)
|
|
||||||
);
|
|
||||||
|
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setAllData(flows.filter((f) => f.is_component === is_component));
|
setAllData(
|
||||||
console.log(allData);
|
flows
|
||||||
|
.filter((f) => f.is_component === is_component)
|
||||||
|
.sort((a, b) => {
|
||||||
|
if (a?.updated_at && b?.updated_at) {
|
||||||
|
return (
|
||||||
|
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()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
);
|
||||||
}, [flows]);
|
}, [flows]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -80,54 +97,36 @@ export default function ComponentsComponent({
|
||||||
<div className="flex w-full flex-col gap-4">
|
<div className="flex w-full flex-col gap-4">
|
||||||
<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?.map((item, idx) => (
|
||||||
?.sort((a, b) => {
|
<CollectionCardComponent
|
||||||
if (a?.updated_at && b?.updated_at) {
|
onDelete={() => {
|
||||||
return (
|
removeFlow(item.id);
|
||||||
new Date(b?.updated_at!).getTime() -
|
}}
|
||||||
new Date(a?.updated_at!).getTime()
|
key={idx}
|
||||||
);
|
data={item}
|
||||||
} else if (a?.updated_at && !b?.updated_at) {
|
disabled={isLoading}
|
||||||
return -1;
|
button={
|
||||||
} else if (!a?.updated_at && b?.updated_at) {
|
!is_component ? (
|
||||||
return 1;
|
<Button
|
||||||
} else {
|
variant="outline"
|
||||||
return (
|
size="sm"
|
||||||
new Date(b?.date_created!).getTime() -
|
className="whitespace-nowrap "
|
||||||
new Date(a?.date_created!).getTime()
|
onClick={() => {
|
||||||
);
|
navigate("/flow/" + item.id);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<IconComponent
|
||||||
|
name="ExternalLink"
|
||||||
|
className="main-page-nav-button"
|
||||||
|
/>
|
||||||
|
Edit Flow
|
||||||
|
</Button>
|
||||||
|
) : (
|
||||||
|
<></>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
})
|
/>
|
||||||
.map((item, idx) => (
|
))
|
||||||
<CollectionCardComponent
|
|
||||||
onDelete={() => {
|
|
||||||
removeFlow(item.id);
|
|
||||||
}}
|
|
||||||
key={idx}
|
|
||||||
data={item}
|
|
||||||
disabled={isLoading}
|
|
||||||
button={
|
|
||||||
!is_component ? (
|
|
||||||
<Button
|
|
||||||
variant="outline"
|
|
||||||
size="sm"
|
|
||||||
className="whitespace-nowrap "
|
|
||||||
onClick={() => {
|
|
||||||
navigate("/flow/" + item.id);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IconComponent
|
|
||||||
name="ExternalLink"
|
|
||||||
className="main-page-nav-button"
|
|
||||||
/>
|
|
||||||
Edit Flow
|
|
||||||
</Button>
|
|
||||||
) : (
|
|
||||||
<></>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
))
|
|
||||||
) : !isLoading && data?.length === 0 ? (
|
) : !isLoading && data?.length === 0 ? (
|
||||||
<>You haven't created {name}s yet.</>
|
<>You haven't created {name}s yet.</>
|
||||||
) : (
|
) : (
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,8 @@ export default function HomePage(): JSX.Element {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setTabId("");
|
setTabId("");
|
||||||
refreshFlows();
|
refreshFlows();
|
||||||
}, []);
|
}, [pathname]);
|
||||||
|
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
// Personal flows display
|
// Personal flows display
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue