Skip to content

Commit

Permalink
feat(terminal):auto switch namespace (#3959)
Browse files Browse the repository at this point in the history
  • Loading branch information
xudaotutou committed Sep 19, 2023
1 parent 9631508 commit 6d047b7
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 38 deletions.
5 changes: 5 additions & 0 deletions frontend/desktop/scripts/getSalt.ps1
@@ -0,0 +1,5 @@
$_salt = (kubectl.exe get secret/desktop-frontend-secret -nsealos -o json |
ConvertFrom-Json).data.jwt_secret
Write-Host $_salt
$salt = ConvertFrom-Base64ToString $_salt
Write-Host $salt
Expand Up @@ -81,13 +81,13 @@ export function CommonBillingTable({ data }: { data: BillingItem[] }) {
minW={'max-content'}
{...(item.type === BillingType.RECHARGE
? {
bg: '#E6F6F6',
color: '#00A9A6'
}
bg: '#E6F6F6',
color: '#00A9A6'
}
: {
bg: '#EBF7FD',
color: '#0884DD'
})}
bg: '#EBF7FD',
color: '#0884DD'
})}
borderRadius="24px"
align={'center'}
justify={'space-evenly'}
Expand Down
18 changes: 4 additions & 14 deletions frontend/providers/cronjob/tsconfig.json
@@ -1,21 +1,11 @@
{
"compilerOptions": {
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"lib": ["dom", "dom.iterable", "esnext"],
"baseUrl": ".",
"paths": {
"@/*": [
"./src/*"
]
"@/*": ["./src/*"]
}
},
"include": [
"next-env.d.ts",
"src/**/*.ts",
"src/**/*.tsx"
],
"include": ["next-env.d.ts", "src/**/*.ts", "src/**/*.tsx"],
"extends": "../../tsconfig.web.json"
}
}
2 changes: 1 addition & 1 deletion frontend/providers/license/next-i18next.config.js
Expand Up @@ -9,4 +9,4 @@ module.exports = {
locales: ['en', 'zh'],
localeDetection: false
}
}
};
18 changes: 4 additions & 14 deletions frontend/providers/license/tsconfig.json
@@ -1,21 +1,11 @@
{
"compilerOptions": {
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"lib": ["dom", "dom.iterable", "esnext"],
"baseUrl": ".",
"paths": {
"@/*": [
"./src/*"
]
"@/*": ["./src/*"]
}
},
"include": [
"next-env.d.ts",
"src/**/*.ts",
"src/**/*.tsx"
],
"include": ["next-env.d.ts", "src/**/*.ts", "src/**/*.tsx"],
"extends": "../../tsconfig.web.json"
}
}
11 changes: 9 additions & 2 deletions frontend/providers/terminal/src/components/terminal/index.tsx
Expand Up @@ -5,6 +5,7 @@ import { nanoid } from 'nanoid';
import { useRouter } from 'next/router';
import { useEffect, useRef, useState } from 'react';
import styles from './index.module.scss';
import useSessionStore from '@/stores/session';

type Terminal = {
id: string;
Expand All @@ -16,7 +17,7 @@ function Terminal({ url, site }: { url: string; site: string }) {
const router = useRouter();
const iframeRef = useRef<HTMLIFrameElement>(null);
const { query } = router;

const session = useSessionStore((s) => s.session);
const [tabContents, setTabContents] = useState<Terminal[]>([
{
id: tabId,
Expand All @@ -37,7 +38,13 @@ function Terminal({ url, site }: { url: string; site: string }) {
}
if (e.data?.ttyd === 'ready') {
const command = iframeRef.current?.getAttribute('data-command');
iframeRef?.current?.contentWindow?.postMessage({ command: command }, url);
iframeRef?.current?.contentWindow?.postMessage({ command }, url);
iframeRef.current?.contentWindow?.postMessage(
{
command: `kubectl config set-context --current --namespace=${session.user.nsid}`
},
url
);
}
} catch (error) {
console.log(error, 'error');
Expand Down
2 changes: 1 addition & 1 deletion frontend/providers/terminal/src/stores/session.ts
@@ -1,5 +1,5 @@
import type { Session } from '@/interfaces/session';
import { sessionKey } from '@/interfaces/session';
import type { SessionV1 as Session } from 'sealos-desktop-sdk/*';
import * as yaml from 'js-yaml';
import { create } from 'zustand';
import { devtools } from 'zustand/middleware';
Expand Down

0 comments on commit 6d047b7

Please sign in to comment.