Skip to content

Commit

Permalink
[WKP-2269] Adds server/ui version to the UI (#30)
Browse files Browse the repository at this point in the history
* Adds server/ui version to the UI

* Fix ui linting

* Moves help/version outside the white content boxes
  • Loading branch information
foot authored Sep 1, 2021
1 parent 8119c57 commit ed8d63e
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ cmd/ui-server/ui-server:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-X main.version=$(VERSION)" -o $@ cmd/ui-server/*.go

ui-cra/build:
cd ui-cra && yarn install --frozen-lockfile && yarn build
cd ui-cra && yarn install --frozen-lockfile && REACT_APP_VERSION=$(VERSION) yarn build

lint:
bin/go-lint
Expand Down
23 changes: 15 additions & 8 deletions ui-cra/src/components/Layout/ContentWrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { FC } from 'react';
import styled, { css } from 'styled-components';
import { spacing } from 'weaveworks-ui-components/lib/theme/selectors';
import useVersions from '../../contexts/Versions';

export const pageDimensionsCss = css`
width: 100%;
Expand All @@ -16,7 +17,7 @@ const medium = spacing('medium');
const large = spacing('large');

export const contentCss = css`
margin: ${medium} ${small} ${small} ${small};
margin: ${medium} ${small} 0 ${small};
padding: ${large} ${medium} ${medium} ${medium};
background-color: white;
border-radius: ${spacing('xs')};
Expand All @@ -27,9 +28,11 @@ export const Content = styled.div`
`;

const HelpLinkWrapper = styled.div`
margin: 0 ${small};
padding: ${small} ${small};
display: flex;
justify-content: flex-end;
margin-top: ${large};
flex-direction: column;
align-items: flex-end;
color: ${({ theme }) => theme.colors.gray600};
white-space: nowrap;
line-height: 1.5em;
Expand All @@ -39,13 +42,17 @@ const HelpLinkWrapper = styled.div`
`;

export const ContentWrapper: FC = ({ children }) => {
const versions = useVersions();
return (
<Content>
{children}
<>
<Content>{children}</Content>
<HelpLinkWrapper>
Need help? Contact us at&nbsp;
<a href="mailto:[email protected]">[email protected]</a>
<div>
Need help? Contact us at{' '}
<a href="mailto:[email protected]">[email protected]</a>
</div>
<div>Version {versions.versions?.capiServer}</div>
</HelpLinkWrapper>
</Content>
</>
);
};
2 changes: 2 additions & 0 deletions ui-cra/src/components/ResponsiveDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
} from '@weaveworks/weave-gitops';
import TemplatesProvider from '../contexts/Templates/Provider';
import NotificationsProvider from '../contexts/Notifications/Provider';
import VersionsProvider from '../contexts/Versions/Provider';
import Compose from './ProvidersCompose';
import Box from '@material-ui/core/Box';
import { PageTemplate } from './Layout/PageTemplate';
Expand Down Expand Up @@ -135,6 +136,7 @@ const ResponsiveDrawer = () => {
ClustersProvider,
AlertsProvider,
WGAppProvider,
VersionsProvider,
]}
>
<div className={classes.root}>
Expand Down
30 changes: 30 additions & 0 deletions ui-cra/src/contexts/Versions/Provider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React, { FC, useCallback, useEffect, useState } from 'react';
import { ClustersService } from '../../capi-server/capi_server.pb';
import { Versions, VersionData } from './index';

const VersionsProvider: FC = ({ children }) => {
const [versions, setVersions] = useState<VersionData>({
ui: process.env.REACT_APP_VERSION || 'no version specified',
});

const getVersions = useCallback(() => {
ClustersService.GetEnterpriseVersion({}).then(res => {
console.log('weave-gitops-enterprise capiServer:', res.version);
setVersions(s => ({ ...s, capiServer: res.version }));
});
}, []);

useEffect(() => getVersions(), [getVersions]);

return (
<Versions.Provider
value={{
versions,
}}
>
{children}
</Versions.Provider>
);
};

export default VersionsProvider;
14 changes: 14 additions & 0 deletions ui-cra/src/contexts/Versions/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { createContext, useContext } from 'react';

export interface VersionData {
ui: string;
capiServer?: string;
}

type VersionsContext = {
versions: VersionData | null;
};

export const Versions = createContext<VersionsContext | null>(null);

export default () => useContext(Versions) as VersionsContext;
2 changes: 2 additions & 0 deletions ui-cra/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import ReactDOM from 'react-dom';
import App from './App';
import reportWebVitals from './reportWebVitals';

console.log('weave-gitops-enterprise ui:', process.env.REACT_APP_VERSION);

ReactDOM.render(
<React.StrictMode>
<App />
Expand Down

0 comments on commit ed8d63e

Please sign in to comment.