Skip to content

Commit 77d6ac7

Browse files
authored
Merge pull request #100 from Open-STEM/kq-bugs
Fixed the layout translation
2 parents d553c2b + 3f4f415 commit 77d6ac7

File tree

4 files changed

+44
-10
lines changed

4 files changed

+44
-10
lines changed

src/assets/images/shell.svg

Lines changed: 16 additions & 0 deletions
Loading

src/components/dialogs/settings.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ function SettingsDlg({ isXrpConnected, toggleDialog }: SettingsProps) {
4242
const [isValidUsername, setIsValidUsername] = useState<boolean | null>(null);
4343
const [, setLSXrpUser] = useLocalStorage(StorageKeys.XRPUSER, '');
4444
const modeLogger = logger.child({ module: 'modes' });
45-
const [language, setLanguage] = useLocalStorage(StorageKeys.LANGUAGE, 'en');
4645

4746
const authService = AppMgr.getInstance().authService;
4847
const USERS = '/users/';
@@ -168,9 +167,8 @@ function SettingsDlg({ isXrpConnected, toggleDialog }: SettingsProps) {
168167
*/
169168
const handleLanguageChange = (event: { target: { value: string } }) => {
170169
const newLanguage = event.target.value;
171-
setLanguage(newLanguage);
172170
i18n.changeLanguage(newLanguage);
173-
if (modeValue === ModeType.GOOUSER) {
171+
if (modeValue === ModeType.GOOUSER && authService.isLogin) {
174172
fireGoogleUserTree(username ?? '');
175173
} else if (modeValue === ModeType.SYSTEM || modeValue === ModeType.USER) {
176174
CommandToXRPMgr.getInstance().getOnBoardFSTree();
@@ -432,7 +430,7 @@ function SettingsDlg({ isXrpConnected, toggleDialog }: SettingsProps) {
432430
<select
433431
id="languageSelectedId"
434432
className="dark:text-white block rounded border border-s-2 border-shark-300 border-s-curious-blue-500 bg-mountain-mist-100 p-2.5 text-sm text-mountain-mist-700 focus:border-mountain-mist-500 focus:ring-curious-blue-500 dark:border-shark-600 dark:border-s-shark-500 dark:bg-shark-500 dark:text-mountain-mist-200 dark:placeholder-mountain-mist-400 dark:focus:border-matisse-500 dark:focus:ring-shark-300"
435-
value={language}
433+
value={i18n.language}
436434
onChange={handleLanguageChange}
437435
>
438436
{languageOptions.map((option) => (

src/components/xrplayout.tsx

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { Layout, Model, IJsonModel, TabNode, Action, Actions } from 'flexlayout-react';
1+
import { Layout, Model, IJsonModel, TabNode, Action, Actions, ITabRenderValues } from 'flexlayout-react';
22
import React, { useEffect } from 'react';
33
import BlocklyEditor from '@components/blockly';
44
import MonacoEditor from '@components/MonacoEditor';
55
import XRPShell from '@components/xrpshell';
66
import FolderIcon from '@assets/images/folder-24.png';
7-
import i18n from '@/utils/i18n';
7+
import ShellIcon from '@assets/images/shell.svg';
88
//import treeDaaJson from '@/utils/testdata';
99
import AppMgr, { EventType, Themes } from '@/managers/appmgr';
1010
import FolderTree from './folder-tree';
@@ -16,6 +16,7 @@ import EditorMgr, { EditorStore } from '@/managers/editormgr';
1616
import { CreateEditorTab } from '@/utils/editorUtils';
1717
import XRPDashboard from '@/components/dashboard/xrp-dashboard';
1818
import AIChat from '@/components/chat/ai-chat';
19+
import { useTranslation } from 'react-i18next';
1920

2021
/**
2122
* Layout-React's layout JSON to specify the XRPWeb's single page application's layout
@@ -40,7 +41,7 @@ const layout_json: IJsonModel = {
4041
{
4142
type: 'tab',
4243
id: Constants.FOLDER_TAB_ID,
43-
name: i18n.t('folders'),
44+
name: 'folders',
4445
component: 'folders',
4546
enableClose: false,
4647
icon: FolderIcon,
@@ -74,8 +75,8 @@ const layout_json: IJsonModel = {
7475
children: [
7576
{
7677
type: 'tab',
77-
id: 'shellId',
78-
name: i18n.t('shell'),
78+
id: Constants.SHELL_TAB_ID,
79+
name: 'shell',
7980
component: 'xterm',
8081
enableClose: false,
8182
},
@@ -139,6 +140,7 @@ function useOnceCall(cb: () => void, condition = true) {
139140
*/
140141
function XRPLayout({ forwardedref }: XRPLayoutProps) {
141142
const [activeTab, setActiveTab] = useLocalStorage(StorageKeys.ACTIVETAB, '');
143+
const { t } = useTranslation();
142144

143145
/**
144146
* changeTheme - set the system selected theme
@@ -268,7 +270,24 @@ function XRPLayout({ forwardedref }: XRPLayoutProps) {
268270
return action;
269271
}
270272

271-
return <Layout ref={forwardedref} model={model} factory={factory} onAction={handleActions} />;
273+
/**
274+
* onRenderTab - render the tab with custom functionality
275+
* @param node
276+
* @param renderValues
277+
* @returns
278+
*/
279+
const onRenderTab = (node: TabNode, renderValues: ITabRenderValues) => {
280+
// Override the content to use the translated tab names
281+
if (node.getId() === Constants.FOLDER_TAB_ID) {
282+
renderValues.leading = <img src={FolderIcon} alt="icon" style={{ width: '16px', height: '16px', marginRight: '16px' }} />;
283+
} else if (node.getId() === Constants.SHELL_TAB_ID) {
284+
renderValues.leading = <img src={ShellIcon} alt="icon" style={{ width: '16px', height: '16px', marginRight: '0px' }} />;
285+
}
286+
renderValues.content = t(node.getName());
287+
return renderValues;
288+
};
289+
290+
return <Layout ref={forwardedref} model={model} factory={factory} onAction={handleActions} onRenderTab={onRenderTab}/>;
272291
}
273292

274293
export default XRPLayout;

src/utils/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export class Constants {
22
static readonly APP_VERSION = '2.0.1';
33
static readonly EDITOR_TABSET_ID = 'editorTabSetId';
44
static readonly SHELL_TABSET_ID = 'shellTabSetId';
5+
static readonly SHELL_TAB_ID = 'shellTabId';
56
static readonly FOLDER_TAB_ID = 'folderTabId';
67
static readonly AI_CHAT_TAB_ID = 'aiChatTabId';
78
static readonly DEFAULT_FONTSIZE = 14;

0 commit comments

Comments
 (0)