import React from 'react';
import PropTypes from 'prop-types';
import { css, Banner, BannerVariant } from '@mongodb-js/compass-components';
import type { InsertCSFLEState } from '../stores/crud-store';
export type InsertCSFLEWarningBannerProps = {
csfleState: InsertCSFLEState;
};
const listStyles = css({ listStyle: 'inherit' });
function InsertCSFLEWarningBanner({
csfleState,
}: InsertCSFLEWarningBannerProps) {
let fieldsNotice = undefined;
if (csfleState.encryptedFields && csfleState.encryptedFields.length > 0) {
fieldsNotice = (
The following fields will be encrypted according to the collection
schema:
{csfleState.encryptedFields.map((fieldName) => (
- {fieldName}
))}
);
}
switch (csfleState.state) {
case 'none':
return <>>;
case 'no-known-schema':
return (
This insert operation will not encrypt any document fields because no
schema or In-Use Encryption configuration is associated with the
collection.
);
case 'incomplete-schema-for-cloned-doc':
return (
This insert operation will not encrypt all fields that were encrypted
in the original document due to a missing or incomplete schema for
this collection.
{fieldsNotice}
);
case 'has-known-schema':
return (
This insert operation will encrypt all fields that are specified in
the schema or In-Use Encryption configuration associated with the
collection.
{fieldsNotice}
);
case 'csfle-disabled':
return (
This insert operation will not encrypt any document fields because
In-Use Encryption support was explicitly disabled.
);
default:
throw new Error(
`Unknown CSFLE state ${csfleState.state as string} (Compass bug)`
);
}
}
(InsertCSFLEWarningBanner as any).displayName = 'InsertCSFLEWarningBanner';
(InsertCSFLEWarningBanner as any).propTypes = {
csfleState: PropTypes.object.isRequired,
};
export default InsertCSFLEWarningBanner;