Skip to content

Commit 48cc245

Browse files
committed
use memoized fn
1 parent 307a26c commit 48cc245

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

packages/compass-data-modeling/src/components/drawer/field-drawer-content.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ import { BSONType } from 'mongodb';
1313
import {
1414
createNewRelationship,
1515
deleteRelationship,
16-
extractFieldsFromSchema,
16+
getCurrentDiagramFromState,
1717
renameField,
18-
selectCurrentModelFromState,
18+
selectCurrentModel,
19+
selectFieldsForCurrentModel,
1920
selectRelationship,
2021
} from '../../store/diagram';
2122
import type { DataModelingState } from '../../store/reducer';
@@ -196,7 +197,8 @@ export default connect(
196197
state: DataModelingState,
197198
ownProps: { namespace: string; fieldPath: FieldPath }
198199
) => {
199-
const model = selectCurrentModelFromState(state);
200+
const diagram = getCurrentDiagramFromState(state);
201+
const model = selectCurrentModel(diagram.edits);
200202
const collectionSchema = model.collections.find(
201203
(collection) => collection.ns === ownProps.namespace
202204
)?.jsonSchema;
@@ -209,7 +211,9 @@ export default connect(
209211
jsonSchema: collectionSchema,
210212
fieldPath: ownProps.fieldPath,
211213
})?.fieldTypes ?? [],
212-
fieldPaths: extractFieldsFromSchema(collectionSchema),
214+
fieldPaths: selectFieldsForCurrentModel(diagram.edits)[
215+
ownProps.namespace
216+
],
213217
relationships: model.relationships.filter(({ relationship }) =>
214218
isRelationshipOfAField(
215219
relationship,

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -822,9 +822,7 @@ export const selectCurrentModelFromState = (state: DataModelingState) => {
822822
return selectCurrentModel(selectCurrentDiagramFromState(state).edits);
823823
};
824824

825-
export function extractFieldsFromSchema(
826-
parentSchema: MongoDBJSONSchema
827-
): FieldPath[] {
825+
function extractFieldsFromSchema(parentSchema: MongoDBJSONSchema): FieldPath[] {
828826
const fields: FieldPath[] = [];
829827
traverseSchema({
830828
jsonSchema: parentSchema,

0 commit comments

Comments
 (0)