Skip to content

Commit

Permalink
Display GraphExplorer version in client UI
Browse files Browse the repository at this point in the history
  • Loading branch information
nestoralvarezd committed Jan 25, 2023
1 parent 637d26b commit 02f60f0
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 8 deletions.
4 changes: 4 additions & 0 deletions packages/graph-explorer/src/@types/typings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ declare global {
interface PromiseWithCancel<T> extends Promise<T> {
cancel?: () => void;
}

/** Graph explorer version extracted from package.json */
const __GRAPH_EXP_VERSION__: string;
}

declare module "rc-dock" {
/**
* TabBase allow to add custom props
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,16 @@ const topBarTitleContent: ThemeStyleFn = ({ theme }) => css`
justify-content: center;
`;

const topBarTitleVersion: ThemeStyleFn = ({ theme }) => css`
display: flex;
margin: ${theme.spacing["2x"]};
justify-content: center;
align-items: center;
font-size: ${theme.typography.sizes.xs};
font-weight: ${theme.typography.weight.light};
color: ${theme.palette.text.secondary};
`;

const styles = {
additionalControlsSectionStyles,
baseStyles,
Expand All @@ -197,6 +207,7 @@ const styles = {
togglesSectionStyles,
topBarSectionStyles,
topBarTitleContent,
topBarTitleVersion,
};

export default styles;
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import WorkspaceTopBarAdditionalControls from "./WorkspaceTopBarAdditionalContro
import WorkspaceTopBarContent from "./WorkspaceTopBarContent";
import WorkspaceTopBarTitle from "./WorkspaceTopBarTitle";
import WorkspaceTopBarToggles from "./WorkspaceTopBarToggles";
import WorkspaceTopBarVersion from "./WorkspaceTopBarVersion";

export type WorkspaceTopBarProps = {
className?: string;
Expand All @@ -24,6 +25,7 @@ interface WorkspaceTopBarComposition {
Toggles: typeof WorkspaceTopBarToggles;
AdditionalControls: typeof WorkspaceTopBarAdditionalControls;
Content: typeof WorkspaceTopBarContent;
Version: typeof WorkspaceTopBarVersion;
}

const WorkspaceTopBar = ({
Expand All @@ -47,6 +49,7 @@ const WorkspaceTopBar = ({
WorkspaceTopBarContent.displayName || WorkspaceTopBarContent.name,
WorkspaceTopBarAdditionalControls.displayName ||
WorkspaceTopBarAdditionalControls.name,
WorkspaceTopBarVersion.displayName || WorkspaceTopBarVersion.name,
],
"rest"
),
Expand Down Expand Up @@ -78,6 +81,11 @@ const WorkspaceTopBar = ({
]
}
<div className={pfx("space")} />
{
childrenByType[
WorkspaceTopBarVersion.displayName || WorkspaceTopBarVersion.name
]
}
{
childrenByType[
WorkspaceTopBarToggles.displayName || WorkspaceTopBarToggles.name
Expand Down Expand Up @@ -108,6 +116,7 @@ WorkspaceTopBar.Title = WorkspaceTopBarTitle;
WorkspaceTopBar.Toggles = WorkspaceTopBarToggles;
WorkspaceTopBar.AdditionalControls = WorkspaceTopBarAdditionalControls;
WorkspaceTopBar.Content = WorkspaceTopBarContent;
WorkspaceTopBar.Version = WorkspaceTopBarVersion;

export default WorkspaceTopBar as ((
props: PropsWithChildren<WorkspaceTopBarProps>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { cx } from "@emotion/css";
import type { PropsWithChildren } from "react";
import { useWithTheme, withClassNamePrefix } from "../../../core";
import styles from "../Workspace.styles";

export type WorkspaceTopBarVersionProps = {
className?: string;
classNamePrefix?: string;
};

const WorkspaceTopBarVersion = ({
className,
classNamePrefix = "ft",
children,
}: PropsWithChildren<WorkspaceTopBarVersionProps>) => {
const pfx = withClassNamePrefix(classNamePrefix);
const stylesWithTheme = useWithTheme();
return (
<div
className={cx(
stylesWithTheme(styles.topBarTitleVersion),
pfx("top-bar-version"),
className
)}
>
{children}
</div>
);
};

WorkspaceTopBarVersion.displayName = "WorkspaceTopBarVersion";

export default WorkspaceTopBarVersion;
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ const DARK_THEME: ProcessedTheme = {
xl: "1.25rem",
},
weight: {
light: 400,
base: 500,
bold: 600,
extraBold: 700,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ const LIGHT_THEME: ProcessedTheme = {
xl: "1.25rem",
},
weight: {
light: 400,
base: 500,
bold: 600,
extraBold: 700,
Expand Down
1 change: 1 addition & 0 deletions packages/graph-explorer/src/core/ThemeProvider/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export type Typography = {
xl?: string;
};
weight?: {
light?: number;
base?: number;
bold?: number;
extraBold?: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const TopBarWithLogo = ({ children }: PropsWithChildren<any>) => {
`}
>
{children}
<Workspace.TopBar.Version>V {__GRAPH_EXP_VERSION__}</Workspace.TopBar.Version>
</Workspace.TopBar>
);
};
Expand Down
27 changes: 19 additions & 8 deletions packages/graph-explorer/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import react from "@vitejs/plugin-react";
import * as fs from "fs";
import { defineConfig, loadEnv } from "vite";
import fs from "fs";

export default defineConfig(async ({ mode }) => {
const env = loadEnv(mode, process.cwd(), "");
Expand All @@ -20,25 +20,36 @@ export default defineConfig(async ({ mode }) => {
};

const serverInfo = () => {
if (env.GRAPH_EXP_HTTPS_CONNECTION != "false") {
if (
env.GRAPH_EXP_HTTPS_CONNECTION != "false" &&
fs.existsSync("../graph-explorer-proxy-server/cert-info/server.key") &&
fs.existsSync("../graph-explorer-proxy-server/cert-info/server.crt")
) {
return {
host: true,
https: {
key: fs.readFileSync("../graph-explorer-proxy-server/cert-info/server.key"),
cert: fs.readFileSync("../graph-explorer-proxy-server/cert-info/server.crt"),
key: fs.readFileSync(
"../graph-explorer-proxy-server/cert-info/server.key"
),
cert: fs.readFileSync(
"../graph-explorer-proxy-server/cert-info/server.crt"
),
},
}
};
} else {
return {
host: true
}
host: true,
};
}
}
};

return {
server: serverInfo(),
base: env.GRAPH_EXP_ENV_ROOT_FOLDER,
envPrefix: "GRAPH_EXP",
define: {
__GRAPH_EXP_VERSION__: JSON.stringify(process.env.npm_package_version),
},
plugins: [htmlPlugin(), react()],
};
});

0 comments on commit 02f60f0

Please sign in to comment.