Skip to content

Commit

Permalink
Improve footer version info
Browse files Browse the repository at this point in the history
  • Loading branch information
jake-low committed Dec 18, 2024
1 parent 9024312 commit fc83c9e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 33 deletions.
58 changes: 25 additions & 33 deletions src/components/Footer/Footer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,63 +3,55 @@ import { FormattedMessage, injectIntl } from 'react-intl'
import SvgSymbol from '../SvgSymbol/SvgSymbol'
import messages from './Messages'

import { version } from '../../../package.json'

class Footer extends Component {
constructor(props) {
super(props);

this.state = {
data : null
};
}
state = {
serviceInfo: null
};

componentDidMount() {
this.renderMyData();
}

renderMyData(){
fetch(`${window.env.REACT_APP_MAP_ROULETTE_SERVER_URL}/api/v2/service/info`)
.then((response) => response.json())
.then((responseJson) => {
this.setState({ data : responseJson })
.then((res) => res.json())
.then((serviceInfo) => {
this.setState({ serviceInfo });
})
.catch((error) => {
console.error(error);
});
}

render() {
let frontendVersion = __GIT_TAG__ !== '' ? __GIT_TAG__ : __GIT_SHA__.slice(0, 7);

Check failure on line 23 in src/components/Footer/Footer.jsx

View workflow job for this annotation

GitHub Actions / build (18)

src/App.test.jsx > App > renders MapRoulette landing page and slogan

ReferenceError: __GIT_TAG__ is not defined ❯ Footer.render src/components/Footer/Footer.jsx:23:27 ❯ finishClassComponent node_modules/react-dom/cjs/react-dom.development.js:17485:31 ❯ updateClassComponent node_modules/react-dom/cjs/react-dom.development.js:17435:24 ❯ beginWork node_modules/react-dom/cjs/react-dom.development.js:19073:16 ❯ HTMLUnknownElement.callCallback node_modules/react-dom/cjs/react-dom.development.js:3945:14 ❯ HTMLUnknownElement.callTheUserObjectsOperation node_modules/jsdom/lib/jsdom/living/generated/EventListener.js:26:30 ❯ innerInvokeEventListeners node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:350:25 ❯ invokeEventListeners node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:286:3 ❯ HTMLUnknownElementImpl._dispatch node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:233:9 ❯ HTMLUnknownElementImpl.dispatchEvent node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:104:17

Check failure on line 23 in src/components/Footer/Footer.jsx

View workflow job for this annotation

GitHub Actions / build (20)

src/App.test.jsx > App > renders MapRoulette landing page and slogan

ReferenceError: __GIT_TAG__ is not defined ❯ Footer.render src/components/Footer/Footer.jsx:23:27 ❯ finishClassComponent node_modules/react-dom/cjs/react-dom.development.js:17485:31 ❯ updateClassComponent node_modules/react-dom/cjs/react-dom.development.js:17435:24 ❯ beginWork node_modules/react-dom/cjs/react-dom.development.js:19073:16 ❯ HTMLUnknownElement.callCallback node_modules/react-dom/cjs/react-dom.development.js:3945:14 ❯ HTMLUnknownElement.callTheUserObjectsOperation node_modules/jsdom/lib/jsdom/living/generated/EventListener.js:26:30 ❯ innerInvokeEventListeners node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:350:25 ❯ invokeEventListeners node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:286:3 ❯ HTMLUnknownElementImpl._dispatch node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:233:9 ❯ HTMLUnknownElementImpl.dispatchEvent node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:104:17
let frontendVersionUrl = __GIT_TAG__ !== ''
? `https://github.com/maproulette/maproulette3/releases/tag/${__GIT_TAG__}`
: `https://github.com/maproulette/maproulette3/commit/${__GIT_SHA__}`;

let info = this.state.serviceInfo?.compiletime;
let backendVersion = info?.version === info?.gitHeadCommit
? info?.gitHeadCommit.slice(0, 7)
: info?.version;
let backendVersionUrl = info?.version === info?.gitHeadCommit
? `https://github.com/maproulette/maproulette-backend/commit/${info?.gitHeadCommit}`
: `https://github.com/maproulette/maproulette-backend/releases/tag/v${info?.version}`;

return (
<footer
className="mr-px-4 mr-py-12 md:mr-py-24 mr-links-green-lighter"
>
<footer className="mr-px-4 mr-py-12 md:mr-py-24 mr-links-green-lighter">
<div className="mr-max-w-3xl mr-mx-auto mr-overflow-hidden">
<div className="md:mr-flex md:mr--mx-4">
<div className="mr-mb-8 md:mr-mb-0 md:mr-px-4 md:mr-flex-1">
<h3 className="mr-text-white mr-text-md mr-mb-2">
<FormattedMessage {...messages.versionLabel} />{' '}
<span className="mr-text-green-light mr-font-mono mr-text-base">
<a
href={`https://github.com/maproulette/maproulette3/releases/tag/v${version}`}
>
v{version}
</a>
<a href={frontendVersionUrl}>{frontendVersion}</a>
</span>
</h3>
{ this.state.data ?
{ this.state.serviceInfo && (
<h3 className="mr-text-white mr-text-md mr-mb-2">
<FormattedMessage {...messages.APIVersionLabel} />{' '}
<span className="mr-text-green-light mr-font-mono mr-text-base">
<a
href={`https://github.com/maproulette/maproulette-backend/releases/tag/v${this.state.data.compiletime.version}`}
>
v{this.state.data.compiletime.version}
</a>
<a href={backendVersionUrl}>{backendVersion}</a>
</span>
</h3> :
null
}
</h3>
)}
</div>

<div className="mr-mb-8 md:mr-mb-0 md:mr-px-4 md:mr-flex-1">
Expand Down
6 changes: 6 additions & 0 deletions vite.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react-swc';

import { execSync } from 'node:child_process';

// https://vitejs.dev/config/
export default defineConfig({
base: '/',
Expand All @@ -12,4 +14,8 @@ export default defineConfig({
port: 3000,
},
plugins: [react()],
define: {
__GIT_SHA__: JSON.stringify(execSync('git rev-parse HEAD').toString()),
__GIT_TAG__: JSON.stringify(execSync('git describe --tags --exact-match 2>/dev/null || true').toString()),
},
});

0 comments on commit fc83c9e

Please sign in to comment.