Skip to content

Commit

Permalink
feat: display daed version in header (#132)
Browse files Browse the repository at this point in the history
* feat: display daed version in header

* feat: use orchestrate as homepage

---------

Co-authored-by: dae-bot[bot] <136105375+dae-bot[bot]@users.noreply.github.com>
  • Loading branch information
kunish and dae-prow[bot] authored Jul 3, 2023
1 parent 90f33d5 commit 6f9b1b8
Show file tree
Hide file tree
Showing 11 changed files with 146 additions and 82 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-react": "^7.32.2",
"eslint-plugin-react-hooks": "^4.6.0",
"execa": "^7.1.1",
"framer-motion": "^10.12.17",
"graphiql": "^3.0.0",
"graphql": "^16.7.1",
Expand All @@ -90,9 +91,11 @@
"react-i18next": "^13.0.1",
"react-router": "^6.14.0",
"react-router-dom": "^6.14.0",
"simple-git": "^3.19.1",
"typescript": "^5.1.6",
"urijs": "^1.19.11",
"vite": "^4.3.9",
"vite-plugin-environment": "^1.1.3",
"zod": "^3.21.4"
}
}
39 changes: 39 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions src/Router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useStore } from '@nanostores/react'
import { GraphiQL } from 'graphiql'
import { BrowserRouter, HashRouter, Route, Routes } from 'react-router-dom'

import { ExperimentPage, HomePage, MainLayout, OrchestratePage, SetupPage } from '~/pages'
import { ExperimentPage, MainLayout, OrchestratePage, SetupPage } from '~/pages'
import { endpointURLAtom } from '~/store'

