Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion packages/compass-components/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ export {
export type {
EdgeProps,
NodeProps,
FieldId,
DiagramInstance,
NodeField,
NodeGlyph,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ describe('DiagramCard', () => {
displayPosition: [0, 0],
shardKey: {},
jsonSchema: { bsonType: 'object' },
isExpanded: true,
},
],
relationships: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,13 @@ const storageItems: MongoDBDataModelDescription[] = [
displayPosition: [50, 50],
shardKey: {},
jsonSchema: { bsonType: 'object' },
isExpanded: true,
},
{
ns: 'db1.collection2',
indexes: [],
displayPosition: [150, 150],
shardKey: {},
jsonSchema: { bsonType: 'object' },
isExpanded: true,
},
],
relationships: [],
Expand All @@ -79,15 +77,13 @@ const storageItems: MongoDBDataModelDescription[] = [
displayPosition: [0, 0],
shardKey: {},
jsonSchema: { bsonType: 'object' },
isExpanded: true,
},
{
ns: 'db1.collection2',
indexes: [],
displayPosition: [0, 0],
shardKey: {},
jsonSchema: { bsonType: 'object' },
isExpanded: true,
},
],
relationships: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,8 @@ import {
createNewRelationship,
addCollection,
selectField,
toggleCollectionExpanded,
} from '../store/diagram';
import type {
EdgeProps,
NodeProps,
FieldId,
} from '@mongodb-js/compass-components';
import type { EdgeProps, NodeProps } from '@mongodb-js/compass-components';
import {
Banner,
CancelLoader,
Expand Down Expand Up @@ -152,7 +147,6 @@ const DiagramContent: React.FunctionComponent<{
}) => void;
onRelationshipDrawn: () => void;
DiagramComponent?: typeof Diagram;
onToggleCollectionExpanded: (namespace: string) => void;
}> = ({
diagramLabel,
database,
Expand All @@ -171,7 +165,6 @@ const DiagramContent: React.FunctionComponent<{
onRelationshipDrawn,
selectedItems,
DiagramComponent = Diagram,
onToggleCollectionExpanded,
}) => {
const isDarkMode = useDarkMode();
const diagram = useRef(useDiagram());
Expand Down Expand Up @@ -217,7 +210,6 @@ const DiagramContent: React.FunctionComponent<{
: undefined,
selected,
isInRelationshipDrawingMode,
isExpanded: coll.isExpanded,
});
});
}, [
Expand Down Expand Up @@ -300,24 +292,9 @@ const DiagramContent: React.FunctionComponent<{
);

const onFieldClick = useCallback(
(
_evt: React.MouseEvent,
{ id, nodeId: namespace }: { id: FieldId; nodeId: string }
) => {
// Diagramming package accepts both string ids and array of string ids for
// fields (to represent the field path better). While all current code in
// compass always uses array of strings as field id, some older saved
// diagrams might not. Also handling this explicitly is sort of needed
// anyway to convinve typescript that we're doing the right thing
const fieldPath = Array.isArray(id)
? id
: typeof id === 'string'
? [id]
: undefined;
if (!fieldPath) {
return;
}
(_evt: React.MouseEvent, { id: fieldPath, nodeId: namespace }) => {
_evt.stopPropagation(); // TODO(COMPASS-9659): should this be handled by the diagramming package?
if (!Array.isArray(fieldPath)) return; // TODO(COMPASS-9659): could be avoided with generics in the diagramming package
onFieldSelect(namespace, fieldPath);
openDrawer(DATA_MODELING_DRAWER_ID);
},
Expand Down Expand Up @@ -357,15 +334,6 @@ const DiagramContent: React.FunctionComponent<{
[onAddFieldToObjectField]
);

const handleNodeExpandedToggle = useCallback(
(evt: React.MouseEvent, nodeId: string) => {
evt.preventDefault();
evt.stopPropagation();
onToggleCollectionExpanded(nodeId);
},
[onToggleCollectionExpanded]
);

const diagramProps = useMemo(
() => ({
isDarkMode,
Expand All @@ -380,7 +348,6 @@ const DiagramContent: React.FunctionComponent<{
onFieldClick,
onNodeDragStop,
onConnect,
onNodeExpandToggle: handleNodeExpandedToggle,
}),
[
isDarkMode,
Expand All @@ -395,7 +362,6 @@ const DiagramContent: React.FunctionComponent<{
onFieldClick,
onNodeDragStop,
onConnect,
handleNodeExpandedToggle,
]
);

Expand Down Expand Up @@ -458,7 +424,6 @@ const ConnectedDiagramContent = connect(
onFieldSelect: selectField,
onDiagramBackgroundClicked: selectBackground,
onCreateNewRelationship: createNewRelationship,
onToggleCollectionExpanded: toggleCollectionExpanded,
}
)(DiagramContent);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ const storageItems: MongoDBDataModelDescription[] = [
displayPosition: [1, 1],
shardKey: {},
jsonSchema: { bsonType: 'object' },
isExpanded: true,
},
],
relationships: [],
Expand All @@ -57,7 +56,6 @@ const storageItems: MongoDBDataModelDescription[] = [
displayPosition: [2, 2],
shardKey: {},
jsonSchema: { bsonType: 'object' },
isExpanded: true,
},
],
relationships: [],
Expand All @@ -84,7 +82,6 @@ const storageItems: MongoDBDataModelDescription[] = [
displayPosition: [3, 3],
shardKey: {},
jsonSchema: { bsonType: 'object' },
isExpanded: true,
},
],
relationships: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ const CollectionSchema = z.object({
shardKey: z.record(z.unknown()).optional(),
displayPosition: z.tuple([z.number(), z.number()]),
note: z.string().optional(),
isExpanded: z.boolean().default(false),
});

export type DataModelCollection = z.output<typeof CollectionSchema>;
Expand Down Expand Up @@ -133,10 +132,6 @@ const EditSchemaVariants = z.discriminatedUnion('type', [
field: FieldPathSchema,
jsonSchema: z.custom<MongoDBJSONSchema>(),
}),
z.object({
type: z.literal('ToggleExpandCollection'),
ns: z.string(),
}),
]);

