import React from 'react';
import {
Icon,
Tooltip,
DropdownMenuButton,
css,
} from '@mongodb-js/compass-components';
import type { MenuAction } from '@mongodb-js/compass-components';
const tooltipContainerStyles = css({
display: 'flex',
alignItems: 'center',
});
type AddDataMenuProps = {
instanceDescription: string;
insertDataHandler: (openInsertKey: AddDataOption) => void;
isWritable: boolean;
};
function AddDataMenuButton({
insertDataHandler,
isDisabled = false,
}: {
insertDataHandler: (openInsertKey: AddDataOption) => void;
isDisabled?: boolean;
}) {
return (
data-testid="crud-add-data"
actions={addDataActions}
onAction={insertDataHandler}
buttonText="Add data"
buttonProps={{
size: 'xsmall',
variant: 'primary',
leftGlyph: ,
disabled: isDisabled,
}}
>
);
}
type AddDataOption = 'import-file' | 'insert-document';
const addDataActions: MenuAction[] = [
{ action: 'import-file', label: 'Import JSON or CSV file' },
{ action: 'insert-document', label: 'Insert document' },
];
const AddDataMenu: React.FunctionComponent = ({
instanceDescription,
insertDataHandler,
isWritable,
}) => {
if (isWritable) {
return ;
}
// When we're not writable return a disabled button with the instance
// description as a tooltip.
return (
) => (
)}
// Disable the tooltip when the instance is in a writable state.
isDisabled={isWritable}
justify="middle"
delay={500}
>
{instanceDescription}
);
};
export { AddDataMenu };