-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
[NP] Inline buildPointSeriesData and buildHierarchicalData dependencies #61575
[NP] Inline buildPointSeriesData and buildHierarchicalData dependencies #61575
Conversation
@elasticmachine merge upstream |
*/ | ||
export function getAspects(table: Table, dimensions: Dimensions) { | ||
const aspects: Aspects = {} as Aspects; | ||
(Object.keys(dimensions) as Array<keyof Dimensions>).forEach(name => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we know Discover's dimensions
object exactly, I simplified all functions for Discover to get rid of unnecessary code.
} | ||
|
||
const { y } = chart.aspects; | ||
chart.yAxisLabel = y.length > 1 ? '' : y[0].title; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't initialize yAxisFormat
, since it isn't used in DiscoverHistogram component.
rawId: id, | ||
label: yLabel == null ? id : yLabel, | ||
count: 0, | ||
id: id.split('-').pop() as string, | ||
values: [point], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the component the values
is used only, so I removed all other fields.
}; | ||
} | ||
|
||
export interface Dimensions { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here I based on this config structure.
series: { accessor: group }, | ||
}; | ||
x: { accessor: x } as Dimension, | ||
y: [{ accessor: y } as Dimension], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -71,10 +107,9 @@ export function getPoint(table, x, series, yScale, row, rowIndex, y, z) { | |||
} | |||
|
|||
if (series) { | |||
const seriesArray = series.length ? series : [series]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
series
will be an array or undefined
const multiY = Array.isArray(aspects.y) && aspects.y.length > 1; | ||
const yScale = chart.yScale; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since chart
object is created in point_series
files and there is no initializing of yScale
, I removed all code related to yScale
|
||
if (firstVal) { | ||
y = _.find(aspects.y, function(y) { | ||
return y.accessor === firstVal.accessor; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here firstVal
is an object with type Point
, which doesn't have accessor
property. It means that y
will be undefined
and an iteratee function will always return series.length
=> there's no sense in sortBy
. That's why I removed this code.
@@ -28,12 +30,7 @@ export function initYAxis(chart) { | |||
|
|||
const z = chart.aspects.series; | |||
if (z) { | |||
if (Array.isArray(z)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
z
is always be an array.
export function getPoint( | ||
table: Table, | ||
x: Aspect, | ||
series: Aspect[] | undefined, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is yScale
gone?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested around and couldn't find any broken things (besides the thing already reported separately). I left a few comments about typings. I think there is still room for improval beyond my comments, but we don't have to be 100% accurate here IMHO - if the things I commented on are working fine it feels to me like it's in a good shape.
Great work on the tests!
return; | ||
} | ||
export interface Row { | ||
[key: string]: number | string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch! Thanks, I updated the PR.
intervalESValue: number; | ||
intervalESUnit: Unit; | ||
format: string; | ||
bounds?: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't bounds
always set in discover when there is a histogram?
Also, it seems like the actual type of this is a moment instance:
kibana/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/discover.js
Line 858 in c0a14cd
const bounds = agg.params.timeRange ? timefilter.calculateBounds(agg.params.timeRange) : null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems so. Please take a look at 10eca3f.
}; | ||
|
||
if (bounds) { | ||
chart.ordered.min = isNaN(bounds.min as number) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the types from the comments above are fixed, then these type casts should go away.
# Conflicts: # x-pack/plugins/translations/translations/ja-JP.json # x-pack/plugins/translations/translations/zh-CN.json
…ta/kibana into agg-response-cleanup
|
||
chart.yAxisLabel = table.columns[y.accessor].name; | ||
|
||
chart.values = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 nits: I am not sure why you're explicitly passing rowIndex
below? Also, what do you think about replacing the below lines with a bit more functional code?
chart.values = table.rows
.filter(row => (row && row[yAccessor] !== 'NaN')
.map(row=>({
x: row[xAccessor] as number,
y: row[yAccessor] as number,
}))
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch! thanks, I updated the PR.
if (!chart.values.length) { | ||
chart.values.push({} as any); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can easily remove this lines, by a modification of histogram.tsx
kibana/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/directives/histogram.tsx
Line 231 in 82e048a
const domainMin = data[0].x > domainStart ? domainStart : data[0].x; |
e.g. by using
const domainMin = data[0]?.x > domainStart ? domainStart : data[0]?.x;
you no longer need to push this empty object, and the histogram is displaying 'No data to display'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested and couldn't find any problems, LGTM I worked a bit on improving types (maryia-lapata#12), but I don't think another round of review is necessary after these are fixed.
}); | ||
|
||
it('properly formats series values', function() { | ||
const seriesAspect = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test isn't really testing whether the formatter gets applied correctly. Could you wrap the deserialize in the mock in a jest.fn
and verify whether it got called with the expected param?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
const aspects = {}; | ||
Object.keys(dimensions).forEach(name => { | ||
const dimension = Array.isArray(dimensions[name]) ? dimensions[name] : [dimensions[name]]; | ||
export function getAspects(table: Table, dimensions: Dimensions) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you change the types a little here you need less casting:
const aspects: Partial<Aspects> = {};
(Object.keys(dimensions) as Array<keyof Dimensions>).forEach(name => {
const dimension = dimensions[name];
const dimensionList = Array.isArray(dimension) ? dimension : [dimension];
dimensionList.forEach(d => {
if (!d) {
return;
}
const column = table.columns[d.accessor];
if (!column) {
return;
}
if (!aspects[name]) {
aspects[name] = [];
}
aspects[name]!.push({
accessor: column.id,
column: d.accessor,
title: column.name,
format: d.format,
params: d.params,
});
});
});
if (!aspects.x) {
aspects.x = [makeFakeXAspect()];
}
return aspects as Aspects;
@@ -62,7 +98,7 @@ export function getPoint(table, x, series, yScale, row, rowIndex, y, z) { | |||
title: table.$parent.name, | |||
}, | |||
parent: series ? series[0] : null, | |||
}; | |||
} as Point; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This cast hides some problems - looks like RowValue
could also be string
or object
. When you change linge 64 to const point: Point = {
, you see the places that don't match.
💛 Build succeeded, but was flaky
Test FailuresKibana Pipeline / kibana-xpack-agent / Chrome X-Pack UI Functional Tests.x-pack/test/functional/apps/canvas/custom_elements·ts.Canvas app custom elements deletes custom element when promptedStandard Out
Stack Trace
History
To update your PR or re-run it, just comment with: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code LGTM 👍 , tested locally with Chrome OS, MacOs 10.14.6, works, Дзякуй!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haven't tested, but went through the code and it LGTM! 💯
…chore/put-all-xjson-together * 'master' of github.com:elastic/kibana: [EPM] Update UI copy to use `integration` (elastic#63077) [NP] Inline buildPointSeriesData and buildHierarchicalData dependencies (elastic#61575) [Maps] create NOT EXISTS filter for tooltip property with no value (elastic#62849) [Endpoint] Add link to Logs UI to the Host Details view (elastic#62852) [UI COPY] Fixes typo in max_shingle_size for search_as_you_type (elastic#63071) [APM] docs: add alerting examples for APM (elastic#62864) [EPM] Change PACKAGES_SAVED_OBJECT_TYPE id (elastic#62818) docs: fix rendering of bulleted list (elastic#62855) Exposed AddMessageVariables as separate component (elastic#63007) Add Data - Adding cloud reset password link to cloud instructions (elastic#62835) [ML] DF Analytics: update memory estimate after adding exclude fields (elastic#62850) [Table Vis] Fix visualization overflow (elastic#62630) [Endpoint][EPM] Endpoint depending on ingest manager to initialize (elastic#62871) [Remote clusters] Fix flaky jest tests (elastic#58768) [Discover] Hide time picker when an indexpattern without timefield is selected (elastic#62134) Move search source parsing and serializing to data (elastic#59919) [ML] Functional tests - stabilize typing in mml input (elastic#63091) [data.search.aggs]: Clean up TimeBuckets implementation (elastic#62123) [ML] Functional transform tests - stabilize source selection (elastic#63087) add embed flag to saved object url as well (elastic#62926) # Conflicts: # x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/es_index.tsx
…es (#61575) (#63145) * Move buildHierarchicalData to vislib * Move shortened version of buildPointSeriesData to Discover * Move buildPointSeriesData to vis_type_vislib * Convert unit tests to jest * Remove ui/agg_response * Convert point_series files to TS * Update TS in unit tests * Convert buildHierarchicalData to TS * Convert buildPointSeriesData to TS in Discover * Clean TS in Discover * Update TS for buildHierarchicalData * Update buildHierarchicalData unit tests * Clean up TS in point_series * Add unit tests fro response_handler.js * Simplify point_series for Discover * Return array for data * Add check for empty row * Simplify point_series for Discover * Return all points * Specify TS * Refactoring * Simplifying * improve types * Update _get_point.test.ts Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> Co-authored-by: Joe Reuter <johannes.reuter@elastic.co> Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> Co-authored-by: Joe Reuter <johannes.reuter@elastic.co>
Summary
Fixes #60090.
This PR contains:
buildHierarchicalData
tovis_type_vislib
;buildPointSeriesData
tovis_type_vislib
;buildPointSeriesData
tovis_type_vislib
and converting them to Jest;buildPointSeriesData
todiscover
;ui/agg_response
;buildPointSeriesData
andbuildHierarchicalData
to TS;