refactoring code

Signed-off-by: kosukeKK <koskacts@gmail.com>
This commit is contained in:
kosukeKK
2024-03-09 15:46:04 +09:00
parent c6864cce72
commit be90610832
2 changed files with 11 additions and 28 deletions
@@ -46,10 +46,7 @@ import {
selectedTemplateRouteRef,
} from '../../routes';
import {
TemplateWizardPageContextMenu,
TemplateWizardPageContextMenuProps,
} from './TemplateWizardPageContextMenu';
import { TemplateWizardPageContextMenu } from './TemplateWizardPageContextMenu';
/**
* @alpha
@@ -90,16 +87,6 @@ export const TemplateWizardPage = (props: TemplateWizardPageProps) => {
return data?.metadata.annotations?.[ANNOTATION_EDIT_URL] || '';
}, [templateRef, catalogApi]);
const templateWizardPageContextMenuProps: TemplateWizardPageContextMenuProps =
{
onEditorClicked:
editUrl !== ''
? () => {
window.open(editUrl, '_blank');
}
: undefined,
};
const onCreate = async (values: Record<string, JsonValue>) => {
const { taskId } = await scaffolderApi.scaffold({
templateRef,
@@ -121,9 +108,7 @@ export const TemplateWizardPage = (props: TemplateWizardPageProps) => {
subtitle="Create new software components using standard templates in your organization"
{...props.headerOptions}
>
<TemplateWizardPageContextMenu
{...templateWizardPageContextMenuProps}
/>
<TemplateWizardPageContextMenu editUrl={editUrl} />
</Header>
<Workflow
namespace={namespace}
@@ -32,17 +32,17 @@ const useStyles = makeStyles(theme => ({
}));
export type TemplateWizardPageContextMenuProps = {
onEditorClicked?: () => void;
editUrl?: string;
};
export function TemplateWizardPageContextMenu(
props: TemplateWizardPageContextMenuProps,
) {
const { onEditorClicked } = props;
const { editUrl } = props;
const classes = useStyles();
const [anchorEl, setAnchorEl] = useState<HTMLButtonElement>();
if (!onEditorClicked) {
if (!editUrl) {
return null;
}
@@ -79,14 +79,12 @@ export function TemplateWizardPageContextMenu(
transformOrigin={{ vertical: 'top', horizontal: 'right' }}
>
<MenuList>
{onEditorClicked && (
<MenuItem onClick={onEditorClicked}>
<ListItemIcon>
<Edit fontSize="small" />
</ListItemIcon>
<ListItemText primary="Edit Configuration" />
</MenuItem>
)}
<MenuItem onClick={() => window.open(editUrl, '_blank')}>
<ListItemIcon>
<Edit fontSize="small" />
</ListItemIcon>
<ListItemText primary="Edit Configuration" />
</MenuItem>
</MenuList>
</Popover>
</>