Skip to content

Commit

Permalink
Merge pull request #233 from zowe/bugfixes-installation-tab
Browse files Browse the repository at this point in the history
Dataset Validation On Installation Stage
  • Loading branch information
skurnevich authored Aug 8, 2024
2 parents 949ed90 + 4e78e86 commit b831061
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 7 deletions.
44 changes: 37 additions & 7 deletions src/renderer/components/stages/installation/Installation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import { getStageDetails, getSubStageDetails } from "../../../../services/StageD
import { getProgress, setDatasetInstallationState, getDatasetInstallationState, getInstallationTypeStatus, mapAndSetSkipStatus, getInstallationArguments, datasetInstallationStatus, isInitComplete } from "../progress/StageProgressStatus";
import { DatasetInstallationState } from "../../../../types/stateInterfaces";
import eventDispatcher from '../../../../services/eventDispatcher';
import { validateDatasetIterator } from '../../../../services/DatasetValidation';
import ErrorIcon from '@mui/icons-material/Error';

const Installation = () => {

Expand All @@ -54,8 +56,6 @@ const Installation = () => {
const [showProgress, setShowProgress] = useState(getProgress('datasetInstallationStatus'));
const [isFormInit, setIsFormInit] = useState(false);
const [editorVisible, setEditorVisible] = useState(false);
const [isFormValid, setIsFormValid] = useState(false);
const [formError, setFormError] = useState('');
const [contentType, setContentType] = useState('');
const [mvsDatasetInitProgress, setMvsDatasetInitProgress] = useState(getDatasetInstallationState());
const [stateUpdated, setStateUpdated] = useState(false);
Expand All @@ -67,8 +67,9 @@ const Installation = () => {
const [installationType] = useState(getInstallationTypeStatus().installationType);

const [validate] = useState(() => ajv.getSchema("https://zowe.org/schemas/v2/server-base") || ajv.compile(setupSchema));


const datasetPropertiesCount = setupSchema ? Object.keys(setupSchema.properties).length : 0;

useEffect(() => {
dispatch(setInitializationStatus(isInitComplete()));
if(getProgress("datasetInstallationStatus")) {
Expand Down Expand Up @@ -168,6 +169,7 @@ const Installation = () => {

return () => {
dispatch(setActiveStep({ activeStepIndex: STAGE_ID, isSubStep: SUB_STAGES, activeSubStepIndex: SUB_STAGE_ID }));
alertEmitter.emit('hideAlert');
}
}, []);

Expand Down Expand Up @@ -221,6 +223,7 @@ const Installation = () => {
stages[STAGE_ID].isSkipped = status;
mapAndSetSkipStatus(SUB_STAGE_ID, status);
}

const updateProgress = (status: boolean) => {
setStateUpdated(!stateUpdated);
setStageSkipStatus(!status);
Expand All @@ -243,6 +246,13 @@ const Installation = () => {

const process = async (event: any) => {

const areDatasetsValid = validateDatasets();
if (!areDatasetsValid){
event.preventDefault();
return;
}

alertEmitter.emit('hideAlert');
setInitClicked(true);
updateProgress(false);
event.preventDefault();
Expand Down Expand Up @@ -298,8 +308,28 @@ const Installation = () => {
initMVS: true
})
updateProgress(true);
}
}
}

const validateDatasets = () => {

if(Object.keys(setupYaml).length < datasetPropertiesCount) {
const errorMessage = `One or more required dataset values are missing. Please ensure all fields are filled in.`;
alertEmitter.emit('showAlert', errorMessage, 'error');
return false;
}

const {isValid, key} = validateDatasetIterator(setupYaml);

if (!isValid) {
const errorMessage = `The dataset '${key.toUpperCase()}' is invalid. Please verify the dataset name and try again.`;
alertEmitter.emit('showAlert', errorMessage, 'error');
return false;
}

return true;
};


// True - a proceed, False - blocked
const installProceedActions = (status: boolean) => {
Expand Down Expand Up @@ -334,8 +364,9 @@ const Installation = () => {
}

const setStageConfig = (isValid: boolean, errorMsg: string, data: any) => {
setIsFormValid(isValid);
setFormError(errorMsg);
if(!isValid) {
alertEmitter.emit('showAlert', errorMsg, 'error');
}
setSetupYaml(data);
}

Expand All @@ -357,7 +388,6 @@ const Installation = () => {
</Typography>

<Box sx={{ width: '60vw' }} onBlur={async () => dispatch(setYaml((await window.electron.ipcRenderer.getConfig()).details ?? yaml))}>
{!isFormValid && formError && <div style={{color: 'red', fontSize: 'small', marginBottom: '20px'}}>{formError}</div>}
<JsonForm schema={setupSchema} onChange={handleFormChange} formData={setupYaml}/>
</Box>
{!showProgress ? <FormControl sx={{display: 'flex', alignItems: 'center', maxWidth: '72ch', justifyContent: 'center'}}>
Expand Down
30 changes: 30 additions & 0 deletions src/services/DatasetValidation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright Contributors to the Zowe Project.
*/

export const validateDatasetIterator = (schema: any) : { isValid: boolean, key: string } => {
for (const key of Object.keys(schema)) {
let value = schema[key];
if (typeof value === 'object' && value !== null) {
const result = validateDatasetIterator(value);
if(!result.isValid) {
return {isValid: false, key: key};
}
} else if(!isDatasetValid(value)) {
return {isValid: false, key: key};
}
}
return {isValid: true, key: ''};
}

export const isDatasetValid = (dsName: string) : boolean => {
const DsNamePattern = "^[a-zA-Z#$@][a-zA-Z0-9#$@-]{0,7}([.][a-zA-Z#$@][a-zA-Z0-9#$@-]{0,7}){0,21}$";
const regEx = new RegExp(DsNamePattern);
return regEx.test(dsName);
}

0 comments on commit b831061

Please sign in to comment.