From 0bee7b6c1a035404ce34ebc5e96cb88100bd5c5d Mon Sep 17 00:00:00 2001 From: alexfront Date: Tue, 4 Aug 2020 15:49:21 +0300 Subject: [PATCH] Install Metrics component refactoring Using notifications for error, removed picking button icon method, simplified button generation. Signed-off-by: alexfront --- .../components/install-metrics.tsx | 129 ++++++++---------- 1 file changed, 55 insertions(+), 74 deletions(-) diff --git a/src/renderer/components/+cluster-settings/components/install-metrics.tsx b/src/renderer/components/+cluster-settings/components/install-metrics.tsx index 171adc6034..9fd99ff576 100644 --- a/src/renderer/components/+cluster-settings/components/install-metrics.tsx +++ b/src/renderer/components/+cluster-settings/components/install-metrics.tsx @@ -1,15 +1,14 @@ import React from "react"; import { Cluster } from "../../../../main/cluster"; import { Button } from "../../button"; -import { autobind } from "../../../utils"; -import { Tooltip, TooltipPosition } from "../../tooltip"; import { MetricsFeature } from "../../../../features/metrics"; import { Spinner } from "../../spinner"; -import { Icon } from "../../icon"; import { clusterIpc } from "../../../../common/cluster-ipc"; import { observable } from "mobx"; import { ActionStatus } from "./statuses" import { observer } from "mobx-react"; +import { SubTitle } from "../../layout/sub-title"; +import { Notifications } from "../../notifications"; interface Props { cluster: Cluster; @@ -20,90 +19,72 @@ export class InstallMetrics extends React.Component { @observable status = ActionStatus.IDLE; @observable errorText?: string; - render() { - return <> -

Metrics

-

- User Mode feature enables non-admin users to see namespaces they have access to. - This is achieved by configuring RBAC rules so that every authenticated user is granted to list namespaces. -

-
- {this.getActionButtons()} -
- ; - } - - getStatusIcon(): React.ReactNode { - switch (this.status) { - case ActionStatus.IDLE: - return null; - case ActionStatus.PROCESSING: - return ; - case ActionStatus.ERROR: - return - } - } - - getDisabledToolTip(id: string, action: string): React.ReactNode { + getActionButtons() { const { cluster } = this.props; - if (cluster.isAdmin) { - return null; - } - + const features = cluster.features[MetricsFeature.id]; + const disabled = !cluster.isAdmin || this.status === ActionStatus.PROCESSING; + const loadingIcon = this.status === ActionStatus.PROCESSING ? : null; + if (!features) return null; return ( - - {action} only allowed by admins - +
+ {features.canUpgrade && + + } + {features.installed && + + } + {!features.installed && !features.canUpgrade && + + } + {loadingIcon} + {!cluster.isAdmin && Actions can only be performed by admins.} +
); } - getActionButtons(): React.ReactNode[] { - const { cluster } = this.props - const buttons = []; - - if (cluster.features[MetricsFeature.id]?.canUpgrade) { - buttons.push( - - ); - } - - if (cluster.features[MetricsFeature.id]?.installed) { - buttons.push( - - ); - } else { - buttons.push( - - ); - } - - return buttons; - } - runAction(action: keyof typeof clusterIpc): () => Promise { return async () => { const { cluster } = this.props; - console.log(`running ${action} ${MetricsFeature.id} onto ${cluster.preferences.clusterName}`); - try { this.status = ActionStatus.PROCESSING await clusterIpc[action].invokeFromRenderer(cluster.id, MetricsFeature.id); - try { - await cluster.refresh(); - } catch (err) { - console.error(err); - } - this.status = ActionStatus.IDLE } catch (err) { - this.status = ActionStatus.ERROR - this.errorText = err.toString() + Notifications.error(err.toString()); } + this.status = ActionStatus.IDLE; }; } + + render() { + return ( + <> + +

+ Enable timeseries data visualization (Prometheus stack) for your cluster. + Install this only if you don't have existing Prometheus stack installed. + You can see preview of manifests{" "} + here. +

+ {this.getActionButtons()} + + ); + } } \ No newline at end of file