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

Show DataHub version in UI #298

Merged
merged 1 commit into from
Oct 29, 2020
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
2 changes: 1 addition & 1 deletion datahub/server/app/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

from app import auth
from app.datasource import register, abort_request

from app.flask_app import flask_app, limiter
from const.path import WEBAPP_PATH


import datasources
import datasources_socketio

Expand Down
18 changes: 14 additions & 4 deletions datahub/server/datasources/user.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
from flask import abort
from app.auth import get_login_config
from flask_login import current_user
from app.db import DBSession
from const.datasources import RESOURCE_NOT_FOUND_STATUS_CODE

from app.auth import get_login_config
from app.auth import logout as auth_logout
from app.datasource import register, api_assert
from app.db import DBSession
from const.datasources import RESOURCE_NOT_FOUND_STATUS_CODE

from lib.notify.all_notifiers import ALL_NOTIFIERS
from lib.utils.version import get_version

from logic import user as logic
from logic import environment as environment_logic
from logic import admin as admin_logic
from lib.notify.all_notifiers import ALL_NOTIFIERS


@register("/user/login_method/", methods=["GET"], require_auth=False)
Expand Down Expand Up @@ -108,3 +112,9 @@ def handle_create_api_access_tokens():
@register("/user/notifiers/", methods=["GET"])
def get_all_query_result_notifier():
return ALL_NOTIFIERS


@register("/version/", methods=["GET"])
def get_datahub_version():
"""This gets the current version of datahub from package.json (source of truth)"""
return get_version()
14 changes: 14 additions & 0 deletions datahub/server/lib/utils/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import os
from const.path import PROJECT_ROOT_PATH
from lib.utils.json import safe_loads

__version = None


def get_version():
global __version
if __version is None:
with open(os.path.join(PROJECT_ROOT_PATH, "./package.json")) as f:
package_config = safe_loads(f.read(), default_value={})
__version = package_config.get("version", None)
return __version
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ exports[`matches enzyme snapshots matches snapshot 1`] = `

exports[`matches test renderer snapshot serializes the styles 1`] = `
<span
className="sc-bdVaJa KeyboardKey mr4 jhrFHl"
className="sc-bdVaJa KeyboardKey mr4 cIEmNq"
>
test
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ exports[`matches test renderer snapshot serializes the styles 1`] = `
className="sc-bwzfXH MenuItem uTxCW"
>
<div
className="sc-ifAKCX MenuItemPing kIfKgp"
className="sc-ifAKCX MenuItemPing cLYKhy"
/>
</span>
<div
Expand Down
17 changes: 17 additions & 0 deletions datahub/webapp/components/InfoMenuButton/DataHubVersion.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React, { useEffect } from 'react';
import { useGlobalState } from 'hooks/redux/useGlobalState';
import ds from 'lib/datasource';

export const DataHubVersion: React.FC = () => {
const [version, setVersion] = useGlobalState('datahubVersion', null);

useEffect(() => {
if (version == null) {
ds.fetch<string>(`/version/`).then(({ data }) => {
setVersion(data);
});
}
}, []);

return <span>{version}</span>;
};
17 changes: 12 additions & 5 deletions datahub/webapp/components/InfoMenuButton/InfoMenuButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ import { ChangeLogValue, CHANGE_LOG_KEY } from 'lib/local-store/const';

import { IconButton } from 'ui/Button/IconButton';
import { Popover } from 'ui/Popover/Popover';
import { MenuDivider, Menu, MenuItem, MenuItemPing } from 'ui/Menu/Menu';
import {
MenuDivider,
Menu,
MenuItem,
MenuItemPing,
MenuInfoItem,
} from 'ui/Menu/Menu';
import { DataHubVersion } from './DataHubVersion';

export const InfoMenuButton: React.FunctionComponent = () => {
const [showPanel, setShowPanel] = React.useState(false);
Expand All @@ -32,19 +39,21 @@ export const InfoMenuButton: React.FunctionComponent = () => {
const getPanelDOM = () => {
const panelContent = (
<Menu>
<MenuInfoItem>
DataHub v<DataHubVersion />
</MenuInfoItem>
<MenuDivider />
<MenuItem
onClick={() => {
navigateWithinEnv('/changelog/', {
isModal: true,
});
setNotification(false);
}}
ping={notification}
>
Change Logs
{notification ? <MenuItemPing /> : null}
</MenuItem>
<MenuDivider />
<MenuItem
onClick={() =>
navigateWithinEnv('/info/shortcut/', {
Expand All @@ -54,7 +63,6 @@ export const InfoMenuButton: React.FunctionComponent = () => {
>
Shortcuts
</MenuItem>
<MenuDivider />
<MenuItem
onClick={() =>
navigateWithinEnv('/info/faq/', {
Expand All @@ -64,7 +72,6 @@ export const InfoMenuButton: React.FunctionComponent = () => {
>
FAQs
</MenuItem>
<MenuDivider />
<MenuItem
onClick={() =>
navigateWithinEnv('/info/tour/', {
Expand Down
3 changes: 2 additions & 1 deletion datahub/webapp/components/UserMenu/UserMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ import { Link } from 'ui/Link/Link';
import { MenuInfoItem, Menu, MenuDivider, MenuItem } from 'ui/Menu/Menu';
import { Modal } from 'ui/Modal/Modal';
import { Popover, PopoverLayout } from 'ui/Popover/Popover';
import './UserMenu.scss';
import { ToggleSwitch } from 'ui/ToggleSwitch/ToggleSwitch';

import './UserMenu.scss';

interface IProps {
tooltipPos?: TooltipDirection;
popoverLayout?: PopoverLayout;
Expand Down
1 change: 1 addition & 0 deletions datahub/webapp/ui/KeyboardKey/KeyboardKey.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import React, { useMemo } from 'react';
const StyledKeyboardKey = styled.span.attrs<{}>({
className: 'KeyboardKey mr4',
})`
cursor: default;
border: var(--border);
border-radius: var(--border-radius);
background-color: var(--bg-color);
Expand Down
2 changes: 1 addition & 1 deletion datahub/webapp/ui/Menu/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const MenuDivider = styled.div.attrs<{}>({
export const MenuItemPing = styled.div.attrs<{}>({
className: 'MenuItemPing',
})`
cursor: default;
pointer-events: none;
border-radius: 100px;
background-color: var(--color-accent-bg);
width: 8px;
Expand Down