export const EditSchema = z.intersection(EditSchemaBase, EditSchemaVariants);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ async function getInitialLayout({
ns: coll.ns,
jsonSchema: coll.schema,
displayPosition: [0, 0],
isExpanded: false,
});
});
return await applyLayout({
Expand Down
15 changes: 0 additions & 15 deletions packages/compass-data-modeling/src/store/apply-edit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ export function applyEdit(edit: Edit, model?: StaticModel): StaticModel {
jsonSchema: edit.initialSchema,
displayPosition: edit.position,
indexes: [],
isExpanded: false,
};
return {
...model,
Expand Down Expand Up @@ -246,20 +245,6 @@ export function applyEdit(edit: Edit, model?: StaticModel): StaticModel {
}),
};
}
case 'ToggleExpandCollection': {
return {
...model,
collections: model.collections.map((collection) => {
if (collection.ns !== edit.ns) {
return collection;
}
return {
...collection,
isExpanded: !collection.isExpanded,
};
}),
};
}
default: {
return model;
}
Expand Down
5 changes: 0 additions & 5 deletions packages/compass-data-modeling/src/store/diagram.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,13 @@ const model: StaticModel = {
displayPosition: [0, 0],
shardKey: {},
jsonSchema: { bsonType: 'object' },
isExpanded: true,
},
{
ns: 'db.collection2',
indexes: [],
displayPosition: [1, 1],
shardKey: {},
jsonSchema: { bsonType: 'object' },
isExpanded: true,
},
],
relationships: [
Expand Down Expand Up @@ -150,7 +148,6 @@ describe('Data Modeling store', function () {
displayPosition: [0, 0],
shardKey: {},
jsonSchema: { bsonType: 'object' },
isExpanded: true,
},
] as StaticModel['collections'],
relationships: [] as StaticModel['relationships'],
Expand Down Expand Up @@ -437,7 +434,6 @@ describe('Data Modeling store', function () {
field3: { bsonType: 'int' },
},
},
isExpanded: true,
},
],
relationships: [],
Expand All @@ -464,7 +460,6 @@ describe('Data Modeling store', function () {
indexes: [],
displayPosition: [0, 0],
shardKey: {},
isExpanded: true,
jsonSchema: {
bsonType: 'object',
properties: {
Expand Down
18 changes: 2 additions & 16 deletions packages/compass-data-modeling/src/store/diagram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,9 @@ export const diagramReducer: Reducer<DiagramState> = (
collections: action.collections.map((collection) => ({
ns: collection.ns,
jsonSchema: collection.schema,
displayPosition: [
collection.position.x,
collection.position.y,
] as const,
displayPosition: [collection.position.x, collection.position.y],
indexes: [],
shardKey: undefined,
isExpanded: false,
})),
relationships: action.relations,
},
Expand Down Expand Up @@ -451,10 +447,6 @@ export function selectBackground(): DiagramBackgroundSelectedAction {
};
}

export function toggleCollectionExpanded(namespace: string) {
return applyEdit({ type: 'ToggleExpandCollection', ns: namespace });
}

export function createNewRelationship({
localNamespace,
foreignNamespace = null,
Expand Down Expand Up @@ -851,7 +843,6 @@ function getPositionForNewCollection(
ns: newCollection.ns,
jsonSchema: newCollection.jsonSchema,
displayPosition: [0, 0],
isExpanded: newCollection.isExpanded,
});
const xyposition = getCoordinatesForNewNode(existingNodes, newNode);
return [xyposition.x, xyposition.y];
Expand Down Expand Up @@ -884,17 +875,12 @@ export function addCollection(
const existingCollections = selectCurrentModelFromState(
getState()
).collections;

if (!ns) {
ns = getNameForNewCollection(existingCollections);
}

if (!ns) ns = getNameForNewCollection(existingCollections);
if (!position) {
position = getPositionForNewCollection(existingCollections, {
ns,
jsonSchema: {} as MongoDBJSONSchema,
indexes: [],
isExpanded: false,
});
}

Expand Down
Loading
Loading