Skip to content

Commit

Permalink
[8.x] [Search Playground] Change route on selector changed in between…
Browse files Browse the repository at this point in the history
… search/chat modes (#197431) (#199635)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Search Playground] Change route on selector changed in between
search/chat modes
(#197431)](#197431)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Efe Gürkan
YALAMAN","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-11-11T12:18:54Z","message":"[Search
Playground] Change route on selector changed in between search/chat
modes (#197431)\n\n## Summary\r\n\r\nChanges the route when Search/Chat
is changed. It was the intended\r\nbehaviour. Missed during the
implementation\r\n\r\n\r\n### Checklist\r\n\r\nDelete any items that are
not applicable to this PR.\r\n\r\n- [ ] Any text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [ ] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests changed\r\n- [x] Any UI touched in this PR is
usable by keyboard only (learn more\r\nabout [keyboard
accessibility](https://webaim.org/techniques/keyboard/))\r\n- [x] Any UI
touched in this PR does not create any new axe failures\r\n(run axe in
browser:\r\n[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),\r\n[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))\r\n-
[ ] If a plugin configuration key changed, check if it needs to
be\r\nallowlisted in the cloud and added to the
[docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n-
[x] This renders correctly on smaller devices using a
responsive\r\nlayout. (You can test this [in
your\r\nbrowser](https://www.browserstack.com/guide/responsive-testing-on-local-server))\r\n-
[x] This was checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<[email protected]>\r\nCo-authored-by:
Elastic Machine
<[email protected]>","sha":"961796d65d49d2ccc649f8dc4d71f0f5da7def48","branchLabelMapping":{"^v9.0.0$":"main","^v8.17.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","backport:version","v8.17.0","v8.16.1"],"title":"[Search
Playground] Change route on selector changed in between search/chat
modes","number":197431,"url":"https://github.com/elastic/kibana/pull/197431","mergeCommit":{"message":"[Search
Playground] Change route on selector changed in between search/chat
modes (#197431)\n\n## Summary\r\n\r\nChanges the route when Search/Chat
is changed. It was the intended\r\nbehaviour. Missed during the
implementation\r\n\r\n\r\n### Checklist\r\n\r\nDelete any items that are
not applicable to this PR.\r\n\r\n- [ ] Any text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [ ] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests changed\r\n- [x] Any UI touched in this PR is
usable by keyboard only (learn more\r\nabout [keyboard
accessibility](https://webaim.org/techniques/keyboard/))\r\n- [x] Any UI
touched in this PR does not create any new axe failures\r\n(run axe in
browser:\r\n[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),\r\n[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))\r\n-
[ ] If a plugin configuration key changed, check if it needs to
be\r\nallowlisted in the cloud and added to the
[docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n-
[x] This renders correctly on smaller devices using a
responsive\r\nlayout. (You can test this [in
your\r\nbrowser](https://www.browserstack.com/guide/responsive-testing-on-local-server))\r\n-
[x] This was checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<[email protected]>\r\nCo-authored-by:
Elastic Machine
<[email protected]>","sha":"961796d65d49d2ccc649f8dc4d71f0f5da7def48"}},"sourceBranch":"main","suggestedTargetBranches":["8.x","8.16"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/197431","number":197431,"mergeCommit":{"message":"[Search
Playground] Change route on selector changed in between search/chat
modes (#197431)\n\n## Summary\r\n\r\nChanges the route when Search/Chat
is changed. It was the intended\r\nbehaviour. Missed during the
implementation\r\n\r\n\r\n### Checklist\r\n\r\nDelete any items that are
not applicable to this PR.\r\n\r\n- [ ] Any text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [ ] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests changed\r\n- [x] Any UI touched in this PR is
usable by keyboard only (learn more\r\nabout [keyboard
accessibility](https://webaim.org/techniques/keyboard/))\r\n- [x] Any UI
touched in this PR does not create any new axe failures\r\n(run axe in
browser:\r\n[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),\r\n[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))\r\n-
[ ] If a plugin configuration key changed, check if it needs to
be\r\nallowlisted in the cloud and added to the
[docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n-
[x] This renders correctly on smaller devices using a
responsive\r\nlayout. (You can test this [in
your\r\nbrowser](https://www.browserstack.com/guide/responsive-testing-on-local-server))\r\n-
[x] This was checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<[email protected]>\r\nCo-authored-by:
Elastic Machine
<[email protected]>","sha":"961796d65d49d2ccc649f8dc4d71f0f5da7def48"}},{"branch":"8.x","label":"v8.17.0","branchLabelMappingKey":"^v8.17.0$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.16","label":"v8.16.1","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Efe Gürkan YALAMAN <[email protected]>
  • Loading branch information
kibanamachine and efegurkan authored Nov 11, 2024
1 parent ac8bf59 commit 5f4ee67
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ import { KibanaLogic } from '../../../shared/kibana';

import { SearchPlaygroundPageTemplate } from './page_template';

export const Playground: React.FC = () => {
interface PlaygroundProps {
pageMode?: 'chat' | 'search';
}

export const Playground: React.FC<PlaygroundProps> = ({ pageMode = 'chat' }) => {
const { searchPlayground } = useValues(KibanaLogic);

if (!searchPlayground) {
Expand All @@ -35,7 +39,7 @@ export const Playground: React.FC = () => {
customPageSections
bottomBorder="extended"
>
<searchPlayground.Playground />
<searchPlayground.Playground pageMode={pageMode} />
</SearchPlaygroundPageTemplate>
</searchPlayground.PlaygroundProvider>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ import { Routes, Route } from '@kbn/shared-ux-router';
import { NotFound } from './components/not_found';
import { Playground } from './components/playground/playground';
import { SearchApplicationsRouter } from './components/search_applications/search_applications_router';
import { PLAYGROUND_PATH, ROOT_PATH, SEARCH_APPLICATIONS_PATH } from './routes';
import {
PLAYGROUND_CHAT_PATH,
PLAYGROUND_PATH,
PLAYGROUND_SEARCH_PATH,
ROOT_PATH,
SEARCH_APPLICATIONS_PATH,
} from './routes';

export const Applications = () => {
return (
Expand All @@ -22,8 +28,12 @@ export const Applications = () => {
<Route path={SEARCH_APPLICATIONS_PATH}>
<SearchApplicationsRouter />
</Route>
<Route path={PLAYGROUND_PATH}>
<Playground />
<Redirect exact from={PLAYGROUND_PATH} to={PLAYGROUND_CHAT_PATH} />
<Route path={PLAYGROUND_CHAT_PATH}>
<Playground pageMode={'chat'} />
</Route>
<Route path={PLAYGROUND_SEARCH_PATH}>
<Playground pageMode={'search'} />
</Route>
<Route>
<NotFound />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ export enum SearchApplicationViewTabs {
export const SEARCH_APPLICATION_CREATION_PATH = `${SEARCH_APPLICATIONS_PATH}/new`;
export const SEARCH_APPLICATION_PATH = `${SEARCH_APPLICATIONS_PATH}/:searchApplicationName`;
export const SEARCH_APPLICATION_TAB_PATH = `${SEARCH_APPLICATION_PATH}/:tabId`;
export const PLAYGROUND_PATH = `${ROOT_PATH}playground`;
export const PLAYGROUND_PATH = `${ROOT_PATH}playground/`;
export const PLAYGROUND_CHAT_PATH = `${PLAYGROUND_PATH}chat`;
export const PLAYGROUND_SEARCH_PATH = `${PLAYGROUND_PATH}search`;

export const SEARCH_APPLICATION_CONNECT_PATH = `${SEARCH_APPLICATION_PATH}/${SearchApplicationViewTabs.CONNECT}/:connectTabId`;
export enum SearchApplicationConnectTabs {
Expand Down
11 changes: 8 additions & 3 deletions x-pack/plugins/search_playground/public/components/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ import { Chat } from './chat';
import { SearchMode } from './search_mode/search_mode';
import { SearchPlaygroundSetupPage } from './setup_page/search_playground_setup_page';
import { usePageMode } from '../hooks/use_page_mode';
import { useKibana } from '../hooks/use_kibana';

export interface AppProps {
showDocs?: boolean;
pageMode?: PlaygroundPageMode;
pageMode?: 'chat' | 'search';
}

export enum ViewMode {
Expand All @@ -33,6 +34,7 @@ export const App: React.FC<AppProps> = ({
showDocs = false,
pageMode = PlaygroundPageMode.chat,
}) => {
const { services } = useKibana();
const [selectedMode, setSelectedMode] = useState<ViewMode>(ViewMode.chat);
const { data: connectors } = useLoadConnectors();
const hasSelectedIndices = Boolean(
Expand All @@ -41,15 +43,18 @@ export const App: React.FC<AppProps> = ({
}).length
);
const handleModeChange = (id: ViewMode) => setSelectedMode(id);
const handlePageModeChange = (mode: PlaygroundPageMode) => setSelectedPageMode(mode);
const handlePageModeChange = (mode: PlaygroundPageMode) => {
services.application?.navigateToUrl(`./${mode}`);
setSelectedPageMode(mode);
};
const {
showSetupPage,
pageMode: selectedPageMode,
setPageMode: setSelectedPageMode,
} = usePageMode({
hasSelectedIndices,
hasConnectors: Boolean(connectors?.length),
initialPageMode: pageMode,
initialPageMode: pageMode === 'chat' ? PlaygroundPageMode.chat : PlaygroundPageMode.search,
});

const restrictedWidth = selectedPageMode === PlaygroundPageMode.search && selectedMode === 'chat';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export const SearchMode: React.FC = () => {
name={ChatFormFields.searchQuery}
render={({ field }) => (
<EuiFieldText
data-test-subj="searchPlaygroundSearchModeFieldText"
{...field}
value={searchBarValue}
icon="search"
Expand Down
6 changes: 5 additions & 1 deletion x-pack/plugins/search_playground/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@ export function plugin(initializerContext: PluginInitializerContext) {
return new SearchPlaygroundPlugin(initializerContext);
}

export type { SearchPlaygroundPluginSetup, SearchPlaygroundPluginStart } from './types';
export type {
SearchPlaygroundPluginSetup,
SearchPlaygroundPluginStart,
PlaygroundPageMode,
} from './types';
2 changes: 1 addition & 1 deletion x-pack/plugins/search_playground/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"@kbn/data-views-plugin",
"@kbn/discover-utils",
"@kbn/data-plugin",
"@kbn/search-index-documents"
"@kbn/search-index-documents",
],
"exclude": [
"target/**/*",
Expand Down

0 comments on commit 5f4ee67

Please sign in to comment.