export const Router = () => {
Expand All @@ -14,8 +14,7 @@ export const Router = () => {
<RouterType>
<Routes>
<Route path="/" element={<MainLayout />}>
<Route index element={<HomePage />} />
<Route path="orchestrate" element={<OrchestratePage />} />
<Route index element={<OrchestratePage />} />
<Route path="experiment" element={<ExperimentPage />} />
</Route>

Expand Down
1 change: 1 addition & 0 deletions src/apis/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ export const useGeneralQuery = () => {
dae {
running
modified
version
}
interfaces(up: $up) {
name
Expand Down
114 changes: 72 additions & 42 deletions src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
Burger,
Button,
Center,
Code,
Container,
Drawer,
FileButton,
Expand All @@ -28,11 +29,11 @@ import {
} from '@mantine/core'
import { useForm, zodResolver } from '@mantine/form'
import { useDisclosure, useMediaQuery } from '@mantine/hooks'
import { useStore } from '@nanostores/react'
import {
IconBrandGithub,
IconChevronDown,
IconCloudCheck,
IconCloudComputing,
IconCloudPause,
IconLanguage,
IconLogout,
Expand All @@ -51,7 +52,7 @@ import { z } from 'zod'
import { useGeneralQuery, useRunMutation, useUpdateAvatarMutation, useUpdateNameMutation, useUserQuery } from '~/apis'
import logo from '~/assets/logo.svg'
import { i18n } from '~/i18n'
import { tokenAtom } from '~/store'
import { endpointURLAtom, tokenAtom } from '~/store'
import { fileToBase64 } from '~/utils'

import { FormActions } from './FormActions'
Expand All @@ -76,6 +77,10 @@ const useStyles = createStyles((theme) => ({
'&:hover': {
backgroundColor: theme.colorScheme === 'dark' ? theme.colors.dark[8] : theme.white,
},

[theme.fn.smallerThan('sm')]: {
padding: 0,
},
},

userActive: {
Expand Down Expand Up @@ -107,7 +112,7 @@ const accountSettingsSchema = z.object({
})

const getLinks = (t: TFunction) => {
const links = [{ link: '/orchestrate', label: t('orchestrate'), icon: <IconCloudComputing /> }]
const links = []

if (import.meta.env.DEV) {
links.push({ link: '/experiment', label: t('experiment'), icon: <IconTestPipe /> })
Expand All @@ -118,6 +123,7 @@ const getLinks = (t: TFunction) => {

export const HeaderWithActions = () => {
const { t } = useTranslation()
const endpointURL = useStore(endpointURLAtom)
const location = useLocation()
const navigate = useNavigate()
const { colorScheme, toggleColorScheme } = useMantineColorScheme()
Expand Down Expand Up @@ -149,17 +155,28 @@ export const HeaderWithActions = () => {
<header className={classes.header}>
<Container className={classes.mainSection}>
<Group position="apart">
<Anchor component={Link} to="/">
<Group>
<Image radius="sm" src={logo} width={32} height={32} />

<Title order={matchSmallScreen ? 5 : 2} color={theme.colorScheme === 'dark' ? theme.white : theme.black}>
daed
</Title>
</Group>
</Anchor>
<Group spacing="sm">
<Anchor component={Link} to="/">
<Group spacing="sm">
<Image radius="sm" src={logo} width={32} height={32} />

<Title
order={matchSmallScreen ? 5 : 2}
color={theme.colorScheme === 'dark' ? theme.white : theme.black}
>
daed
</Title>
</Group>
</Anchor>

<Tooltip label={endpointURL} withArrow>
<Code fz="xs" fw={700}>
{generalQuery?.general.dae.version || import.meta.env.__VERSION__}
</Code>
</Tooltip>
</Group>

<Group>
<Group spacing={matchSmallScreen ? 'xs' : 'md'}>
<Menu
width={260}
position="bottom-end"
Expand Down Expand Up @@ -252,41 +269,54 @@ export const HeaderWithActions = () => {

<Tooltip label={t('actions.switchRunning')} withArrow>
<Box>
<Switch
size="md"
onLabel={<IconCloudCheck />}
offLabel={<IconCloudPause />}
disabled={!generalQuery?.general.dae.running && runMutation.isLoading}
checked={generalQuery?.general.dae.running}
onChange={(e) => {
runMutation.mutateAsync(!e.target.checked)
}}
/>
{matchSmallScreen ? (
<Switch
size="xs"
disabled={!generalQuery?.general.dae.running && runMutation.isLoading}
checked={generalQuery?.general.dae.running}
onChange={(e) => {
runMutation.mutateAsync(!e.target.checked)
}}
/>
) : (
<Switch
size="md"
onLabel={<IconCloudCheck />}
offLabel={<IconCloudPause />}
disabled={!generalQuery?.general.dae.running && runMutation.isLoading}
checked={generalQuery?.general.dae.running}
onChange={(e) => {
runMutation.mutateAsync(!e.target.checked)
}}
/>
)}
</Box>
</Tooltip>
</Group>
</Group>
</Container>

<Center>
<Tabs
variant="outline"
value={location.pathname}
onTabChange={(to) => navigate(`${to}`)}
classNames={{
tabsList: classes.tabsList,
tab: classes.tab,
}}
>
<Tabs.List>
{links.map(({ link, icon, label }) => (
<Tabs.Tab key={link} value={link} icon={icon}>
{label}
</Tabs.Tab>
))}
</Tabs.List>
</Tabs>
</Center>
{links.length > 0 && (
<Center>
<Tabs
variant="outline"
value={location.pathname}
onTabChange={(to) => navigate(`${to}`)}
classNames={{
tabsList: classes.tabsList,
tab: classes.tab,
}}
>
<Tabs.List>
{links.map(({ link, icon, label }) => (
<Tabs.Tab key={link} value={link} icon={icon}>
{label}
</Tabs.Tab>
))}
</Tabs.List>
</Tabs>
</Center>
)}

<Drawer opened={openedBurger} onClose={closeBurger} size="100%">
<SimpleGrid cols={3}>
Expand Down
25 changes: 0 additions & 25 deletions src/pages/Home.tsx

This file was deleted.

1 change: 0 additions & 1 deletion src/pages/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export * from './Experiment'
export * from './Home'
export * from './MainLayout'
export * from './Orchestrate'
export * from './Setup'
6 changes: 3 additions & 3 deletions src/schemas/gql/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const documents = {
types.InterfacesDocument,
'\n query JsonStorage($paths: [String!]) {\n jsonStorage(paths: $paths)\n }\n ':
types.JsonStorageDocument,
'\n query General($up: Boolean) {\n general {\n dae {\n running\n modified\n }\n interfaces(up: $up) {\n name\n ifindex\n ip\n flag {\n default {\n gateway\n }\n }\n }\n }\n }\n ':
'\n query General($up: Boolean) {\n general {\n dae {\n running\n modified\n version\n }\n interfaces(up: $up) {\n name\n ifindex\n ip\n flag {\n default {\n gateway\n }\n }\n }\n }\n }\n ':
types.GeneralDocument,
'\n query Nodes {\n nodes {\n edges {\n id\n name\n link\n address\n protocol\n tag\n }\n }\n }\n ':
types.NodesDocument,
Expand Down Expand Up @@ -349,8 +349,8 @@ export function graphql(
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
export function graphql(
source: '\n query General($up: Boolean) {\n general {\n dae {\n running\n modified\n }\n interfaces(up: $up) {\n name\n ifindex\n ip\n flag {\n default {\n gateway\n }\n }\n }\n }\n }\n '
): (typeof documents)['\n query General($up: Boolean) {\n general {\n dae {\n running\n modified\n }\n interfaces(up: $up) {\n name\n ifindex\n ip\n flag {\n default {\n gateway\n }\n }\n }\n }\n }\n ']
source: '\n query General($up: Boolean) {\n general {\n dae {\n running\n modified\n version\n }\n interfaces(up: $up) {\n name\n ifindex\n ip\n flag {\n default {\n gateway\n }\n }\n }\n }\n }\n '
): (typeof documents)['\n query General($up: Boolean) {\n general {\n dae {\n running\n modified\n version\n }\n interfaces(up: $up) {\n name\n ifindex\n ip\n flag {\n default {\n gateway\n }\n }\n }\n }\n }\n ']
/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
Expand Down
3 changes: 2 additions & 1 deletion src/schemas/gql/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,7 @@ export type GeneralQuery = {
__typename?: 'Query'
general: {
__typename?: 'General'
dae: { __typename?: 'Dae'; running: boolean; modified: boolean }
dae: { __typename?: 'Dae'; running: boolean; modified: boolean; version: string }
interfaces: Array<{
__typename?: 'Interface'
name: string
Expand Down Expand Up @@ -2763,6 +2763,7 @@ export const GeneralDocument = {
selections: [
{ kind: 'Field', name: { kind: 'Name', value: 'running' } },
{ kind: 'Field', name: { kind: 'Name', value: 'modified' } },
{ kind: 'Field', name: { kind: 'Name', value: 'version' } },
],
},
},
Expand Down
8 changes: 8 additions & 0 deletions src/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
/// <reference types="vite/client" />

interface ImportMetaEnv {
readonly __VERSION__: string
}

interface ImportMeta {
readonly env: ImportMetaEnv
}
Loading

0 comments on commit 6f9b1b8

Please sign in to comment.