chore: get started for add cluster
This commit is contained in:
@@ -0,0 +1,113 @@
|
||||
import { clusterSessionAtom } from '@/atoms/clusters';
|
||||
import IconFont from '@/components/icon-font';
|
||||
import { PageAction } from '@/config';
|
||||
import NoResult from '@/pages/_components/no-result';
|
||||
import { useIntl, useNavigate } from '@umijs/max';
|
||||
import { useMemoizedFn } from 'ahooks';
|
||||
import { Button } from 'antd';
|
||||
import { useAtom } from 'jotai';
|
||||
import React, { useMemo } from 'react';
|
||||
|
||||
const useNoResourceResult = (props: {
|
||||
iconType: string;
|
||||
loading?: boolean;
|
||||
loadend?: boolean;
|
||||
dataSource?: any[];
|
||||
queryParams?: Record<string, any>;
|
||||
title: React.ReactNode;
|
||||
noClusters?: boolean;
|
||||
noWorkers?: boolean;
|
||||
subTitle?: React.ReactNode;
|
||||
defaultContent?: {
|
||||
subTitle: string;
|
||||
noFoundText: string;
|
||||
buttonText: string;
|
||||
onClick: () => void;
|
||||
};
|
||||
}) => {
|
||||
const intl = useIntl();
|
||||
const navigate = useNavigate();
|
||||
const {
|
||||
noClusters,
|
||||
noWorkers,
|
||||
defaultContent,
|
||||
loading,
|
||||
loadend,
|
||||
dataSource,
|
||||
queryParams,
|
||||
iconType,
|
||||
title,
|
||||
subTitle
|
||||
} = props;
|
||||
const [, setClusterSession] = useAtom(clusterSessionAtom);
|
||||
|
||||
const handleClick = useMemoizedFn(() => {
|
||||
if (noClusters) {
|
||||
setClusterSession({
|
||||
firstAddWorker: false,
|
||||
firstAddCluster: true
|
||||
});
|
||||
|
||||
navigate(
|
||||
`/cluster-management/clusters/create?action=${PageAction.CREATE}`
|
||||
);
|
||||
}
|
||||
|
||||
if (noWorkers) {
|
||||
setClusterSession({
|
||||
firstAddWorker: true,
|
||||
firstAddCluster: false
|
||||
});
|
||||
navigate(`/cluster-management/clusters/list`);
|
||||
}
|
||||
});
|
||||
|
||||
const statusContent = useMemo(() => {
|
||||
if (noClusters) {
|
||||
return {
|
||||
subTitle:
|
||||
subTitle || intl.formatMessage({ id: 'noresult.resources.cluster' }),
|
||||
noFoundText: defaultContent?.noFoundText || '',
|
||||
buttonText: intl.formatMessage({
|
||||
id: 'noresult.resources.gotocluster'
|
||||
}),
|
||||
onClick: handleClick
|
||||
};
|
||||
}
|
||||
|
||||
if (noWorkers) {
|
||||
return {
|
||||
subTitle:
|
||||
subTitle || intl.formatMessage({ id: 'noresult.resources.worker' }),
|
||||
noFoundText: defaultContent?.noFoundText || '',
|
||||
buttonText: intl.formatMessage({ id: 'noresult.resources.gotoworker' }),
|
||||
onClick: handleClick
|
||||
};
|
||||
}
|
||||
return {
|
||||
...defaultContent
|
||||
};
|
||||
}, [noClusters, noWorkers, intl]);
|
||||
|
||||
const noResourceResult = (
|
||||
<NoResult
|
||||
loading={loading}
|
||||
loadend={loadend}
|
||||
dataSource={dataSource}
|
||||
image={<IconFont type={iconType} />}
|
||||
filters={queryParams}
|
||||
noFoundText={statusContent.noFoundText}
|
||||
title={title}
|
||||
subTitle={statusContent.subTitle}
|
||||
>
|
||||
<Button type="primary" iconPosition="end" onClick={statusContent.onClick}>
|
||||
{statusContent.buttonText}
|
||||
</Button>
|
||||
</NoResult>
|
||||
);
|
||||
return {
|
||||
noResourceResult
|
||||
};
|
||||
};
|
||||
|
||||
export default useNoResourceResult;
|
||||
Reference in New Issue
Block a user