Skip to content

Commit

Permalink
Merge branch 'main' into feature/allow-special-keyword-characters
Browse files Browse the repository at this point in the history
  • Loading branch information
Alejandro Hernandez committed Apr 24, 2024
2 parents c7b2930 + 284ad0f commit 5cdeda6
Show file tree
Hide file tree
Showing 14 changed files with 55 additions and 14 deletions.
3 changes: 2 additions & 1 deletion packages/provider-elasticsearch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@
"homepage": "https://github.com/smartprocure/contexture/tree/main/packages/provider-elasticsearch",
"dependencies": {
"@elastic/datemath": "^2.3.0",
"contexture-util": "workspace:^",
"contexture-util": "^0.1.0",
"debug": "^4.3.1",
"escape-string-regexp": "^5.0.0",
"futil": "^1.76.4",
"js-combinatorics": "^2.1.1",
"lodash": "^4.17.4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import _ from 'lodash/fp.js'
import F from 'futil'
import { Permutation } from 'js-combinatorics'
import { stripLegacySubFields } from '../../utils/fields.js'
import { sanitizeTagInputs } from '../../utils/keywordGenerations.js'
import { sanitizeTagInputs } from 'contexture-util/keywordGenerations.js'
import { queryStringCharacterBlacklist } from 'contexture-util/exampleTypes/tagsQuery.js'
import escapeStringRegexp from 'escape-string-regexp'

let maxTagCount = 100

Expand All @@ -30,9 +31,14 @@ let addQuotesAndDistance = _.curry((tag, text) => {
return text + (tag.misspellings ? '~1' : '')
})

let replaceRegexp = new RegExp(
`[${escapeStringRegexp(queryStringCharacterBlacklist)}]`,
'g'
)

let replaceReservedChars = _.flow(
_.toString,
_.replace(new RegExp(`([${queryStringCharacterBlacklist}])`, 'g'), ' '),
_.replace(replaceRegexp, ' '),
// These characters are not stripped out by our analyzers but they are
// `query_string` reserved characters so we need to escape them.
_.replace(/([&+\-=:/])/g, '\\$1')
Expand Down Expand Up @@ -70,7 +76,7 @@ let limitResultsToCertainTags = _.find('onlyShowTheseResults')
let tagsToQueryString = (tags, join) =>
_.flow(
F.when(limitResultsToCertainTags, _.filter('onlyShowTheseResults')),
_.map(tagToQueryString),
F.compactMap(tagToQueryString),
joinTags(join)
)(tags)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ describe('tagsToQueryString', () => {
)
).toEqual('foo OR bar')
})
it('should ignore empty words', () => {
expect(
tagsToQueryString([{ word: 'foo' }, { word: '' }, { word: 'bar' }], 'any')
).toEqual('foo OR bar')
})
})

