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

Add: Validation for Policy Upload #634

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { styled } from '@mui/material/styles';
import { List, IconButton , Theme } from '@mui/material';
import Typography from '@mui/material/Typography';
import Box from '@mui/material/Box';
import { FormattedMessage } from 'react-intl';
import { FormattedMessage, useIntl } from 'react-intl';
import ListItem from '@mui/material/ListItem';
import ListItemAvatar from '@mui/material/ListItemAvatar';
import ListItemSecondaryAction from '@mui/material/ListItemSecondaryAction';
Expand All @@ -35,10 +35,11 @@ import clsx from 'clsx';
import Icon from '@mui/material/Icon';
import { HelpOutline } from '@mui/icons-material';
import { green, red } from '@mui/material/colors';

import APIMAlert from 'AppComponents/Shared/Alert';

const PREFIX = 'UploadPolicyDropzone';


const classes = {
dropZoneWrapper: `${PREFIX}-dropZoneWrapper`,
acceptDrop: `${PREFIX}-acceptDrop`,
Expand Down Expand Up @@ -102,10 +103,19 @@ const UploadPolicyDropzone: FC<UploadPolicyDropzoneProps> = ({
policyDefinitionFile,
setPolicyDefinitionFile,
}) => {

const intl = useIntl();

const handleDrop = (policyDefinition: any) => {
setPolicyDefinitionFile(policyDefinition);
if (policyDefinition && policyDefinition[0] &&
(policyDefinition[0].name.endsWith('.j2') ||
policyDefinition[0].name.endsWith('.xml'))) {
setPolicyDefinitionFile(policyDefinition);
return;
}
APIMAlert.error(intl.formatMessage({
id: 'Uploading.Policies.Error',
defaultMessage: 'Incompatible file type',
}));
};

const renderPolicyFileDropzone = () => {
Expand Down