Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: rewrite useVersion and healthcheck with RQ #1716

Merged
merged 1 commit into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions packages/backend/src/graphql/queries/healthcheck.js

This file was deleted.

27 changes: 0 additions & 27 deletions packages/backend/src/graphql/queries/healthcheck.test.js

This file was deleted.

2 changes: 0 additions & 2 deletions packages/backend/src/graphql/query-resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import getSubscriptionStatus from './queries/get-subscription-status.ee.js';
import getTrialStatus from './queries/get-trial-status.ee.js';
import getUser from './queries/get-user.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 testConnection from './queries/test-connection.js';

Expand Down Expand Up @@ -55,7 +54,6 @@ const queryResolvers = {
getTrialStatus,
getUser,
getUsers,
healthcheck,
listSamlAuthProviders,
testConnection,
};
Expand Down
5 changes: 0 additions & 5 deletions packages/backend/src/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ type Query {
getTrialStatus: GetTrialStatus
getUser(id: String!): User
getUsers(limit: Int!, offset: Int!): UserConnection
healthcheck: AppHealth
listSamlAuthProviders: [ListSamlAuthProvider]
}

Expand Down Expand Up @@ -627,10 +626,6 @@ type ExecutionStepConnection {
pageInfo: PageInfo
}

type AppHealth {
version: String
}

type License {
id: String
name: String
Expand Down
1 change: 0 additions & 1 deletion packages/backend/src/helpers/authentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ export const authenticationRules = {
'*': isAuthenticatedRule,
getConfig: allow,
getNotifications: allow,
healthcheck: allow,
listSamlAuthProviders: allow,
},
Mutation: {
Expand Down
14 changes: 14 additions & 0 deletions packages/web/src/components/Layout/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import SwapCallsIcon from '@mui/icons-material/SwapCalls';
import HistoryIcon from '@mui/icons-material/History';
import NotificationsIcon from '@mui/icons-material/Notifications';
import ArrowBackIosNew from '@mui/icons-material/ArrowBackIosNew';

import * as URLS from 'config/urls';
import useFormatMessage from 'hooks/useFormatMessage';
import useVersion from 'hooks/useVersion';
import AppBar from 'components/AppBar';
import Drawer from 'components/Drawer';
import useConfig from 'hooks/useConfig';

const drawerLinks = [
{
Icon: SwapCallsIcon,
Expand All @@ -35,6 +37,7 @@ const drawerLinks = [
dataTest: 'executions-page-drawer-link',
},
];

const generateDrawerBottomLinks = async ({
disableNotificationsPage,
notificationBadgeContent = 0,
Expand All @@ -48,23 +51,30 @@ const generateDrawerBottomLinks = async ({
to: URLS.UPDATES,
badgeContent: notificationBadgeContent,
};

const hasAdditionalDrawerLink =
additionalDrawerLink && additionalDrawerLinkText;

const additionalDrawerLinkObject = {
Icon: ArrowBackIosNew,
primary: additionalDrawerLinkText || '',
to: additionalDrawerLink || '',
target: '_blank',
};

const links = [];

if (!disableNotificationsPage) {
links.push(notificationsPageLinkObject);
}

if (hasAdditionalDrawerLink) {
links.push(additionalDrawerLinkObject);
}

return links;
};

export default function PublicLayout({ children }) {
const version = useVersion();
const { config, loading } = useConfig([
Expand All @@ -79,6 +89,7 @@ export default function PublicLayout({ children }) {
const [isDrawerOpen, setDrawerOpen] = React.useState(!matchSmallScreens);
const openDrawer = () => setDrawerOpen(true);
const closeDrawer = () => setDrawerOpen(false);

React.useEffect(() => {
async function perform() {
const newBottomLinks = await generateDrawerBottomLinks({
Expand All @@ -90,9 +101,12 @@ export default function PublicLayout({ children }) {
});
setBottomLinks(newBottomLinks);
}

if (loading) return;

perform();
}, [config, loading, version.newVersionCount]);

return (
<>
<AppBar
Expand Down
8 changes: 0 additions & 8 deletions packages/web/src/graphql/queries/healthcheck.js

This file was deleted.

21 changes: 17 additions & 4 deletions packages/web/src/hooks/useVersion.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
import { useQuery } from '@apollo/client';
import { compare } from 'compare-versions';
import { HEALTHCHECK } from 'graphql/queries/healthcheck';
import { useQuery } from '@tanstack/react-query';

import useNotifications from 'hooks/useNotifications';
import api from 'helpers/api';

export default function useVersion() {
const { notifications } = useNotifications();
const { data } = useQuery(HEALTHCHECK, { fetchPolicy: 'cache-and-network' });
const version = data?.healthcheck.version;
const { data } = useQuery({
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) => {
if (!version) return 0;
// an unexpectedly invalid version would throw and thus, try-catch.
Expand All @@ -16,6 +28,7 @@ export default function useVersion() {
return count;
}
}, 0);

return {
version,
newVersionCount,
Expand Down
Loading