Skip to content

Commit 3a46524

Browse files
Confluence multiple pages (#42)
Co-authored-by: Cafer Elgin <[email protected]>
1 parent b3a33e1 commit 3a46524

File tree

16 files changed

+1232
-530
lines changed

16 files changed

+1232
-530
lines changed

plugins/confluence-plugin/README.md

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,30 @@ Your Confluence instance URL should look like `https://something.atlassian.net`.
1414

1515
### Set your Confluence credentials
1616

17-
If you are using username and password authentication, type them in to a text editor with a colon (`:`) between them. If you are using SSO, use an API token in place of the password. To create an API token in Confluence, follow the [instructions provided by Atlassian](https://support.atlassian.com/atlassian-account/docs/manage-api-tokens-for-your-atlassian-account/). Once you have your text in your text editor like `[email protected]:MySecretPassWordOrToken`, you need to base64 encode it. You can do this using an online tool like [this](https://www.base64encode.org). You will add the base64 encoded value to Cortex as a secret. Copy the base64 encoded value. In Cortex, click on Settings > Secrets > Add secret. In Secret name, type `confluence_secret`, paste the base64 encoded secret into Secret value, and click on Create secret.
17+
1. If you are using username and password authentication, type them in to a text editor with a colon (`:`) between them. If you are using SSO, use an API token in place of the password. To create an API token in Confluence, follow the [instructions provided by Atlassian](https://support.atlassian.com/atlassian-account/docs/manage-api-tokens-for-your-atlassian-account/).
18+
2. Once you have your text in your text editor like `[email protected]:MySecretPassWordOrToken`, you need to base64 encode it. You can do this using an online tool like [this](https://www.base64encode.org).
19+
3. You will add the base64 encoded value to Cortex as a secret. Copy the base64 encoded value. In Cortex, click on Settings > Secrets > Add secret. In Secret name, type `confluence_secret`, paste the base64 encoded secret into Secret value, and click on Create secret.
1820

1921
### Set up a Plugin Proxy
2022

21-
After you've saved the secret, we will set up a proxy to use that secret to communicate with Confluence. In Cortex, click on Plugins > Proxies > Create Proxy. In Name, type `Confluence Proxy`. Click on Add URL, and put in your Confluence Instance URL, like `https://something.atlassian.net`. Click Save. Next, click on "Add header to https://something.atlassian.net". In the dialog box that appears, type `Authorization` in the Name field, and in the Value field, type `Basic {{{secrets.confluence_secret}}}`. Make sure you include the three curly braces, and make sure the secret name matches the secret you created above, with `secrets.` in front of it. Click Save, then click on the Create Proxy button.
23+
After you've saved the secret, we will set up a proxy to use that secret to communicate with Confluence.
2224

23-
### Associate the plugin with the plugin proxy
25+
1. In Cortex, click on Plugins > Proxies > Create Proxy.
26+
2. In Name, type `Confluence Proxy`.
27+
3. Click on Add URL, and put in your Confluence Instance URL, like `https://something.atlassian.net`. Click Save.
28+
4. Next, click on "Add header to https://something.atlassian.net". In the dialog box that appears, type `Authorization` in the Name field, and in the Value field, type `Basic {{{secrets.confluence_secret}}}`. Make sure you include the three curly braces, and make sure the secret name matches the secret you created above, with `secrets.` in front of it. Click Save, then click on the Create Proxy button.
2429

25-
Create or edit your Confluence Plugin. In the dropdown under the Associated Proxy heading, choose the Confluence proxy you created above. Next, click Save plugin at the bottom of the page.
30+
### Associate the plugin with the plugin proxy and set entity types
31+
32+
1. Create or edit your Confluence Plugin.
33+
2. In the Plugin Context section, find the dropdown under the Associated Proxy heading, choose the Confluence proxy you created above.
34+
3. At the bottom of Plugin Context section, click on **"Add another context"** and add the `entity types` you want to display your plugin. (eg. `service`)
35+
4. Next, click Save plugin at the bottom of the page.
2636

2737
### Create a plugin configuration entity
2838

29-
- Consider creating a new entity type, so that any existing scorecards are not affected by ths configuration entity. In this example, we have created a new entity type called `plugin-configuration`
30-
- Create a new entity with the tag `confluence-plugin-config`
39+
- Consider creating a new **entity type**, so that any existing scorecards are not affected by ths configuration entity. In this example, we have created a new entity type called `plugin-configuration`
40+
- Create a new **entity** with the tag `confluence-plugin-config`
3141
- Set `x-cortex-definition.confluence-url` to the value of your Confluence Instance URL. For example, if my Confluence Instance URL was `https://martindstone.service-now.com`, my `confluence-plugin-config` entity would look like this:
3242

3343
```
@@ -43,18 +53,38 @@ info:
4353

4454
### Adding Confluence content to entities
4555

46-
Entities can be associated with Confluence Page IDs by adding a PageID tag to the `x-cortex-confluence` object. In the Entity yaml for the entity to the Page ID that you'd like to view inside of Cortex, such as:
56+
To associate confluence pages with entities you will require `id` for each page in which you can find by following the instructions on [here](https://confluence.atlassian.com/confkb/how-to-get-confluence-page-id-648380445.html).
57+
58+
Entities can be associated with Confluence Page IDs in two ways:
59+
60+
1. If there is only one confluence page, adding a PageID tag to the `x-cortex-confluence` object will be ok. In the Entity yaml for the entity to the Page ID that you'd like to view inside of Cortex, such as:
4761

4862
```
4963
x-cortex-confluence:
5064
pageID: "123456"
5165
```
5266

67+
2. If there are multiple confluence pages, adding pages under `x-cortex-confluence` and then under `pages` you can enter multiple `id`s and `title`s as well to describe the corresponding confluence page. Entity yaml should look like this:
68+
69+
```
70+
x-cortex-confluence:
71+
pages:
72+
- id: "327681"
73+
title: Page Title 1
74+
- id: "65718"
75+
title: Page Title 2
76+
- id: "1179675"
77+
title: ""
78+
- id: "1277954"
79+
```
80+
81+
The `id` field is mandatory but `title` filed is optional for each page.
82+
5383
You can do this for Custom Entities, as well as any Service entity.
5484

5585
### Done!
5686

57-
Now when you load the Confluence plugin on an entity that has a Confluence page ID in `x-cortex-confluence.pageID`, you should see the content of that page in Cortex!
87+
Now when you load the Confluence plugin on an entity, you should see the contents of associated pages in Cortex!
5888

5989
## Building the plugin
6090

plugins/confluence-plugin/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
"version": "0.1.0",
44
"license": "MIT",
55
"dependencies": {
6+
"@chakra-ui/react": "^2.10.2",
67
"@cortexapps/plugin-core": "^2.0.0",
8+
"@emotion/react": "^11.14.0",
9+
"@emotion/styled": "^11.14.0",
10+
"framer-motion": "^11.15.0",
711
"react": "^18.2.0",
812
"react-dom": "^18.2.0"
913
},

plugins/confluence-plugin/src/api/Cortex.ts

Lines changed: 0 additions & 8 deletions
This file was deleted.

plugins/confluence-plugin/src/components/App.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@ import { PluginProvider } from "@cortexapps/plugin-core/components";
33
import "../baseStyles.css";
44
import ErrorBoundary from "./ErrorBoundary";
55
import PageContent from "./PageContent";
6+
import { ChakraProvider } from "@chakra-ui/react";
67

78
const App: React.FC = () => {
89
return (
910
<ErrorBoundary>
1011
<PluginProvider>
11-
<PageContent />
12+
<ChakraProvider toastOptions={{ defaultOptions: { position: "top" } }}>
13+
<PageContent />
14+
</ChakraProvider>
1215
</PluginProvider>
1316
</ErrorBoundary>
1417
);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Box, Spinner, Text } from "@chakra-ui/react";
2+
3+
export default function Loading(): JSX.Element {
4+
return (
5+
<Box
6+
w={"full"}
7+
minH={400}
8+
display={"flex"}
9+
justifyContent={"center"}
10+
alignItems={"center"}
11+
flexDirection={"column"}
12+
gap={6}
13+
>
14+
<Spinner color="purple" size="xl" />
15+
<Text fontSize="2xl">Loading...</Text>
16+
</Box>
17+
);
18+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { render, waitFor } from "@testing-library/react";
2+
import Notice from "./Notice";
3+
4+
describe("Notice component", () => {
5+
it("renders children correctly", async () => {
6+
const { getByText } = render(<Notice>Test Notice</Notice>);
7+
await waitFor(() => {
8+
expect(getByText("Test Notice")).toBeInTheDocument();
9+
});
10+
});
11+
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { Box, Text } from "@chakra-ui/react";
2+
import type { ReactNode } from "react";
3+
4+
export default function Notice({
5+
children,
6+
}: {
7+
children: ReactNode;
8+
}): JSX.Element {
9+
return (
10+
<Box bg="gray.200" p={3} borderRadius={4}>
11+
<Text m={0}>{children}</Text>
12+
</Box>
13+
);
14+
}

plugins/confluence-plugin/src/components/PageContent.test.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ describe("PageContent", () => {
2424

2525
await waitFor(() => {
2626
expect(
27-
screen.getByText("No Confluence details exist on this entity.")
27+
screen.getByText(
28+
"We could not find any Confluence pages associated with this entity."
29+
)
2830
).toBeInTheDocument();
2931
});
3032
});

0 commit comments

Comments
 (0)