Skip to content

Instantly share code, notes, and snippets.

@mahileeb
Created October 21, 2019 01:06
Show Gist options
  • Save mahileeb/1ce0c625634d10595351c1110711901f to your computer and use it in GitHub Desktop.
Save mahileeb/1ce0c625634d10595351c1110711901f to your computer and use it in GitHub Desktop.
enum EnvironmentMode {
UNKNOWN_MODE = 1;
DEMO = 2;
LIVE = 3;
}
import React, { useState } from "react";
import { enumToString } from "helpers/enum";
import { EnvironmentMode } from "protobuf/generated/com/mahifx/model/echo_protomap_pb";
type OwnProps = {
name?: string;
mode?: EnvironmentMode;
version?: string;
build?: string;
className?: string;
}
const EnvLabel: React.FC<OwnProps> = props => {
const {name, mode, version, build} = props;
const hasBuild: boolean = !!build;
const [showBuild, setShowBuild] = useState(false);
const modeName: string = enumToString(mode, EnvironmentMode);
const onClick = () => {
setShowBuild(!showBuild);
};
return <span
className={props.className}
onClick={onClick}
>
<b>{name} {mode !== EnvironmentMode.LIVE ? modeName : ""}</b>
{" "}
v{version}
{hasBuild && showBuild && `-${build}`}
</span>;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment