Skip to content

Commit de13119

Browse files
authored
Use swagger autogenerated ts API for session endpoint (#2859)
1 parent bf9acd7 commit de13119

File tree

6 files changed

+38
-87
lines changed

6 files changed

+38
-87
lines changed

portal-ui/src/ProtectedRoutes.tsx

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
import React, { useEffect, useState } from "react";
1818
import { Navigate, useLocation } from "react-router-dom";
19-
import api from "./common/api";
20-
import { ISessionResponse } from "./screens/Console/types";
2119
import useApi from "./screens/Console/Common/Hooks/useApi";
2220
import { ErrorResponseHandler } from "./common/types";
2321
import { ReplicationSite } from "./screens/Console/Configurations/SiteReplication/SiteReplication";
@@ -34,6 +32,7 @@ import { AppState, useAppDispatch } from "./store";
3432
import { saveSessionResponse } from "./screens/Console/consoleSlice";
3533
import { getOverrideColorVariants } from "./utils/stylesUtils";
3634
import LoadingComponent from "./common/LoadingComponent";
35+
import { api } from "api";
3736

3837
interface ProtectedRouteProps {
3938
Component: any;
@@ -58,17 +57,17 @@ const ProtectedRoute = ({ Component }: ProtectedRouteProps) => {
5857
const screen = pathnameParts.length > 2 ? pathnameParts[1] : "";
5958

6059
useEffect(() => {
61-
api
62-
.invoke("GET", `/api/v1/session`)
63-
.then((res: ISessionResponse) => {
64-
dispatch(saveSessionResponse(res));
60+
api.session
61+
.sessionCheck()
62+
.then((res) => {
63+
dispatch(saveSessionResponse(res.data));
6564
dispatch(userLogged(true));
6665
setSessionLoading(false);
67-
dispatch(globalSetDistributedSetup(res?.distributedMode || false));
66+
dispatch(globalSetDistributedSetup(res.data?.distributedMode || false));
6867

69-
if (res.customStyles && res.customStyles !== "") {
68+
if (res.data.customStyles && res.data.customStyles !== "") {
7069
const overrideColorVariants = getOverrideColorVariants(
71-
res.customStyles
70+
res.data.customStyles
7271
);
7372

7473
if (overrideColorVariants !== false) {
@@ -86,16 +85,13 @@ const ProtectedRoute = ({ Component }: ProtectedRouteProps) => {
8685
return;
8786
}
8887
// before marking the session as done, let's check if the bucket is publicly accessible
89-
api
90-
.invoke(
91-
"GET",
92-
`/api/v1/buckets/${bucket}/objects?limit=1`,
93-
undefined,
94-
{
95-
"X-Anonymous": "1",
96-
}
88+
api.buckets
89+
.listObjects(
90+
bucket,
91+
{ limit: 1 },
92+
{ headers: { "X-Anonymous": "1" } }
9793
)
98-
.then((value) => {
94+
.then(() => {
9995
dispatch(setAnonymousMode());
10096
setSessionLoading(false);
10197
})

portal-ui/src/screens/Console/Buckets/ListBuckets/Objects/utils.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1616

1717
import { BucketObjectItem } from "./ListObjects/types";
18-
import { IAllowResources } from "../../../types";
1918
import { encodeURLString } from "../../../../../common/utils";
2019
import { removeTrace } from "../../../ObjectBrowser/transferManager";
2120
import streamSaver from "streamsaver";
2221
import store from "../../../../../store";
22+
import { PermissionResource } from "api/consoleApi";
2323

2424
export const download = (
2525
bucketName: string,
@@ -278,7 +278,7 @@ export const sortListObjects = (fieldSort: string) => {
278278
export const permissionItems = (
279279
bucketName: string,
280280
currentPath: string,
281-
permissionsArray: IAllowResources[]
281+
permissionsArray: PermissionResource[]
282282
): BucketObjectItem[] | null => {
283283
if (permissionsArray.length === 0) {
284284
return null;
@@ -287,8 +287,8 @@ export const permissionItems = (
287287
// We get permissions applied to the current bucket
288288
const filteredPermissionsForBucket = permissionsArray.filter(
289289
(permissionItem) =>
290-
permissionItem.resource.endsWith(`:${bucketName}`) ||
291-
permissionItem.resource.includes(`:${bucketName}/`)
290+
permissionItem.resource?.endsWith(`:${bucketName}`) ||
291+
permissionItem.resource?.includes(`:${bucketName}/`)
292292
);
293293

294294
// No permissions for this bucket. we can throw the error message at this point
@@ -305,8 +305,8 @@ export const permissionItems = (
305305
// We review paths in resource address
306306

307307
// We split ARN & get the last item to check the URL
308-
const splitARN = permissionElement.resource.split(":");
309-
const urlARN = splitARN.pop() || "";
308+
const splitARN = permissionElement.resource?.split(":");
309+
const urlARN = splitARN?.pop() || "";
310310

311311
// We split the paths of the URL & compare against current location to see if there are more items to include. In case current level is a wildcard or is the last one, we omit this validation
312312

@@ -347,7 +347,7 @@ export const permissionItems = (
347347
permissionElement.conditionOperator === "StringEquals" ||
348348
permissionElement.conditionOperator === "StringLike"
349349
) {
350-
permissionElement.prefixes.forEach((prefixItem) => {
350+
permissionElement.prefixes?.forEach((prefixItem) => {
351351
// Prefix Item is not empty?
352352
if (prefixItem !== "") {
353353
const splitItems = prefixItem.split("/");

portal-ui/src/screens/Console/Common/ModalWrapper/ConfirmDialog.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,15 @@ import { Theme } from "@mui/material/styles";
2020
import createStyles from "@mui/styles/createStyles";
2121
import withStyles from "@mui/styles/withStyles";
2222
import { deleteDialogStyles } from "../FormComponents/common/styleLibrary";
23-
import { ButtonProps } from "../../types";
23+
interface ButtonProps {
24+
label?: string;
25+
variant?: "regular" | "callAction" | "secondary";
26+
icon?: React.ReactNode;
27+
iconLocation?: "start" | "end";
28+
fullWidth?: boolean;
29+
disabled?: boolean;
30+
onClick?: React.MouseEventHandler<HTMLButtonElement>;
31+
}
2432

2533
const styles = (theme: Theme) =>
2634
createStyles({

portal-ui/src/screens/Console/consoleSlice.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,22 @@
1515
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1616

1717
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
18-
import { ISessionResponse } from "./types";
1918
import { AppState } from "../../store";
19+
import { SessionResponse } from "api/consoleApi";
2020

2121
export interface ConsoleState {
22-
session: ISessionResponse;
22+
session: SessionResponse;
2323
}
2424

2525
const initialState: ConsoleState = {
2626
session: {
27-
status: "",
27+
status: undefined,
2828
features: [],
2929
distributedMode: false,
3030
permissions: {},
31-
allowResources: null,
32-
customStyles: null,
33-
envConstants: null,
31+
allowResources: undefined,
32+
customStyles: undefined,
33+
envConstants: undefined,
3434
serverEndPoint: "",
3535
},
3636
};
@@ -39,7 +39,7 @@ export const consoleSlice = createSlice({
3939
name: "console",
4040
initialState,
4141
reducers: {
42-
saveSessionResponse: (state, action: PayloadAction<ISessionResponse>) => {
42+
saveSessionResponse: (state, action: PayloadAction<SessionResponse>) => {
4343
state.session = action.payload;
4444
},
4545
resetSession: (state) => {

portal-ui/src/screens/Console/kbar-actions.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { IAM_PAGES } from "../../common/SecureComponent/permissions";
2121
import { Bucket } from "../../api/consoleApi";
2222

2323
export const routesAsKbarActions = (
24-
features: string[] | null,
24+
features: string[] | undefined,
2525
buckets: Bucket[],
2626
navigate: (url: string) => void
2727
) => {

portal-ui/src/screens/Console/types.ts

Lines changed: 0 additions & 53 deletions
This file was deleted.

0 commit comments

Comments
 (0)