Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into fix_default_query
Browse files Browse the repository at this point in the history
  • Loading branch information
gaobinlong committed Oct 29, 2024
2 parents 4ad8129 + 53e8404 commit a1c151c
Show file tree
Hide file tree
Showing 16 changed files with 43 additions and 56 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/8680.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
refactor:
- Update change access modal display name ([#8680](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/8680))
2 changes: 0 additions & 2 deletions changelogs/fragments/8709.yml

This file was deleted.

2 changes: 2 additions & 0 deletions changelogs/fragments/8719.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fix:
- Generate short url with workspace info ([#8719](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/8719))
9 changes: 6 additions & 3 deletions src/core/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,12 @@ export {
} from './metrics';

export { AppCategory, WorkspaceAttribute, PermissionModeId } from '../types';
export { DEFAULT_APP_CATEGORIES, WORKSPACE_TYPE, DEFAULT_NAV_GROUPS } from '../utils';
export {
DEFAULT_APP_CATEGORIES,
WORKSPACE_TYPE,
DEFAULT_NAV_GROUPS,
WORKSPACE_PATH_PREFIX,
} from '../utils';

export {
SavedObject,
Expand Down Expand Up @@ -553,5 +558,3 @@ export const config = {
appenders: appendersSchema as Type<AppenderConfigType>,
},
};

export { getRedirectUrl } from './http';
20 changes: 10 additions & 10 deletions src/plugins/data/public/query/query_string/query_history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ export const HISTORY_KEY_PREFIX = 'query_';
export class QueryHistory {
private changeEmitter: BehaviorSubject<any[]>;

constructor(private readonly storage: DataStorage) {
constructor(private readonly sessionStorage: DataStorage) {
this.changeEmitter = new BehaviorSubject<any[]>(this.getHistory());
}

public getHistoryKeys(): string[] {
return this.storage
return this.sessionStorage
.keys()
.filter((key: string) => key.startsWith(HISTORY_KEY_PREFIX))
.sort((a, b) => {
Expand All @@ -31,7 +31,7 @@ export class QueryHistory {

public getHistory(): any[] {
return this.getHistoryKeys()
.map((key) => this.storage.get(key))
.map((key) => this.sessionStorage.get(key))
.sort((a, b) => b.time - a.time);
}

Expand All @@ -45,13 +45,13 @@ export class QueryHistory {

// Check if the query already exists
const existingKey = existingKeys.find((key) => {
const item = this.storage.get(key);
const item = this.sessionStorage.get(key);
return item && item.query.query === query.query && item.query.language === query.language;
});

if (existingKey) {
// If the query exists, remove it from its current position
this.storage.remove(existingKey);
this.sessionStorage.remove(existingKey);
existingKeys.splice(existingKeys.indexOf(existingKey), 1);
}

Expand All @@ -64,24 +64,24 @@ export class QueryHistory {
dateRange,
id: uuid.v4(),
};
this.storage.set(newKey, newItem);
this.sessionStorage.set(newKey, newItem);

// Trim the history if it exceeds the maximum size
if (existingKeys.length >= MAX_HISTORY_SIZE) {
const keysToRemove = existingKeys.slice(MAX_HISTORY_SIZE - 1);
keysToRemove.forEach((key) => this.storage.remove(key));
keysToRemove.forEach((key) => this.sessionStorage.remove(key));
}

// Emit the updated history
this.changeEmitter.next(this.getHistory());
}

public clearHistory(): void {
this.getHistoryKeys().forEach((key) => this.storage.remove(key));
this.getHistoryKeys().forEach((key) => this.sessionStorage.remove(key));
this.changeEmitter.next([]);
}
}

export function createHistory(deps: { storage: DataStorage }): QueryHistory {
return new QueryHistory(deps.storage);
export function createHistory(deps: { sessionStorage: DataStorage }): QueryHistory {
return new QueryHistory(deps.sessionStorage);
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class QueryStringManager {
private readonly notifications: NotificationsSetup
) {
this.query$ = new BehaviorSubject<Query>(this.getDefaultQuery());
this.queryHistory = createHistory({ storage });
this.queryHistory = new QueryHistory(this.sessionStorage);
this.datasetService = new DatasetService(uiSettings, this.sessionStorage);
this.languageService = new LanguageService(this.defaultSearchInterceptor, this.storage);
}
Expand Down
22 changes: 0 additions & 22 deletions src/plugins/query_enhancements/public/assets/query_assist_mark.svg

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import { FormattedMessage } from '@osd/i18n/react';
import React, { useState } from 'react';
import { QueryEditorExtensionDependencies } from '../../../../data/public';
import assistantMark from '../../assets/query_assist_mark.svg';
import assistantMark from '../../assets/sparkle_mark.svg';
import { getStorage } from '../../services';

const BANNER_STORAGE_KEY = 'queryAssist:banner:show';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { EuiFieldText, EuiIcon, EuiOutsideClickDetector, EuiPortal } from '@elas
import { i18n } from '@osd/i18n';
import React, { useMemo, useState } from 'react';
import { PersistedLog, QuerySuggestionTypes } from '../../../../data/public';
import assistantMark from '../../assets/query_assist_mark.svg';
import assistantMark from '../../assets/sparkle_mark.svg';
import { getData } from '../../services';
import { AgentError } from '../utils';
import { WarningBadge } from './warning_badge';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
} from '../../../../data/public';
import { API } from '../../../common';
import { ConfigSchema } from '../../../common/config';
import assistantMark from '../../assets/query_assist_mark.svg';
import assistantMark from '../../assets/sparkle_mark.svg';
import {
QueryAssistBanner,
QueryAssistBar,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ export function registerDataSourceConnectionsRoutes(
if (error.statusCode === 404 || error.statusCode === 400) {
return response.ok({ body: [] });
}
return response.custom({ statusCode: error.statusCode || 500, body: error.message });
// Transform 500 errors to 503 to indicate service availability issues
const statusCode = error.statusCode === 500 ? 503 : error.statusCode || 503;
return response.custom({
statusCode,
body: error.message,
});
}
}
);
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/share/public/services/share_menu_manager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class ShareMenuManager {
...options,
menuItems,
post: core.http.post,
basePath: core.http.basePath.get(),
basePath: core.http.basePath.getBasePath(),
});
},
};
Expand Down
12 changes: 1 addition & 11 deletions src/plugins/share/server/routes/goto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ import { modifyUrl } from '@osd/std';
import { shortUrlAssertValid } from './lib/short_url_assert_valid';
import { ShortUrlLookupService } from './lib/short_url_lookup';
import { getGotoPath } from '../../common/short_url_routes';
import { getWorkspaceState } from '../../../../core/server/utils';
import { getRedirectUrl } from '../../../../core/server';

export const createGotoRoute = ({
router,
Expand Down Expand Up @@ -67,15 +65,7 @@ export const createGotoRoute = ({

const prependedUrl = modifyUrl(url, (parts) => {
if (!parts.hostname && parts.pathname && parts.pathname.startsWith('/')) {
if (getWorkspaceState(request).requestWorkspaceId) {
parts.pathname = getRedirectUrl({
request,
nextUrl: parts.pathname,
basePath,
});
} else {
parts.pathname = `${basePath}${parts.pathname}`;
}
parts.pathname = `${basePath}${parts.pathname}`;
}
});
return response.redirected({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ describe('shortUrlAssertValid()', () => {
['path with an extra leading slash', '///app/opensearch-dashboards', HOSTNAME_ERROR], // parser detects '' as the hostname
['path without app', '/foo/opensearch-dashboards', PATH_ERROR], // fails because first path part is not 'app'
['path without appId', '/app/', PATH_ERROR], // fails because there is only one path part (leading and trailing slashes are trimmed)
'/w/app/dashboards', // fails because it is not a standard workspace path
];

invalid.forEach(([desc, url, error]) => {
Expand All @@ -67,6 +68,7 @@ describe('shortUrlAssertValid()', () => {
'/app/some?with=query',
'/app/some?with=query#and-a-hash',
'/app/some/deeper?with=query#and-a-hash',
'/w/workspaceid/app/foo',
];

valid.forEach((url) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import { parse } from 'url';
import { trim } from 'lodash';
import Boom from '@hapi/boom';
import { WORKSPACE_PATH_PREFIX } from '../../../../../core/server';

export function shortUrlAssertValid(url: string) {
const { protocol, hostname, pathname } = parse(
Expand All @@ -47,7 +48,13 @@ export function shortUrlAssertValid(url: string) {
throw Boom.notAcceptable(`Short url targets cannot have a hostname, found "${hostname}"`);
}

const pathnameParts = trim(pathname === null ? undefined : pathname, '/').split('/');
let pathnameParts = trim(pathname === null ? undefined : pathname, '/').split('/');

// Workspace introduced paths like `/w/${workspaceId}/app`
// ignore the first 2 elements if it starts with /w
if (`/${pathnameParts[0]}` === WORKSPACE_PATH_PREFIX) {
pathnameParts = pathnameParts.slice(2);
}
if (pathnameParts[0] !== 'app' || !pathnameParts[1]) {
throw Boom.notAcceptable(
`Short url target path must be in the format "/app/{{appId}}", found "${pathname}"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ export const WorkspaceCollaboratorTable = ({
values: {
numCollaborators: selections.length,
pluralSuffix: selections.length > 1 ? 's' : '',
accessLevel: type,
accessLevel: WORKSPACE_ACCESS_LEVEL_NAMES[type],
},
})}
</p>
Expand Down

0 comments on commit a1c151c

Please sign in to comment.