Skip to content

Commit 219a3b1

Browse files
committed
feat(compass-data-modeling): add info banner COMPASS-9773
1 parent f9c9b27 commit 219a3b1

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

packages/compass-data-modeling/src/components/diagram-editor.tsx

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import {
4747
getHighlightedFields,
4848
relationshipToDiagramEdge,
4949
} from '../utils/nodes-and-edges';
50+
import toNS from 'mongodb-ns';
5051

5152
const loadingContainerStyles = css({
5253
width: '100%',
@@ -57,14 +58,25 @@ const loaderStyles = css({
5758
margin: '0 auto',
5859
});
5960

60-
const bannerStyles = css({
61+
const errorBannerStyles = css({
6162
margin: spacing[200],
6263
'& > div': {
6364
display: 'flex',
6465
alignItems: 'center',
6566
},
6667
});
6768

69+
const dataInfoBannerStyles = css({
70+
margin: spacing[400],
71+
position: 'absolute',
72+
zIndex: 100,
73+
74+
h4: {
75+
marginTop: 0,
76+
marginBottom: 0,
77+
},
78+
});
79+
6880
const bannerButtonStyles = css({
6981
marginLeft: 'auto',
7082
});
@@ -73,7 +85,7 @@ const ErrorBannerWithRetry: React.FunctionComponent<{
7385
onRetryClick: () => void;
7486
}> = ({ children, onRetryClick }) => {
7587
return (
76-
<Banner variant="danger" className={bannerStyles}>
88+
<Banner variant="danger" className={errorBannerStyles}>
7789
<div>{children}</div>
7890
<Button
7991
className={bannerButtonStyles}
@@ -113,6 +125,8 @@ type SelectedItems = NonNullable<DiagramState>['selectedItems'];
113125

114126
const DiagramContent: React.FunctionComponent<{
115127
diagramLabel: string;
128+
database: string | null;
129+
isNewlyCreatedDiagram?: boolean;
116130
model: StaticModel | null;
117131
isInRelationshipDrawingMode: boolean;
118132
editErrors?: string[];
@@ -134,6 +148,8 @@ const DiagramContent: React.FunctionComponent<{
134148
onRelationshipDrawn: () => void;
135149
}> = ({
136150
diagramLabel,
151+
database,
152+
isNewlyCreatedDiagram,
137153
model,
138154
isInRelationshipDrawingMode,
139155
newCollection,
@@ -151,6 +167,9 @@ const DiagramContent: React.FunctionComponent<{
151167
const diagram = useRef(useDiagram());
152168
const { openDrawer } = useDrawerActions();
153169
const { isDrawerOpen } = useDrawerState();
170+
const [showDataInfoBanner, setshowDataInfoBanner] = useState(
171+
isNewlyCreatedDiagram ?? false
172+
);
154173

155174
const setDiagramContainerRef = useCallback((ref: HTMLDivElement | null) => {
156175
if (ref) {
@@ -307,6 +326,20 @@ const DiagramContent: React.FunctionComponent<{
307326
data-testid="diagram-editor-container"
308327
>
309328
<div className={modelPreviewStyles} data-testid="model-preview">
329+
{showDataInfoBanner && (
330+
<Banner
331+
variant="info"
332+
dismissible
333+
onClose={() => setshowDataInfoBanner(false)}
334+
className={dataInfoBannerStyles}
335+
>
336+
<h4>Worried about your data?</h4>
337+
This diagram was generated based on a sample of documents from{' '}
338+
{database ?? 'a database'}. Changes made to the model here persist
339+
in the diagram for planning purposes only and will not impact your
340+
data.
341+
</Banner>
342+
)}
310343
<Diagram
311344
isDarkMode={isDarkMode}
312345
title={diagramLabel}
@@ -331,11 +364,16 @@ const DiagramContent: React.FunctionComponent<{
331364
const ConnectedDiagramContent = connect(
332365
(state: DataModelingState) => {
333366
const { diagram } = state;
367+
const model = diagram ? selectCurrentModelFromState(state) : null;
334368
return {
335-
model: diagram ? selectCurrentModelFromState(state) : null,
369+
model,
336370
diagramLabel: diagram?.name || 'Schema Preview',
337371
selectedItems: state.diagram?.selectedItems ?? null,
338372
newCollection: diagram?.draftCollection,
373+
isNewlyCreatedDiagram: diagram?.isNewlyCreated,
374+
database: model?.collections[0]?.ns
375+
? toNS(model.collections[0].ns).database
376+
: null, // TODO(COMPASS-9718): use diagram.database
339377
};
340378
},
341379
{

packages/compass-data-modeling/src/store/diagram.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export type DiagramState =
6161
};
6262
editErrors?: string[];
6363
selectedItems: SelectedItems | null;
64+
isNewlyCreated: boolean;
6465
draftCollection?: string;
6566
})
6667
| null; // null when no diagram is currently open
@@ -159,6 +160,7 @@ export const diagramReducer: Reducer<DiagramState> = (
159160
prev.shift(); // Remove the first item, which is initial SetModel and there's no previous edit for it.
160161
return {
161162
...action.diagram,
163+
isNewlyCreated: false,
162164
edits: {
163165
prev,
164166
current,
@@ -171,6 +173,7 @@ export const diagramReducer: Reducer<DiagramState> = (
171173
if (isAction(action, AnalysisProcessActionTypes.ANALYSIS_FINISHED)) {
172174
return {
173175
id: new UUID().toString(),
176+
isNewlyCreated: true,
174177
name: action.name,
175178
connectionId: action.connectionId,
176179
createdAt: new Date().toISOString(),

0 commit comments

Comments
 (0)