Skip to content

Commit 2e7af15

Browse files
authored
Merge pull request #42 from Flared/mahinse/show_version_in_status
Showing the application version in the status page
2 parents 949c76f + a680c6c commit 2e7af15

4 files changed

Lines changed: 62 additions & 20 deletions

File tree

packages/status-screen/src/StatusScreen.tsx

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useEffect, FC, useState } from 'react';
22
import './global.css';
33
import './StatusScreen.css';
4-
import { findCollection, retrieveTenantId } from './utils/setupConfiguration';
4+
import { findCollection, getVersionName, retrieveTenantId } from './utils/setupConfiguration';
55
import { SplunkCollectionItem } from './models/splunk';
66
import Button from './components/Button';
77

@@ -21,28 +21,32 @@ interface StatusItem {
2121
}
2222

2323
const StatusScreen: FC<{ theme: string }> = ({ theme }) => {
24+
const [versionName, setVersionName] = useState<string>('unknown');
2425
const [statusItems, setStatusItem] = useState<StatusItem[]>([]);
2526
const [isShowingAllItems, setShowingAllItems] = useState<boolean>(false);
2627

2728
useEffect(() => {
28-
Promise.all([retrieveTenantId(), findCollection()]).then(([id, splunkCollectionItems]) => {
29-
const items: StatusItem[] = [];
30-
items.push({
31-
key: StatusItemKeys.CURRENT_TENANT_ID,
32-
name: getItemName(StatusItemKeys.CURRENT_TENANT_ID),
33-
value: `${id}`,
34-
});
35-
splunkCollectionItems.forEach((item) => {
29+
Promise.all([retrieveTenantId(), findCollection(), getVersionName()]).then(
30+
([id, splunkCollectionItems, version]) => {
31+
const items: StatusItem[] = [];
3632
items.push({
37-
key: item.key.startsWith(COLLECTION_KEYS_NEXT_PREFIX)
38-
? StatusItemKeys.NEXT_TOKEN
39-
: (item.key as StatusItemKeys),
40-
name: getItemName(item.key),
41-
value: formatValue(item),
33+
key: StatusItemKeys.CURRENT_TENANT_ID,
34+
name: getItemName(StatusItemKeys.CURRENT_TENANT_ID),
35+
value: `${id}`,
4236
});
43-
});
44-
setStatusItem(items);
45-
});
37+
splunkCollectionItems.forEach((item) => {
38+
items.push({
39+
key: item.key.startsWith(COLLECTION_KEYS_NEXT_PREFIX)
40+
? StatusItemKeys.NEXT_TOKEN
41+
: (item.key as StatusItemKeys),
42+
name: getItemName(item.key),
43+
value: formatValue(item),
44+
});
45+
});
46+
setStatusItem(items);
47+
setVersionName(version);
48+
}
49+
);
4650
}, []);
4751

4852
useEffect(() => {
@@ -101,7 +105,10 @@ const StatusScreen: FC<{ theme: string }> = ({ theme }) => {
101105
<div id="container" className={theme === 'dark' ? 'dark' : ''}>
102106
<div id="experimental">This is an experimental release</div>
103107
<div className="content">
104-
<h2>Status</h2>
108+
<div>
109+
<h2>Status</h2>
110+
<small>{`Version: ${versionName}`}</small>
111+
</div>
105112
<div id="status-list">
106113
{getItems().map((item) => {
107114
return (

packages/status-screen/src/global.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ h2 {
102102
h5 {
103103
font-size: 1rem;
104104
color: var(--text-color);
105-
margin-top: 8px;
106105
text-align: start;
107106
font-weight: normal;
108107
}

packages/status-screen/src/utils/configurationFileHelper.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,29 @@ export async function getCurrentIndexName(service: SplunkService): Promise<strin
164164

165165
return currentIndex;
166166
}
167+
168+
export async function getVersion(service: SplunkService): Promise<string> {
169+
// Retrieve the accessor used to get a configuration file
170+
let configurations = service.configurations({
171+
// Name space information not provided
172+
});
173+
configurations = await promisify(configurations.fetch)();
174+
175+
// Retrieves the configuration file accessor
176+
let configurationFileAccessor = getConfigurationFile(configurations, 'app');
177+
configurationFileAccessor = await promisify(configurationFileAccessor.fetch)();
178+
179+
// Retrieves the configuration stanza accessor
180+
let configurationStanzaAccessor = getConfigurationFileStanza(
181+
configurationFileAccessor,
182+
'launcher'
183+
);
184+
configurationStanzaAccessor = await promisify(configurationStanzaAccessor.fetch)();
185+
186+
let versionName = 'unknown';
187+
if ('version' in configurationStanzaAccessor._properties) {
188+
versionName = configurationStanzaAccessor._properties.version;
189+
}
190+
191+
return versionName;
192+
}

packages/status-screen/src/utils/setupConfiguration.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { updateConfigurationFile, getCurrentIndexName } from './configurationFileHelper';
1+
import {
2+
updateConfigurationFile,
3+
getCurrentIndexName,
4+
getVersion,
5+
} from './configurationFileHelper';
26
import { Tenant } from '../models/flare';
37
import {
48
PasswordKeys,
@@ -51,6 +55,11 @@ async function getFlareDataUrl(): Promise<string> {
5155
return `/app/${appName}/search?q=search%20index%3D"${indexName}"%20source%3D"flare"`;
5256
}
5357

58+
async function getVersionName(): Promise<string> {
59+
const service = createService(applicationNameSpace);
60+
return getVersion(service);
61+
}
62+
5463
function redirectToHomepage(): void {
5564
window.location.href = getRedirectUrl();
5665
}
@@ -197,4 +206,5 @@ export {
197206
getRedirectUrl,
198207
getFlareDataUrl,
199208
findCollection,
209+
getVersionName,
200210
};

0 commit comments

Comments
 (0)