Skip to content

Commit 1f2d29f

Browse files
authored
chore(import-export, schema, field-store): update mongodb-schema, use schema paths helper COMPASS-6720 (#4401)
This updates our mongodb-schema dependency in Compass. Updating to the new version involves a few changes: - Schema field paths now use string arrays instead of dot separated strings. This will make it easier for us to handle cases like dots in field names (previously we would join and split on dots). - Better schema type definitions are now exported from mongodb-schema. This involved some changes in compass-schema and compass-import-export as we were supporting our own types. - Removed the getSchemaPaths function from compass-import-export and updated to use the one from the mongodb-schema package,. - Removed the unused dimensionality and nestedFields properties and calculations in compass-field-store. (could be separated to another pr if preferred). - In compass-field-store renamed the aceFields flattened map used for editor field autocompletion to autocompleteFields to be more generic as we are using this in code-mirror and no longer have ace. (could be separated to another pr if preferred). - Updated schema property variable names, has_duplicates, average_length, and total_count, are now camelCase. When integrating changes in compass-schema there were updates needed in the telemetry methods, schemaContainsGeoData and calculateSchemaDepth. I ended up refactoring both and hopefully simplifying calculateSchemaDepth a bit, it looks like it might fix a recent error we had. Moved them off the store. Updated tests to be easier to maintain. We could consider moving the calculateSchemaDepth into mongodb-schema, but that's not included in these changes. I'm thinking this should fix COMPASS-6809
1 parent 55370d8 commit 1f2d29f

File tree

29 files changed

+837
-1140
lines changed

29 files changed

+837
-1140
lines changed

package-lock.json

Lines changed: 136 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/compass-aggregations/src/stores/store.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,19 +185,19 @@ describe('Aggregation Store', function () {
185185
fields: {
186186
harry: {
187187
name: 'harry',
188-
path: 'harry',
188+
path: ['harry'],
189189
count: 1,
190190
type: 'Number',
191191
},
192192
potter: {
193193
name: 'potter',
194-
path: 'potter',
194+
path: ['potter'],
195195
count: 1,
196196
type: 'Boolean',
197197
},
198198
},
199199
topLevelFields: ['harry', 'potter'],
200-
aceFields: [
200+
autocompleteFields: [
201201
{
202202
name: 'harry',
203203
value: 'harry',

packages/compass-aggregations/src/stores/store.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ const configureStore = (options: ConfigureStoreOptions) => {
242242
* @param {Object} fields - The fields.
243243
*/
244244
localAppRegistry.on('fields-changed', (fields) => {
245-
store.dispatch(fieldsChanged(fields.aceFields));
245+
store.dispatch(fieldsChanged(fields.autocompleteFields));
246246
});
247247

248248
localAppRegistry.on('indexes-changed', (indexes: IndexInfo[]) => {

packages/compass-crud/src/stores/crud-store.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,10 @@ class CrudStoreImpl
350350
this.listenables = options.actions as any; // TODO: The types genuinely mismatch here
351351
}
352352

353-
updateFields(fields: { aceFields: { name: string }[] }) {
354-
this.setState({ fields: fields.aceFields.map((field) => field.name) });
353+
updateFields(fields: { autocompleteFields: { name: string }[] }) {
354+
this.setState({
355+
fields: fields.autocompleteFields.map((field) => field.name),
356+
});
355357
}
356358

357359
getInitialState(): CrudState {

packages/compass-field-store/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
"hadron-app-registry": "^9.0.6",
7070
"lodash": "^4.17.21",
7171
"mocha": "^10.2.0",
72-
"mongodb-schema": "^10.0.2",
72+
"mongodb-schema": "^11.1.0",
7373
"nyc": "^15.1.0",
7474
"prettier": "^2.7.1",
7575
"redux": "^4.2.1",

packages/compass-field-store/src/modules/index.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export const CHANGE_FIELDS = 'field-store/CHANGE_FIELDS';
1111
export const INITIAL_STATE = {
1212
fields: {},
1313
topLevelFields: [],
14-
aceFields: [],
14+
autocompleteFields: [],
1515
};
1616

1717
/**
@@ -27,7 +27,7 @@ const reducer = (state = INITIAL_STATE, action) => {
2727
return {
2828
fields: action.fields,
2929
topLevelFields: action.topLevelFields,
30-
aceFields: action.aceFields,
30+
autocompleteFields: action.autocompleteFields,
3131
};
3232
}
3333
if (action.type === RESET) {
@@ -41,15 +41,15 @@ const reducer = (state = INITIAL_STATE, action) => {
4141
*
4242
* @param {Object} fields - The fields.
4343
* @param {Object} topLevelFields - The top level fields.
44-
* @param {Object} aceFields - The ace fields.
44+
* @param {Object} autocompleteFields - Map of flattened field paths to field auto completion info.
4545
*
4646
* @returns {Object} The action.
4747
*/
48-
export const changeFields = (fields, topLevelFields, aceFields) => ({
48+
export const changeFields = (fields, topLevelFields, autocompleteFields) => ({
4949
type: CHANGE_FIELDS,
50-
fields: fields,
51-
topLevelFields: topLevelFields,
52-
aceFields: aceFields,
50+
fields,
51+
topLevelFields,
52+
autocompleteFields,
5353
});
5454

5555
export default reducer;

0 commit comments

Comments
 (0)