Merge pull request #1716 from automatisch/AUT-828
refactor: rewrite useVersion and healthcheck with RQ
This commit is contained in:
@@ -1,9 +0,0 @@
|
|||||||
import appConfig from '../../config/app.js';
|
|
||||||
|
|
||||||
const healthcheck = () => {
|
|
||||||
return {
|
|
||||||
version: appConfig.version,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
export default healthcheck;
|
|
@@ -1,27 +0,0 @@
|
|||||||
import { describe, it, expect } from 'vitest';
|
|
||||||
import request from 'supertest';
|
|
||||||
import app from '../../app';
|
|
||||||
import appConfig from '../../config/app';
|
|
||||||
|
|
||||||
describe('graphQL healthcheck query', () => {
|
|
||||||
it('should return application version', async () => {
|
|
||||||
const query = `
|
|
||||||
query {
|
|
||||||
healthcheck {
|
|
||||||
version
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
|
|
||||||
const response = await request(app)
|
|
||||||
.post('/graphql')
|
|
||||||
.send({ query })
|
|
||||||
.expect(200);
|
|
||||||
|
|
||||||
const expectedResponsePayload = {
|
|
||||||
data: { healthcheck: { version: appConfig.version } },
|
|
||||||
};
|
|
||||||
|
|
||||||
expect(response.body).toEqual(expectedResponsePayload);
|
|
||||||
});
|
|
||||||
});
|
|
@@ -21,7 +21,6 @@ import getSubscriptionStatus from './queries/get-subscription-status.ee.js';
|
|||||||
import getTrialStatus from './queries/get-trial-status.ee.js';
|
import getTrialStatus from './queries/get-trial-status.ee.js';
|
||||||
import getUser from './queries/get-user.js';
|
import getUser from './queries/get-user.js';
|
||||||
import getUsers from './queries/get-users.js';
|
import getUsers from './queries/get-users.js';
|
||||||
import healthcheck from './queries/healthcheck.js';
|
|
||||||
import listSamlAuthProviders from './queries/list-saml-auth-providers.ee.js';
|
import listSamlAuthProviders from './queries/list-saml-auth-providers.ee.js';
|
||||||
import testConnection from './queries/test-connection.js';
|
import testConnection from './queries/test-connection.js';
|
||||||
|
|
||||||
@@ -49,7 +48,6 @@ const queryResolvers = {
|
|||||||
getTrialStatus,
|
getTrialStatus,
|
||||||
getUser,
|
getUser,
|
||||||
getUsers,
|
getUsers,
|
||||||
healthcheck,
|
|
||||||
listSamlAuthProviders,
|
listSamlAuthProviders,
|
||||||
testConnection,
|
testConnection,
|
||||||
};
|
};
|
||||||
|
@@ -37,7 +37,6 @@ type Query {
|
|||||||
getTrialStatus: GetTrialStatus
|
getTrialStatus: GetTrialStatus
|
||||||
getUser(id: String!): User
|
getUser(id: String!): User
|
||||||
getUsers(limit: Int!, offset: Int!): UserConnection
|
getUsers(limit: Int!, offset: Int!): UserConnection
|
||||||
healthcheck: AppHealth
|
|
||||||
listSamlAuthProviders: [ListSamlAuthProvider]
|
listSamlAuthProviders: [ListSamlAuthProvider]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -602,10 +601,6 @@ type ExecutionStepConnection {
|
|||||||
pageInfo: PageInfo
|
pageInfo: PageInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
type AppHealth {
|
|
||||||
version: String
|
|
||||||
}
|
|
||||||
|
|
||||||
type License {
|
type License {
|
||||||
id: String
|
id: String
|
||||||
name: String
|
name: String
|
||||||
|
@@ -44,7 +44,6 @@ export const authenticationRules = {
|
|||||||
'*': isAuthenticatedRule,
|
'*': isAuthenticatedRule,
|
||||||
getConfig: allow,
|
getConfig: allow,
|
||||||
getNotifications: allow,
|
getNotifications: allow,
|
||||||
healthcheck: allow,
|
|
||||||
listSamlAuthProviders: allow,
|
listSamlAuthProviders: allow,
|
||||||
},
|
},
|
||||||
Mutation: {
|
Mutation: {
|
||||||
|
@@ -9,12 +9,14 @@ import SwapCallsIcon from '@mui/icons-material/SwapCalls';
|
|||||||
import HistoryIcon from '@mui/icons-material/History';
|
import HistoryIcon from '@mui/icons-material/History';
|
||||||
import NotificationsIcon from '@mui/icons-material/Notifications';
|
import NotificationsIcon from '@mui/icons-material/Notifications';
|
||||||
import ArrowBackIosNew from '@mui/icons-material/ArrowBackIosNew';
|
import ArrowBackIosNew from '@mui/icons-material/ArrowBackIosNew';
|
||||||
|
|
||||||
import * as URLS from 'config/urls';
|
import * as URLS from 'config/urls';
|
||||||
import useFormatMessage from 'hooks/useFormatMessage';
|
import useFormatMessage from 'hooks/useFormatMessage';
|
||||||
import useVersion from 'hooks/useVersion';
|
import useVersion from 'hooks/useVersion';
|
||||||
import AppBar from 'components/AppBar';
|
import AppBar from 'components/AppBar';
|
||||||
import Drawer from 'components/Drawer';
|
import Drawer from 'components/Drawer';
|
||||||
import useConfig from 'hooks/useConfig';
|
import useConfig from 'hooks/useConfig';
|
||||||
|
|
||||||
const drawerLinks = [
|
const drawerLinks = [
|
||||||
{
|
{
|
||||||
Icon: SwapCallsIcon,
|
Icon: SwapCallsIcon,
|
||||||
@@ -35,6 +37,7 @@ const drawerLinks = [
|
|||||||
dataTest: 'executions-page-drawer-link',
|
dataTest: 'executions-page-drawer-link',
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const generateDrawerBottomLinks = async ({
|
const generateDrawerBottomLinks = async ({
|
||||||
disableNotificationsPage,
|
disableNotificationsPage,
|
||||||
notificationBadgeContent = 0,
|
notificationBadgeContent = 0,
|
||||||
@@ -48,23 +51,30 @@ const generateDrawerBottomLinks = async ({
|
|||||||
to: URLS.UPDATES,
|
to: URLS.UPDATES,
|
||||||
badgeContent: notificationBadgeContent,
|
badgeContent: notificationBadgeContent,
|
||||||
};
|
};
|
||||||
|
|
||||||
const hasAdditionalDrawerLink =
|
const hasAdditionalDrawerLink =
|
||||||
additionalDrawerLink && additionalDrawerLinkText;
|
additionalDrawerLink && additionalDrawerLinkText;
|
||||||
|
|
||||||
const additionalDrawerLinkObject = {
|
const additionalDrawerLinkObject = {
|
||||||
Icon: ArrowBackIosNew,
|
Icon: ArrowBackIosNew,
|
||||||
primary: additionalDrawerLinkText || '',
|
primary: additionalDrawerLinkText || '',
|
||||||
to: additionalDrawerLink || '',
|
to: additionalDrawerLink || '',
|
||||||
target: '_blank',
|
target: '_blank',
|
||||||
};
|
};
|
||||||
|
|
||||||
const links = [];
|
const links = [];
|
||||||
|
|
||||||
if (!disableNotificationsPage) {
|
if (!disableNotificationsPage) {
|
||||||
links.push(notificationsPageLinkObject);
|
links.push(notificationsPageLinkObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasAdditionalDrawerLink) {
|
if (hasAdditionalDrawerLink) {
|
||||||
links.push(additionalDrawerLinkObject);
|
links.push(additionalDrawerLinkObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
return links;
|
return links;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function PublicLayout({ children }) {
|
export default function PublicLayout({ children }) {
|
||||||
const version = useVersion();
|
const version = useVersion();
|
||||||
const { config, loading } = useConfig([
|
const { config, loading } = useConfig([
|
||||||
@@ -79,6 +89,7 @@ export default function PublicLayout({ children }) {
|
|||||||
const [isDrawerOpen, setDrawerOpen] = React.useState(!matchSmallScreens);
|
const [isDrawerOpen, setDrawerOpen] = React.useState(!matchSmallScreens);
|
||||||
const openDrawer = () => setDrawerOpen(true);
|
const openDrawer = () => setDrawerOpen(true);
|
||||||
const closeDrawer = () => setDrawerOpen(false);
|
const closeDrawer = () => setDrawerOpen(false);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
async function perform() {
|
async function perform() {
|
||||||
const newBottomLinks = await generateDrawerBottomLinks({
|
const newBottomLinks = await generateDrawerBottomLinks({
|
||||||
@@ -90,9 +101,12 @@ export default function PublicLayout({ children }) {
|
|||||||
});
|
});
|
||||||
setBottomLinks(newBottomLinks);
|
setBottomLinks(newBottomLinks);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (loading) return;
|
if (loading) return;
|
||||||
|
|
||||||
perform();
|
perform();
|
||||||
}, [config, loading, version.newVersionCount]);
|
}, [config, loading, version.newVersionCount]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<AppBar
|
<AppBar
|
||||||
|
@@ -1,8 +0,0 @@
|
|||||||
import { gql } from '@apollo/client';
|
|
||||||
export const HEALTHCHECK = gql`
|
|
||||||
query Healthcheck {
|
|
||||||
healthcheck {
|
|
||||||
version
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`;
|
|
@@ -1,11 +1,23 @@
|
|||||||
import { useQuery } from '@apollo/client';
|
|
||||||
import { compare } from 'compare-versions';
|
import { compare } from 'compare-versions';
|
||||||
import { HEALTHCHECK } from 'graphql/queries/healthcheck';
|
import { useQuery } from '@tanstack/react-query';
|
||||||
|
|
||||||
import useNotifications from 'hooks/useNotifications';
|
import useNotifications from 'hooks/useNotifications';
|
||||||
|
import api from 'helpers/api';
|
||||||
|
|
||||||
export default function useVersion() {
|
export default function useVersion() {
|
||||||
const { notifications } = useNotifications();
|
const { notifications } = useNotifications();
|
||||||
const { data } = useQuery(HEALTHCHECK, { fetchPolicy: 'cache-and-network' });
|
const { data } = useQuery({
|
||||||
const version = data?.healthcheck.version;
|
queryKey: ['automatischVersion'],
|
||||||
|
queryFn: async ({ signal }) => {
|
||||||
|
const { data } = await api.get('/v1/automatisch/version', {
|
||||||
|
signal,
|
||||||
|
});
|
||||||
|
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const version = data?.data?.version;
|
||||||
|
|
||||||
const newVersionCount = notifications.reduce((count, notification) => {
|
const newVersionCount = notifications.reduce((count, notification) => {
|
||||||
if (!version) return 0;
|
if (!version) return 0;
|
||||||
// an unexpectedly invalid version would throw and thus, try-catch.
|
// an unexpectedly invalid version would throw and thus, try-catch.
|
||||||
@@ -16,6 +28,7 @@ export default function useVersion() {
|
|||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
}, 0);
|
}, 0);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
version,
|
version,
|
||||||
newVersionCount,
|
newVersionCount,
|
||||||
|
Reference in New Issue
Block a user