-
Notifications
You must be signed in to change notification settings - Fork 615
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use page route instead of resource for vmtemplates
- Loading branch information
Showing
4 changed files
with
151 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
frontend/packages/kubevirt-plugin/src/components/vm-template.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import * as React from 'react'; | ||
import * as _ from 'lodash-es'; | ||
|
||
import { | ||
getTemplateOperatingSystems, | ||
DASHES, | ||
getTemplateFlavors, | ||
TemplateSource, | ||
} from 'kubevirt-web-ui-components'; | ||
|
||
import { NamespaceModel } from '@console/internal/models'; | ||
import { | ||
ListHeader, | ||
ColHead, | ||
List, | ||
ListPage, | ||
ResourceRow, | ||
} from '@console/internal/components/factory'; | ||
import { ResourceLink, resourcePath } from '@console/internal/components/utils'; | ||
|
||
import { VmTemplateModel } from '../models'; | ||
|
||
const mainRowStyle = 'col-lg-2 col-sm-4 col-xs-4'; | ||
const otherRowStyle = 'col-lg-2 hidden-sm hidden-xs'; | ||
|
||
const VmTemplateHeader = (props) => ( | ||
<ListHeader> | ||
<ColHead {...props} className={mainRowStyle} sortField="metadata.name"> | ||
Name | ||
</ColHead> | ||
<ColHead {...props} className={mainRowStyle} sortField="metadata.namespace"> | ||
Namespace | ||
</ColHead> | ||
<ColHead {...props} className={mainRowStyle} sortField="metadata.annotations.description"> | ||
Description | ||
</ColHead> | ||
<ColHead {...props} className={otherRowStyle}> | ||
Source | ||
</ColHead> | ||
<ColHead {...props} className={otherRowStyle}> | ||
OS | ||
</ColHead> | ||
<ColHead {...props} className={otherRowStyle}> | ||
Flavor | ||
</ColHead> | ||
</ListHeader> | ||
); | ||
const VmTemplateRow = ({ obj: template }: React.ComponentProps<typeof ResourceRow>) => { | ||
const os = getTemplateOperatingSystems([template])[0]; | ||
|
||
return ( | ||
<ResourceRow obj={template}> | ||
<div className={mainRowStyle}> | ||
<ResourceLink | ||
kind={VmTemplateModel.kind} | ||
name={template.metadata.name} | ||
namespace={template.metadata.namespace} | ||
title={template.metadata.uid} | ||
/> | ||
</div> | ||
<div className={mainRowStyle}> | ||
<ResourceLink | ||
kind={NamespaceModel.kind} | ||
name={template.metadata.namespace} | ||
title={template.metadata.namespace} | ||
/> | ||
</div> | ||
<div className={mainRowStyle}> | ||
{_.get(template.metadata, 'annotations.description', DASHES)} | ||
</div> | ||
<div className={otherRowStyle}> | ||
<div className="co-resource-list__item--templateSource"> | ||
<TemplateSource template={template} /> | ||
</div> | ||
</div> | ||
<div className={otherRowStyle}>{os ? os.name || os.id : DASHES}</div> | ||
<div className={otherRowStyle}>{getTemplateFlavors([template])[0]}</div> | ||
</ResourceRow> | ||
); | ||
}; | ||
const VmTemplateList = (props) => <List {...props} Header={VmTemplateHeader} Row={VmTemplateRow} />; | ||
|
||
export const VmTemplatesPageTitle = 'Virtual Machine Templates'; | ||
|
||
const createItems = { | ||
wizard: 'Create with Wizard', | ||
yaml: 'Create from YAML', | ||
}; | ||
|
||
const createProps = (namespace) => ({ | ||
items: createItems, | ||
createLink: (type) => { | ||
switch (type) { | ||
case 'wizard': | ||
return () => ''; | ||
default: | ||
return `${resourcePath(VmTemplateModel.kind, null, namespace)}/~new`; | ||
} | ||
}, | ||
}); | ||
|
||
export const VirtualMachineTemplatesPage = (props) => ( | ||
<ListPage | ||
{...props} | ||
title={VmTemplatesPageTitle} | ||
selector={VmTemplateModel.selector} | ||
kind={VmTemplateModel.kind} | ||
ListComponent={VmTemplateList} | ||
createProps={createProps(_.get(props, 'match.params.ns'))} | ||
canCreate | ||
/> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters