Skip to content

Commit

Permalink
fix:adapt to desktop open template (#4398)
Browse files Browse the repository at this point in the history
Signed-off-by: jingyang <3161362058@qq.com>
  • Loading branch information
zjy365 committed Dec 11, 2023
1 parent 5c01b5a commit 56123b8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
5 changes: 4 additions & 1 deletion frontend/desktop/src/pages/index.tsx
Expand Up @@ -47,7 +47,7 @@ export default function Home({ sealos_cloud_domain }: { sealos_cloud_domain: str
useEffect(() => {
const { query } = router;
const is_login = isUserLogin();
const whitelistApps = ['system-template'];
const whitelistApps = ['system-template', 'system-fastdeploy'];
if (!is_login) {
const { appkey, appQuery } = parseOpenappQuery((query?.openapp as string) || '');
// sealos_inside=true internal call
Expand All @@ -71,6 +71,9 @@ export default function Home({ sealos_cloud_domain }: { sealos_cloud_domain: str
appQuery = state.launchQuery.raw;
}
if (!appkey) return;
if (appkey === 'system-fastdeploy') {
appkey = 'system-template';
}
const app = state.installedApps.find((item) => item.key === appkey);
if (!app) return;
state.openApp(app, { raw: appQuery }).then(() => {
Expand Down
9 changes: 1 addition & 8 deletions frontend/providers/applaunchpad/src/hooks/useDriver.tsx
@@ -1,11 +1,9 @@
import { getPlatformEnv, getUserAccount, updateDesktopGuide } from '@/api/platform';
import { GUIDE_LAUNCHPAD_CREATE_KEY } from '@/constants/account';
import { AppEditType } from '@/types/app';
import { Flex, FlexProps, Icon, Text } from '@chakra-ui/react';
import { driver } from '@sealos/driver';
import { useTranslation } from 'next-i18next';
import { useEffect, useState } from 'react';
import { UseFormReturn } from 'react-hook-form';

export function DriverStarIcon() {
return (
Expand Down Expand Up @@ -40,11 +38,7 @@ export function DriverStarIcon() {
);
}

export default function useDriver({
formHook
}: {
formHook: UseFormReturn<AppEditType, any, undefined>;
}) {
export default function useDriver() {
const { t } = useTranslation();
const [isGuided, setIsGuided] = useState(true);

Expand All @@ -57,7 +51,6 @@ export default function useDriver({
const isGuided = !!userAccount.metadata.annotations?.[GUIDE_LAUNCHPAD_CREATE_KEY];
if (!isGuided) {
startGuide();
formHook.setValue('appName', 'hello-world-guide');
}
setIsGuided(isGuided);
}
Expand Down
17 changes: 11 additions & 6 deletions frontend/providers/applaunchpad/src/pages/app/edit/index.tsx
Expand Up @@ -21,7 +21,7 @@ import {
json2Service
} from '@/utils/deployYaml2Json';
import { serviceSideProps } from '@/utils/i18n';
import { getErrText, patchYamlListV1 } from '@/utils/tools';
import { getErrText, patchYamlList, patchYamlListV1 } from '@/utils/tools';
import { Box, Flex } from '@chakra-ui/react';
import { useQuery } from '@tanstack/react-query';
import { useTranslation } from 'next-i18next';
Expand Down Expand Up @@ -89,6 +89,7 @@ export const formData2Yamls = (

const EditApp = ({ appName, tabType }: { appName?: string; tabType: string }) => {
const { t } = useTranslation();
const formOldYamls = useRef<YamlItemType[]>([]);
const crOldYamls = useRef<DeployKindsType[]>([]);
const oldAppEditData = useRef<AppEditType>();
const { toast } = useToast();
Expand Down Expand Up @@ -123,7 +124,7 @@ const EditApp = ({ appName, tabType }: { appName?: string; tabType: string }) =>
const formHook = useForm<AppEditType>({
defaultValues: defaultEditVal
});
const { isGuided, closeGuide } = useDriver({ formHook });
const { isGuided, closeGuide } = useDriver();

const realTimeForm = useRef(defaultEditVal);

Expand Down Expand Up @@ -154,10 +155,10 @@ const EditApp = ({ appName, tabType }: { appName?: string; tabType: string }) =>
setIsLoading(true);
try {
const yamls = yamlList.map((item) => item.value);

if (appName) {
const patch = patchYamlListV1({
oldYamlList: crOldYamls.current,
const patch = patchYamlList({
formOldYamlList: formOldYamls.current.map((item) => item.value),
crYamlList: crOldYamls.current,
newYamlList: yamls
});

Expand Down Expand Up @@ -257,7 +258,11 @@ const EditApp = ({ appName, tabType }: { appName?: string; tabType: string }) =>
onSuccess(res) {
if (!res) return;
oldAppEditData.current = res;

formOldYamls.current = formData2Yamls(
res,
appName !== '' ? 'edit' : 'create',
res.crYamlList
);
crOldYamls.current = res.crYamlList;

setDefaultStorePathList(res.storeList.map((item) => item.path));
Expand Down

0 comments on commit 56123b8

Please sign in to comment.