Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GS-7591] Add new Step Slider component #250

Merged
merged 15 commits into from
Aug 19, 2024
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
7 changes: 7 additions & 0 deletions .changeset/early-lies-share.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'contexture-elasticsearch': minor
'contexture-client': minor
'contexture-react': minor
---

New type Step Slider type added
4 changes: 2 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"extends": ["eslint:recommended", "plugin:import/recommended"],
"ignorePatterns": ["dist", "node_modules", "*.ts"],
"ignorePatterns": ["dist", "node_modules"],
"parserOptions": {
"ecmaVersion": "2022",
"sourceType": "module"
Expand All @@ -16,7 +16,7 @@
"settings": {
"import/resolver": {
"typescript": {
"extensions": [".js", ".jsx"]
"extensions": [".ts", ".tsx", ".js", ".jsx"]
}
}
}
Expand Down
14 changes: 14 additions & 0 deletions packages/client/src/exampleTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,20 @@ export default F.stampKey('type', {
max: null,
},
},
step: {
label: 'Number Slider',
reactors: {
range: 'all',
},
defaults: {
field: null,
range: [0, 1000],
steps: [0, 1000, 5000, 10000, 25000, 50000, 1000000],
context: {
recordsCount: 0,
},
},
},
bool: {
validate: validateValueExistence,
reactors: {
Expand Down
53 changes: 53 additions & 0 deletions packages/provider-elasticsearch/src/example-types/filters/step.js
JBezerra marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import _ from 'lodash/fp.js'
import { pickSafeNumbers } from '../../utils/futil.js'

const getMinAndMax = (range) => {
const min = range[0]
const max = range[range.length - 1]
return { min, max }
}

const isValueMaxOnSteps = (value, steps) => {
const max = steps[steps.length - 1]
return value === max
}

let filter = ({ field, range, steps }) => {
JBezerra marked this conversation as resolved.
Show resolved Hide resolved
const { min, max } = getMinAndMax(range)

/** In the last step, we do not filter by the upper bound */
if (isValueMaxOnSteps(max, steps)) {
return {
range: { [field]: pickSafeNumbers({ gte: min }) },
}
}

return {
range: { [field]: pickSafeNumbers({ gte: min, lte: max }) },
}
}

let buildQuery = (field, range, steps) => {
return {
aggs: {
rangeFilter: {
filter: filter({ field, range, steps }),
},
},
}
}

let result = async (node, search) => {
let { field, range, steps } = node
const result = await search(buildQuery(field, range, steps))
const recordsCount = result.aggregations.rangeFilter.doc_count
return { recordsCount }
}

export default {
hasValue: ({ range }) => !_.isEmpty(range),
filter,
validContext: ({ range }) => !_.isEmpty(range),
result,
buildQuery,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import step from './step.js'

const { hasValue, filter, buildQuery } = step

describe('step', () => {
const input = {
type: 'step',
field: 'test',
range: [0, 500],
steps: [0, 500, 1000],
}

it('checks if range is present and not empty', () => {
let inputWithoutRange = { type: 'step', field: 'test' }
expect(!!hasValue(input)).toBe(true)
expect(!!hasValue(inputWithoutRange)).toBe(false)
})

it('returns proper elastic query', () => {
let expectedValue = { range: { test: { gte: 0, lte: 500 } } }
expect(filter(input)).toEqual(expectedValue)
})

it('removes upper bound when range is last step', () => {
const inputWithNewRange = {
...input,
range: [0, 1000],
}
let expectedValue = { range: { test: { gte: 0 } } }
expect(filter(inputWithNewRange)).toEqual(expectedValue)
})

it('returns proper elastic DSL', async () => {
let expectedDSL = {
aggs: {
rangeFilter: {
filter: { range: { test: { gte: 0, lte: 500 } } },
},
},
}
let output = buildQuery(input.field, input.range, input.steps)
expect(output).toEqual(expectedDSL)
})
})
2 changes: 2 additions & 0 deletions packages/provider-elasticsearch/src/example-types/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import tagsQuery from './filters/tagsQuery.js'
// Combo Filter + Results
import facet from './filters/facet.js'
import number from './filters/number.js'
import step from './filters/step.js'
import dateRangeFacet from './filters/dateRangeFacet.js'

// Single Metrics
Expand Down Expand Up @@ -48,6 +49,7 @@ export {
tagsQuery,
facet,
number,
step,
dateRangeFacet,
results,
stats,
Expand Down
1 change: 1 addition & 0 deletions packages/provider-elasticsearch/src/types.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ describe('All Example Types', () => {
'smartIntervalHistogram',
'statistical',
'stats',
'step',
'tagsQuery',
'tagsQueryGroupStats',
'tagsText',
Expand Down
17 changes: 0 additions & 17 deletions packages/react/.babelrc.json

This file was deleted.

7 changes: 7 additions & 0 deletions packages/react/.storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ export default {
titlePrefix: 'Live Demos/Index Explorer',
},
],
features: { emotionAlias: false },
refs: {
// https://github.com/storybookjs/storybook/discussions/18821
'@chakra-ui/react': {
disable: true, // 👈 chakra stories disabled here
},
},
}

function getAbsolutePath(value) {
Expand Down
9 changes: 6 additions & 3 deletions packages/react/.storybook/preview.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { base, greyVest } from '../src/themes/index.js'
import Fonts from '../src/greyVest/Fonts.js'
import Style from '../src/greyVest/Style.js'
import { ThemeProvider } from '../src/utils/theme.js'
import { ChakraProvider } from '@chakra-ui/react'

configure({ enforceActions: 'never', useProxies: 'never' })

Expand All @@ -19,9 +20,11 @@ export const parameters = {
export const decorators = [
(Story) => (
<ThemeProvider theme={{ ...base, ...greyVest }}>
<Fonts />
<Style />
<Story />
<ChakraProvider>
<Fonts />
<Style />
<Story />
</ChakraProvider>
</ThemeProvider>
),
]
18 changes: 18 additions & 0 deletions packages/react/babel.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = {
sourceType: 'unambiguous',
presets: [
[
'@babel/preset-env',
{
targets: {
chrome: 100,
safari: 15,
firefox: 91,
},
},
],
'@babel/preset-react',
'@babel/preset-typescript',
],
plugins: [],
}
Loading