Skip to content

Commit 5af678e

Browse files
committed
feat(compass-data-modeling): add info banner COMPASS-9773
1 parent 99c53c2 commit 5af678e

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}
@@ -108,6 +120,8 @@ type SelectedItems = NonNullable<DiagramState>['selectedItems'];
108120

109121
const DiagramContent: React.FunctionComponent<{
110122
diagramLabel: string;
123+
database: string | null;
124+
isNewlyCreatedDiagram?: boolean;
111125
model: StaticModel | null;
112126
isInRelationshipDrawingMode: boolean;
113127
editErrors?: string[];
@@ -129,6 +143,8 @@ const DiagramContent: React.FunctionComponent<{
129143
onRelationshipDrawn: () => void;
130144
}> = ({
131145
diagramLabel,
146+
database,
147+
isNewlyCreatedDiagram,
132148
model,
133149
isInRelationshipDrawingMode,
134150
newCollection,
@@ -146,6 +162,9 @@ const DiagramContent: React.FunctionComponent<{
146162
const diagram = useRef(useDiagram());
147163
const { openDrawer } = useDrawerActions();
148164
const { isDrawerOpen } = useDrawerState();
165+
const [showDataInfoBanner, setshowDataInfoBanner] = useState(
166+
isNewlyCreatedDiagram ?? false
167+
);
149168

150169
const setDiagramContainerRef = useCallback((ref: HTMLDivElement | null) => {
151170
if (ref) {
@@ -255,6 +274,20 @@ const DiagramContent: React.FunctionComponent<{
255274
data-testid="diagram-editor-container"
256275
>
257276
<div className={modelPreviewStyles} data-testid="model-preview">
277+
{showDataInfoBanner && (
278+
<Banner
279+
variant="info"
280+
dismissible
281+
onClose={() => setshowDataInfoBanner(false)}
282+
className={dataInfoBannerStyles}
283+
>
284+
<h4>Worried about your data?</h4>
285+
This diagram was generated based on a sample of documents from{' '}
286+
{database ?? 'a database'}. Changes made to the model here persist
287+
in the diagram for planning purposes only and will not impact your
288+
data.
289+
</Banner>
290+
)}
258291
<Diagram
259292
isDarkMode={isDarkMode}
260293
title={diagramLabel}
@@ -300,11 +333,16 @@ const DiagramContent: React.FunctionComponent<{
300333
const ConnectedDiagramContent = connect(
301334
(state: DataModelingState) => {
302335
const { diagram } = state;
336+
const model = diagram ? selectCurrentModelFromState(state) : null;
303337
return {
304-
model: diagram ? selectCurrentModelFromState(state) : null,
338+
model,
305339
diagramLabel: diagram?.name || 'Schema Preview',
306340
selectedItems: state.diagram?.selectedItems ?? null,
307341
newCollection: diagram?.draftCollection,
342+
isNewlyCreatedDiagram: diagram?.isNewlyCreated,
343+
database: model?.collections[0]?.ns
344+
? toNS(model.collections[0].ns).database
345+
: null, // TODO(COMPASS-9718): use diagram.database
308346
};
309347
},
310348
{

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)