Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for launching creation page in launchpad #4984

Merged
merged 2 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions frontend/desktop/src/api/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ import {
CloudConfigType,
AuthClientConfigType,
AppClientConfigType,
CommonConfigType,
CommonClientConfigType,
TNotification
} from '@/types';
import { AccountCRD } from '@/types/user';
import { getBaiduId } from '@/utils/sessionConfig';

// handle baidu
export const uploadConvertData = (newType: number[], url?: string) => {
const defaultUrl = 'https://sealos.run/self-hosting';
const main_url = url || defaultUrl;
const bd_vid = localStorage.getItem('bd_vid');
const bd_vid = getBaiduId();
if (!bd_vid) {
return Promise.reject('upload convert data params error');
}
Expand Down
4 changes: 3 additions & 1 deletion frontend/desktop/src/components/signin/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ import { useRouter } from 'next/router';
import { useEffect, useMemo, useRef, useState } from 'react';
import useWechat from './auth/useWechat';
import { Turnstile, TurnstileInstance } from '@marsidev/react-turnstile';
import { getBaiduId } from '@/utils/sessionConfig';

export default function SigninComponent() {
const conf = useConfigStore();
const hasBaiduToken = conf.authConfig?.hasBaiduToken;
const needPassword = conf.authConfig?.idp.password?.enabled;
const needSms = conf.authConfig?.idp.sms?.enabled;
const needTabs = conf.authConfig?.idp.password?.enabled && conf.authConfig?.idp.sms?.enabled;
Expand Down Expand Up @@ -247,7 +249,7 @@ export default function SigninComponent() {
? (t('common:loading') || 'Loading') + '...'
: t('common:log_in') || 'Log In'}
</Button>
<AuthList />
{hasBaiduToken && getBaiduId() ? <Box></Box> : <AuthList />}
</>
)}
</Flex>
Expand Down
2 changes: 1 addition & 1 deletion frontend/desktop/src/pages/api/platform/getAuthConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function genResAuthClientConfig(conf: AuthConfigType) {
}
},
proxyAddress: conf.proxyAddress || '',
baiduToken: conf.baiduToken || ''
hasBaiduToken: !!conf.baiduToken
};
return authClientConfig;
}
Expand Down
4 changes: 2 additions & 2 deletions frontend/desktop/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import useAppStore from '@/stores/app';
import { useConfigStore } from '@/stores/config';
import useSessionStore from '@/stores/session';
import { parseOpenappQuery } from '@/utils/format';
import { setInviterId, setUserSemData } from '@/utils/sessionConfig';
import { setBaiduId, setInviterId, setUserSemData } from '@/utils/sessionConfig';
import { compareFirstLanguages } from '@/utils/tools';
import { Box, useColorMode } from '@chakra-ui/react';
import { serverSideTranslations } from 'next-i18next/serverSideTranslations';
Expand Down Expand Up @@ -87,7 +87,7 @@ export default function Home({ sealos_cloud_domain }: { sealos_cloud_domain: str
useEffect(() => {
const { bd_vid, s, k } = router.query;
if (bd_vid) {
localStorage.setItem('bd_vid', bd_vid as string);
setBaiduId(bd_vid as string);
}

// handle new user sem source
Expand Down
4 changes: 3 additions & 1 deletion frontend/desktop/src/types/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export type AuthConfigType = {
callbackURL: string;
signUpEnabled?: boolean;
baiduToken?: string;
hasBaiduToken?: boolean;
jwt: JwtConfigType;
billingUrl?: string;
workorderUrl?: string;
Expand Down Expand Up @@ -137,6 +138,7 @@ export type AuthClientConfigType = DeepRequired<
OmitPathArr<
AuthConfigType,
[
'baiduToken',
'signUpEnabled',
'invite.lafSecretKey',
'invite.lafBaseURL',
Expand Down Expand Up @@ -225,7 +227,7 @@ export const DefaultLayoutConfig: LayoutConfigType = {
};

export const DefaultAuthClientConfig: AuthClientConfigType = {
baiduToken: '',
hasBaiduToken: false,
invite: {
enabled: false
},
Expand Down
4 changes: 4 additions & 0 deletions frontend/desktop/src/utils/sessionConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,7 @@ export const getUserSemData = (): SemData | null => {
export const setUserSemData = (data: SemData): void => {
localStorage.setItem('sealos_sem', JSON.stringify(data));
};

export const getBaiduId = () => localStorage.getItem('bd_vid');

export const setBaiduId = (id: string) => localStorage.setItem('bd_vid', id);
31 changes: 23 additions & 8 deletions frontend/providers/applaunchpad/src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { createSealosApp, sealosApp } from 'sealos-desktop-sdk/app';
import '@/styles/reset.scss';
import 'nprogress/nprogress.css';
import '@sealos/driver/src/driver.css';
import { AppEditSyncedFields } from '@/types/app';

//Binding events.
Router.events.on('routeChangeStart', () => NProgress.start());
Expand Down Expand Up @@ -132,19 +133,33 @@ const App = ({ Component, pageProps }: AppProps) => {
useEffect(() => {
const setupInternalAppCallListener = async () => {
try {
const event = async (e: MessageEvent) => {
const event = async (
e: MessageEvent<{
type?: string;
name?: string;
formData?: AppEditSyncedFields;
}>
) => {
const whitelist = [`https://${SEALOS_DOMAIN}`];
if (!whitelist.includes(e.origin)) {
return;
}
try {
if (e.data?.type === 'InternalAppCall' && e.data?.name) {
router.push({
pathname: '/app/detail',
query: {
name: e.data.name
}
});
if (e.data?.type === 'InternalAppCall') {
const { name, formData } = e.data;
if (name) {
router.push({
pathname: '/app/detail',
query: {
name: name
}
});
} else if (formData?.imageName) {
router.push({
pathname: '/app/edit',
query: formData
});
}
}
} catch (error) {
console.log(error, 'error');
Expand Down
18 changes: 17 additions & 1 deletion frontend/providers/applaunchpad/src/pages/app/edit/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { useAppStore } from '@/store/app';
import { useGlobalStore } from '@/store/global';
import { useUserStore } from '@/store/user';
import type { YamlItemType } from '@/types';
import type { AppEditType, DeployKindsType } from '@/types/app';
import type { AppEditSyncedFields, AppEditType, DeployKindsType } from '@/types/app';
import { adaptEditAppData } from '@/utils/adapt';
import {
json2ConfigMap,
Expand Down Expand Up @@ -288,6 +288,22 @@ const EditApp = ({ appName, tabType }: { appName?: string; tabType: string }) =>
}
}, [router.query.name, tabType]);

useEffect(() => {
const query = router.query;
const updates: Partial<AppEditSyncedFields> = {
imageName: query.imageName as string,
replicas: query.replicas ? Number(query.replicas) : undefined,
cpu: query.cpu ? Number(query.cpu) : undefined,
memory: query.memory ? Number(query.memory) : undefined
};

Object.entries(updates).forEach(([key, value]) => {
if (value !== undefined) {
formHook.setValue(key as keyof AppEditSyncedFields, value);
}
});
}, []);

return (
<>
<Flex
Expand Down
2 changes: 2 additions & 0 deletions frontend/providers/applaunchpad/src/types/app.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ export interface AppEditType {
}[];
}

export type AppEditSyncedFields = Pick<AppEditType, 'imageName' | 'replicas' | 'cpu' | 'memory'>;

export type TAppSourceType = 'app_store' | 'sealaf';

export type TAppSource = {
Expand Down
Loading