From 9371c027f34db79654231ca850a48b3241f20f5a Mon Sep 17 00:00:00 2001 From: Alex <33497058+bexsoft@users.noreply.github.com> Date: Thu, 30 Jun 2022 23:40:23 -0500 Subject: [PATCH] Added Prettier test to workflow (#2159) Signed-off-by: Benjamin Perez --- .github/workflows/jobs.yaml | 7 +- portal-ui/Makefile | 6 + portal-ui/check-prettier.sh | 4 + portal-ui/package.json | 2 +- .../BucketDetails/AddReplicationModal.tsx | 20 +- .../FormComponents/common/styleLibrary.ts | 4 +- .../Console/Marketplace/Marketplace.tsx | 15 +- .../Console/Marketplace/SetEmailModal.tsx | 40 +- .../Console/Marketplace/euTimezones.ts | 122 +++--- .../ObjectBrowser/objectBrowserSlice.ts | 8 +- .../Steps/TenantResources/NameTenantMain.tsx | 10 +- .../Console/Tenants/ListTenants/types.ts | 2 +- .../TenantDetails/LoggingDBDetails.tsx | 363 +++++++++--------- .../Tenants/TenantDetails/LoggingDetails.tsx | 203 +++++----- .../TenantDetails/TenantAuditLogsScreen.tsx | 339 ++++++++-------- .../Tenants/TenantDetails/TenantDetails.tsx | 4 +- .../TenantDetails/tenantAuditLogSlice.ts | 96 ++--- .../Tenants/securityContextSelector.tsx | 174 +++++---- .../src/screens/Console/Tenants/types.ts | 1 - portal-ui/src/screens/LoginPage/LoginPage.tsx | 15 +- portal-ui/src/store.ts | 1 - portal-ui/src/systemSlice.ts | 3 +- portal-ui/yarn.lock | 8 +- 23 files changed, 770 insertions(+), 677 deletions(-) create mode 100755 portal-ui/check-prettier.sh diff --git a/.github/workflows/jobs.yaml b/.github/workflows/jobs.yaml index 9ebe4e2c3..5544d5edd 100644 --- a/.github/workflows/jobs.yaml +++ b/.github/workflows/jobs.yaml @@ -276,7 +276,7 @@ jobs: semgrep --config semgrep.yaml $(pwd)/portal-ui --error no-warnings-and-make-assets: - name: "React Code Has No Warnings and then Make Assets" + name: "React Code Has No Warning & Prettified and then Make Assets" runs-on: ${{ matrix.os }} strategy: matrix: @@ -329,6 +329,11 @@ jobs: continue-on-error: false run: | ./check-warnings.sh + - name: Check if Files are Prettified + working-directory: ./portal-ui + continue-on-error: false + run: | + ./check-prettier.sh reuse-golang-dependencies: name: reuse golang dependencies diff --git a/portal-ui/Makefile b/portal-ui/Makefile index 25f5685f4..43d6cad12 100644 --- a/portal-ui/Makefile +++ b/portal-ui/Makefile @@ -6,3 +6,9 @@ build-static: test-warnings: ./check-warnings.sh + +test-prettier: + ./check-prettier.sh + +prettify: + yarn prettier --write . --loglevel warn diff --git a/portal-ui/check-prettier.sh b/portal-ui/check-prettier.sh new file mode 100755 index 000000000..1b35677d3 --- /dev/null +++ b/portal-ui/check-prettier.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +yarn install +yarn prettier --check . diff --git a/portal-ui/package.json b/portal-ui/package.json index e77ba323a..86fb34761 100644 --- a/portal-ui/package.json +++ b/portal-ui/package.json @@ -73,7 +73,7 @@ "@types/react-window": "^1.8.5", "@types/react-window-infinite-loader": "^1.0.6", "@types/recharts": "^1.8.22", - "prettier": "2.6.2", + "prettier": "2.7.1", "react-scripts": "5.0.1", "testcafe": "^1.18.6", "typescript": "^4.4.3" diff --git a/portal-ui/src/screens/Console/Buckets/BucketDetails/AddReplicationModal.tsx b/portal-ui/src/screens/Console/Buckets/BucketDetails/AddReplicationModal.tsx index 4d12c6c03..d81eef3ad 100644 --- a/portal-ui/src/screens/Console/Buckets/BucketDetails/AddReplicationModal.tsx +++ b/portal-ui/src/screens/Console/Buckets/BucketDetails/AddReplicationModal.tsx @@ -170,10 +170,12 @@ const AddReplicationModal = ({ setAddLoading(false); if (itemVal.errorString && itemVal.errorString !== "") { - dispatch(setModalErrorSnackMessage({ - errorMessage: itemVal.errorString, - detailedError: "", - })); + dispatch( + setModalErrorSnackMessage({ + errorMessage: itemVal.errorString, + detailedError: "", + }) + ); return; } @@ -181,10 +183,12 @@ const AddReplicationModal = ({ return; } - dispatch(setModalErrorSnackMessage({ - errorMessage: "No changes applied", - detailedError: "", - })); + dispatch( + setModalErrorSnackMessage({ + errorMessage: "No changes applied", + detailedError: "", + }) + ); }) .catch((err: ErrorResponseHandler) => { setAddLoading(false); diff --git a/portal-ui/src/screens/Console/Common/FormComponents/common/styleLibrary.ts b/portal-ui/src/screens/Console/Common/FormComponents/common/styleLibrary.ts index bdde80a78..3e6a1c50b 100644 --- a/portal-ui/src/screens/Console/Common/FormComponents/common/styleLibrary.ts +++ b/portal-ui/src/screens/Console/Common/FormComponents/common/styleLibrary.ts @@ -796,8 +796,8 @@ export const wizardCommon = { justifyContent: "flex-start" as const, }, multiContainerStackNarrow: { - display: "flex" , - alignItems: "center" , + display: "flex", + alignItems: "center", justifyContent: "flex-start", gap: "8px", "@media (max-width: 750px)": { diff --git a/portal-ui/src/screens/Console/Marketplace/Marketplace.tsx b/portal-ui/src/screens/Console/Marketplace/Marketplace.tsx index e09ccd0c0..9a8d24308 100644 --- a/portal-ui/src/screens/Console/Marketplace/Marketplace.tsx +++ b/portal-ui/src/screens/Console/Marketplace/Marketplace.tsx @@ -33,7 +33,6 @@ const Marketplace = () => { const displayMarketplace = useSelector(selShowMarketplace); const [isMPMode, setMPMode] = useState(true); - useEffect(() => { let mpMode = false; if (features && features.length !== 0) { @@ -49,17 +48,20 @@ const Marketplace = () => { const getTargetPath = () => { let targetPath = "/"; - if (localStorage.getItem("redirect-path") && localStorage.getItem("redirect-path") !== "") { + if ( + localStorage.getItem("redirect-path") && + localStorage.getItem("redirect-path") !== "" + ) { targetPath = `${localStorage.getItem("redirect-path")}`; localStorage.setItem("redirect-path", ""); } return targetPath; - } + }; const closeModal = () => { dispatch(showMarketplace(false)); navigate(getTargetPath()); - } + }; if (!displayMarketplace || !isMPMode) { return ; @@ -70,10 +72,7 @@ const Marketplace = () => { - + ); diff --git a/portal-ui/src/screens/Console/Marketplace/SetEmailModal.tsx b/portal-ui/src/screens/Console/Marketplace/SetEmailModal.tsx index 6608f6829..d5050c9bd 100644 --- a/portal-ui/src/screens/Console/Marketplace/SetEmailModal.tsx +++ b/portal-ui/src/screens/Console/Marketplace/SetEmailModal.tsx @@ -42,8 +42,9 @@ const styles = (theme: Theme) => ...containerForHeader(theme.spacing(4)), }); -// eslint-disable-next-line -const reEmail = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; +const reEmail = + // eslint-disable-next-line + /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; const SetEmailModal = ({ open, closeModal }: ISetEmailModalProps) => { const dispatch = useAppDispatch(); @@ -52,7 +53,7 @@ const SetEmailModal = ({ open, closeModal }: ISetEmailModalProps) => { dispatch(setErrorSnackMessage(err)); closeModal(); }; - + const onSuccess = (res: any) => { let msg = `Email ${email} has been saved`; dispatch(setSnackBarMessage(msg)); @@ -62,7 +63,6 @@ const SetEmailModal = ({ open, closeModal }: ISetEmailModalProps) => { const [isLoading, invokeApi] = useApi(onSuccess, onError); const [email, setEmail] = useState(""); const [isEmailSet, setIsEmailSet] = useState(false); - const handleInputChange = (event: React.ChangeEvent) => { let v = event.target.value; @@ -72,13 +72,13 @@ const SetEmailModal = ({ open, closeModal }: ISetEmailModalProps) => { const onConfirm = () => { const isInEU = isEU(); - invokeApi("POST", "/api/v1/mp-integration", { email, isInEU}); + invokeApi("POST", "/api/v1/mp-integration", { email, isInEU }); }; const isEU = () => { const tz = Intl.DateTimeFormat().resolvedOptions().timeZone; return euTimezones.includes(tz.toLocaleLowerCase()); - } + }; return open ? ( { - MinIO Subscription Network (SUBNET) - . + rel="noreferrer" + > + MinIO Subscription Network (SUBNET) + + .
Enter your email to register now.

- To register later, contact support@min.io. + To register later, contact{" "} + support@min.io.

- + id="set-mp-email" + name="set-mp-email" + onChange={handleInputChange} + label={""} + placeholder="Enter email" + type={"email"} + value={email} + /> } /> diff --git a/portal-ui/src/screens/Console/Marketplace/euTimezones.ts b/portal-ui/src/screens/Console/Marketplace/euTimezones.ts index dbbd4d488..b0a2aeec0 100644 --- a/portal-ui/src/screens/Console/Marketplace/euTimezones.ts +++ b/portal-ui/src/screens/Console/Marketplace/euTimezones.ts @@ -15,64 +15,64 @@ // along with this program. If not, see . export const euTimezones = [ - "europe/amsterdam", - "europe/andorra", - "europe/astrakhan", - "europe/athens", - "europe/belgrade", - "europe/berlin", - "europe/bratislava", - "europe/brussels", - "europe/bucharest", - "europe/budapest", - "europe/busingen", - "europe/chisinau", - "europe/copenhagen", - "europe/dublin", - "europe/gibraltar", - "europe/guernsey", - "europe/helsinki", - "europe/isle_of_man", - "europe/istanbul", - "europe/jersey", - "europe/kaliningrad", - "europe/kiev", - "europe/kirov", - "europe/lisbon", - "europe/ljubljana", - "europe/london", - "europe/luxembourg", - "europe/madrid", - "europe/malta", - "europe/mariehamn", - "europe/minsk", - "europe/monaco", - "europe/moscow", - "europe/oslo", - "europe/paris", - "europe/podgorica", - "europe/prague", - "europe/riga", - "europe/rome", - "europe/samara", - "europe/san_marino", - "europe/sarajevo", - "europe/saratov", - "europe/simferopol", - "europe/skopje", - "europe/sofia", - "europe/stockholm", - "europe/tallinn", - "europe/tirane", - "europe/ulyanovsk", - "europe/uzhgorod", - "europe/vaduz", - "europe/vatican", - "europe/vienna", - "europe/vilnius", - "europe/volgograd", - "europe/warsaw", - "europe/zagreb", - "europe/zaporozhye", - "europe/zurich" - ]; \ No newline at end of file + "europe/amsterdam", + "europe/andorra", + "europe/astrakhan", + "europe/athens", + "europe/belgrade", + "europe/berlin", + "europe/bratislava", + "europe/brussels", + "europe/bucharest", + "europe/budapest", + "europe/busingen", + "europe/chisinau", + "europe/copenhagen", + "europe/dublin", + "europe/gibraltar", + "europe/guernsey", + "europe/helsinki", + "europe/isle_of_man", + "europe/istanbul", + "europe/jersey", + "europe/kaliningrad", + "europe/kiev", + "europe/kirov", + "europe/lisbon", + "europe/ljubljana", + "europe/london", + "europe/luxembourg", + "europe/madrid", + "europe/malta", + "europe/mariehamn", + "europe/minsk", + "europe/monaco", + "europe/moscow", + "europe/oslo", + "europe/paris", + "europe/podgorica", + "europe/prague", + "europe/riga", + "europe/rome", + "europe/samara", + "europe/san_marino", + "europe/sarajevo", + "europe/saratov", + "europe/simferopol", + "europe/skopje", + "europe/sofia", + "europe/stockholm", + "europe/tallinn", + "europe/tirane", + "europe/ulyanovsk", + "europe/uzhgorod", + "europe/vaduz", + "europe/vatican", + "europe/vienna", + "europe/vilnius", + "europe/volgograd", + "europe/warsaw", + "europe/zagreb", + "europe/zaporozhye", + "europe/zurich", +]; diff --git a/portal-ui/src/screens/Console/ObjectBrowser/objectBrowserSlice.ts b/portal-ui/src/screens/Console/ObjectBrowser/objectBrowserSlice.ts index fa1aa29ac..23e356011 100644 --- a/portal-ui/src/screens/Console/ObjectBrowser/objectBrowserSlice.ts +++ b/portal-ui/src/screens/Console/ObjectBrowser/objectBrowserSlice.ts @@ -120,7 +120,10 @@ export const objectBrowserSlice = createSlice({ false; state.objectManager.objectsToManage[objectToComplete].done = true; }, - failObject: (state, action: PayloadAction<{instanceID: string; msg: string}>) => { + failObject: ( + state, + action: PayloadAction<{ instanceID: string; msg: string }> + ) => { const objectToFail = state.objectManager.objectsToManage.findIndex( (item) => item.instanceID === action.payload.instanceID ); @@ -128,7 +131,8 @@ export const objectBrowserSlice = createSlice({ state.objectManager.objectsToManage[objectToFail].failed = true; state.objectManager.objectsToManage[objectToFail].waitingForFile = false; state.objectManager.objectsToManage[objectToFail].done = true; - state.objectManager.objectsToManage[objectToFail].errorMessage = action.payload.msg; + state.objectManager.objectsToManage[objectToFail].errorMessage = + action.payload.msg; }, cancelObjectInList: (state, action: PayloadAction) => { const objectToCancel = state.objectManager.objectsToManage.findIndex( diff --git a/portal-ui/src/screens/Console/Tenants/AddTenant/Steps/TenantResources/NameTenantMain.tsx b/portal-ui/src/screens/Console/Tenants/AddTenant/Steps/TenantResources/NameTenantMain.tsx index 49dfa8b31..23428766a 100644 --- a/portal-ui/src/screens/Console/Tenants/AddTenant/Steps/TenantResources/NameTenantMain.tsx +++ b/portal-ui/src/screens/Console/Tenants/AddTenant/Steps/TenantResources/NameTenantMain.tsx @@ -164,10 +164,12 @@ const NameTenantMain = ({ classes, formToRender }: INameTenantMainScreen) => { id="storage_type" name="storage_type" onChange={(e: SelectChangeEvent) => { - dispatch(setStorageType({ - storageType: e.target.value as string, - features: features, - })); + dispatch( + setStorageType({ + storageType: e.target.value as string, + features: features, + }) + ); }} label={get( mkPanelConfigurations, diff --git a/portal-ui/src/screens/Console/Tenants/ListTenants/types.ts b/portal-ui/src/screens/Console/Tenants/ListTenants/types.ts index 1a83a125a..94cc6d7b9 100644 --- a/portal-ui/src/screens/Console/Tenants/ListTenants/types.ts +++ b/portal-ui/src/screens/Console/Tenants/ListTenants/types.ts @@ -281,4 +281,4 @@ export interface ITenantAuditLogs { labels: IKeyValue[]; annotations: IKeyValue[]; nodeSelector: IKeyValue[]; -} \ No newline at end of file +} diff --git a/portal-ui/src/screens/Console/Tenants/TenantDetails/LoggingDBDetails.tsx b/portal-ui/src/screens/Console/Tenants/TenantDetails/LoggingDBDetails.tsx index 318bd1651..e4ee75200 100644 --- a/portal-ui/src/screens/Console/Tenants/TenantDetails/LoggingDBDetails.tsx +++ b/portal-ui/src/screens/Console/Tenants/TenantDetails/LoggingDBDetails.tsx @@ -44,18 +44,17 @@ import { import { IKeyValue, ITenantAuditLogs } from "../ListTenants/types"; import KeyPairEdit from "./KeyPairEdit"; import InputUnitMenu from "../../Common/FormComponents/InputUnitMenu/InputUnitMenu"; -import { - setDBImage, - setDBInitImage, - setDBCPURequest, - setDBMemRequest, - setDBRunAsUser, - setDBFSGroup, - setDBRunAsGroup, - setDBRunAsNonRoot, - setRefreshLoggingInfo, - } from "../TenantDetails/tenantAuditLogSlice"; - +import { + setDBImage, + setDBInitImage, + setDBCPURequest, + setDBMemRequest, + setDBRunAsUser, + setDBFSGroup, + setDBRunAsGroup, + setDBRunAsNonRoot, + setRefreshLoggingInfo, +} from "../TenantDetails/tenantAuditLogSlice"; import SecurityContextSelector from "../securityContextSelector"; @@ -85,7 +84,12 @@ const styles = (theme: Theme) => ...wizardCommon, }); -const LoggingDBDetails = ({ classes, labels, annotations, nodeSelector }: ITenantAuditLogs) => { +const LoggingDBDetails = ({ + classes, + labels, + annotations, + nodeSelector, +}: ITenantAuditLogs) => { const dispatch = useAppDispatch(); const { tenantName, tenantNamespace } = useParams(); const dbImage = useSelector( @@ -109,18 +113,28 @@ const LoggingDBDetails = ({ classes, labels, annotations, nodeSelector }: ITenan ); const dbRunAsUser = useSelector( (state: AppState) => state.editTenantLogging.dbSecurityContext.runAsUser - ) + ); const dbFSGroup = useSelector( (state: AppState) => state.editTenantLogging.dbSecurityContext.fsGroup - ) + ); const dbRunAsNonRoot = useSelector( (state: AppState) => state.editTenantLogging.dbSecurityContext.runAsNonRoot - ) + ); const [validationErrors, setValidationErrors] = useState({}); - const [dbLabels, setDBLabels] = useState((labels != null && labels.length > 0) ? labels : [{ key: "", value: "" }]); - const [dbAnnotations, setDBAnnotations] = useState((annotations != null && annotations.length > 0)? annotations : [{ key: "", value: "" }]); - const [dbNodeSelector, setDBNodeSelector] = useState((nodeSelector != null && nodeSelector.length > 0)? nodeSelector :[{ key: "", value: "" }]); + const [dbLabels, setDBLabels] = useState( + labels != null && labels.length > 0 ? labels : [{ key: "", value: "" }] + ); + const [dbAnnotations, setDBAnnotations] = useState( + annotations != null && annotations.length > 0 + ? annotations + : [{ key: "", value: "" }] + ); + const [dbNodeSelector, setDBNodeSelector] = useState( + nodeSelector != null && nodeSelector.length > 0 + ? nodeSelector + : [{ key: "", value: "" }] + ); const [dbLabelsError, setDBLabelsError] = useState({}); const [dbAnnotationsError, setDBAnnotationsError] = useState({}); @@ -130,8 +144,6 @@ const LoggingDBDetails = ({ classes, labels, annotations, nodeSelector }: ITenan setValidationErrors(clearValidationError(validationErrors, fieldName)); }; - - const trim = (x: IKeyValue[]): IKeyValue[] => { let retval: IKeyValue[] = []; for (let i = 0; i < x.length; i++) { @@ -147,7 +159,7 @@ const LoggingDBDetails = ({ classes, labels, annotations, nodeSelector }: ITenan Object.keys(validationErrors).length !== 0 || Object.keys(dbNodeSelectorError).length !== 0 || Object.keys(dbAnnotationsError).length !== 0 || - Object.keys(dbLabelsError).length !== 0 + Object.keys(dbLabelsError).length !== 0 ) { let err: ErrorResponseHandler = { errorMessage: "Invalid entry", @@ -160,32 +172,30 @@ const LoggingDBDetails = ({ classes, labels, annotations, nodeSelector }: ITenan } }; - - const submitLoggingInfo = () => { - if (checkValid()) { + if (checkValid()) { const dbSecurityContext = { runAsGroup: dbRunAsGroup != null ? dbRunAsGroup : "", runAsUser: dbRunAsUser != null ? dbRunAsUser : "", fsGroup: dbFSGroup != null ? dbFSGroup : "", runAsNonRoot: dbRunAsNonRoot != null ? dbRunAsNonRoot : true, - } + }; api - .invoke( - "PUT", - `/api/v1/namespaces/${tenantNamespace}/tenants/${tenantName}/log`, - { - dbLabels: trim(dbLabels), - dbAnnotations: trim(dbAnnotations), - dbNodeSelector: trim(dbNodeSelector), - dbImage: dbImage, - dbInitImage: dbInitImage, - dbServiceAccountName: dbServiceAccountName, - logDBCPURequest: dbCpuRequest, - logDBMemRequest: dbMemRequest, - dbSecurityContext: dbSecurityContext, - } - ) + .invoke( + "PUT", + `/api/v1/namespaces/${tenantNamespace}/tenants/${tenantName}/log`, + { + dbLabels: trim(dbLabels), + dbAnnotations: trim(dbAnnotations), + dbNodeSelector: trim(dbNodeSelector), + dbImage: dbImage, + dbInitImage: dbInitImage, + dbServiceAccountName: dbServiceAccountName, + logDBCPURequest: dbCpuRequest, + logDBMemRequest: dbMemRequest, + dbSecurityContext: dbSecurityContext, + } + ) .then(() => { setRefreshLoggingInfo(true); dispatch(setSnackBarMessage(`Audit Log DB configuration updated.`)); @@ -196,149 +206,150 @@ const LoggingDBDetails = ({ classes, labels, annotations, nodeSelector }: ITenan } }; - return ( - - - - ) => { - if (event.target.validity.valid) { - dispatch(setDBImage(event.target.value)); - } - cleanValidation(`dbImage`); - }} - key={`dbImage`} - pattern={"^[a-zA-Z0-9-./:]{1,253}$"} - error={validationErrors[`dbImage`] || ""} - /> - - - ) => { - if (event.target.validity.valid) { - dispatch(setDBInitImage(event.target.value)); - } - cleanValidation(`dbInitImage`); - }} - key={`dbInitImage`} - pattern={"^[a-zA-Z0-9-./:]{1,253}$"} - error={validationErrors[`dbInitImage`] || ""} - /> - - - ) => { - if (event.target.validity.valid) { - dispatch(setDBCPURequest(event.target.value)); - } - cleanValidation(`dbCPURequest`); - }} - key={`dbCPURequest`} - error={validationErrors[`dbCPURequest`] || ""} - /> - - - ) => { - if (event.target.validity.valid) { - dispatch(setDBMemRequest(event.target.value)); - } - cleanValidation(`dbMemRequest`); - }} - pattern={"[0-9]*"} - key={`dbMemRequest`} - error={validationErrors[`dbMemRequest`] || ""} - overlayObject={ - {}} - unitSelected={"Gi"} - unitsList={[{ label: "Gi", value: "Gi" }]} - disabled={true} - /> + + + ) => { + if (event.target.validity.valid) { + dispatch(setDBImage(event.target.value)); } - /> - - - - DB Labels - + + + ) => { + if (event.target.validity.valid) { + dispatch(setDBInitImage(event.target.value)); + } + cleanValidation(`dbInitImage`); + }} + key={`dbInitImage`} + pattern={"^[a-zA-Z0-9-./:]{1,253}$"} + error={validationErrors[`dbInitImage`] || ""} + /> + + + ) => { + if (event.target.validity.valid) { + dispatch(setDBCPURequest(event.target.value)); + } + cleanValidation(`dbCPURequest`); + }} + key={`dbCPURequest`} + error={validationErrors[`dbCPURequest`] || ""} + /> + + + ) => { + if (event.target.validity.valid) { + dispatch(setDBMemRequest(event.target.value)); + } + cleanValidation(`dbMemRequest`); + }} + pattern={"[0-9]*"} + key={`dbMemRequest`} + error={validationErrors[`dbMemRequest`] || ""} + overlayObject={ + {}} + unitSelected={"Gi"} + unitsList={[{ label: "Gi", value: "Gi" }]} + disabled={true} /> - - - DB Annotations - - - - - DB Node Selector - - - - - + + + + DB Labels + + + + DB Annotations + + + + + DB Node Selector + + + + + dispatch(setDBFSGroup(value))} - setRunAsUser={(value : string)=>dispatch(setDBRunAsUser(value))} - setRunAsGroup={(value : string)=>dispatch(setDBRunAsGroup(value))} - setRunAsNonRoot={(value : boolean)=>dispatch(setDBRunAsNonRoot(value))} - /> - - - - - + setFSGroup={(value: string) => dispatch(setDBFSGroup(value))} + setRunAsUser={(value: string) => dispatch(setDBRunAsUser(value))} + setRunAsGroup={(value: string) => dispatch(setDBRunAsGroup(value))} + setRunAsNonRoot={(value: boolean) => + dispatch(setDBRunAsNonRoot(value)) + } + /> + + + + + ); }; diff --git a/portal-ui/src/screens/Console/Tenants/TenantDetails/LoggingDetails.tsx b/portal-ui/src/screens/Console/Tenants/TenantDetails/LoggingDetails.tsx index 24d5db8a9..5ca31b6a1 100644 --- a/portal-ui/src/screens/Console/Tenants/TenantDetails/LoggingDetails.tsx +++ b/portal-ui/src/screens/Console/Tenants/TenantDetails/LoggingDetails.tsx @@ -45,18 +45,18 @@ import KeyPairEdit from "./KeyPairEdit"; import InputUnitMenu from "../../Common/FormComponents/InputUnitMenu/InputUnitMenu"; import SecurityContextSelector from "../securityContextSelector"; import { clearValidationError } from "../utils"; -import { - setImage, - setDiskCapacityGB, - setServiceAccountName, - setCPURequest, - setMemRequest, - setRunAsUser, - setFSGroup, - setRunAsGroup, - setRunAsNonRoot, - setRefreshLoggingInfo, - } from "../TenantDetails/tenantAuditLogSlice"; +import { + setImage, + setDiskCapacityGB, + setServiceAccountName, + setCPURequest, + setMemRequest, + setRunAsUser, + setFSGroup, + setRunAsGroup, + setRunAsNonRoot, + setRefreshLoggingInfo, +} from "../TenantDetails/tenantAuditLogSlice"; const styles = (theme: Theme) => createStyles({ @@ -82,15 +82,18 @@ const styles = (theme: Theme) => ...wizardCommon, }); -const TenantAuditLogging = ({ classes, labels, annotations, nodeSelector }: ITenantAuditLogs) => { +const TenantAuditLogging = ({ + classes, + labels, + annotations, + nodeSelector, +}: ITenantAuditLogs) => { const dispatch = useAppDispatch(); const { tenantName, tenantNamespace } = useParams(); const auditLoggingEnabled = useSelector( (state: AppState) => state.editTenantLogging.auditLoggingEnabled ); - const image = useSelector( - (state: AppState) => state.editTenantLogging.image - ); + const image = useSelector((state: AppState) => state.editTenantLogging.image); const diskCapacityGB = useSelector( (state: AppState) => state.editTenantLogging.diskCapacityGB ); @@ -108,21 +111,31 @@ const TenantAuditLogging = ({ classes, labels, annotations, nodeSelector }: ITen ); const runAsUser = useSelector( (state: AppState) => state.editTenantLogging.securityContext.runAsUser - ) + ); const fsGroup = useSelector( (state: AppState) => state.editTenantLogging.securityContext.fsGroup - ) + ); const runAsNonRoot = useSelector( (state: AppState) => state.editTenantLogging.securityContext.runAsNonRoot - ) - + ); + const [validationErrors, setValidationErrors] = useState({}); const [loading, setLoading] = useState(false); - const [logLabels, setLabels] = useState((labels != null && labels.length > 0) ? labels : [{ key: "", value: "" }]); - const [logAnnotations, setAnnotations] = useState((annotations != null && annotations.length > 0)? annotations : [{ key: "", value: "" }]); - const [logNodeSelector, setNodeSelector] = useState((nodeSelector != null && nodeSelector.length > 0)? nodeSelector :[{ key: "", value: "" }]); - + const [logLabels, setLabels] = useState( + labels != null && labels.length > 0 ? labels : [{ key: "", value: "" }] + ); + const [logAnnotations, setAnnotations] = useState( + annotations != null && annotations.length > 0 + ? annotations + : [{ key: "", value: "" }] + ); + const [logNodeSelector, setNodeSelector] = useState( + nodeSelector != null && nodeSelector.length > 0 + ? nodeSelector + : [{ key: "", value: "" }] + ); + const [labelsError, setLabelsError] = useState({}); const [annotationsError, setAnnotationsError] = useState({}); const [nodeSelectorError, setNodeSelectorError] = useState({}); @@ -146,7 +159,7 @@ const TenantAuditLogging = ({ classes, labels, annotations, nodeSelector }: ITen Object.keys(validationErrors).length !== 0 || Object.keys(labelsError).length !== 0 || Object.keys(annotationsError).length !== 0 || - Object.keys(nodeSelectorError).length !== 0 + Object.keys(nodeSelectorError).length !== 0 ) { let err: ErrorResponseHandler = { errorMessage: "Invalid entry", @@ -160,32 +173,31 @@ const TenantAuditLogging = ({ classes, labels, annotations, nodeSelector }: ITen }; const submitLoggingInfo = () => { - if (checkValid()) { - setLoading(true); - const securityContext = { + setLoading(true); + const securityContext = { runAsGroup: runAsGroup != null ? runAsGroup : "", runAsUser: runAsUser != null ? runAsUser : "", fsGroup: fsGroup != null ? fsGroup : "", runAsNonRoot: runAsNonRoot != null ? runAsNonRoot : true, - } - + }; + api - .invoke( - "PUT", - `/api/v1/namespaces/${tenantNamespace}/tenants/${tenantName}/log`, - { - labels: trim(logLabels), - annotations: trim(logAnnotations), - nodeSelector: trim(logNodeSelector), - image: image, - diskCapacityGB: diskCapacityGB.toString(), - serviceAccountName: serviceAccountName, - logCPURequest: cpuRequest, - logMemRequest: memRequest, - securityContext: securityContext, - } - ) + .invoke( + "PUT", + `/api/v1/namespaces/${tenantNamespace}/tenants/${tenantName}/log`, + { + labels: trim(logLabels), + annotations: trim(logAnnotations), + nodeSelector: trim(logNodeSelector), + image: image, + diskCapacityGB: diskCapacityGB.toString(), + serviceAccountName: serviceAccountName, + logCPURequest: cpuRequest, + logMemRequest: memRequest, + securityContext: securityContext, + } + ) .then(() => { setRefreshLoggingInfo(true); dispatch(setSnackBarMessage(`Audit Log configuration updated.`)); @@ -197,9 +209,9 @@ const TenantAuditLogging = ({ classes, labels, annotations, nodeSelector }: ITen }); } }; - + return ( - + {auditLoggingEnabled && ( @@ -220,7 +232,7 @@ const TenantAuditLogging = ({ classes, labels, annotations, nodeSelector }: ITen error={validationErrors[`image`] || ""} /> - + - + - + - dispatch(setFSGroup(value))} - setRunAsUser={(value : string)=>dispatch(setRunAsUser(value))} - setRunAsGroup={(value : string)=>dispatch(setRunAsGroup(value))} - setRunAsNonRoot={(value : boolean)=>dispatch(setRunAsNonRoot(value))} + dispatch(setFSGroup(value))} + setRunAsUser={(value: string) => dispatch(setRunAsUser(value))} + setRunAsGroup={(value: string) => dispatch(setRunAsGroup(value))} + setRunAsNonRoot={(value: boolean) => + dispatch(setRunAsNonRoot(value)) + } /> - - - - Labels - - - - - Annotations - - - - - Node Selector - - - + + + + Labels + + + + + Annotations + + + + + Node Selector + + +