describe('hasValue', () => {
Expand Down
6 changes: 6 additions & 0 deletions packages/react/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 2.59.4

### Patch Changes

- f3e07ee0: Hide scrollbars from individual filters

## 2.59.3

### Patch Changes
Expand Down
5 changes: 3 additions & 2 deletions packages/react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "contexture-react",
"version": "2.59.3",
"version": "2.59.4",
"description": "React components for building contexture interfaces",
"type": "module",
"exports": {
Expand Down Expand Up @@ -68,7 +68,6 @@
"mobx": "^4.3.1",
"mobx-react": "^6.3.0",
"mobx-utils": "^5.0.0",
"moment": "^2.24.0",
"react": "^16.8.0",
"react-dom": "^16.8.0",
"react-select": "^2.0.0",
Expand All @@ -80,6 +79,8 @@
"dependencies": {
"@chakra-ui/react-use-outside-click": "^2.1.0",
"contexture": "^0.12.21",
"contexture-util": "0.1.0",
"escape-string-regexp": "^5.0.0",
"futil": "^1.76.4",
"lodash": "^4.17.15",
"moment": "^2.24.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
} from '../TagsQuery/utils.js'
import ActionsMenu from '../TagsQuery/ActionsMenu.js'
import { useOutsideClick } from '@chakra-ui/react-use-outside-click'
import { sanitizeTagInputs } from 'contexture-elasticsearch/utils/keywordGenerations.js'
import { sanitizeTagInputs } from 'contexture-util/keywordGenerations.js'
import KeywordGenerations from './KeywordGenerations.js'
import { sanitizeQueryStringTag } from '../../greyVest/utils.js'

Expand Down
7 changes: 7 additions & 0 deletions packages/react/src/greyVest/Style.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ export default () => (
overflow-y: auto;
max-height: 80vh;
transition: max-height .3s ease-in;
/* Gecko-based browsers */
scrollbar-width: none;
}
/* WebKit-based browsers */
.gv-expandable-body.expanded::-webkit-scrollbar {
display: none;
}
/* Table */
Expand Down
12 changes: 9 additions & 3 deletions packages/react/src/greyVest/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import _ from 'lodash/fp.js'
import F from 'futil'
import { queryStringCharacterBlacklist } from 'contexture-util/exampleTypes/tagsQuery.js'
import escapeStringRegexp from 'escape-string-regexp'

export let openBinding = (...lens) => ({
isOpen: F.view(...lens),
Expand All @@ -16,12 +18,15 @@ let maxCharsPerTagWord = 100
//
// If in doubt, make a request to the `/{index}/analyze` elasticsearch endpoint
// to see exactly which characters get stripped out of text.
let wordRegex = /[^|!(){}[\]^"~*?\\<>;,$']+/g
let wordRegexp = new RegExp(
`[^${escapeStringRegexp(queryStringCharacterBlacklist)}]+`,
'g'
)
let words = _.words.convert({ fixed: false })

// Convert string to words, take the first maxWordsPerTag, truncate them and convert back to string
export let sanitizeQueryStringTag = _.flow(
(string) => words(string, wordRegex),
(string) => words(string, wordRegexp),
_.take(maxWordsPerTag),
_.map((word) =>
_.flow(
Expand All @@ -48,5 +53,6 @@ export let createTags = ({ input, splitCommas, sanitizeTagFn }) =>
_.trim,
splitCommas ? splitTagOnComma : _.identity,
_.castArray,
sanitizeTagFn ? _.map(sanitizeTagFn) : _.identity
sanitizeTagFn ? _.map(sanitizeTagFn) : _.identity,
_.compact
)(input)
2 changes: 1 addition & 1 deletion packages/util/src/exampleTypes/tagsQuery.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// These are reserved characters in the context of an elastic `query_string`
// query that are unlikely to be searched for by an user.
// See https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html#_reserved_characters
let queryStringReserved = `|!(){}[\\]^"~*?\\<>`
let queryStringReserved = `|!(){}[]^"~*?\\<>`

// These are characters stripped out by our analyzers so there's no point in
// sending them.
Expand Down
Empty file removed packages/util/src/index.js
Empty file.
File renamed without changes.
1 change: 0 additions & 1 deletion scripts/esbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ await fs.rm('dist', { force: true, recursive: true })
let entryPoints = glob.sync('src/**/*.js', {
ignore: ['src/**/*.{test,stories}.js', 'src/**/{test,stories}/**/*'],
})
console.log(entryPoints)

// Build project

Expand Down
14 changes: 12 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7817,8 +7817,9 @@ __metadata:
"@elastic/elasticsearch": ^7.11.0
agentkeepalive: ^4.1.4
contexture: ^0.12.21
contexture-util: "workspace:^"
contexture-util: ^0.1.0
debug: ^4.3.1
escape-string-regexp: ^5.0.0
futil: ^1.76.4
js-combinatorics: ^2.1.1
json-stable-stringify: ^1.0.1
Expand Down Expand Up @@ -7897,8 +7898,10 @@ __metadata:
contexture: ^0.12.21
contexture-client: ^2.53.7
contexture-elasticsearch: ^1.27.3
contexture-util: 0.1.0
elasticsearch-browser: ^14.2.2
emoji-datasource: ^5.0.1
escape-string-regexp: ^5.0.0
eslint-plugin-react: ^7.32.0
eslint-plugin-storybook: ^0.6.14
futil: ^1.76.4
Expand Down Expand Up @@ -7931,7 +7934,7 @@ __metadata:
languageName: unknown
linkType: soft

"contexture-util@workspace:^, contexture-util@workspace:packages/util":
"contexture-util@0.1.0, contexture-util@^0.1.0, contexture-util@workspace:packages/util":
version: 0.0.0-use.local
resolution: "contexture-util@workspace:packages/util"
languageName: unknown
Expand Down Expand Up @@ -9192,6 +9195,13 @@ __metadata:
languageName: node
linkType: hard

"escape-string-regexp@npm:^5.0.0":
version: 5.0.0
resolution: "escape-string-regexp@npm:5.0.0"
checksum: 20daabe197f3cb198ec28546deebcf24b3dbb1a5a269184381b3116d12f0532e06007f4bc8da25669d6a7f8efb68db0758df4cd981f57bc5b57f521a3e12c59e
languageName: node
linkType: hard

"escodegen@npm:^2.1.0":
version: 2.1.0
resolution: "escodegen@npm:2.1.0"
Expand Down

0 comments on commit 5cdeda6

Please sign in to comment.