Skip to content

Commit

Permalink
feat: add support for launching creation page in launchpad
Browse files Browse the repository at this point in the history
  • Loading branch information
zjy365 committed Aug 20, 2024
1 parent d32471d commit ec969d7
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 9 deletions.
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

0 comments on commit ec969d7

Please sign in to comment.