Skip to content

Commit

Permalink
fix: refactor classes to apply shorter calls and remove redundant checks
Browse files Browse the repository at this point in the history
  • Loading branch information
wtrocki committed Mar 29, 2021
1 parent 61c393d commit 330a4b1
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 66 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as React from 'react';
import { useTranslation } from 'react-i18next';
import { FormFooter, FormHeader, FlexForm, FormBody } from '@console/shared';
import CubesIcon from '@patternfly/react-icons/dist/js/icons/cubes-icon';
import { FormFooter, FormHeader, FlexForm, FormBody } from '@console/shared';
import FormSection from '@console/dev-console/src/components/import/section/FormSection';
import { history } from '@console/internal/components/utils';
import ServiceInstanceFilter from '../service-table/ServiceInstanceFilter';
import ServiceInstanceTable from '../service-table/ServiceInstanceTable';
import { history } from '@console/internal/components/utils';
import { ServicesEmptyState } from '../states/ServicesEmptyState';
import { CloudKafka } from '../../utils/rhoas-types';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ const ServiceInstanceTable: React.FC<ServiceInstanceTableProps> = ({
const filterColumns = ['name', 'provider', 'region', 'owner', 'status', 'createdAt'];
filterKey = filterColumns[index - 1];

const sortedRows = kafkaRows.sort(function(a, b) {
const sortedRows = kafkaRows.sort((a, b) => {
const keyA = a[filterKey];
const keyB = b[filterKey];
if (keyA < keyB) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';
import { Button, EmptyState, EmptyStateIcon, Title } from '@patternfly/react-core';
import { history } from '@console/internal/components/utils';

export type ServicesEmptyStateProps = {
type ServicesEmptyStateProps = {
title: string;
message?: string;
actionLabel: string;
Expand All @@ -16,21 +16,19 @@ export const ServicesEmptyState = ({
actionLabel,
icon,
iconClass,
}: ServicesEmptyStateProps) => {
return (
<EmptyState>
<EmptyStateIcon className={iconClass} icon={icon} />
<Title headingLevel="h4" size="lg">
{title}
}: ServicesEmptyStateProps) => (
<EmptyState>
<EmptyStateIcon className={iconClass} icon={icon} />
<Title headingLevel="h4" size="lg">
{title}
</Title>
{message || (
<Title headingLevel="h5" size="md">
{message}
</Title>
{message || (
<Title headingLevel="h5" size="md">
{message}
</Title>
)}
<Button variant="link" onClick={history.goBack}>
{actionLabel}
</Button>
</EmptyState>
);
};
)}
<Button variant="link" onClick={history.goBack}>
{actionLabel}
</Button>
</EmptyState>
);
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import * as React from 'react';
import ErrorCircle from '@patternfly/react-icons/dist/js/icons/error-circle-o-icon';
import './ServicesErrorState.css';
import { ServicesEmptyState, ServicesEmptyStateProps } from './ServicesEmptyState';
import { ServicesEmptyState } from './ServicesEmptyState';

export const ServicesErrorState = ({ title, message, actionLabel }: ServicesEmptyStateProps) => {
return (
<ServicesEmptyState
title={title}
message={message}
actionLabel={actionLabel}
icon={ErrorCircle}
iconClass="rhoas-services-error-state-icon"
/>
);
};
import './ServicesErrorState.scss';

export const ServicesErrorState = ({
title,
message,
actionLabel,
}: React.ComponentProps<typeof ServicesEmptyState>) => (
<ServicesEmptyState
title={title}
message={message}
actionLabel={actionLabel}
icon={ErrorCircle}
iconClass="rhoas-services-error-state-icon"
/>
);
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { navFactory, SimpleTabNav } from '@console/internal/components/utils';
import { ResourcesComponent } from './ResourceComponent';
import { DetailsComponent } from './DetailsComponent';

import './TopologyKafkaPanel.css';
import './TopologyKafkaPanel.scss';

type PropsFromState = {
selectedDetailsTab?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { EdgeModel, Model, NodeModel } from '@patternfly/react-topology';
import { apiVersionForModel, K8sResourceKind } from '@console/internal/module/k8s';
import { getTopologyNodeItem } from '@console/topology/src/data-transforms/transform-utils';
import { OverviewItem } from '@console/shared/src';
import { TYPE_SERVICE_BINDING } from '@console/topology/src/const';
import { edgesFromServiceBinding } from '@console/topology/src/operators/operators-data-transformer';
import { TopologyDataObject, TopologyDataResources } from '@console/topology/src/topology-types';
import {
KAFKA_WIDTH,
Expand All @@ -10,8 +12,6 @@ import {
TYPE_MANAGED_KAFKA_CONNECTION,
} from './components/const';
import { KafkaConnectionModel } from '../models';
import { edgesFromServiceBinding } from '@console/topology/src/operators/operators-data-transformer';
import { TYPE_SERVICE_BINDING } from '@console/topology/src/const';

const KAFKA_PROPS = {
width: KAFKA_WIDTH,
Expand Down Expand Up @@ -107,7 +107,7 @@ export const getRhoasTopologyDataModel = () => (
if (rhoasDataModel.nodes?.length) {
workloads.forEach((dc) => {
rhoasDataModel.edges.push(
...[...getRhoasServiceBindingEdges(dc, rhoasDataModel.nodes, serviceBindingRequests)],
...getRhoasServiceBindingEdges(dc, rhoasDataModel.nodes, serviceBindingRequests),
);
});
}
Expand Down
19 changes: 6 additions & 13 deletions frontend/packages/rhoas-plugin/src/utils/conditionHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,18 @@ import { StatusCondition } from './rhoas-types';
import { K8sResourceKind } from '@console/internal/module/k8s';

export const getCondition = (request: K8sResourceKind, name: string) => {
if (request && request.status && request.status.conditions) {
for (const condition of request.status.conditions) {
if (condition.type === name) {
return condition as StatusCondition;
}
}
if (request?.status?.conditions) {
return request.status.conditions.find((condition: StatusCondition) => condition.type === name);
}
return undefined;
};

export const getFinishedCondition = (request: K8sResourceKind) => {
return getCondition(request, 'Finished');
};
export const getFinishedCondition = (request: K8sResourceKind) => getCondition(request, 'Finished');

export const isResourceStatusSuccessfull = (request: K8sResourceKind) => {
const condition = getCondition(request, 'Finished');
return condition && condition.status === 'True';
return condition?.status === 'True';
};

export const isAcccesTokenSecretValid = (request: K8sResourceKind) => {
return getCondition(request, 'AcccesTokenSecretValid')?.status === 'True';
};
export const isAcccesTokenSecretValid = (request: K8sResourceKind) =>
getCondition(request, 'AcccesTokenSecretValid')?.status === 'True';
21 changes: 6 additions & 15 deletions frontend/packages/rhoas-plugin/src/utils/resourceCreators.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { SecretModel } from '@console/internal/models';
import { k8sWaitForUpdate } from '@console/internal/module/k8s';
import {
k8sCreate,
k8sGet,
k8sPatch,
k8sUpdate,
k8sKillByName,
} from '@console/internal/module/k8s/resource';

import {
AccessTokenSecretName,
ServiceAccountCRName,
Expand All @@ -19,7 +19,6 @@ import {
CloudServicesRequestModel,
} from '../models/rhoas';
import { getFinishedCondition, isResourceStatusSuccessfull } from './conditionHandler';
import { k8sWaitForUpdate } from '@console/internal/module/k8s';

/**
* Create service account for purpose of supplying connection credentials
Expand Down Expand Up @@ -49,7 +48,7 @@ export const createManagedServiceAccount = async (currentNamespace: string) => {
/**
* Create request to fetch all kafkas from upstream
*/
export const createCloudServicesRequest = async function(currentNamespace: string) {
export const createCloudServicesRequest = async (currentNamespace: string) => {
const mkRequest = {
apiVersion: `${CloudServicesRequestModel.apiGroup}/${CloudServicesRequestModel.apiVersion}`,
kind: CloudServicesRequestModel.kind,
Expand All @@ -66,7 +65,7 @@ export const createCloudServicesRequest = async function(currentNamespace: strin
return k8sCreate(CloudServicesRequestModel, mkRequest);
};

export const patchServiceAccountRequest = async function(request: any) {
export const patchServiceAccountRequest = async (request: any) => {
const path = '/spec/forceRefresh';
return k8sPatch(CloudServiceAccountRequest, request, [
{
Expand All @@ -77,7 +76,7 @@ export const patchServiceAccountRequest = async function(request: any) {
]);
};

export const patchCloudServicesRequest = async function(request: any) {
export const patchCloudServicesRequest = async (request: any) => {
const path = '/spec/forceRefresh';

return k8sPatch(CloudServicesRequestModel, request, [
Expand Down Expand Up @@ -214,16 +213,8 @@ export const createKafkaConnection = async (
);
};

/**
* createKafkaConnection
*
* @param kafkaId
* @param kafkaName
* @param currentNamespace
*/
export const deleteKafkaConnection = (kafkaName: string, currentNamespace: string) => {
return k8sKillByName(KafkaConnectionModel, kafkaName, currentNamespace);
};
export const deleteKafkaConnection = (kafkaName: string, currentNamespace: string) =>
k8sKillByName(KafkaConnectionModel, kafkaName, currentNamespace);

export const listOfCurrentKafkaConnectionsById = async (currentNamespace: string) => {
const kafkaConnections = await k8sGet(KafkaConnectionModel, null, currentNamespace);
Expand Down

0 comments on commit 330a4b1

Please sign in to comment.