-
Notifications
You must be signed in to change notification settings - Fork 892
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
[Data Explorer][Discover 2.0] restore single and surroundings doc view #4816
[Data Explorer][Discover 2.0] restore single and surroundings doc view #4816
Conversation
Codecov Report
@@ Coverage Diff @@
## feature/data-explorer #4816 +/- ##
=========================================================
- Coverage 66.50% 66.33% -0.17%
=========================================================
Files 3289 3396 +107
Lines 62821 64851 +2030
Branches 9788 10349 +561
=========================================================
+ Hits 41782 43022 +1240
- Misses 18658 19271 +613
- Partials 2381 2558 +177
Flags with carried forward coverage won't be shown. Click here to find out 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.
Most of the big changes look good. Just 3 callouts:
- Lets keep the
doc_view
anddoc_view_links
services where they were initially. The are used more outside of the context and view single doc vies anyways and are not actually components but services. - Can you move
doc_views_components
tocomponents/doc_views
? Having all components be in the same place is how we've had it so far. - The most important change is loading the legacy doc view URL's and context URL's correctly. And also only loading the new experience when the legacy discover is turned off for these two pages. See my comment on that for more details.
if (path.startsWith('#/context') || path.startsWith('#/doc')) { | ||
const { renderDocView } = await import('./application/doc_views_components'); | ||
const unmount = renderDocView(params.element); | ||
return () => { | ||
unmount(); | ||
}; | ||
} else if (!v2Enabled) { |
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 should only happen if the legacy app is turned off. You can move this to the else
condition since this view is only for the new discover pages.
Also use the migrateUrlState
function to migrate legacy context and single doc view URLs correctly to the new URL's
import { DocViewsRegistry } from './application/doc_views_components/doc_views/doc_views_registry'; | ||
import { DocViewsLinksRegistry } from './application/doc_views_components/doc_views_links/doc_views_links_registry'; |
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.
Do we need to move this? cant we keep all the components inside the components
folder? Thats a pattern we have followed so far.
@@ -14,7 +14,7 @@ import { search } from '../../../../../data/public'; | |||
import { validateTimeRange } from '../../helpers/validate_time_range'; | |||
import { updateSearchSource } from './update_search_source'; | |||
import { useIndexPattern } from './use_index_pattern'; | |||
import { OpenSearchSearchHit } from '../../doc_views/doc_views_types'; | |||
import { OpenSearchSearchHit } from '../../doc_view_components/doc_views/doc_views_types'; |
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.
Same here. I want to keep the diff as small as possible, so i'd like to avoid moving things unless its necessary.
@@ -19,7 +19,7 @@ import { | |||
} from '../../utils/state_management'; | |||
import { ResultStatus, SearchData } from '../utils/use_search'; | |||
import { IndexPatternField, opensearchFilters } from '../../../../../data/public'; | |||
import { DocViewFilterFn } from '../../doc_views/doc_views_types'; | |||
import { DocViewFilterFn } from '../../doc_views_components/doc_views/doc_views_types'; |
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.
Same here. I want to keep the diff as small as possible, so i'd like to avoid moving things unless its necessary.
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.
can we move this to components
?
const handleUrlClick = (url) => { | ||
// split the pathname into segments | ||
const urlSegments = window.location.href.split('/'); | ||
|
||
// find the index of the "data-explorer" segment | ||
const indexOfDataExplorerInUrl = urlSegments.indexOf('data-explorer'); | ||
|
||
// if "data-explorer" is found, remove it from the array | ||
if (indexOfDataExplorerInUrl !== -1) { | ||
urlSegments.splice(indexOfDataExplorerInUrl, 1); | ||
} | ||
|
||
// Create a new URL object from the current location | ||
const newUrl = urlSegments.join('/'); | ||
const updatedUrlSegments = newUrl.split('#'); | ||
updatedUrlSegments[1] = url; | ||
const updatedUrl = updatedUrlSegments.join(''); | ||
window.location.href = updatedUrl; | ||
}; |
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.
You dont need to do this. In src/plugins/discover/public/plugin.ts
the different docViewLinks are registered. There you can update the generateCb
function to create the URL you need.
| v | ||
| |* state | ||
| v | ||
| |* angular templates render state |
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.
You may want to do a quick update of this file. It still talks about the angular code.
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.
will update the whole file
if (typeof anchor !== 'object' || anchor === null || !size) { | ||
return []; | ||
} | ||
const timeField = indexPattern.timeFieldName!; |
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.
Wont this be undefined
if the indexPattern does not have a timeField
.
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 angular implimentation, this is called as timeField
in this function but sortField
in src/plugins/discover_legacy/public/application/angular/context/query/actions.js
. SortField makes sense since you likely wont always have a timeField
.
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 it is okay for now. For index pattern without a timeField, we only have view single doc
which won't use context fetch to re-fetch data.
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.
But the legacy app has view surrounding docs for index patterns without timestamps
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
* Any modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ |
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.
Cant this be the new license? looks like you have modified quite a bit here
import { Filter } from '../../../../../../../../src/plugins/data/public'; | ||
import { fetchAnchor } from '../api/anchor'; | ||
import { OpenSearchHitRecord, fetchSurroundingDocs } from '../api/context'; | ||
// import { MarkdownSimple, toMountPoint } from '../../../../../../opensearch_dashboards_react/public'; |
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.
Delete?
8563a6e
to
160ddad
Compare
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.
The change looks good to me. The two major changes are:
- The imports for
DocViewFilterFn
are incorrect, looks like you added an extra../
in most cases - I have a suggested fix for the breadcrumb issue, can you make the change?
const contextAppMemoized = useMemo( | ||
() => ( | ||
<ContextApp | ||
onAddFilter={onAddFilter as DocViewFilterFn} | ||
rows={rows} | ||
indexPattern={indexPattern} | ||
setAppState={setContextAppState} | ||
contextQueryState={contextQueryState} | ||
appState={contextAppState} | ||
/> | ||
), | ||
[onAddFilter, rows, indexPattern, setContextAppState, contextQueryState, contextAppState] | ||
); |
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.
nit: do we need this memoization?
// so we can use the saved legacy path in new discover | ||
case `doc`: | ||
case `context`: | ||
path = oldPath; |
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.
Have you tested this?
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.
Yes
const { | ||
services: { chrome, indexPatterns }, | ||
} = useOpenSearchDashboards<DiscoverServices>(); |
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 should fix the broken breadcrumb issue. You will need to do the same for the single doc view
const { | |
services: { chrome, indexPatterns }, | |
} = useOpenSearchDashboards<DiscoverServices>(); | |
const { | |
services: { | |
chrome, | |
indexPatterns, | |
core: { | |
application: { getUrlForApp }, | |
}, | |
}, | |
} = useOpenSearchDashboards<DiscoverServices>(); | |
const baseUrl = getUrlForApp(PLUGIN_ID); |
And then down below where you set the breadcrumbs you can do:
...getRootBreadcrumbs(baseUrl),
Then in src/plugins/discover/public/application/helpers/breadcrumbs.ts
update rootBreadcrumb as follows:
export function getRootBreadcrumbs(baseURL: string) {
return [
{
text: i18n.translate('discover.rootBreadcrumb', {
defaultMessage: 'Discover',
}),
href: baseURL,
},
];
}
@@ -12,9 +12,9 @@ import { DocViewExpandButton } from './data_grid_table_docview_expand_button'; | |||
import { DataGridFlyout } from './data_grid_table_flyout'; | |||
import { DiscoverGridContextProvider } from './data_grid_table_context'; | |||
import { toolbarVisibility } from './constants'; | |||
import { DocViewFilterFn } from '../../doc_views/doc_views_types'; | |||
import { DocViewFilterFn } from '../../../doc_views/doc_views_types'; |
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.
My linter is showing that these paths are wrong, can you look at it? Seems to be the case wherever you have updated this path
@ashwin-pc thanks for the review. I am double check all the import path and take the breadcrumb change. |
a3a041d
to
f381e0d
Compare
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.
LGTM :)
* add initial route logic to single/surroundings doc view and re-organize files * restore surrounding doc view comp * restore single doc view comp Signed-off-by: ananzh <ananzh@amazon.com>
f381e0d
to
6234ce5
Compare
The backport to
To backport manually, run these commands in your terminal: # Navigate to the root of your repository
cd $(git rev-parse --show-toplevel)
# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add ../.worktrees/OpenSearch-Dashboards/backport-2.x 2.x
# Navigate to the new working tree
pushd ../.worktrees/OpenSearch-Dashboards/backport-2.x
# Create a new branch
git switch --create backport/backport-4816-to-2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 4aa6d37b5ccee963c840ff9d1457e4265e4b4d96
# Push it to GitHub
git push --set-upstream origin backport/backport-4816-to-2.x
# Go back to the original working tree
popd
# Delete the working tree
git worktree remove ../.worktrees/OpenSearch-Dashboards/backport-2.x Then, create a pull request where the |
opensearch-project#4816) * add initial route logic to single/surroundings doc view and re-organize files * restore surrounding doc view comp * restore single doc view comp Signed-off-by: ananzh <ananzh@amazon.com> (cherry picked from commit 4aa6d37)
Description
Issues Resolved
#4231
#4230
Check List
yarn test:jest
yarn test:jest_integration
yarn test:ftr