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:modify the format of the exported file #4040

Merged
merged 1 commit into from
Oct 7, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,12 @@ const Header = ({
const { lastRoute } = useGlobalStore();

const handleExportYaml = useCallback(async () => {
const zip = new JSZip();
yamlList.forEach((item) => {
zip.file(item.filename, item.value);
});
const res = await zip.generateAsync({ type: 'blob' });
const exportYamlString = yamlList.map((i) => i.value).join('---\n');
if (!exportYamlString) return;
downLoadBold(
res,
'application/zip',
appName ? `${appName}.zip` : `yaml${dayjs().format('YYYYMMDDHHmmss')}.zip`
exportYamlString,
'application/yaml',
appName ? `${appName}.yaml` : `yaml${dayjs().format('YYYYMMDDHHmmss')}.yaml`
);
}, [appName, yamlList]);

Expand Down
2 changes: 1 addition & 1 deletion frontend/providers/cronjob/src/utils/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ export const getUserNamespace = () => {
export const getUserServiceAccount = () => {
const kubeConfig = getUserKubeConfig();
const json = yaml.load(kubeConfig) as KC;
return json?.contexts[0]?.context?.namespace?.replace('ns-', '') || `${json?.users[0]?.name}`;
return json?.contexts[0]?.context?.user || json?.users[0]?.name;
};
25 changes: 9 additions & 16 deletions frontend/providers/template/src/pages/deploy/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,12 @@ const Header = ({
const { t } = useTranslation();

const handleExportYaml = useCallback(async () => {
const zip = new JSZip();
yamlList.forEach((item) => {
zip.file(item.filename, item.value);
});
const res = await zip.generateAsync({ type: 'blob' });
const exportYamlString = yamlList.map((i) => i.value).join('---\n');
if (!exportYamlString) return;
downLoadBold(
res,
'application/zip',
appName ? `${appName}.zip` : `yaml${dayjs().format('YYYYMMDDHHmmss')}.zip`
exportYamlString,
'application/yaml',
appName ? `${appName}.yaml` : `yaml${dayjs().format('YYYYMMDDHHmmss')}.yaml`
);
}, [appName, yamlList]);

Expand All @@ -49,8 +46,7 @@ const Header = ({
w={'100%'}
h={'80px'}
alignItems={'center'}
backgroundColor={'rgba(255, 255, 255, 0.90)'}
>
backgroundColor={'rgba(255, 255, 255, 0.90)'}>
<Flex
boxShadow={'0px 1px 2px 0.5px rgba(84, 96, 107, 0.20)'}
flexShrink={0}
Expand All @@ -60,8 +56,7 @@ const Header = ({
h={'80px'}
borderRadius={'8px'}
backgroundColor={'#FBFBFC'}
border={' 1px solid rgba(255, 255, 255, 0.50)'}
>
border={' 1px solid rgba(255, 255, 255, 0.50)'}>
<Image src={templateDetail?.spec?.icon} alt="" width={'60px'} height={'60px'} />
</Flex>
<Flex ml={'24px'} w="520px" flexDirection={'column'}>
Expand All @@ -83,8 +78,7 @@ const Header = ({
mt={'8px'}
fontSize={'12px'}
color={'5A646E'}
fontWeight={400}
>
fontWeight={400}>
{templateDetail?.spec?.description}
</Text>
</Flex>
Expand All @@ -98,8 +92,7 @@ const Header = ({
bg={'myWhite.600'}
borderColor={'myGray.200'}
variant={'base'}
onClick={handleExportYaml}
>
onClick={handleExportYaml}>
{t('Export')} Yaml
</Button>
<Button px={4} minW={'140px'} h={'40px'} variant={'primary'} onClick={applyCb}>
Expand Down
21 changes: 7 additions & 14 deletions frontend/providers/template/src/pages/deploy/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,7 @@ export default function EditApp({ appName, tabType }: { appName?: string; tabTyp
overflow={'auto'}
position={'relative'}
borderRadius={'12px'}
background={'linear-gradient(180deg, #FFF 0%, rgba(255, 255, 255, 0.70) 100%)'}
>
background={'linear-gradient(180deg, #FFF 0%, rgba(255, 255, 255, 0.70) 100%)'}>
<Flex
zIndex={99}
position={'sticky'}
Expand All @@ -265,15 +264,13 @@ export default function EditApp({ appName, tabType }: { appName?: string; tabTyp
justifyContent={'start'}
alignItems={'center'}
backgroundColor={'rgba(255, 255, 255)'}
backdropBlur={'100px'}
>
backdropBlur={'100px'}>
<Flex
alignItems={'center'}
fontWeight={500}
fontSize={16}
color={'#7B838B'}
cursor={'pointer'}
>
cursor={'pointer'}>
<Flex
alignItems={'center'}
css={{
Expand All @@ -284,16 +281,14 @@ export default function EditApp({ appName, tabType }: { appName?: string; tabTyp
fill: '#219BF4'
}
}
}}
>
}}>
<Icon
ml={'19px'}
viewBox="0 0 15 15"
fill={'#24282C'}
w={'15px'}
h="15px"
onClick={() => router.push('/')}
>
onClick={() => router.push('/')}>
<path d="M9.1875 13.1875L3.92187 7.9375C3.85937 7.875 3.81521 7.80729 3.78937 7.73438C3.76312 7.66146 3.75 7.58333 3.75 7.5C3.75 7.41667 3.76312 7.33854 3.78937 7.26562C3.81521 7.19271 3.85937 7.125 3.92187 7.0625L9.1875 1.79687C9.33333 1.65104 9.51562 1.57812 9.73438 1.57812C9.95312 1.57812 10.1406 1.65625 10.2969 1.8125C10.4531 1.96875 10.5312 2.15104 10.5312 2.35938C10.5312 2.56771 10.4531 2.75 10.2969 2.90625L5.70312 7.5L10.2969 12.0938C10.4427 12.2396 10.5156 12.4192 10.5156 12.6325C10.5156 12.8463 10.4375 13.0312 10.2812 13.1875C10.125 13.3438 9.94271 13.4219 9.73438 13.4219C9.52604 13.4219 9.34375 13.3438 9.1875 13.1875Z" />
</Icon>
<Text ml="4px" onClick={() => router.push('/')}>
Expand All @@ -303,8 +298,7 @@ export default function EditApp({ appName, tabType }: { appName?: string; tabTyp
<Text px="6px">/</Text>
<Text
_hover={{ fill: '#219BF4', color: '#219BF4' }}
color={router.pathname === '/deploy' ? '#262A32' : '#7B838B'}
>
color={router.pathname === '/deploy' ? '#262A32' : '#7B838B'}>
{data?.templateYaml?.metadata?.name}
</Text>
</Flex>
Expand All @@ -315,8 +309,7 @@ export default function EditApp({ appName, tabType }: { appName?: string; tabTyp
flexDirection={'column'}
width={'100%'}
flexGrow={1}
backgroundColor={'rgba(255, 255, 255, 0.90)'}
>
backgroundColor={'rgba(255, 255, 255, 0.90)'}>
<Header
templateDetail={data?.templateYaml!}
appName={''}
Expand Down
31 changes: 14 additions & 17 deletions frontend/providers/template/src/pages/develop/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ export default function Develop() {
const parseTemplate = (str: string) => {
try {
const result = getYamlSource(str);
const defaultInputes = getTemplateDefaultValues(result);
setYamlSource(result);
const correctYaml = generateCorrectYaml(result);
const correctYaml = generateCorrectYaml(result, defaultInputes);
setYamlList(developGenerateYamlList(correctYaml, detailName));
} catch (error: any) {
toast({
Expand Down Expand Up @@ -167,12 +168,13 @@ export default function Develop() {
};

const handleExportYaml = useCallback(async () => {
const zip = new JSZip();
yamlList.forEach((item) => {
zip.file(item.filename, item.value);
});
const res = await zip.generateAsync({ type: 'blob' });
downLoadBold(res, 'application/zip', `yaml${dayjs().format('YYYYMMDDHHmmss')}.zip`);
const exportYamlString = yamlList.map((i) => i.value).join('---\n');
if (!exportYamlString) return;
downLoadBold(
exportYamlString,
'application/yaml',
`yaml${dayjs().format('YYYYMMDDHHmmss')}.yaml`
);
}, [yamlList]);

return (
Expand All @@ -183,8 +185,7 @@ export default function Develop() {
borderRadius={'8px'}
overflowY={'hidden'}
overflowX={'scroll'}
flex={1}
>
flex={1}>
{/* left */}
<Flex flexDirection={'column'} w="50%" borderRight={'1px solid #EFF0F1'}>
<Flex
Expand All @@ -194,8 +195,7 @@ export default function Develop() {
alignItems={'center'}
backgroundColor={'#F8FAFB'}
px="36px"
borderRadius={'8px 8px 0px 0px '}
>
borderRadius={'8px 8px 0px 0px '}>
<MyIcon name="dev" color={'#24282C'} w={'24px'} h={'24px'}></MyIcon>
<Text fontWeight={'500'} fontSize={'16px'} color={'#24282C'} ml="8px">
{t('develop.Development')}
Expand Down Expand Up @@ -223,8 +223,7 @@ export default function Develop() {
alignItems={'center'}
backgroundColor={'#F8FAFB'}
pl="42px"
borderRadius={'8px 8px 0px 0px '}
>
borderRadius={'8px 8px 0px 0px '}>
<MyIcon name="eyeShow" color={'#24282C'} w={'24px'} h={'24px'}></MyIcon>
<Text fontWeight={'500'} fontSize={'16px'} color={'#24282C'} ml="8px">
{t('develop.Preview')}
Expand All @@ -236,8 +235,7 @@ export default function Develop() {
pt="26px"
pr={{ sm: '20px', md: '60px' }}
borderBottom={'1px solid #EFF0F1'}
flexDirection={'column'}
>
flexDirection={'column'}>
<Text fontWeight={'500'} fontSize={'18px'} color={'#24282C'}>
{t('develop.Configure Form')}
</Text>
Expand All @@ -253,8 +251,7 @@ export default function Develop() {
minW={'100px'}
h={'34px'}
variant={'link'}
onClick={handleExportYaml}
>
onClick={handleExportYaml}>
{t('Export')} Yaml
</Button>
</Flex>
Expand Down
1 change: 1 addition & 0 deletions frontend/providers/template/src/types/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export type TemplateType = {
spec: {
gitRepo: string; // new
templateType: 'inline'; // new
template_type?: string;
author: string;
title: string;
url: string;
Expand Down
4 changes: 2 additions & 2 deletions frontend/providers/template/src/utils/json-yaml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export const handleTemplateToInstanceYaml = (
instanceName: string
): TemplateInstanceType => {
const {
spec: { gitRepo, templateType, ...resetSpec }
spec: { gitRepo, templateType, template_type, ...resetSpec }
} = template;

return {
Expand All @@ -161,7 +161,7 @@ export const handleTemplateToInstanceYaml = (
},
spec: {
gitRepo: gitRepo,
templateType: templateType,
templateType: templateType || template_type,
...resetSpec
}
};
Expand Down
Loading