Created
June 28, 2022 17:16
-
-
Save craigthomasfrost/edee4bdbb10a514c8f6b9ff7a3cd1bab to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import api, { route } from "@forge/api"; | |
| const fetchSpaces = async () => { | |
| const res = await api.asApp().requestConfluence(route`/wiki/rest/api/space?type=global`, { | |
| headers: { | |
| 'Accept': 'application/json' | |
| } | |
| }); | |
| const data = await res.json(); | |
| return data.results; | |
| }; | |
| export default fetchSpaces; |
This file contains hidden or 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
| import ForgeUI, { render, Macro, MacroConfig, Link, Text, useState, useConfig, Table, Head, Row, Cell, Select, Option } from "@forge/ui"; | |
| import fetchSpaces from "./api/fetch-spaces"; | |
| import fetchLabelInfo from "./api/fetch-contents"; | |
| const App = () => { | |
| const [spaces] = useState(async () => await fetchSpaces()); | |
| const defaultConfig = { | |
| space: spaces[0].key | |
| }; | |
| const config = useConfig() || defaultConfig; | |
| const [labelInfo] = useState(async () => await fetchLabelInfo(config.space)); | |
| return ( | |
| <Table> | |
| <Head> | |
| <Cell> | |
| <Text>Label</Text> | |
| </Cell> | |
| <Cell> | |
| <Text>Page count</Text> | |
| </Cell> | |
| </Head> | |
| {labelInfo.sort((a, b) => parseInt(b.contentsCount) - parseInt(a.contentsCount)).map(label => ( | |
| <Row> | |
| <Cell> | |
| <Text> | |
| <Link href={`/wiki/label/PR/${label.labelName}`}>{label.labelName}</Link> | |
| </Text> | |
| </Cell> | |
| <Cell> | |
| <Text>{label.contentsCount}</Text> | |
| </Cell> | |
| </Row> | |
| ))} | |
| </Table> | |
| ); | |
| }; | |
| const Config = () => { | |
| const [spaces] = useState(async () => await fetchSpaces()); | |
| return ( | |
| <MacroConfig> | |
| <Select name="space" label="Space"> | |
| {spaces.map((space, index) => { | |
| return <Option label={space.name} value={space.key} defaultSelected={index == 0} /> | |
| })} | |
| </Select> | |
| </MacroConfig> | |
| ); | |
| }; | |
| export const config = render(<Config />); | |
| export const run = render( | |
| <Macro | |
| app={<App />} | |
| /> | |
| ); |
This file contains hidden or 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
| modules: | |
| macro: | |
| - key: labels-by-page-count | |
| function: main | |
| title: Labels by page count | |
| description: Displays labels and page count | |
| config: | |
| function: primary-config | |
| function: | |
| - key: main | |
| handler: index.run | |
| - key: primary-config | |
| handler: index.config | |
| app: | |
| id: ari:cloud:ecosystem::app/{appId} | |
| permissions: | |
| scopes: | |
| - read:confluence-space.summary | |
| - read:confluence-content.summary | |
| - read:content:confluence | |
| - read:label:confluence | |
| - read:content-details:confluence |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment