mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Add eslint rule padding-line-between-statements (#1593)
Signed-off-by: Panu Horsmalahti <phorsmalahti@mirantis.com>
This commit is contained in:
1 parent
7b77f18376
commit
dcf253e7d5
401 files changed
+2018
-40
No files matched your search
@@ -38,6 +38,7 @@ export class DeploymentDetails extends React.Component<Props> {
|
||||
if (!podsStore.isLoaded) {
|
||||
podsStore.loadAll();
|
||||
}
|
||||
|
||||
if (!replicaSetStore.isLoaded) {
|
||||
replicaSetStore.loadAll();
|
||||
}
|
||||
@@ -49,6 +50,7 @@ export class DeploymentDetails extends React.Component<Props> {
|
||||
|
||||
render() {
|
||||
const { object: deployment } = this.props;
|
||||
|
||||
if (!deployment) return null;
|
||||
const { status, spec } = deployment;
|
||||
const nodeSelector = deployment.getNodeSelectors();
|
||||
@@ -56,6 +58,7 @@ export class DeploymentDetails extends React.Component<Props> {
|
||||
const childPods = deploymentStore.getChildPods(deployment);
|
||||
const replicaSets = replicaSetStore.getReplicaSetsByOwner(deployment);
|
||||
const metrics = deploymentStore.metrics;
|
||||
|
||||
return (
|
||||
<div className="DeploymentDetails">
|
||||
{podsStore.isLoaded && (
|
||||
@@ -95,6 +98,7 @@ export class DeploymentDetails extends React.Component<Props> {
|
||||
{
|
||||
deployment.getConditions().map(condition => {
|
||||
const { type, message, lastTransitionTime, status } = condition;
|
||||
|
||||
return (
|
||||
<Badge
|
||||
key={type}
|
||||
|
||||
@@ -97,6 +97,7 @@ describe("<DeploymentScaleDialog />", () => {
|
||||
|
||||
it("renders w/o errors", () => {
|
||||
const { container } = render(<DeploymentScaleDialog />);
|
||||
|
||||
expect(container).toBeInstanceOf(HTMLElement);
|
||||
});
|
||||
|
||||
@@ -104,8 +105,10 @@ describe("<DeploymentScaleDialog />", () => {
|
||||
// mock deploymentApi.getReplicas() which will be called
|
||||
// when <DeploymentScaleDialog /> rendered.
|
||||
const initReplicas = 3;
|
||||
|
||||
deploymentApi.getReplicas = jest.fn().mockImplementationOnce(async () => initReplicas);
|
||||
const { getByTestId } = render(<DeploymentScaleDialog />);
|
||||
|
||||
DeploymentScaleDialog.open(dummyDeployment);
|
||||
// we need to wait for the DeploymentScaleDialog to show up
|
||||
// because there is an <Animate /> in <Dialog /> which renders null at start.
|
||||
@@ -114,6 +117,7 @@ describe("<DeploymentScaleDialog />", () => {
|
||||
getByTestId("current-scale"),
|
||||
getByTestId("desired-scale"),
|
||||
]);
|
||||
|
||||
expect(currentScale).toHaveTextContent(`${initReplicas}`);
|
||||
expect(desiredScale).toHaveTextContent(`${initReplicas}`);
|
||||
});
|
||||
@@ -122,15 +126,19 @@ describe("<DeploymentScaleDialog />", () => {
|
||||
|
||||
it("changes the desired scale when clicking the icon buttons +/-", async () => {
|
||||
const initReplicas = 1;
|
||||
|
||||
deploymentApi.getReplicas = jest.fn().mockImplementationOnce(async () => initReplicas);
|
||||
const { getByTestId } = render(<DeploymentScaleDialog />);
|
||||
|
||||
DeploymentScaleDialog.open(dummyDeployment);
|
||||
await waitFor(async () => {
|
||||
const desiredScale = await getByTestId("desired-scale");
|
||||
|
||||
expect(desiredScale).toHaveTextContent(`${initReplicas}`);
|
||||
});
|
||||
const up = await getByTestId("desired-replicas-up");
|
||||
const down = await getByTestId("desired-replicas-down");
|
||||
|
||||
fireEvent.click(up);
|
||||
expect(await getByTestId("desired-scale")).toHaveTextContent(`${initReplicas + 1}`);
|
||||
fireEvent.click(down);
|
||||
@@ -140,6 +148,7 @@ describe("<DeploymentScaleDialog />", () => {
|
||||
fireEvent.click(down);
|
||||
expect(await getByTestId("desired-scale")).toHaveTextContent("1");
|
||||
const times = 120;
|
||||
|
||||
// edge case, desiredScale must < scaleMax (100)
|
||||
for (let i = 0; i < times; i++) {
|
||||
fireEvent.click(up);
|
||||
|
||||
@@ -44,6 +44,7 @@ export class DeploymentScaleDialog extends Component<Props> {
|
||||
@computed get scaleMax() {
|
||||
const { currentReplicas } = this;
|
||||
const defaultMax = 50;
|
||||
|
||||
return currentReplicas <= defaultMax
|
||||
? defaultMax * 2
|
||||
: currentReplicas * 2;
|
||||
@@ -51,6 +52,7 @@ export class DeploymentScaleDialog extends Component<Props> {
|
||||
|
||||
onOpen = async () => {
|
||||
const { deployment } = this;
|
||||
|
||||
this.currentReplicas = await deploymentApi.getReplicas({
|
||||
namespace: deployment.getNs(),
|
||||
name: deployment.getName(),
|
||||
@@ -70,6 +72,7 @@ export class DeploymentScaleDialog extends Component<Props> {
|
||||
scale = async () => {
|
||||
const { deployment } = this;
|
||||
const { currentReplicas, desiredReplicas, close } = this;
|
||||
|
||||
try {
|
||||
if (currentReplicas !== desiredReplicas) {
|
||||
await deploymentApi.scale({
|
||||
@@ -94,6 +97,7 @@ export class DeploymentScaleDialog extends Component<Props> {
|
||||
renderContents() {
|
||||
const { currentReplicas, desiredReplicas, onChange, scaleMax } = this;
|
||||
const warning = currentReplicas < 10 && desiredReplicas > 90;
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="current-scale" data-testid="current-scale">
|
||||
@@ -137,6 +141,7 @@ export class DeploymentScaleDialog extends Component<Props> {
|
||||
<Trans>Scale Deployment <span>{deploymentName}</span></Trans>
|
||||
</h5>
|
||||
);
|
||||
|
||||
return (
|
||||
<Dialog
|
||||
{...dialogProps}
|
||||
|
||||
@@ -18,13 +18,16 @@ export class DeploymentStore extends KubeObjectStore<Deployment> {
|
||||
|
||||
async loadMetrics(deployment: Deployment) {
|
||||
const pods = this.getChildPods(deployment);
|
||||
|
||||
this.metrics = await podsApi.getMetrics(pods, deployment.getNs(), "");
|
||||
}
|
||||
|
||||
getStatuses(deployments?: Deployment[]) {
|
||||
const status = { failed: 0, pending: 0, running: 0 };
|
||||
|
||||
deployments.forEach(deployment => {
|
||||
const pods = this.getChildPods(deployment);
|
||||
|
||||
if (pods.some(pod => pod.getStatus() === PodStatus.FAILED)) {
|
||||
status.failed++;
|
||||
}
|
||||
@@ -35,6 +38,7 @@ export class DeploymentStore extends KubeObjectStore<Deployment> {
|
||||
status.running++;
|
||||
}
|
||||
});
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
@@ -40,11 +40,13 @@ interface Props extends RouteComponentProps<IDeploymentsRouteParams> {
|
||||
export class Deployments extends React.Component<Props> {
|
||||
renderPods(deployment: Deployment) {
|
||||
const { replicas, availableReplicas } = deployment.status;
|
||||
|
||||
return `${availableReplicas || 0}/${replicas || 0}`;
|
||||
}
|
||||
|
||||
renderConditions(deployment: Deployment) {
|
||||
const conditions = orderBy(deployment.getConditions(true), "type", "asc");
|
||||
|
||||
return conditions.map(({ type, message }) => (
|
||||
<span key={type} className={cssNames("condition", kebabCase(type))} title={message}>
|
||||
{type}
|
||||
@@ -97,6 +99,7 @@ export class Deployments extends React.Component<Props> {
|
||||
|
||||
export function DeploymentMenu(props: KubeObjectMenuProps<Deployment>) {
|
||||
const { object, toolbar } = props;
|
||||
|
||||
return (
|
||||
<>
|
||||
<MenuItem onClick={() => DeploymentScaleDialog.open(object)}>
|
||||
|
||||
Reference in new issue
Block a user