-
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.
Merge branch 'refs/heads/feature/1319-promotion-subscriptions' into r…
…elease/4.9
- Loading branch information
Showing
11 changed files
with
191 additions
and
12 deletions.
There are no files selected for viewing
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
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
31 changes: 31 additions & 0 deletions
31
...-model/src/test/java/net/nemerosa/ontrack/model/pagination/PaginatedListExtensionsTest.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,31 @@ | ||
package net.nemerosa.ontrack.model.pagination | ||
|
||
import org.junit.jupiter.api.Test | ||
import kotlin.test.assertEquals | ||
import kotlin.test.assertNotNull | ||
|
||
class PaginatedListExtensionsTest { | ||
|
||
@Test | ||
fun `Spanning pagination with one seed`() { | ||
val items = (1..3).map { "Item $it" } | ||
val seed: (offset: Int, size: Int) -> Pair<Int, List<String>> = { offset, size: Int -> | ||
3 to items.drop(offset).take(size) | ||
} | ||
val pl = spanningPaginatedList( | ||
offset = 0, | ||
size = 2, | ||
seeds = listOf(seed) | ||
) | ||
assertEquals(3, pl.pageInfo.totalSize) | ||
assertNotNull(pl.pageInfo.nextPage) | ||
assertEquals( | ||
listOf( | ||
"Item 1", | ||
"Item 2" | ||
), | ||
pl.pageItems | ||
) | ||
} | ||
|
||
} |
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
84 changes: 84 additions & 0 deletions
84
ontrack-web-core/components/extension/notifications/EntitySubscriptions.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,84 @@ | ||
import {useGraphQLClient} from "@components/providers/ConnectionContextProvider"; | ||
import {useEffect, useState} from "react"; | ||
import {gql} from "graphql-request"; | ||
import {List, Space, Tag, Typography} from "antd"; | ||
import SubscriptionLink from "@components/extension/notifications/SubscriptionLink"; | ||
import Link from "next/link"; | ||
import SubscriptionsLink from "@components/extension/notifications/SubscriptionsLink"; | ||
|
||
/** | ||
* This component displays a list of the subscriptions attached to a given entity. | ||
* | ||
* Each subscription can be navigated to and a general link allows to go the list | ||
* of all subscriptions for this entity. | ||
* | ||
* @param type Project entity type | ||
* @param id Project entity ID | ||
*/ | ||
export default function EntitySubscriptions({type, id}) { | ||
|
||
const client = useGraphQLClient() | ||
const [subscriptions, setSubscriptions] = useState([]) | ||
const [pageInfo, setPageInfo] = useState({}) | ||
|
||
useEffect(() => { | ||
if (client) { | ||
client.request( | ||
gql` | ||
query GetEntitySubscriptions($entity: ProjectEntityIDInput!) { | ||
eventSubscriptions(size: 10, filter: { | ||
entity: $entity, | ||
}) { | ||
pageInfo { | ||
totalSize | ||
nextPage { | ||
offset | ||
} | ||
} | ||
pageItems { | ||
name | ||
channel | ||
} | ||
} | ||
} | ||
`, | ||
{entity: {type, id}} | ||
).then(data => { | ||
setSubscriptions(data.eventSubscriptions.pageItems) | ||
setPageInfo(data.eventSubscriptions.pageInfo) | ||
}) | ||
} | ||
}, [client, type, id]) | ||
|
||
return ( | ||
<> | ||
<List | ||
dataSource={subscriptions} | ||
header={ | ||
<Typography.Title type="secondary" level={5}>Subscriptions (<SubscriptionsLink entity={{type, id}} | ||
text={pageInfo.totalSize} | ||
/>)</Typography.Title> | ||
} | ||
size="small" | ||
renderItem={(subscription) => ( | ||
<List.Item> | ||
<List.Item.Meta | ||
title={<SubscriptionLink entity={{type, id}} subscription={subscription}/>} | ||
avatar={<Tag>{subscription.channel}</Tag>} | ||
/> | ||
</List.Item> | ||
)} | ||
footer={ | ||
<div style={{paddingLeft: 16}}> | ||
{ | ||
pageInfo.nextPage && | ||
<SubscriptionsLink entity={{type, id}} | ||
text="More..." | ||
/> | ||
} | ||
</div> | ||
} | ||
/> | ||
</> | ||
) | ||
} |
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