Skip to content

Commit

Permalink
#1275 Issue service configurations select component
Browse files Browse the repository at this point in the history
  • Loading branch information
dcoraboeuf committed Jul 29, 2024
1 parent d02e08c commit e2240d5
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 11 deletions.
50 changes: 39 additions & 11 deletions ontrack-web-core/components/extension/issues/SelectIssueService.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,56 @@
import {Select, Space, Typography} from "antd";
import {useEffect, useState} from "react";
import {useGraphQLClient} from "@components/providers/ConnectionContextProvider";
import {gql} from "graphql-request";

export default function SelectIssueService({value, onChange, self}) {

const client = useGraphQLClient()

const [loading, setLoading] = useState(false)
const [options, setOptions] = useState([])
const [selfAdded, setSelfAdded] = useState(false)

useEffect(() => {
if (self && !selfAdded) {
setOptions(items => [...items, {
value: "self",
label: <Space>
<Typography.Text>{self}</Typography.Text>
<Typography.Text type="secondary">[self]</Typography.Text>
</Space>,
}])
setSelfAdded(true)
if (client) {
setLoading(true)
client.request(
gql`
query GetIssueServicesConfigurations {
issueServiceConfigurations {
name
id
}
}
`
).then(data => {
const options = data.issueServiceConfigurations.map(({name, id}) => ({
value: id,
label: <Space>
<Typography.Text>{name}</Typography.Text>
<Typography.Text type="secondary">[{id}]</Typography.Text>
</Space>,
}))
if (self) {
options.push({
value: "self",
label: <Space>
<Typography.Text>{self}</Typography.Text>
<Typography.Text type="secondary">[self]</Typography.Text>
</Space>,
})
}
setOptions(options)
}).finally(() => {
setLoading(false)
})
}
}, [self, selfAdded])
}, [client, self])

return (
<>
<Select
options={options}
loading={loading}
value={value}
onChange={onChange}
allowClear={true}
Expand Down
2 changes: 2 additions & 0 deletions ontrack-web-core/ontrack.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -5302,6 +5302,8 @@ type Query {
info: Info
"List of available export formats"
issueExportFormats: [IssueExportFormat!]! @deprecated(reason: "Use the templating service")
"List of issue services"
issueServiceConfigurations: [IssueServiceConfigurationRepresentation!]!
"Getting a Jenkins configuration by name"
jenkinsConfiguration(name: String!): JenkinsConfiguration
"List of Jenkins configurations"
Expand Down

0 comments on commit e2240d5

Please sign in to comment.