mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
refactoring as per review comments
Signed-off-by: Jim Ehrismann <jehrismann@mirantis.com>
This commit is contained in:
parent
1272041a9e
commit
4f3abb6dd6
@ -24,12 +24,12 @@ export class WorkspaceClusterMenu extends React.Component<Props> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@autobind()
|
@autobind()
|
||||||
settings() {
|
gotoSettings() {
|
||||||
const { clusterItem } = this.props;
|
const { clusterItem } = this.props;
|
||||||
|
|
||||||
navigate(clusterSettingsURL({
|
navigate(clusterSettingsURL({
|
||||||
params: {
|
params: {
|
||||||
clusterId: clusterItem.getId()
|
clusterId: clusterItem.id
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
@ -39,7 +39,7 @@ export class WorkspaceClusterMenu extends React.Component<Props> {
|
|||||||
const { clusterItem, workspace } = this.props;
|
const { clusterItem, workspace } = this.props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<p>Remove cluster <b>{clusterItem.getName()}</b> from workspace {workspace.name}?</p>
|
<p>Remove cluster <b>{clusterItem.name}</b> from workspace <b>{workspace.name}</b>?</p>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,7 +49,7 @@ export class WorkspaceClusterMenu extends React.Component<Props> {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<MenuItem onClick={this.settings}>
|
<MenuItem onClick={this.gotoSettings}>
|
||||||
<Icon material="settings" interactive={toolbar} title="Settings"/>
|
<Icon material="settings" interactive={toolbar} title="Settings"/>
|
||||||
<span className="title">Settings</span>
|
<span className="title">Settings</span>
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
@ -58,13 +58,13 @@ export class WorkspaceClusterMenu extends React.Component<Props> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { clusterItem, className, ...menuProps } = this.props;
|
const { clusterItem: { cluster: { isManaged } }, className, ...menuProps } = this.props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MenuActions
|
<MenuActions
|
||||||
{...menuProps}
|
{...menuProps}
|
||||||
className={cssNames("WorkspaceClusterMenu", className)}
|
className={cssNames("WorkspaceClusterMenu", className)}
|
||||||
removeAction={clusterItem.cluster.isManaged ? null : this.remove}
|
removeAction={isManaged ? null : this.remove}
|
||||||
removeConfirmationMessage={this.renderRemoveMessage}
|
removeConfirmationMessage={this.renderRemoveMessage}
|
||||||
>
|
>
|
||||||
{this.renderContent()}
|
{this.renderContent()}
|
||||||
|
|||||||
@ -7,13 +7,25 @@ import { autobind } from "../../utils";
|
|||||||
export class ClusterItem implements ItemObject {
|
export class ClusterItem implements ItemObject {
|
||||||
constructor(public cluster: Cluster) {}
|
constructor(public cluster: Cluster) {}
|
||||||
|
|
||||||
getName() {
|
get name() {
|
||||||
return this.cluster.name;
|
return this.cluster.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
getId() {
|
getName() {
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
get id() {
|
||||||
return this.cluster.id;
|
return this.cluster.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get clusterId() {
|
||||||
|
return this.cluster.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
getId() {
|
||||||
|
return this.id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** an ItemStore of the clusters belonging to a given workspace */
|
/** an ItemStore of the clusters belonging to a given workspace */
|
||||||
@ -38,15 +50,11 @@ export class WorkspaceClusterStore extends ItemStore<ClusterItem> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async remove(clusterItem: ClusterItem) {
|
async remove(clusterItem: ClusterItem) {
|
||||||
const { cluster } = clusterItem;
|
const { cluster: { isManaged, id: clusterId }} = clusterItem;
|
||||||
|
|
||||||
if (cluster.isManaged) {
|
if (!isManaged) {
|
||||||
return;
|
return super.removeItem(clusterItem, () => clusterStore.removeById(clusterId));
|
||||||
}
|
}
|
||||||
|
|
||||||
const clusterId = cluster.id;
|
|
||||||
|
|
||||||
return super.removeItem(clusterItem, () => clusterStore.removeById(clusterId));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async removeSelectedItems() {
|
async removeSelectedItems() {
|
||||||
|
|||||||
@ -22,12 +22,10 @@ enum sortBy {
|
|||||||
@observer
|
@observer
|
||||||
export class WorkspaceOverview extends Component<Props> {
|
export class WorkspaceOverview extends Component<Props> {
|
||||||
|
|
||||||
showCluster = (clusterItem: ClusterItem) => {
|
showCluster = ({ clusterId }: ClusterItem) => {
|
||||||
const clusterId = clusterItem.getId();
|
|
||||||
|
|
||||||
navigate(clusterViewURL({ params: { clusterId } }));
|
navigate(clusterViewURL({ params: { clusterId } }));
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { workspace } = this.props;
|
const { workspace } = this.props;
|
||||||
const workspaceClusterStore = new WorkspaceClusterStore(workspace.id);
|
const workspaceClusterStore = new WorkspaceClusterStore(workspace.id);
|
||||||
@ -43,7 +41,7 @@ export class WorkspaceOverview extends Component<Props> {
|
|||||||
className="WorkspaceOverview"
|
className="WorkspaceOverview"
|
||||||
store={workspaceClusterStore}
|
store={workspaceClusterStore}
|
||||||
sortingCallbacks={{
|
sortingCallbacks={{
|
||||||
[sortBy.name]: (item: ClusterItem) => item.getName(),
|
[sortBy.name]: (item: ClusterItem) => item.name,
|
||||||
[sortBy.contextName]: (item: ClusterItem) => item.cluster.contextName,
|
[sortBy.contextName]: (item: ClusterItem) => item.cluster.contextName,
|
||||||
[sortBy.version]: (item: ClusterItem) => item.cluster.version,
|
[sortBy.version]: (item: ClusterItem) => item.cluster.version,
|
||||||
}}
|
}}
|
||||||
@ -54,7 +52,7 @@ export class WorkspaceOverview extends Component<Props> {
|
|||||||
{ title: "Status", className: "status" },
|
{ title: "Status", className: "status" },
|
||||||
]}
|
]}
|
||||||
renderTableContents={(item: ClusterItem) => [
|
renderTableContents={(item: ClusterItem) => [
|
||||||
item.getName(),
|
item.name,
|
||||||
item.cluster.contextName,
|
item.cluster.contextName,
|
||||||
item.cluster.version,
|
item.cluster.version,
|
||||||
item.cluster.online ? "online" : "offline"
|
item.cluster.online ? "online" : "offline"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user