Skip to content

Commit

Permalink
Merge pull request #79 from launchrctl/improvements
Browse files Browse the repository at this point in the history
Frontend improvements.
  • Loading branch information
iberdinsky-skilld authored Sep 11, 2024
2 parents baf6b60 + 52b5bc6 commit 5c3dfbb
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 7 deletions.
4 changes: 2 additions & 2 deletions client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<!-- @todo use launchr app name-->
<meta
name="description"
content="refine | Build your React-based CRUD applications, without constraints."
content="Platform | actions web ui"
/>
<meta
data-rh="true"
Expand All @@ -22,7 +22,7 @@
/>
<!-- @todo use launchr app name-->
<title>
refine - Build your React-based CRUD applications, without constraints.
Platform
</title>
</head>
<body>
Expand Down
Binary file modified client/public/favicon.ico
Binary file not shown.
13 changes: 11 additions & 2 deletions client/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import routerBindings, {
DocumentTitleHandler,
UnsavedChangesNotifier,
} from '@refinedev/react-router-v6'
import { useEffect } from 'react'
import {
BrowserRouter,
Navigate,
Expand All @@ -25,10 +26,19 @@ import { FlowShow } from './pages/flow'
import { dataProvider as launchrDataProvider } from './rest-data-provider'
import { ThemeProvider } from './ThemeProvider'
import { getApiUrl } from './utils/app-urls-resolver'
import { getCustomisation, setCustomisation } from './utils/page-customisation'

const apiUrl = getApiUrl()

const customTitleHandler = () => {
return getCustomisation()?.plasmactl_web_ui_platform_page_name ?? 'Platform'
}

export function App() {
useEffect(() => {
setCustomisation()
}, [])

return (
<AppProvider>
<ActionProvider>
Expand Down Expand Up @@ -82,10 +92,9 @@ export function App() {
<Route path="*" element={<ErrorComponent />} />
</Route>
</Routes>

<RefineKbar />
<UnsavedChangesNotifier />
<DocumentTitleHandler />
<DocumentTitleHandler handler={customTitleHandler} />
</Refine>
</ThemeProvider>
</RefineKbarProvider>
Expand Down
10 changes: 8 additions & 2 deletions client/src/components/layout/Title.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { useTranslation } from 'react-i18next'

import Logo from '/images/logo.svg'

import { getCustomisation } from '../../utils/page-customisation'

const defaultText = import.meta.env.VITE_APP_NAME

export const ThemedTitleV2: FC<RefineLayoutThemedTitleProps> = ({
Expand All @@ -20,6 +22,9 @@ export const ThemedTitleV2: FC<RefineLayoutThemedTitleProps> = ({

const ActiveLink = routerType === 'legacy' ? LegacyLink : Link

const logoUrl = getCustomisation()?.plasmactl_web_ui_platform_logo ?? Logo
const logoText = getCustomisation()?.plasmactl_web_ui_platform_header_name ?? text

return (
<MuiLink
to="/"
Expand All @@ -32,16 +37,17 @@ export const ThemedTitleV2: FC<RefineLayoutThemedTitleProps> = ({
...wrapperStyles,
}}
>
<img src={Logo} width="24" height="24" alt={t('Logo')} />
<img src={logoUrl} width="24" height="24" alt={t('Logo')} />
<Typography
variant="h5"
fontWeight={700}
color="text.primary"
fontSize="15px"
textOverflow="ellipsis"
overflow="hidden"
sx={{ textTransform: 'uppercase' }}
>
{text}
{logoText}
</Typography>
</MuiLink>
)
Expand Down
9 changes: 9 additions & 0 deletions client/src/utils/helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,12 @@ export const extractDateTimeFromId = (id: string) => {

return formattedDate
}

export const svgToBase64 = (svg: string) => {
const base64 = btoa(
encodeURIComponent(svg).replaceAll(/%([\dA-F]{2})/g, (_, p1) =>
String.fromCodePoint(Number.parseInt(p1, 16))
)
)
return `data:image/svg+xml;base64,${base64}`
}
50 changes: 50 additions & 0 deletions client/src/utils/page-customisation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { getApiUrl } from './app-urls-resolver'
import { svgToBase64 } from './helpers'

const apiUrl = getApiUrl()

export const setCustomisation = async () => {
if (!localStorage.getItem('plasmactl_web_ui_customisation')) {
const response = await fetch(`${apiUrl}/customisation`, {
method: 'GET',
})
const data = await response.json()
localStorage.setItem('plasmactl_web_ui_customisation', JSON.stringify(data))
}

setFavicon()
}

export const getCustomisation = () => {
const customisation = localStorage.getItem('plasmactl_web_ui_customisation')
if (customisation) {
const parsed = JSON.parse(customisation)
if (parsed) {
if (parsed.plasmactl_web_ui_platform_favicon) {
parsed.plasmactl_web_ui_platform_favicon = svgToBase64(
parsed.plasmactl_web_ui_platform_favicon
)
}
if (parsed.plasmactl_web_ui_platform_logo) {
parsed.plasmactl_web_ui_platform_logo = svgToBase64(
parsed.plasmactl_web_ui_platform_logo
)
}
return parsed
}
}
return {}
}

export const setFavicon = () => {
const favicon = getCustomisation()?.plasmactl_web_ui_platform_favicon
if (favicon) {
const link: HTMLLinkElement =
(document.querySelector("link[rel*='icon']") as HTMLLinkElement) ||
(document.createElement('link') as HTMLLinkElement)
link.type = 'image/svg+xml'
link.rel = 'icon'
link.href = favicon
document.getElementsByTagName('head')[0]?.append(link)
}
}
8 changes: 7 additions & 1 deletion client/src/utils/react-flow-builder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { GetListResponse } from '@refinedev/core'

import { IFlowNodeType } from '../types'
import { sentenceCase } from '../utils/helpers'
import { getCustomisation } from '../utils/page-customisation'

// Coefficient less than 0.51 behaves unpredictably.
// Use coefficient between 0.51 till endless
Expand Down Expand Up @@ -469,9 +470,14 @@ export const getNodesAndEdges = (
return []
}

const nameText =
getCustomisation()?.plasmactl_web_ui_platform_name ?? 'Platform'

const nodes: IFolder = {
id: 'start',
data: { label: 'Platform name' },
data: {
label: nameText,
},
type: 'node-start',
folders: {},
actions: {},
Expand Down

0 comments on commit 5c3dfbb

Please sign in to comment.