diff --git a/package-lock.json b/package-lock.json index 7e7d4802e50..9309353502e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,7 +15,7 @@ "@babel/core": "7.16.0", "@babel/parser": "7.16.0", "@mongodb-js/monorepo-tools": "^1.1.1", - "@mongodb-js/sbom-tools": "^0.5.3", + "@mongodb-js/sbom-tools": "^0.5.2", "@testing-library/dom": "^8.11.1", "babel-loader": "^7.1.5", "husky": "^8.0.3", @@ -44664,7 +44664,7 @@ "@mongodb-js/mocha-config-compass": "^1.3.1", "@mongodb-js/mongodb-downloader": "^0.2.1", "@mongodb-js/prettier-config-compass": "^1.0.1", - "@mongodb-js/sbom-tools": "^0.5.2", + "@mongodb-js/sbom-tools": "^0.5.3", "@mongodb-js/tsconfig-compass": "^1.0.3", "@mongodb-js/webpack-config-compass": "^1.2.0", "@types/analytics-node": "^3.1.11", @@ -44734,7 +44734,7 @@ "@mongodb-js/compass-user-data": "^0.1.2", "@mongodb-js/compass-utils": "^0.4.0", "@mongodb-js/explain-plan-helper": "^1.1.2", - "@mongodb-js/mongodb-constants": "^0.8.3", + "@mongodb-js/mongodb-constants": "^0.8.4", "@mongodb-js/mongodb-redux-common": "^2.0.11", "bson": "^6.0.0", "compass-preferences-model": "^2.14.0", @@ -44793,7 +44793,7 @@ "@mongodb-js/compass-user-data": "^0.1.2", "@mongodb-js/compass-utils": "^0.4.0", "@mongodb-js/explain-plan-helper": "^1.1.2", - "@mongodb-js/mongodb-constants": "^0.8.3", + "@mongodb-js/mongodb-constants": "^0.8.4", "@mongodb-js/mongodb-redux-common": "^2.0.11", "bson": "^6.0.0", "compass-preferences-model": "^2.14.0", @@ -44815,11 +44815,10 @@ } }, "packages/compass-aggregations/node_modules/@mongodb-js/mongodb-constants": { - "version": "0.8.3", - "resolved": "https://registry.npmjs.org/@mongodb-js/mongodb-constants/-/mongodb-constants-0.8.3.tgz", - "integrity": "sha512-OAqD4c17C7Hmw+k++qFtaJ+ASeECuXi12wZu4ezGxY6Ew47oEj8eGQjK13VSNTFU0L66+qcA/UQn8Hijk2CsZA==", + "version": "0.8.4", + "resolved": "https://registry.npmjs.org/@mongodb-js/mongodb-constants/-/mongodb-constants-0.8.4.tgz", + "integrity": "sha512-hi6f78pwdOqG8ZdZKRXZUq7oIC2y3CPwg1dyF3wOiFuDs5k3mgWoFb7ldiTFyRyEkRsyvp3ukP+CHDf+bGEUBA==", "dependencies": { - "dedent": "^1.5.1", "semver": "^7.5.4" } }, @@ -44837,19 +44836,6 @@ "node": ">=10" } }, - "packages/compass-aggregations/node_modules/dedent": { - "version": "1.5.1", - "resolved": "https://registry.npmjs.org/dedent/-/dedent-1.5.1.tgz", - "integrity": "sha512-+LxW+KLWxu3HW3M2w2ympwtqPrqYRzU8fqi6Fhd18fBALe15blJPI/I4+UHveMVG6lJqB4JNd4UG0S5cnVHwIg==", - "peerDependencies": { - "babel-plugin-macros": "^3.1.0" - }, - "peerDependenciesMeta": { - "babel-plugin-macros": { - "optional": true - } - } - }, "packages/compass-aggregations/node_modules/diff": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", @@ -45544,7 +45530,7 @@ "ps-list": "^8.1.0", "puppeteer": "^15.4.0", "resolve-mongodb-srv": "^1.1.2", - "semver": "^7.5.0", + "semver": "^7.5.4", "ts-node": "^10.9.1", "webdriverio": "^7.16.13", "xvfb-maybe": "^0.2.1" @@ -46358,7 +46344,7 @@ "@codemirror/view": "^6.7.1", "@lezer/highlight": "^1.1.3", "@mongodb-js/compass-components": "^1.14.0", - "@mongodb-js/mongodb-constants": "^0.8.3", + "@mongodb-js/mongodb-constants": "^0.8.4", "polished": "^4.2.2", "prettier": "^2.7.1" }, @@ -46384,27 +46370,13 @@ } }, "packages/compass-editor/node_modules/@mongodb-js/mongodb-constants": { - "version": "0.8.3", - "resolved": "https://registry.npmjs.org/@mongodb-js/mongodb-constants/-/mongodb-constants-0.8.3.tgz", - "integrity": "sha512-OAqD4c17C7Hmw+k++qFtaJ+ASeECuXi12wZu4ezGxY6Ew47oEj8eGQjK13VSNTFU0L66+qcA/UQn8Hijk2CsZA==", + "version": "0.8.4", + "resolved": "https://registry.npmjs.org/@mongodb-js/mongodb-constants/-/mongodb-constants-0.8.4.tgz", + "integrity": "sha512-hi6f78pwdOqG8ZdZKRXZUq7oIC2y3CPwg1dyF3wOiFuDs5k3mgWoFb7ldiTFyRyEkRsyvp3ukP+CHDf+bGEUBA==", "dependencies": { - "dedent": "^1.5.1", "semver": "^7.5.4" } }, - "packages/compass-editor/node_modules/dedent": { - "version": "1.5.1", - "resolved": "https://registry.npmjs.org/dedent/-/dedent-1.5.1.tgz", - "integrity": "sha512-+LxW+KLWxu3HW3M2w2ympwtqPrqYRzU8fqi6Fhd18fBALe15blJPI/I4+UHveMVG6lJqB4JNd4UG0S5cnVHwIg==", - "peerDependencies": { - "babel-plugin-macros": "^3.1.0" - }, - "peerDependenciesMeta": { - "babel-plugin-macros": { - "optional": true - } - } - }, "packages/compass-editor/node_modules/sinon": { "version": "9.2.4", "resolved": "https://registry.npmjs.org/sinon/-/sinon-9.2.4.tgz", @@ -46955,6 +46927,7 @@ "@mongodb-js/compass-components": "^1.14.0", "@mongodb-js/compass-editor": "^0.13.0", "@mongodb-js/compass-logging": "^1.2.0", + "@mongodb-js/mongodb-constants": "^0.8.4", "@mongodb-js/mongodb-redux-common": "^2.0.11", "bson": "^6.0.0", "compass-preferences-model": "^2.14.0" @@ -46995,12 +46968,35 @@ "@mongodb-js/compass-components": "^1.14.0", "@mongodb-js/compass-editor": "^0.13.0", "@mongodb-js/compass-logging": "^1.2.0", + "@mongodb-js/mongodb-constants": "^0.8.4", "@mongodb-js/mongodb-redux-common": "^2.0.11", "bson": "^6.0.0", "compass-preferences-model": "^2.14.0", "react": "^17.0.2" } }, + "packages/compass-indexes/node_modules/@mongodb-js/mongodb-constants": { + "version": "0.8.4", + "resolved": "https://registry.npmjs.org/@mongodb-js/mongodb-constants/-/mongodb-constants-0.8.4.tgz", + "integrity": "sha512-hi6f78pwdOqG8ZdZKRXZUq7oIC2y3CPwg1dyF3wOiFuDs5k3mgWoFb7ldiTFyRyEkRsyvp3ukP+CHDf+bGEUBA==", + "dependencies": { + "semver": "^7.5.4" + } + }, + "packages/compass-indexes/node_modules/@mongodb-js/mongodb-constants/node_modules/semver": { + "version": "7.5.4", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz", + "integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==", + "dependencies": { + "lru-cache": "^6.0.0" + }, + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, "packages/compass-indexes/node_modules/numeral": { "version": "2.0.6", "resolved": "https://registry.npmjs.org/numeral/-/numeral-2.0.6.tgz", @@ -47309,7 +47305,7 @@ "@mongodb-js/compass-editor": "^0.13.0", "@mongodb-js/compass-logging": "^1.2.0", "@mongodb-js/compass-user-data": "^0.1.2", - "@mongodb-js/mongodb-constants": "^0.8.3", + "@mongodb-js/mongodb-constants": "^0.8.4", "bson": "^6.0.0", "compass-preferences-model": "^2.14.0", "mongodb-query-util": "^2.1.0" @@ -47349,7 +47345,7 @@ "@mongodb-js/compass-editor": "^0.13.0", "@mongodb-js/compass-logging": "^1.2.0", "@mongodb-js/compass-user-data": "^0.1.2", - "@mongodb-js/mongodb-constants": "^0.8.3", + "@mongodb-js/mongodb-constants": "^0.8.4", "bson": "^6.0.0", "compass-preferences-model": "^2.14.0", "mongodb-query-util": "^2.1.0", @@ -47357,27 +47353,13 @@ } }, "packages/compass-query-bar/node_modules/@mongodb-js/mongodb-constants": { - "version": "0.8.3", - "resolved": "https://registry.npmjs.org/@mongodb-js/mongodb-constants/-/mongodb-constants-0.8.3.tgz", - "integrity": "sha512-OAqD4c17C7Hmw+k++qFtaJ+ASeECuXi12wZu4ezGxY6Ew47oEj8eGQjK13VSNTFU0L66+qcA/UQn8Hijk2CsZA==", + "version": "0.8.4", + "resolved": "https://registry.npmjs.org/@mongodb-js/mongodb-constants/-/mongodb-constants-0.8.4.tgz", + "integrity": "sha512-hi6f78pwdOqG8ZdZKRXZUq7oIC2y3CPwg1dyF3wOiFuDs5k3mgWoFb7ldiTFyRyEkRsyvp3ukP+CHDf+bGEUBA==", "dependencies": { - "dedent": "^1.5.1", "semver": "^7.5.4" } }, - "packages/compass-query-bar/node_modules/dedent": { - "version": "1.5.1", - "resolved": "https://registry.npmjs.org/dedent/-/dedent-1.5.1.tgz", - "integrity": "sha512-+LxW+KLWxu3HW3M2w2ympwtqPrqYRzU8fqi6Fhd18fBALe15blJPI/I4+UHveMVG6lJqB4JNd4UG0S5cnVHwIg==", - "peerDependencies": { - "babel-plugin-macros": "^3.1.0" - }, - "peerDependenciesMeta": { - "babel-plugin-macros": { - "optional": true - } - } - }, "packages/compass-query-bar/node_modules/diff": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", @@ -58794,7 +58776,7 @@ "@mongodb-js/eslint-config-compass": "^1.0.9", "@mongodb-js/explain-plan-helper": "^1.1.2", "@mongodb-js/mocha-config-compass": "^1.3.1", - "@mongodb-js/mongodb-constants": "^0.8.3", + "@mongodb-js/mongodb-constants": "^0.8.4", "@mongodb-js/mongodb-redux-common": "^2.0.11", "@mongodb-js/prettier-config-compass": "^1.0.1", "@mongodb-js/tsconfig-compass": "^1.0.3", @@ -58842,11 +58824,10 @@ "dev": true }, "@mongodb-js/mongodb-constants": { - "version": "0.8.3", - "resolved": "https://registry.npmjs.org/@mongodb-js/mongodb-constants/-/mongodb-constants-0.8.3.tgz", - "integrity": "sha512-OAqD4c17C7Hmw+k++qFtaJ+ASeECuXi12wZu4ezGxY6Ew47oEj8eGQjK13VSNTFU0L66+qcA/UQn8Hijk2CsZA==", + "version": "0.8.4", + "resolved": "https://registry.npmjs.org/@mongodb-js/mongodb-constants/-/mongodb-constants-0.8.4.tgz", + "integrity": "sha512-hi6f78pwdOqG8ZdZKRXZUq7oIC2y3CPwg1dyF3wOiFuDs5k3mgWoFb7ldiTFyRyEkRsyvp3ukP+CHDf+bGEUBA==", "requires": { - "dedent": "^1.5.1", "semver": "^7.5.4" }, "dependencies": { @@ -58860,11 +58841,6 @@ } } }, - "dedent": { - "version": "1.5.1", - "resolved": "https://registry.npmjs.org/dedent/-/dedent-1.5.1.tgz", - "integrity": "sha512-+LxW+KLWxu3HW3M2w2ympwtqPrqYRzU8fqi6Fhd18fBALe15blJPI/I4+UHveMVG6lJqB4JNd4UG0S5cnVHwIg==" - }, "diff": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", @@ -59485,7 +59461,7 @@ "@mongodb-js/compass-components": "^1.14.0", "@mongodb-js/eslint-config-compass": "^1.0.9", "@mongodb-js/mocha-config-compass": "^1.3.1", - "@mongodb-js/mongodb-constants": "^0.8.3", + "@mongodb-js/mongodb-constants": "^0.8.4", "@mongodb-js/prettier-config-compass": "^1.0.1", "@mongodb-js/tsconfig-compass": "^1.0.3", "@types/chai": "^4.2.21", @@ -59504,19 +59480,13 @@ }, "dependencies": { "@mongodb-js/mongodb-constants": { - "version": "0.8.3", - "resolved": "https://registry.npmjs.org/@mongodb-js/mongodb-constants/-/mongodb-constants-0.8.3.tgz", - "integrity": "sha512-OAqD4c17C7Hmw+k++qFtaJ+ASeECuXi12wZu4ezGxY6Ew47oEj8eGQjK13VSNTFU0L66+qcA/UQn8Hijk2CsZA==", + "version": "0.8.4", + "resolved": "https://registry.npmjs.org/@mongodb-js/mongodb-constants/-/mongodb-constants-0.8.4.tgz", + "integrity": "sha512-hi6f78pwdOqG8ZdZKRXZUq7oIC2y3CPwg1dyF3wOiFuDs5k3mgWoFb7ldiTFyRyEkRsyvp3ukP+CHDf+bGEUBA==", "requires": { - "dedent": "^1.5.1", "semver": "^7.5.4" } }, - "dedent": { - "version": "1.5.1", - "resolved": "https://registry.npmjs.org/dedent/-/dedent-1.5.1.tgz", - "integrity": "sha512-+LxW+KLWxu3HW3M2w2ympwtqPrqYRzU8fqi6Fhd18fBALe15blJPI/I4+UHveMVG6lJqB4JNd4UG0S5cnVHwIg==" - }, "sinon": { "version": "9.2.4", "resolved": "https://registry.npmjs.org/sinon/-/sinon-9.2.4.tgz", @@ -59960,6 +59930,7 @@ "@mongodb-js/compass-logging": "^1.2.0", "@mongodb-js/eslint-config-compass": "^1.0.9", "@mongodb-js/mocha-config-compass": "^1.3.1", + "@mongodb-js/mongodb-constants": "^0.8.4", "@mongodb-js/mongodb-redux-common": "^2.0.11", "@mongodb-js/prettier-config-compass": "^1.0.1", "@mongodb-js/tsconfig-compass": "^1.0.3", @@ -59993,6 +59964,24 @@ "xvfb-maybe": "^0.2.1" }, "dependencies": { + "@mongodb-js/mongodb-constants": { + "version": "0.8.4", + "resolved": "https://registry.npmjs.org/@mongodb-js/mongodb-constants/-/mongodb-constants-0.8.4.tgz", + "integrity": "sha512-hi6f78pwdOqG8ZdZKRXZUq7oIC2y3CPwg1dyF3wOiFuDs5k3mgWoFb7ldiTFyRyEkRsyvp3ukP+CHDf+bGEUBA==", + "requires": { + "semver": "^7.5.4" + }, + "dependencies": { + "semver": { + "version": "7.5.4", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz", + "integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==", + "requires": { + "lru-cache": "^6.0.0" + } + } + } + }, "numeral": { "version": "2.0.6", "resolved": "https://registry.npmjs.org/numeral/-/numeral-2.0.6.tgz", @@ -60163,7 +60152,7 @@ "@mongodb-js/compass-user-data": "^0.1.2", "@mongodb-js/eslint-config-compass": "^1.0.9", "@mongodb-js/mocha-config-compass": "^1.3.1", - "@mongodb-js/mongodb-constants": "^0.8.3", + "@mongodb-js/mongodb-constants": "^0.8.4", "@mongodb-js/prettier-config-compass": "^1.0.1", "@mongodb-js/tsconfig-compass": "^1.0.3", "@mongodb-js/webpack-config-compass": "^1.2.0", @@ -60195,19 +60184,13 @@ }, "dependencies": { "@mongodb-js/mongodb-constants": { - "version": "0.8.3", - "resolved": "https://registry.npmjs.org/@mongodb-js/mongodb-constants/-/mongodb-constants-0.8.3.tgz", - "integrity": "sha512-OAqD4c17C7Hmw+k++qFtaJ+ASeECuXi12wZu4ezGxY6Ew47oEj8eGQjK13VSNTFU0L66+qcA/UQn8Hijk2CsZA==", + "version": "0.8.4", + "resolved": "https://registry.npmjs.org/@mongodb-js/mongodb-constants/-/mongodb-constants-0.8.4.tgz", + "integrity": "sha512-hi6f78pwdOqG8ZdZKRXZUq7oIC2y3CPwg1dyF3wOiFuDs5k3mgWoFb7ldiTFyRyEkRsyvp3ukP+CHDf+bGEUBA==", "requires": { - "dedent": "^1.5.1", "semver": "^7.5.4" } }, - "dedent": { - "version": "1.5.1", - "resolved": "https://registry.npmjs.org/dedent/-/dedent-1.5.1.tgz", - "integrity": "sha512-+LxW+KLWxu3HW3M2w2ympwtqPrqYRzU8fqi6Fhd18fBALe15blJPI/I4+UHveMVG6lJqB4JNd4UG0S5cnVHwIg==" - }, "diff": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", @@ -73493,7 +73476,7 @@ "ps-list": "^8.1.0", "puppeteer": "^15.4.0", "resolve-mongodb-srv": "^1.1.2", - "semver": "^7.5.0", + "semver": "^7.5.4", "ts-node": "^10.9.1", "webdriverio": "^7.16.13", "xvfb-maybe": "^0.2.1" @@ -86418,7 +86401,7 @@ "@mongodb-js/mocha-config-compass": "^1.3.1", "@mongodb-js/mongodb-downloader": "^0.2.1", "@mongodb-js/prettier-config-compass": "^1.0.1", - "@mongodb-js/sbom-tools": "^0.5.2", + "@mongodb-js/sbom-tools": "^0.5.3", "@mongodb-js/tsconfig-compass": "^1.0.3", "@mongodb-js/webpack-config-compass": "^1.2.0", "@mongosh/node-runtime-worker-thread": "^2.0.0", diff --git a/package.json b/package.json index 010fba97d20..c559218ba6f 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,7 @@ "@babel/core": "7.16.0", "@babel/parser": "7.16.0", "@mongodb-js/monorepo-tools": "^1.1.1", - "@mongodb-js/sbom-tools": "^0.5.3", + "@mongodb-js/sbom-tools": "^0.5.2", "@testing-library/dom": "^8.11.1", "babel-loader": "^7.1.5", "husky": "^8.0.3", diff --git a/packages/compass-aggregations/package.json b/packages/compass-aggregations/package.json index 9d5d033dfc7..fcf106e08be 100644 --- a/packages/compass-aggregations/package.json +++ b/packages/compass-aggregations/package.json @@ -46,7 +46,7 @@ "@mongodb-js/compass-user-data": "^0.1.2", "@mongodb-js/compass-utils": "^0.4.0", "@mongodb-js/explain-plan-helper": "^1.1.2", - "@mongodb-js/mongodb-constants": "^0.8.3", + "@mongodb-js/mongodb-constants": "^0.8.4", "@mongodb-js/mongodb-redux-common": "^2.0.11", "bson": "^6.0.0", "compass-preferences-model": "^2.14.0", @@ -106,7 +106,7 @@ "@mongodb-js/compass-user-data": "^0.1.2", "@mongodb-js/compass-utils": "^0.4.0", "@mongodb-js/explain-plan-helper": "^1.1.2", - "@mongodb-js/mongodb-constants": "^0.8.3", + "@mongodb-js/mongodb-constants": "^0.8.4", "@mongodb-js/mongodb-redux-common": "^2.0.11", "bson": "^6.0.0", "compass-preferences-model": "^2.14.0", diff --git a/packages/compass-e2e-tests/package.json b/packages/compass-e2e-tests/package.json index 25f56f4ff77..211facf9d9e 100644 --- a/packages/compass-e2e-tests/package.json +++ b/packages/compass-e2e-tests/package.json @@ -63,7 +63,7 @@ "ps-list": "^8.1.0", "puppeteer": "^15.4.0", "resolve-mongodb-srv": "^1.1.2", - "semver": "^7.5.0", + "semver": "^7.5.4", "ts-node": "^10.9.1", "webdriverio": "^7.16.13", "xvfb-maybe": "^0.2.1" diff --git a/packages/compass-editor/package.json b/packages/compass-editor/package.json index 5d3a2d9667c..1cdfd88c40e 100644 --- a/packages/compass-editor/package.json +++ b/packages/compass-editor/package.json @@ -76,7 +76,7 @@ "@codemirror/view": "^6.7.1", "@lezer/highlight": "^1.1.3", "@mongodb-js/compass-components": "^1.14.0", - "@mongodb-js/mongodb-constants": "^0.8.3", + "@mongodb-js/mongodb-constants": "^0.8.4", "polished": "^4.2.2", "prettier": "^2.7.1" } diff --git a/packages/compass-indexes/package.json b/packages/compass-indexes/package.json index 2710c6d83a8..e658c6e7e99 100644 --- a/packages/compass-indexes/package.json +++ b/packages/compass-indexes/package.json @@ -60,6 +60,7 @@ "@mongodb-js/compass-editor": "^0.13.0", "@mongodb-js/compass-logging": "^1.2.0", "@mongodb-js/mongodb-redux-common": "^2.0.11", + "@mongodb-js/mongodb-constants": "^0.8.4", "bson": "^6.0.0", "compass-preferences-model": "^2.14.0", "react": "^17.0.2" @@ -74,6 +75,7 @@ "@testing-library/user-event": "^13.5.0", "chai": "^4.2.0", "depcheck": "^1.4.1", + "ejson-shell-parser": "^1.2.4", "electron": "^26.2.2", "enzyme": "^3.11.0", "eslint": "^7.25.0", @@ -93,14 +95,14 @@ "redux-thunk": "^2.4.1", "semver": "^5.4.1", "sinon": "^9.2.3", - "xvfb-maybe": "^0.2.1", - "ejson-shell-parser": "^1.2.4" + "xvfb-maybe": "^0.2.1" }, "dependencies": { "@mongodb-js/compass-components": "^1.14.0", "@mongodb-js/compass-editor": "^0.13.0", "@mongodb-js/compass-logging": "^1.2.0", "@mongodb-js/mongodb-redux-common": "^2.0.11", + "@mongodb-js/mongodb-constants": "^0.8.4", "bson": "^6.0.0", "compass-preferences-model": "^2.14.0" } diff --git a/packages/compass-indexes/src/components/search-index-template-dropdown/index.spec.tsx b/packages/compass-indexes/src/components/search-index-template-dropdown/index.spec.tsx new file mode 100644 index 00000000000..e640de7caaa --- /dev/null +++ b/packages/compass-indexes/src/components/search-index-template-dropdown/index.spec.tsx @@ -0,0 +1,48 @@ +import { ATLAS_SEARCH_TEMPLATES } from '@mongodb-js/mongodb-constants'; +import { expect } from 'chai'; +import { SearchIndexTemplateDropdown } from './'; +import sinon from 'sinon'; +import type { SinonSpy } from 'sinon'; + +import { render, screen, cleanup } from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; + +import React from 'react'; + +function templateNamed(name: string) { + return ATLAS_SEARCH_TEMPLATES.find((t) => t.name === name); +} + +describe('Search Index Template Dropdown', function () { + let onTemplateSpy: SinonSpy; + + beforeEach(function () { + onTemplateSpy = sinon.spy(); + + render( + + ); + }); + + afterEach(cleanup); + + it('notifies upwards with onTemplate when a new template is choosen', async function () { + const dropDown = screen + .getByText('Dynamic field mappings') + .closest('button')!; + + userEvent.click(dropDown); + + const staticFieldMappingOption = await screen.findByText( + 'Static field mappings' + ); + userEvent.click(staticFieldMappingOption); + + expect(onTemplateSpy).to.have.been.calledWith( + templateNamed('Static field mappings') + ); + }); +}); diff --git a/packages/compass-indexes/src/components/search-index-template-dropdown/index.tsx b/packages/compass-indexes/src/components/search-index-template-dropdown/index.tsx new file mode 100644 index 00000000000..eddb34ac846 --- /dev/null +++ b/packages/compass-indexes/src/components/search-index-template-dropdown/index.tsx @@ -0,0 +1,84 @@ +import { ATLAS_SEARCH_TEMPLATES } from '@mongodb-js/mongodb-constants'; +import type { SearchTemplate } from '@mongodb-js/mongodb-constants'; +import React, { useState, useCallback } from 'react'; +import { + Select, + Option, + Icon, + css, + Tooltip, +} from '@mongodb-js/compass-components'; + +const dropdownLabelStyles = css({ + display: 'flex', + pointerEvents: 'auto', // leafy green specifies none in the label, which is wrong +}); + +const fillParentStyles = css({ + flexGrow: 1, +}); + +type SearchIndexTemplateDropdownLabelProps = { + label: string; + tooltip: string; +}; + +const SearchIndexTemplateDropdownLabel: React.FunctionComponent< + SearchIndexTemplateDropdownLabelProps +> = ({ label, tooltip }) => ( +
+ {label} + ( +
+ + {children} +
+ )} + > + {tooltip} +
+
+); + +type SearchIndexTemplateDropdownProps = { + tooltip: string; + onTemplate: (template: SearchTemplate) => void; +}; + +export const SearchIndexTemplateDropdown: React.FunctionComponent< + SearchIndexTemplateDropdownProps +> = ({ tooltip, onTemplate }) => { + const [templateValue, setTemplateValue] = useState('0'); + + const onChooseTemplate = useCallback( + (value: string) => { + setTemplateValue(value); + onTemplate(ATLAS_SEARCH_TEMPLATES[+value]); + }, + [onTemplate] + ); + + return ( + + ); +}; diff --git a/packages/compass-indexes/src/components/search-indexes-modals/base-search-index-modal.spec.tsx b/packages/compass-indexes/src/components/search-indexes-modals/base-search-index-modal.spec.tsx index 2d1a24f7614..7e6e4569cfe 100644 --- a/packages/compass-indexes/src/components/search-indexes-modals/base-search-index-modal.spec.tsx +++ b/packages/compass-indexes/src/components/search-indexes-modals/base-search-index-modal.spec.tsx @@ -1,14 +1,25 @@ +import { ATLAS_SEARCH_TEMPLATES } from '@mongodb-js/mongodb-constants'; import { expect } from 'chai'; import { BaseSearchIndexModal } from './base-search-index-modal'; import sinon from 'sinon'; import type { SinonSpy } from 'sinon'; -import { render, screen, cleanup } from '@testing-library/react'; +import { render, screen, cleanup, waitFor } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import React from 'react'; import { getCodemirrorEditorValue } from '@mongodb-js/compass-editor'; +function normalizedTemplateNamed(name: string) { + const snippet = + ATLAS_SEARCH_TEMPLATES.find((t) => t.name === name)?.snippet || ''; + // code mirror 'changes' the template placeholders, so let's do the same + // this regexp removes `tab` markers to their default value, for example: + // ${1:default} => default + // + return snippet.replace(/\${\d+:([^}]+)}/gm, '$1'); +} + describe('Create Search Index Modal', function () { let onSubmitSpy: SinonSpy; let onCloseSpy: SinonSpy; @@ -88,4 +99,27 @@ describe('Create Search Index Modal', function () { expect(onSubmitSpy).to.have.been.calledOnceWithExactly('default', {}); }); }); + + describe('templates', function () { + it('replaces the contents of the index editor when a template is selected', async function () { + const dropDown = screen + .getByText('Dynamic field mappings') + .closest('button')!; + + userEvent.click(dropDown); + + const staticFieldMappingOption = await screen.findByText( + 'Static field mappings' + ); + userEvent.click(staticFieldMappingOption); + + await waitFor(() => { + const indexDef = getCodemirrorEditorValue('definition-of-search-index'); + + expect(indexDef).to.equal( + normalizedTemplateNamed('Static field mappings') + ); + }); + }); + }); }); diff --git a/packages/compass-indexes/src/components/search-indexes-modals/base-search-index-modal.tsx b/packages/compass-indexes/src/components/search-indexes-modals/base-search-index-modal.tsx index ef90a7ed0a9..f583a605acd 100644 --- a/packages/compass-indexes/src/components/search-indexes-modals/base-search-index-modal.tsx +++ b/packages/compass-indexes/src/components/search-indexes-modals/base-search-index-modal.tsx @@ -1,4 +1,4 @@ -import React, { useCallback, useEffect, useState } from 'react'; +import React, { useCallback, useEffect, useRef, useState } from 'react'; import { Modal, ModalFooter, @@ -16,11 +16,15 @@ import { ErrorSummary, Body, Banner, + rafraf, } from '@mongodb-js/compass-components'; import { CodemirrorMultilineEditor } from '@mongodb-js/compass-editor'; +import type { EditorRef } from '@mongodb-js/compass-editor'; import _parseShellBSON, { ParseMode } from 'ejson-shell-parser'; import type { Document } from 'mongodb'; import { useTrackOnChange } from '@mongodb-js/compass-logging'; +import { SearchIndexTemplateDropdown } from '../search-index-template-dropdown'; +import type { SearchTemplate } from '@mongodb-js/mongodb-constants'; // Copied from packages/compass-aggregations/src/modules/pipeline-builder/pipeline-parser/utils.ts function parseShellBSON(source: string): Document[] { @@ -36,10 +40,24 @@ function parseShellBSON(source: string): Document[] { const bodyStyles = css({ display: 'flex', flexDirection: 'column', - overflow: 'hidden', gap: spacing[3], }); +const templateToolbarStyles = css({ + display: 'flex', + flexDirection: 'row', + gap: spacing[3], + padding: spacing[1], +}); + +const templateToolbarTextDescriptionStyles = css({ + width: '60%', +}); + +const templateToolbarDropdownStyles = css({ + width: '40%', +}); + const formContainerStyles = css({ display: 'flex', flexDirection: 'column', @@ -80,6 +98,8 @@ export const BaseSearchIndexModal: React.FunctionComponent< onSubmit, onClose, }) => { + const editorRef = useRef(null); + const [indexName, setIndexName] = useState(initialIndexName); const [indexDefinition, setIndexDefinition] = useState( initialIndexDefinition @@ -141,6 +161,16 @@ export const BaseSearchIndexModal: React.FunctionComponent< onSubmit(indexName, indexDefinitionDoc); }, [onSubmit, parsingError, indexName, indexDefinition]); + const onChangeTemplate = useCallback( + (template: SearchTemplate) => { + rafraf(() => { + editorRef.current?.focus(); + editorRef.current?.applySnippet(template.snippet); + }); + }, + [editorRef] + ); + return ( )} -
- -
- {mode === 'create' && ( - - By default, search indexes will have the following search - configurations. You can refine this later. - - )} - - View Atlas Search tutorials{' '} - - - +
+
+ +
+ {mode === 'create' && ( + + By default, search indexes will have the following search + configurations. You can refine this later. + + )} + + View Atlas Search tutorials{' '} + + +
+
+ +
+ {parsingError && } {!parsingError && error && } diff --git a/packages/compass-query-bar/package.json b/packages/compass-query-bar/package.json index 20c9419d1d3..3b9e9b70313 100644 --- a/packages/compass-query-bar/package.json +++ b/packages/compass-query-bar/package.json @@ -61,7 +61,7 @@ "@mongodb-js/compass-editor": "^0.13.0", "@mongodb-js/compass-logging": "^1.2.0", "@mongodb-js/compass-user-data": "^0.1.2", - "@mongodb-js/mongodb-constants": "^0.8.3", + "@mongodb-js/mongodb-constants": "^0.8.4", "bson": "^6.0.0", "compass-preferences-model": "^2.14.0", "mongodb-query-util": "^2.1.0", @@ -102,7 +102,7 @@ "@mongodb-js/compass-editor": "^0.13.0", "@mongodb-js/compass-logging": "^1.2.0", "@mongodb-js/compass-user-data": "^0.1.2", - "@mongodb-js/mongodb-constants": "^0.8.3", + "@mongodb-js/mongodb-constants": "^0.8.4", "bson": "^6.0.0", "compass-preferences-model": "^2.14.0", "mongodb-query-util": "^2.1.0" diff --git a/packages/compass/package.json b/packages/compass/package.json index b64612cc2b7..35e5af608b2 100644 --- a/packages/compass/package.json +++ b/packages/compass/package.json @@ -212,7 +212,7 @@ "@mongodb-js/mocha-config-compass": "^1.3.1", "@mongodb-js/mongodb-downloader": "^0.2.1", "@mongodb-js/prettier-config-compass": "^1.0.1", - "@mongodb-js/sbom-tools": "^0.5.2", + "@mongodb-js/sbom-tools": "^0.5.3", "@mongodb-js/tsconfig-compass": "^1.0.3", "@mongodb-js/webpack-config-compass": "^1.2.0", "@types/analytics-node": "^3.1.11",