Skip to content

Commit 2dd2dce

Browse files
authored
refactor: frontend (#184)
This pull request introduces several improvements and fixes to the frontend UI customization system, environment variable handling, and document upload features. The most significant changes are the overhaul of environment variable usage for runtime customization, updates to theme and logo configuration, and the addition of a configurable parser option for sitemap uploads. There are also UI improvements, including icon updates and minor code cleanups. **Environment Variable Handling and Customization:** * Updated `.env.development` and `.env.production` files to use placeholder values (e.g., `VITE_API_URL=VITE_API_URL`) instead of hardcoded values, enabling runtime environment variable replacement in built frontend assets. (Fef0a99bL3R3, [[1]](diffhunk://#diff-d75aa0c448ddadae4b29e6c34aa5f7331fbacb37d08d956e9c2b23eedd46d3e7L94-R96) [[2]](diffhunk://#diff-cb142dded0e67e187c53e2de9036d0f6c65432835579422c35ff1dad08c78473L1-R1) * Improved `env.sh` script to robustly replace all `VITE_` variables in built JS/CSS files, correctly handling values with spaces or `=` characters, and added documentation comments. * Enhanced documentation in `UI_Customization.md` with troubleshooting steps for runtime environment variable injection, clarifying the need for placeholders at build time and the use of `env.sh` in Docker/Kubernetes deployments. [[1]](diffhunk://#diff-a4d41f884f97f18943db8c18e934c6fbba2c61f180314fae2211a771d11054e4L287-R292) [[2]](diffhunk://#diff-a4d41f884f97f18943db8c18e934c6fbba2c61f180314fae2211a771d11054e4R318) **Theme and Logo Configuration:** * Changed the default theme to "dark", updated theme and logo fallback logic, and clarified the available theme options and their defaults in both documentation and `.env` files. [[1]](diffhunk://#diff-a4d41f884f97f18943db8c18e934c6fbba2c61f180314fae2211a771d11054e4L27-R28) [[2]](diffhunk://#diff-a4d41f884f97f18943db8c18e934c6fbba2c61f180314fae2211a771d11054e4L96-R97) [[3]](diffhunk://#diff-a4d41f884f97f18943db8c18e934c6fbba2c61f180314fae2211a771d11054e4L116-R117) [[4]](diffhunk://#diff-a4d41f884f97f18943db8c18e934c6fbba2c61f180314fae2211a771d11054e4L142-R142) [[5]](diffhunk://#diff-d75aa0c448ddadae4b29e6c34aa5f7331fbacb37d08d956e9c2b23eedd46d3e7L94-R96) * Updated logo fallback order to use theme-specific assets (`navigation-logo-light.svg`, `navigation-logo-dark.svg`) as defaults. [[1]](diffhunk://#diff-a4d41f884f97f18943db8c18e934c6fbba2c61f180314fae2211a771d11054e4L96-R97) [[2]](diffhunk://#diff-d75aa0c448ddadae4b29e6c34aa5f7331fbacb37d08d956e9c2b23eedd46d3e7L94-R96) **Document Upload and Sitemap Parser:** * Added support for specifying a sitemap parser (`docusaurus`, `astro`, or `generic`) in the document upload UI and API, with validation on both frontend and backend. [[1]](diffhunk://#diff-0f7547155cd6592b947aae6327e72dbe57073ae43aba24e82ad7ef78fee08153R26) [[2]](diffhunk://#diff-0f7547155cd6592b947aae6327e72dbe57073ae43aba24e82ad7ef78fee08153R94-R101) [[3]](diffhunk://#diff-a6fc8bcaabdced0bd0b5b642bd5a4aa9cb124a5bbebd0762e76f9dcb0df884c1R35-R42) [[4]](diffhunk://#diff-a6fc8bcaabdced0bd0b5b642bd5a4aa9cb124a5bbebd0762e76f9dcb0df884c1R93-R104) **UI and Icon Updates:** * Replaced Heroicons with Onyx icon components throughout the admin and chat app navigation and document upload UI for consistency and improved appearance. [[1]](diffhunk://#diff-aec53716ff6c4f2c234b589983906d2ffddd1cc67eabf7cd5c676fad77ff0751L3-R5) [[2]](diffhunk://#diff-aec53716ff6c4f2c234b589983906d2ffddd1cc67eabf7cd5c676fad77ff0751L15-R19) [[3]](diffhunk://#diff-98ed9fb0f39bd9e26a573ebe1296e1e723eb79275bd4b4d6064c64dbf81dcefaL3-R19) [[4]](diffhunk://#diff-a6fc8bcaabdced0bd0b5b642bd5a4aa9cb124a5bbebd0762e76f9dcb0df884c1L2-R4) [[5]](diffhunk://#diff-a6fc8bcaabdced0bd0b5b642bd5a4aa9cb124a5bbebd0762e76f9dcb0df884c1L133-R152) [[6]](diffhunk://#diff-a6fc8bcaabdced0bd0b5b642bd5a4aa9cb124a5bbebd0762e76f9dcb0df884c1L165-R177) [[7]](diffhunk://#diff-a6fc8bcaabdced0bd0b5b642bd5a4aa9cb124a5bbebd0762e76f9dcb0df884c1L180-R192) **Code Quality and Cleanup:** * Removed unused imports and cleaned up component initialization code in `App.vue` files. [[1]](diffhunk://#diff-cb142dded0e67e187c53e2de9036d0f6c65432835579422c35ff1dad08c78473L1-R1) [[2]](diffhunk://#diff-98ed9fb0f39bd9e26a573ebe1296e1e723eb79275bd4b4d6064c64dbf81dcefaL3-R19) These changes collectively improve the flexibility, maintainability, and user experience of the frontend application.
1 parent 79b8254 commit 2dd2dce

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1878
-334
lines changed

docs/UI_Customization.md

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ All customization is done through environment variables that can be set at build
2424
| `VITE_UI_LOGO_PATH` | Common path to the main navigation logo (fallback for both light/dark) | "/assets/navigation-logo.svg" | "/assets/my-logo.png" |
2525
| `VITE_UI_LOGO_PATH_LIGHT` | Path to logo used in light mode (falls back to `VITE_UI_LOGO_PATH`) || "/assets/logo-light.svg" |
2626
| `VITE_UI_LOGO_PATH_DARK` | Path to logo used in dark mode (falls back to `VITE_UI_LOGO_PATH`) || "/assets/logo-dark.svg" |
27-
| `VITE_UI_THEME_DEFAULT` | Default theme when user first visits | "light" | "dark" |
28-
| `VITE_UI_THEME_OPTIONS` | Available theme options (comma-separated) | "light,dark" | "light,dark,auto" |
27+
| `VITE_UI_THEME_DEFAULT` | Default theme when user first visits | "dark" | "light" |
28+
| `VITE_UI_THEME_OPTIONS` | Available theme options (comma-separated) | "light,dark" | "light" |
2929

3030
### Bot Name Customization
3131

@@ -93,8 +93,8 @@ The logo appears in the navigation header of both chat and admin applications. Y
9393

9494
**Fallback order:**
9595

96-
- Light: `VITE_UI_LOGO_PATH_LIGHT``VITE_UI_LOGO_PATH``/assets/navigation-logo.svg` (default asset exists in both apps: [chat](../services/frontend/apps/chat-app/public/assets/navigation-logo.svg), [admin](../services/frontend/apps/admin-app/public/assets/navigation-logo.svg))
97-
- Dark: `VITE_UI_LOGO_PATH_DARK``VITE_UI_LOGO_PATH``/assets/navigation-logo.svg` (default asset exists in both apps: [chat](../services/frontend/apps/chat-app/public/assets/navigation-logo.svg), [admin](../services/frontend/apps/admin-app/public/assets/navigation-logo.svg))
96+
- Light: `VITE_UI_LOGO_PATH_LIGHT``VITE_UI_LOGO_PATH``/assets/navigation-logo-light.svg` (default asset exists in both apps: [chat](../services/frontend/apps/chat-app/public/assets/navigation-logo-light.svg), [admin](../services/frontend/apps/admin-app/public/assets/navigation-logo-light.svg))
97+
- Dark: `VITE_UI_LOGO_PATH_DARK``VITE_UI_LOGO_PATH``/assets/navigation-logo-dark.svg` (default asset exists in both apps: [chat](../services/frontend/apps/chat-app/public/assets/navigation-logo-dark.svg), [admin](../services/frontend/apps/admin-app/public/assets/navigation-logo-dark.svg))
9898

9999
**Examples:**
100100

@@ -113,8 +113,8 @@ The application supports a flexible theme system with user preference persistenc
113113

114114
**Available Themes:**
115115

116-
- `light`: Light mode (default)
117-
- `dark`: Dark mode
116+
- `light`: Light mode
117+
- `dark`: Dark mode (default)
118118

119119
**Theme Configuration:**
120120

@@ -139,7 +139,7 @@ The application supports a flexible theme system with user preference persistenc
139139

140140
- Theme preference is saved in browser's localStorage
141141
- Theme persists across browser sessions
142-
- Theme toggle button appears only when multiple options are available
142+
- The built-in theme toggle is shown only when both `light` and `dark` are available
143143
- Manual theme switching overrides the default setting
144144

145145
## Development Setup
@@ -284,9 +284,12 @@ Bot names and messages support internationalization:
284284

285285
### Bot Name Not Updating
286286

287-
- **Issue**: Bot name shows as `{bot_name}` instead of actual name
288-
- **Cause**: Vue computed property not accessed correctly
289-
- **Solution**: Use `initialMessage.value` instead of `initialMessage` in the store
287+
- **Issue**: Bot name stays at the default or shows a placeholder value (e.g. `VITE_BOT_NAME`)
288+
- **Cause**: Runtime env replacement did not run (Vite env vars are build-time by default)
289+
- **Solutions**:
290+
- Ensure `services/frontend/.env.production` contains placeholders for the variables you want to replace (this repo includes `VITE_BOT_NAME`, `VITE_UI_*`, etc.)
291+
- Ensure the container runs `env.sh` after copying the built files into `/usr/share/nginx/html`
292+
- Verify the variable is set in the container environment (Kubernetes `ConfigMap`/`Secret`, Docker `-e`, etc.)
290293

291294
### Logo Not Loading / Wrong for Theme
292295

@@ -312,6 +315,7 @@ Bot names and messages support internationalization:
312315
- **Issue**: Customization works in development but not production
313316
- **Cause**: Vite environment variables are build-time only
314317
- **Solutions**:
318+
- Ensure the variables exist as placeholders at build time (see `services/frontend/.env.production`)
315319
- For Docker: Ensure `env.sh` script runs after copying files
316320
- For Kubernetes: Use ConfigMap/Secret with proper mounting
317321
- Verify environment variables are set in container

services/frontend/.env.development

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
VITE_API_URL=http://doctopus.localhost/api
2-
VITE_ADMIN_URL=http://admin.doctopus.localhost/api
3-
VITE_CHAT_URL=http://localhost:4200
4-
VITE_AUTH_USERNAME=foo
5-
VITE_AUTH_PASSWORD=bar
6-
VITE_CHAT_AUTH_ENABLED=false
1+
VITE_API_URL=VITE_API_URL
2+
VITE_ADMIN_URL=VITE_ADMIN_URL
3+
VITE_CHAT_URL=VITE_CHAT_URL
4+
VITE_AUTH_USERNAME=VITE_AUTH_USERNAME
5+
VITE_AUTH_PASSWORD=VITE_AUTH_PASSWORD
6+
VITE_CHAT_AUTH_ENABLED=VITE_CHAT_AUTH_ENABLED

services/frontend/.env.production

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,10 @@ VITE_ADMIN_URL=VITE_ADMIN_URL
33
VITE_CHAT_URL=VITE_CHAT_URL
44
VITE_AUTH_USERNAME=VITE_AUTH_USERNAME
55
VITE_AUTH_PASSWORD=VITE_AUTH_PASSWORD
6-
VITE_CHAT_AUTH_ENABLED=true
6+
VITE_CHAT_AUTH_ENABLED=VITE_CHAT_AUTH_ENABLED
7+
VITE_BOT_NAME=VITE_BOT_NAME
8+
VITE_UI_LOGO_PATH=VITE_UI_LOGO_PATH
9+
VITE_UI_LOGO_PATH_LIGHT=VITE_UI_LOGO_PATH_LIGHT
10+
VITE_UI_LOGO_PATH_DARK=VITE_UI_LOGO_PATH_DARK
11+
VITE_UI_THEME_DEFAULT=VITE_UI_THEME_DEFAULT
12+
VITE_UI_THEME_OPTIONS=VITE_UI_THEME_OPTIONS

services/frontend/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ To change the theme, open the `tailwind.config.js` file and refer to the availab
9191

9292
### UI Customization
9393
- VITE_BOT_NAME = The AI assistant's display name (default: "Knowledge Agent")
94-
- VITE_UI_LOGO_PATH = Common path to the main navigation logo (default: "/assets/navigation-logo.svg"). Used as a fallback for both light/dark.
95-
- VITE_UI_LOGO_PATH_LIGHT = Path to the logo used in light mode (fallbacks to VITE_UI_LOGO_PATH)
96-
- VITE_UI_LOGO_PATH_DARK = Path to the logo used in dark mode (fallbacks to VITE_UI_LOGO_PATH)
94+
- VITE_UI_LOGO_PATH = Common path to the main navigation logo (fallback for both light/dark, default: "/assets/navigation-logo.svg")
95+
- VITE_UI_LOGO_PATH_LIGHT = Path to the logo used in light mode (fallbacks to VITE_UI_LOGO_PATH, default: "/assets/navigation-logo-light.svg")
96+
- VITE_UI_LOGO_PATH_DARK = Path to the logo used in dark mode (fallbacks to VITE_UI_LOGO_PATH, default: "/assets/navigation-logo-dark.svg")
9797
- VITE_UI_THEME_DEFAULT = Default theme when user first visits (default: "dark")
9898
- VITE_UI_THEME_OPTIONS = Available theme options, comma-separated (default: "light,dark")
9999

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
/// <reference types="vite/client" />
2-
/* eslint-disable */
32
declare module '*.vue' {
4-
import type { DefineComponent } from 'vue';
5-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
6-
const component: DefineComponent<object, object, any>;
7-
export default component;
8-
}
3+
import type { DefineComponent } from 'vue';
4+
const component: DefineComponent<object, object, unknown>;
5+
export default component;
6+
}

services/frontend/apps/admin-app/src/App.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<script lang="ts" setup>
22
import { RouterView } from "vue-router";
3-
import { LogoContainer, NavigationContainer } from "@shared/ui";
3+
import { NavigationContainer, OnyxIcon } from "@shared/ui";
44
import { useI18n } from "vue-i18n";
5-
import { ArrowTopRightOnSquareIcon } from "@heroicons/vue/24/outline";
5+
import { iconArrowSmallUpRightTop } from "@sit-onyx/icons";
66
77
const { t } = useI18n();
88
const chatURL = import.meta.env.VITE_CHAT_URL;
@@ -12,11 +12,11 @@ const chatURL = import.meta.env.VITE_CHAT_URL;
1212
<main class="bg-base-100 flex flex-col overflow-hidden">
1313
<NavigationContainer>
1414
<a
15-
class="flex gap-2 items-center btn btn-primary border border-opacity-10 border-white btn-sm"
15+
class="flex gap-2 items-center btn btn-primary btn-sm"
1616
target="_blank"
1717
:href="chatURL"
1818
>
19-
<ArrowTopRightOnSquareIcon class="w-4 h-4" />
19+
<OnyxIcon :icon="iconArrowSmallUpRightTop" :size="16" />
2020
{{ t("documents.chat") }}
2121
</a>
2222
</NavigationContainer>
Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
/// <reference types="vite/client" />
2-
/* eslint-disable */
32
declare module '*.vue' {
4-
import type { DefineComponent } from 'vue';
5-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
6-
const component: DefineComponent<object, object, any>;
7-
export default component;
8-
}
3+
import type { DefineComponent } from 'vue';
4+
const component: DefineComponent<object, object, unknown>;
5+
export default component;
6+
}

services/frontend/apps/chat-app/src/App.vue

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,22 @@
11
<script lang="ts" setup>
22
import { RouterView } from "vue-router";
3-
import { NavigationContainer } from "@shared/ui";
3+
import { NavigationContainer, OnyxIcon } from "@shared/ui";
44
import { useI18n } from "vue-i18n";
5-
import { ArrowTopRightOnSquareIcon } from "@heroicons/vue/24/outline";
5+
import { iconArrowSmallUpRightTop } from "@sit-onyx/icons";
66
77
const { t } = useI18n();
88
const adminURL = import.meta.env.VITE_ADMIN_URL;
9-
10-
import { onMounted } from "vue";
11-
import { useThemeStore } from "@shared/store/theme.store";
12-
onMounted(() => {
13-
// Initialize theme
14-
const themeStore = useThemeStore();
15-
});
169
</script>
1710

1811
<template>
1912
<main class="bg-base-100 flex flex-col">
2013
<NavigationContainer>
2114
<a
22-
class="flex gap-2 items-center btn btn-primary border border-opacity-10 border-white btn-sm"
15+
class="flex gap-2 items-center btn btn-primary btn-sm"
2316
target="_blank"
2417
:href="adminURL"
2518
>
26-
<ArrowTopRightOnSquareIcon class="w-4 h-4" />
19+
<OnyxIcon :icon="iconArrowSmallUpRightTop" :size="16" />
2720
{{ t("chat.documents") }}
2821
</a>
2922
</NavigationContainer>

services/frontend/env.sh

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
#!/bin/sh
22
# Replace all environment variables starting with VITE_ in the files in /usr/share/nginx/html
3-
for i in $(env | grep VITE_)
4-
do
5-
key=$(echo $i | cut -d '=' -f 1)
6-
value=$(echo $i | cut -d '=' -f 2-)
7-
# sed All files
8-
# find /usr/share/nginx/html -type f -exec sed -i "s|${key}|${value}|g" '{}' +
9-
# sed JS and CSS only
10-
find /usr/share/nginx/html -type f \( -name '*.js' -o -name '*.css' \) -exec sed -i "s|${key}|${value}|g" '{}' +
3+
#
4+
# Notes:
5+
# - This script is used to inject runtime env vars into a Vite-built static app by replacing
6+
# placeholder strings (e.g. "VITE_API_URL") in built JS/CSS files.
7+
# - It must correctly handle values containing spaces and "=".
8+
9+
TARGET_DIR="${TARGET_DIR:-/usr/share/nginx/html}"
10+
11+
env | grep '^VITE_' | while IFS= read -r line; do
12+
key="${line%%=*}"
13+
value="${line#*=}"
14+
15+
# Escape replacement string for sed (delimiter is "|")
16+
escaped_value=$(printf '%s' "$value" | sed -e 's/[\\&|]/\\&/g')
17+
18+
find "$TARGET_DIR" -type f \( -name '*.js' -o -name '*.css' \) \
19+
-exec sed -i "s|${key}|${escaped_value}|g" '{}' +
1120
done

services/frontend/libs/admin-app/data-access/document.api.mock.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import axios, { AxiosProgressEvent } from "axios";
1+
import type { AxiosProgressEvent } from "axios";
22
import { DocumentModel } from "../models/document.model";
33
import { newUid } from "@shared/utils";
44

0 commit comments

Comments
 (0)