-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathRootProjectSelectionPage.tsx
More file actions
69 lines (63 loc) · 1.79 KB
/
RootProjectSelectionPage.tsx
File metadata and controls
69 lines (63 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import React, { useEffect } from "react";
import {
EuiCard,
EuiFlexGrid,
EuiFlexItem,
EuiIcon,
EuiSkeletonText,
EuiPageTemplate,
EuiText,
EuiTitle,
EuiHorizontalRule,
} from "@elastic/eui";
import { useLoadProjectsList } from "../contexts/ProjectListContext";
import { useNavigate } from "react-router-dom";
import FeastIconBlue from "../graphics/FeastIconBlue";
const RootProjectSelectionPage = () => {
const { isLoading, isSuccess, data } = useLoadProjectsList();
const navigate = useNavigate();
useEffect(() => {
if (data && data.default) {
// If a default is set, redirect there.
navigate(`/p/${data.default}`);
}
if (data && data.projects.length === 1) {
// If there is only one project, redirect there.
navigate(`/p/${data.projects[0].id}`);
}
}, [data, navigate]);
const projectCards = data?.projects.map((item, index) => {
return (
<EuiFlexItem key={index}>
<EuiCard
icon={<EuiIcon size="xxl" type={FeastIconBlue} />}
title={`${item.name}`}
description={item?.description || ""}
onClick={() => {
navigate(`/p/${item.id}`);
}}
/>
</EuiFlexItem>
);
});
return (
<EuiPageTemplate panelled>
<EuiPageTemplate.Section>
<EuiTitle size="s">
<h1>Welcome to Feast</h1>
</EuiTitle>
<EuiText>
<p>Select one of the projects.</p>
</EuiText>
<EuiHorizontalRule margin="m" />
{isLoading && <EuiSkeletonText lines={1} />}
{isSuccess && data?.projects && (
<EuiFlexGrid columns={3} gutterSize="l">
{projectCards}
</EuiFlexGrid>
)}
</EuiPageTemplate.Section>
</EuiPageTemplate>
);
};
export default RootProjectSelectionPage;