Skip to content

Commit

Permalink
Address review comment by Alex
Browse files Browse the repository at this point in the history
  • Loading branch information
prakashsvmx committed Apr 14, 2022
1 parent a220d3f commit 7a57582
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import React from "react";
import { StatsResponseType } from "../SiteReplicationStatus";
import LookupStatusTable from "./LookupStatusTable";
import { EntityNotFound, syncStatus } from "./Utils";
import { EntityNotFound, isEntityNotFound, syncStatus } from "./Utils";

type BucketEntityStatusProps = Partial<StatsResponseType> & {
lookupValue?: string;
Expand All @@ -42,10 +42,7 @@ const BucketEntityStatus = ({

const siteKeys = Object.keys(sites);

const notFound = siteKeys.find((sk) => {
// @ts-ignore
return !bucketSites[sk]?.HasBucket;
});
const notFound = isEntityNotFound(sites, bucketSites, "HasBucket");
const resultMatrix: any = [];
if (notFound) {
return <EntityNotFound entityType={"Bucket"} entityValue={lookupValue} />;
Expand Down Expand Up @@ -124,7 +121,7 @@ const BucketEntityStatus = ({
<LookupStatusTable
matrixData={resultMatrix}
entityName={lookupValue}
entityType={"Policy"}
entityType={"Bucket"}
/>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import React from "react";
import { StatsResponseType } from "../SiteReplicationStatus";
import LookupStatusTable from "./LookupStatusTable";
import { EntityNotFound, syncStatus } from "./Utils";
import { EntityNotFound, isEntityNotFound, syncStatus } from "./Utils";

type GroupEntityStatusProps = Partial<StatsResponseType> & {
lookupValue?: string;
Expand All @@ -34,11 +34,7 @@ const UserEntityStatus = ({
if (!lookupValue) return null;

const siteKeys = Object.keys(sites);

const notFound = siteKeys.find((sk) => {
// @ts-ignore
return !groupSites[sk]?.HasGroup;
});
const notFound = isEntityNotFound(sites, groupSites, "HasGroup");
const resultMatrix: any = [];
if (notFound) {
return <EntityNotFound entityType={"Group"} entityValue={lookupValue} />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import React from "react";
import { StatsResponseType } from "../SiteReplicationStatus";
import LookupStatusTable from "./LookupStatusTable";
import { EntityNotFound, syncStatus } from "./Utils";
import { EntityNotFound, isEntityNotFound, syncStatus } from "./Utils";

type PolicyEntityStatusProps = Partial<StatsResponseType> & {
lookupValue?: string;
Expand All @@ -34,11 +34,7 @@ const PolicyEntityStatus = ({
if (!lookupValue) return null;

const siteKeys = Object.keys(sites);

const notFound = siteKeys.find((sk) => {
// @ts-ignore
return !policySites[sk]?.HasPolicy;
});
const notFound = isEntityNotFound(sites, policySites, "HasPolicy");
const resultMatrix: any = [];
if (notFound) {
return <EntityNotFound entityType={"Policy"} entityValue={lookupValue} />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import React from "react";
import { StatsResponseType } from "../SiteReplicationStatus";
import LookupStatusTable from "./LookupStatusTable";
import { EntityNotFound, syncStatus } from "./Utils";
import { EntityNotFound, isEntityNotFound, syncStatus } from "./Utils";

type PolicyEntityStatusProps = Partial<StatsResponseType> & {
lookupValue?: string;
Expand All @@ -35,10 +35,8 @@ const UserEntityStatus = ({

const siteKeys = Object.keys(sites);

const notFound = siteKeys.find((sk) => {
// @ts-ignore
return !userSites[sk]?.HasUser;
});
const notFound = isEntityNotFound(sites, userSites, "HasUser");

const resultMatrix: any = [];
if (notFound) {
return <EntityNotFound entityType={"User"} entityValue={lookupValue} />;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Box } from "@mui/material";
import React from "react";
import { StatsResponseType } from "../SiteReplicationStatus";

export function syncStatus(mismatch: boolean, set: boolean): string | boolean {
if (!set) {
Expand All @@ -8,6 +9,20 @@ export function syncStatus(mismatch: boolean, set: boolean): string | boolean {
return !mismatch;
}

export function isEntityNotFound(
sites: Partial<StatsResponseType>,
lookupList: Partial<StatsResponseType>,
lookupKey: string
) {
const siteKeys: string[] = Object.keys(sites);
return siteKeys.find((sk: string) => {
// there is no way to find the type of this ! as it is an entry in the structure itself.
// @ts-ignore
const result: Record<string, any> = lookupList[sk] || {};
return !result[lookupKey];
});
}

export const EntityNotFound = ({
entityType,
entityValue,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export type StatsResponseType = {
userStats?: Record<string, any>;
maxPolicies?: number;
policyStats?: Record<string, any>;
sites?: any;
sites?: Record<string, any>;
};

const SREntityStatus = ({
Expand Down

0 comments on commit 7a57582

Please sign in to comment.