-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6e95a56
commit 533db42
Showing
7 changed files
with
167 additions
and
30 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
...ck-model/src/main/java/net/nemerosa/ontrack/model/dashboards/widgets/ProjectListWidget.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package net.nemerosa.ontrack.model.dashboards.widgets | ||
|
||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class ProjectListWidget : AbstractWidget<ProjectListWidget.ProjectListWidgetConfig>( | ||
key = "home/ProjectList", | ||
name = "Project list", | ||
description = "Fixed list of projects, suitable to easily a list of projects in a dashboard.", | ||
defaultConfig = ProjectListWidgetConfig(), | ||
preferredHeight = 6, | ||
) { | ||
|
||
data class ProjectListWidgetConfig( | ||
val projectNames: List<String> = emptyList(), | ||
) : WidgetConfig | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import {Empty, Space, Typography} from "antd"; | ||
import RowTag from "@components/common/RowTag"; | ||
import ProjectBox from "@components/projects/ProjectBox"; | ||
|
||
export default function SimpleProjectList({projects, emptyText}) { | ||
return ( | ||
<> | ||
{ | ||
projects && projects.length > 0 && | ||
<Space direction="horizontal" size={16} wrap> | ||
{ | ||
projects.map(project => <RowTag key={project.id}> | ||
<ProjectBox project={project}/> | ||
</RowTag> | ||
) | ||
} | ||
</Space> | ||
} | ||
{ | ||
(!projects || projects.length === 0) && <Empty | ||
image={Empty.PRESENTED_IMAGE_SIMPLE} | ||
description={<Typography.Text>{emptyText}</Typography.Text>} | ||
/> | ||
} | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
ontrack-web-core/components/widgets/home/ProjectListWidget.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import {gql} from "graphql-request"; | ||
import React, {useContext, useEffect, useState} from "react"; | ||
import {DashboardWidgetCellContext} from "@components/dashboards/DashboardWidgetCellContextProvider"; | ||
import {useGraphQLClient} from "@components/providers/ConnectionContextProvider"; | ||
import PaddedContent from "@components/common/PaddedContent"; | ||
import SimpleProjectList from "@components/projects/SimpleProjectList"; | ||
import {Skeleton} from "antd"; | ||
import {gqlDecorationFragment} from "@components/services/fragments"; | ||
|
||
export default function ProjectListWidget({projectNames}) { | ||
|
||
const client = useGraphQLClient() | ||
const [loading, setLoading] = useState(true) | ||
const [projects, setProjects] = useState([]) | ||
|
||
const {setTitle} = useContext(DashboardWidgetCellContext) | ||
setTitle("Project list") | ||
|
||
const fetchProject = async (name) => { | ||
const data = await client.request( | ||
gql` | ||
query GetProjectByName($name: String!) { | ||
projects(name: $name) { | ||
id | ||
name | ||
favourite | ||
decorations { | ||
...decorationContent | ||
} | ||
} | ||
} | ||
${gqlDecorationFragment} | ||
`, | ||
{name} | ||
) | ||
const projects = data.projects | ||
if (projects.length > 0) { | ||
return projects[0] | ||
} else { | ||
return null | ||
} | ||
} | ||
|
||
useEffect(() => { | ||
if (client) { | ||
|
||
const fetchProjects = async () => { | ||
setLoading(true) | ||
try { | ||
const projectPromises = projectNames.map(name => fetchProject(name)) | ||
const projectsData = await Promise.all(projectPromises) | ||
setProjects(projectsData.filter(it => it !== null)) | ||
} finally { | ||
setLoading(false) | ||
} | ||
} | ||
|
||
// noinspection JSIgnoredPromiseFromCall | ||
fetchProjects() | ||
} | ||
}, [client, projectNames]); | ||
|
||
return ( | ||
<PaddedContent> | ||
<Skeleton loading={loading} active> | ||
<SimpleProjectList | ||
projects={projects} | ||
emptyText={ | ||
<> | ||
No project has been selected. | ||
</> | ||
} | ||
/> | ||
</Skeleton> | ||
</PaddedContent> | ||
) | ||
} |
27 changes: 27 additions & 0 deletions
27
ontrack-web-core/components/widgets/home/ProjectListWidgetForm.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import {useContext} from "react"; | ||
import {Form} from "antd"; | ||
import SelectProject from "@components/projects/SelectProject"; | ||
import {DashboardWidgetCellContext} from "@components/dashboards/DashboardWidgetCellContextProvider"; | ||
|
||
export default function ProjectListWidgetForm({projectNames}) { | ||
|
||
const {widgetEditionForm} = useContext(DashboardWidgetCellContext) | ||
|
||
return ( | ||
<> | ||
<Form | ||
layout="vertical" | ||
form={widgetEditionForm} | ||
> | ||
<Form.Item | ||
name="projectNames" | ||
label="Projects" | ||
initialValue={projectNames} | ||
extra="List of projects to display" | ||
> | ||
<SelectProject multiple={true} width="100%"/> | ||
</Form.Item> | ||
</Form> | ||
</> | ||
) | ||
} |