Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor to swagger TS API #2888

Merged
merged 6 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions portal-ui/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ test-warnings:
test-prettier:
./check-prettier.sh

find-deadcode:
./check-deadcode.sh

prettify:
yarn prettier --write . --loglevel warn

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,11 @@ import createStyles from "@mui/styles/createStyles";
import withStyles from "@mui/styles/withStyles";
import get from "lodash/get";
import Grid from "@mui/material/Grid";
import { BucketEvent, BucketEventList } from "../types";
import {
actionsTray,
searchField,
} from "../../Common/FormComponents/common/styleLibrary";
import { ErrorResponseHandler } from "../../../../common/types";
import TableWrapper from "../../Common/TableWrapper/TableWrapper";
import api from "../../../../common/api";

import PanelTitle from "../../Common/PanelTitle/PanelTitle";
import {
Expand All @@ -44,6 +41,9 @@ import { setErrorSnackMessage, setHelpName } from "../../../../systemSlice";
import { selBucketDetailsLoading } from "./bucketDetailsSlice";
import { useAppDispatch } from "../../../../store";
import TooltipWrapper from "../../Common/TooltipWrapper/TooltipWrapper";
import { api } from "api";
import { NotificationConfig } from "api/consoleApi";
import { errorToHandler } from "api/errors";

const DeleteEvent = withSuspense(React.lazy(() => import("./DeleteEvent")));
const AddEvent = withSuspense(React.lazy(() => import("./AddEvent")));
Expand All @@ -69,9 +69,11 @@ const BucketEventsPanel = ({ classes }: IBucketEventsProps) => {

const [addEventScreenOpen, setAddEventScreenOpen] = useState<boolean>(false);
const [loadingEvents, setLoadingEvents] = useState<boolean>(true);
const [records, setRecords] = useState<BucketEvent[]>([]);
const [records, setRecords] = useState<NotificationConfig[]>([]);
const [deleteOpen, setDeleteOpen] = useState<boolean>(false);
const [selectedEvent, setSelectedEvent] = useState<BucketEvent | null>(null);
const [selectedEvent, setSelectedEvent] = useState<NotificationConfig | null>(
null
);

const bucketName = params.bucketName || "";

Expand All @@ -94,16 +96,16 @@ const BucketEventsPanel = ({ classes }: IBucketEventsProps) => {
useEffect(() => {
if (loadingEvents) {
if (displayEvents) {
api
.invoke("GET", `/api/v1/buckets/${bucketName}/events`)
.then((res: BucketEventList) => {
const events = get(res, "events", []);
api.buckets
.listBucketEvents(bucketName)
.then((res) => {
const events = get(res.data, "events", []);
setLoadingEvents(false);
setRecords(events || []);
})
.catch((err: ErrorResponseHandler) => {
.catch((err) => {
setLoadingEvents(false);
dispatch(setErrorSnackMessage(err));
dispatch(setErrorSnackMessage(errorToHandler(err.error)));
});
} else {
setLoadingEvents(false);
Expand All @@ -115,7 +117,7 @@ const BucketEventsPanel = ({ classes }: IBucketEventsProps) => {
return <Fragment>{events.join(", ")}</Fragment>;
};

const confirmDeleteEvent = (evnt: BucketEvent) => {
const confirmDeleteEvent = (evnt: NotificationConfig) => {
setDeleteOpen(true);
setSelectedEvent(evnt);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ import {
actionsTray,
searchField,
} from "../../Common/FormComponents/common/styleLibrary";
import { ErrorResponseHandler } from "../../../../common/types";
import api from "../../../../common/api";
import EditLifecycleConfiguration from "./EditLifecycleConfiguration";
import AddLifecycleModal from "./AddLifecycleModal";
import TableWrapper from "../../Common/TableWrapper/TableWrapper";
Expand All @@ -44,6 +42,8 @@ import { useParams } from "react-router-dom";
import TooltipWrapper from "../../Common/TooltipWrapper/TooltipWrapper";
import { setHelpName } from "../../../../systemSlice";
import { useAppDispatch } from "../../../../store";
import { api } from "api";
import { ObjectBucketLifecycle } from "api/consoleApi";

const styles = (theme: Theme) =>
createStyles({
Expand All @@ -63,7 +63,9 @@ const BucketLifecyclePanel = ({ classes }: IBucketLifecyclePanelProps) => {
const params = useParams();

const [loadingLifecycle, setLoadingLifecycle] = useState<boolean>(true);
const [lifecycleRecords, setLifecycleRecords] = useState<LifeCycleItem[]>([]);
const [lifecycleRecords, setLifecycleRecords] = useState<
ObjectBucketLifecycle[]
>([]);
const [addLifecycleOpen, setAddLifecycleOpen] = useState<boolean>(false);
const [editLifecycleOpen, setEditLifecycleOpen] = useState<boolean>(false);
const [selectedLifecycleRule, setSelectedLifecycleRule] =
Expand Down Expand Up @@ -94,16 +96,16 @@ const BucketLifecyclePanel = ({ classes }: IBucketLifecyclePanelProps) => {
useEffect(() => {
if (loadingLifecycle) {
if (displayLifeCycleRules) {
api
.invoke("GET", `/api/v1/buckets/${bucketName}/lifecycle`)
.then((res: any) => {
const records = get(res, "lifecycle", []);
api.buckets
.getBucketLifecycle(bucketName)
.then((res) => {
const records = get(res.data, "lifecycle", []);

setLifecycleRecords(records || []);
setLoadingLifecycle(false);
})
.catch((err: ErrorResponseHandler) => {
console.error(err);
.catch((err) => {
console.error(err.error);
setLifecycleRecords([]);
setLoadingLifecycle(false);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,10 @@ import createStyles from "@mui/styles/createStyles";
import withStyles from "@mui/styles/withStyles";
import { Box, Grid } from "@mui/material";
import get from "lodash/get";
import {
BucketEncryptionInfo,
BucketObjectLocking,
BucketQuota,
BucketReplication,
BucketVersioningInfo,
} from "../types";
import { BucketList } from "../../Watch/types";
import {
spacingUtils,
textStyleUtils,
} from "../../Common/FormComponents/common/styleLibrary";
import {
ErrorResponseHandler,
IRetentionConfig,
} from "../../../../common/types";
import api from "../../../../common/api";

import { IAM_SCOPES } from "../../../../common/SecureComponent/permissions";
import {
Expand Down Expand Up @@ -66,6 +53,14 @@ import {
} from "./bucketDetailsSlice";
import { useAppDispatch } from "../../../../store";
import VersioningInfo from "../VersioningInfo";
import { api } from "api";
import {
BucketEncryptionInfo,
BucketQuota,
BucketVersioningResponse,
GetBucketRetentionConfig,
} from "api/consoleApi";
import { errorToHandler } from "api/errors";

const SetAccessPolicy = withSuspense(
React.lazy(() => import("./SetAccessPolicy"))
Expand Down Expand Up @@ -113,8 +108,10 @@ const BucketSummary = ({ classes }: IBucketSummaryProps) => {

const [encryptionCfg, setEncryptionCfg] =
useState<BucketEncryptionInfo | null>(null);
const [bucketSize, setBucketSize] = useState<string>("0");
const [hasObjectLocking, setHasObjectLocking] = useState<boolean>(false);
const [bucketSize, setBucketSize] = useState<number | "0">("0");
const [hasObjectLocking, setHasObjectLocking] = useState<boolean | undefined>(
false
);
const [accessPolicyScreenOpen, setAccessPolicyScreenOpen] =
useState<boolean>(false);
const [replicationRules, setReplicationRules] = useState<boolean>(false);
Expand All @@ -126,13 +123,14 @@ const BucketSummary = ({ classes }: IBucketSummaryProps) => {
const [loadingQuota, setLoadingQuota] = useState<boolean>(true);
const [loadingReplication, setLoadingReplication] = useState<boolean>(true);
const [loadingRetention, setLoadingRetention] = useState<boolean>(true);
const [versioningInfo, setVersioningInfo] = useState<BucketVersioningInfo>();
const [versioningInfo, setVersioningInfo] =
useState<BucketVersioningResponse>();
const [quotaEnabled, setQuotaEnabled] = useState<boolean>(false);
const [quota, setQuota] = useState<BucketQuota | null>(null);
const [encryptionEnabled, setEncryptionEnabled] = useState<boolean>(false);
const [retentionEnabled, setRetentionEnabled] = useState<boolean>(false);
const [retentionConfig, setRetentionConfig] =
useState<IRetentionConfig | null>(null);
useState<GetBucketRetentionConfig | null>(null);
const [retentionConfigOpen, setRetentionConfigOpen] =
useState<boolean>(false);
const [enableEncryptionScreenOpen, setEnableEncryptionScreenOpen] =
Expand Down Expand Up @@ -182,16 +180,17 @@ const BucketSummary = ({ classes }: IBucketSummaryProps) => {
useEffect(() => {
if (loadingEncryption) {
if (displayGetBucketEncryptionConfiguration) {
api
.invoke("GET", `/api/v1/buckets/${bucketName}/encryption/info`)
.then((res: BucketEncryptionInfo) => {
if (res.algorithm) {
api.buckets
.getBucketEncryptionInfo(bucketName)
.then((res) => {
if (res.data.algorithm) {
setEncryptionEnabled(true);
setEncryptionCfg(res);
setEncryptionCfg(res.data);
}
setLoadingEncryption(false);
})
.catch((err: ErrorResponseHandler) => {
.catch((err) => {
err = errorToHandler(err.error);
if (
err.errorMessage ===
"The server side encryption configuration was not found"
Expand All @@ -211,14 +210,14 @@ const BucketSummary = ({ classes }: IBucketSummaryProps) => {

useEffect(() => {
if (loadingVersioning && distributedSetup) {
api
.invoke("GET", `/api/v1/buckets/${bucketName}/versioning`)
.then((res: BucketVersioningInfo) => {
setVersioningInfo(res);
api.buckets
.getBucketVersioning(bucketName)
.then((res) => {
setVersioningInfo(res.data);
setLoadingVersioning(false);
})
.catch((err: ErrorResponseHandler) => {
dispatch(setErrorSnackMessage(err));
.catch((err) => {
dispatch(setErrorSnackMessage(errorToHandler(err.error)));
setLoadingVersioning(false);
});
}
Expand All @@ -227,19 +226,19 @@ const BucketSummary = ({ classes }: IBucketSummaryProps) => {
useEffect(() => {
if (loadingQuota && distributedSetup) {
if (displayGetBucketQuota) {
api
.invoke("GET", `/api/v1/buckets/${bucketName}/quota`)
.then((res: BucketQuota) => {
setQuota(res);
if (res.quota) {
api.buckets
.getBucketQuota(bucketName)
.then((res) => {
setQuota(res.data);
if (res.data.quota) {
setQuotaEnabled(true);
} else {
setQuotaEnabled(false);
}
setLoadingQuota(false);
})
.catch((err: ErrorResponseHandler) => {
dispatch(setErrorSnackMessage(err));
.catch((err) => {
dispatch(setErrorSnackMessage(errorToHandler(err.error)));
setQuotaEnabled(false);
setLoadingQuota(false);
});
Expand All @@ -260,14 +259,14 @@ const BucketSummary = ({ classes }: IBucketSummaryProps) => {
useEffect(() => {
if (loadingVersioning && distributedSetup) {
if (displayGetBucketObjectLockConfiguration) {
api
.invoke("GET", `/api/v1/buckets/${bucketName}/object-locking`)
.then((res: BucketObjectLocking) => {
setHasObjectLocking(res.object_locking_enabled);
api.buckets
.getBucketObjectLockingStatus(bucketName)
.then((res) => {
setHasObjectLocking(res.data.object_locking_enabled);
setLoadingLocking(false);
})
.catch((err: ErrorResponseHandler) => {
dispatch(setErrorSnackMessage(err));
.catch((err) => {
dispatch(setErrorSnackMessage(errorToHandler(err.error)));
setLoadingLocking(false);
});
} else {
Expand All @@ -285,10 +284,10 @@ const BucketSummary = ({ classes }: IBucketSummaryProps) => {

useEffect(() => {
if (loadingSize) {
api
.invoke("GET", `/api/v1/buckets`)
.then((res: BucketList) => {
const resBuckets = get(res, "buckets", []);
api.buckets
.listBuckets()
.then((res) => {
const resBuckets = get(res.data, "buckets", []);

const bucketInfo = resBuckets.find(
(bucket) => bucket.name === bucketName
Expand All @@ -299,39 +298,39 @@ const BucketSummary = ({ classes }: IBucketSummaryProps) => {
setLoadingSize(false);
setBucketSize(size);
})
.catch((err: ErrorResponseHandler) => {
.catch((err) => {
setLoadingSize(false);
dispatch(setErrorSnackMessage(err));
dispatch(setErrorSnackMessage(errorToHandler(err.error)));
});
}
}, [loadingSize, dispatch, bucketName]);

useEffect(() => {
if (loadingReplication && distributedSetup) {
api
.invoke("GET", `/api/v1/buckets/${bucketName}/replication`)
.then((res: BucketReplication) => {
const r = res.rules ? res.rules : [];
api.buckets
.getBucketReplication(bucketName)
.then((res) => {
const r = res.data.rules ? res.data.rules : [];
setReplicationRules(r.length > 0);
setLoadingReplication(false);
})
.catch((err: ErrorResponseHandler) => {
dispatch(setErrorSnackMessage(err));
.catch((err) => {
dispatch(setErrorSnackMessage(errorToHandler(err.error)));
setLoadingReplication(false);
});
}
}, [loadingReplication, dispatch, bucketName, distributedSetup]);

useEffect(() => {
if (loadingRetention && hasObjectLocking) {
api
.invoke("GET", `/api/v1/buckets/${bucketName}/retention`)
.then((res: IRetentionConfig) => {
api.buckets
.getBucketRetentionConfig(bucketName)
.then((res) => {
setLoadingRetention(false);
setRetentionEnabled(true);
setRetentionConfig(res);
setRetentionConfig(res.data);
})
.catch((err: ErrorResponseHandler) => {
.catch((err) => {
setRetentionEnabled(false);
setLoadingRetention(false);
setRetentionConfig(null);
Expand Down Expand Up @@ -558,7 +557,7 @@ const BucketSummary = ({ classes }: IBucketSummaryProps) => {
alignItems: "flex-start",
}}
>
<ReportedUsage bucketSize={bucketSize} />
<ReportedUsage bucketSize={`${bucketSize}`} />
{quotaEnabled && quota ? (
<BucketQuotaSize quota={quota} />
) : null}
Expand Down Expand Up @@ -683,7 +682,7 @@ const BucketSummary = ({ classes }: IBucketSummaryProps) => {
{retentionConfig && retentionConfig.validity}{" "}
{retentionConfig &&
(retentionConfig.validity === 1
? retentionConfig.unit.slice(0, -1)
? retentionConfig.unit?.slice(0, -1)
: retentionConfig.unit)}
</label>
}
Expand Down
Loading