Skip to content

Commit

Permalink
Add new verioned document links
Browse files Browse the repository at this point in the history
Fix the Query DQL linking bug: opensearch-project#769

Signed-off-by: Zuocheng Ding <[email protected]>
  • Loading branch information
zuochengding committed Nov 3, 2021
1 parent 509b0dd commit 1330f20
Show file tree
Hide file tree
Showing 14 changed files with 128 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/core/public/chrome/chrome_service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ export class ChromeService {
basePath={http.basePath}
breadcrumbs$={breadcrumbs$.pipe(takeUntil(this.stop$))}
customNavLink$={customNavLink$.pipe(takeUntil(this.stop$))}
opensearchDashboardsDocLink={docLinks.links.opensearchDashboards}
opensearchDashboardsDocLink={docLinks.links.opensearchDashboards.introduction}
forceAppSwitcherNavigation$={navLinks.getForceAppSwitcherNavigation$()}
helpExtension$={helpExtension$.pipe(takeUntil(this.stop$))}
helpSupportUrl$={helpSupportUrl$.pipe(takeUntil(this.stop$))}
Expand Down
4 changes: 3 additions & 1 deletion src/core/public/doc_links/doc_links_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ describe('DocLinksService#start()', () => {
const service = new DocLinksService();
const api = service.start({ injectedMetadata });
expect(api.DOC_LINK_VERSION).toEqual('test-branch');
expect(api.links.opensearchDashboards).toEqual('https://opensearch.org/docs/dashboards/');
expect(api.links.opensearchDashboards.introduction).toEqual(
'https://www.opensearch.org/docs/test-branch/dashboards/index'
);
});
});
114 changes: 112 additions & 2 deletions src/core/public/doc_links/doc_links_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,84 @@ export class DocLinksService {
const OPENSEARCH_DOCS = `https://opensearch.org/docs/opensearch/`;
const OPENSEARCH_DASHBOARDS_DOCS = `https://opensearch.org/docs/dashboards/`;

const OPENSEARCH_VERSIONED_DOCS =
OPENSEARCH_WEBSITE_URL + `docs/` + DOC_LINK_VERSION + `/opensearch/`;
const OPENSEARCH_DASHBOARDS_VERSIONED_DOCS =
OPENSEARCH_WEBSITE_URL + `docs/` + DOC_LINK_VERSION + `/dashboards/`;

return deepFreeze({
DOC_LINK_VERSION,
OPENSEARCH_WEBSITE_URL,
links: {
opensearch: {
// https://opensearch.org/docs/latest/opensearch/index/
introduction: `${OPENSEARCH_VERSIONED_DOCS}index`,
// https://opensearch.org/docs/latest/opensearch/install/index/
installation: `${OPENSEARCH_VERSIONED_DOCS}install/index`,
// https://opensearch.org/docs/latest/opensearch/configuration/
configuration: `${OPENSEARCH_VERSIONED_DOCS}configuration`,
// https://opensearch.org/docs/latest/opensearch/cluster/
cluster: `${OPENSEARCH_VERSIONED_DOCS}cluster`,
// https://opensearch.org/docs/latest/opensearch/index-data/
indexData: `${OPENSEARCH_VERSIONED_DOCS}index-data`,
// https://opensearch.org/docs/latest/opensearch/index-alias/
indexAlias: `${OPENSEARCH_VERSIONED_DOCS}index-alias`,
// https://opensearch.org/docs/latest/opensearch/data-streams/
dataStreams: `${OPENSEARCH_VERSIONED_DOCS}data-streams`,
// https://opensearch.org/docs/latest/opensearch/aggregations/
aggregations: {
// https://opensearch.org/docs/latest/opensearch/metric-agg/
matric: `${OPENSEARCH_VERSIONED_DOCS}metric-agg`,
// https://opensearch.org/docs/latest/opensearch/bucket-agg/
bucket: `${OPENSEARCH_VERSIONED_DOCS}bucket-agg`,
// https://opensearch.org/docs/latest/opensearch/pipeline-agg/
pipeline: `${OPENSEARCH_VERSIONED_DOCS}pipeline-agg`,
},
// https://opensearch.org/docs/latest/opensearch/index-templates/
indexTemplates: `${OPENSEARCH_VERSIONED_DOCS}/index-templates`,
// https://opensearch.org/docs/latest/opensearch/reindex-data/
reindexData: `${OPENSEARCH_VERSIONED_DOCS}/reindex-data`,
queryDSL: {
// https://opensearch.org/docs/latest/opensearch/query-dsl/index/
introduction: `${OPENSEARCH_VERSIONED_DOCS}query-dsl/index`,
// https://opensearch.org/docs/latest/opensearch/query-dsl/term/
term: `${OPENSEARCH_VERSIONED_DOCS}query-dsl/term`,
// https://opensearch.org/docs/latest/opensearch/query-dsl/full-text/
fullText: `${OPENSEARCH_VERSIONED_DOCS}query-dsl/full-text`,
// https://opensearch.org/docs/latest/opensearch/query-dsl/bool/
boolQuery: `${OPENSEARCH_VERSIONED_DOCS}query-dsl/bool`,
},
// https://opensearch.org/docs/latest/opensearch/search-template/
searchTemplate: `${OPENSEARCH_VERSIONED_DOCS}/search-template`,
// https://opensearch.org/docs/latest/opensearch/ux/
searchExperience: `${OPENSEARCH_VERSIONED_DOCS}/ux`,
// https://opensearch.org/docs/latest/opensearch/logs/
logs: `${OPENSEARCH_VERSIONED_DOCS}/logs`,
// https://opensearch.org/docs/latest/opensearch/snapshot-restore/
snapshotRestore: `${OPENSEARCH_VERSIONED_DOCS}/snapshot-restore`,
// https://opensearch.org/docs/latest/opensearch/units/
supportedUnits: `${OPENSEARCH_VERSIONED_DOCS}/units`,
// https://opensearch.org/docs/latest/opensearch/common-parameters/
commonParameters: `${OPENSEARCH_VERSIONED_DOCS}/common-parameters`,
// https://opensearch.org/docs/latest/opensearch/popular-api/
popularAPI: `${OPENSEARCH_VERSIONED_DOCS}/popular-api`,
},
opensearchDashboards: {
// https://opensearch.org/docs/latest/dashboards/index/
introduction: `${OPENSEARCH_DASHBOARDS_VERSIONED_DOCS}index`,
// https://opensearch.org/docs/latest/dashboards/install/index/
installation: `${OPENSEARCH_DASHBOARDS_VERSIONED_DOCS}install/index`,
// https://opensearch.org/docs/latest/dashboards/maptiles/
mapTiles: `${OPENSEARCH_DASHBOARDS_VERSIONED_DOCS}maptiles`,
// https://opensearch.org/docs/latest/dashboards/gantt/
ganttCharts: `${OPENSEARCH_DASHBOARDS_VERSIONED_DOCS}gantt`,
// https://opensearch.org/docs/latest/dashboards/reporting/
reporting: `${OPENSEARCH_DASHBOARDS_VERSIONED_DOCS}reporting`,
// https://opensearch.org/docs/latest/dashboards/notebooks/
notebooks: `${OPENSEARCH_DASHBOARDS_VERSIONED_DOCS}notebooks`,
// https://opensearch.org/docs/latest/dashboards/dql/
dql: `${OPENSEARCH_DASHBOARDS_VERSIONED_DOCS}dql`,
},
dashboard: {
drilldowns: `${OPENSEARCH_WEBSITE_URL}guide/en/opensearch/${DOC_LINK_VERSION}/drilldowns.html`,
drilldownsTriggerPicker: `${OPENSEARCH_WEBSITE_URL}guide/en/opensearch/${DOC_LINK_VERSION}/drilldowns.html#url-drilldowns`,
Expand Down Expand Up @@ -131,7 +205,6 @@ export class DocLinksService {
// TODO: [RENAMEME] Need prod urls.
// issue: https://github.com/opensearch-project/OpenSearch-Dashboards/issues/335#issuecomment-868294864
addData: `${OPENSEARCH_DASHBOARDS_DOCS}`,
opensearchDashboards: `${OPENSEARCH_DASHBOARDS_DOCS}`,
siem: {
guide: `${OPENSEARCH_WEBSITE_URL}guide/en/security/${DOC_LINK_VERSION}/index.html`,
gettingStarted: `${OPENSEARCH_WEBSITE_URL}guide/en/security/${DOC_LINK_VERSION}/index.html`,
Expand Down Expand Up @@ -164,6 +237,44 @@ export interface DocLinksStart {
readonly DOC_LINK_VERSION: string;
readonly OPENSEARCH_WEBSITE_URL: string;
readonly links: {
readonly opensearch: {
readonly introduction: string;
readonly installation: string;
readonly configuration: string;
readonly cluster: string;
readonly indexData: string;
readonly indexAlias: string;
readonly dataStreams: string;
readonly aggregations: {
readonly matric: string;
readonly bucket: string;
readonly pipeline: string;
};
readonly indexTemplates: string;
readonly reindexData: string;
readonly queryDSL: {
readonly introduction: string;
readonly term: string;
readonly fullText: string;
readonly boolQuery: string;
};
readonly searchTemplate: string;
readonly searchExperience: string;
readonly logs: string;
readonly snapshotRestore: string;
readonly supportedUnits: string;
readonly commonParameters: string;
readonly popularAPI: string;
};
readonly opensearchDashboards: {
readonly introduction: string;
readonly installation: string;
readonly mapTiles: string;
readonly ganttCharts: string;
readonly reporting: string;
readonly notebooks: string;
readonly dql: string;
};
readonly dashboard: {
readonly drilldowns: string;
readonly drilldownsTriggerPicker: string;
Expand Down Expand Up @@ -241,7 +352,6 @@ export interface DocLinksStart {
readonly introduction: string;
};
readonly addData: string;
readonly opensearchDashboards: string;
readonly siem: {
readonly guide: string;
readonly gettingStarted: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
"{indices}/_msearch",
"{indices}/{type}/_msearch"
],
"documentation": "https://opensearch.org/docs/opensearch/query-dsl/full-text/#multi-match"
"documentation": "https://opensearch.org/docs/latest/opensearch/query-dsl/full-text/#multi-match"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
"{indices}/_msearch/template",
"{indices}/{type}/_msearch/template"
],
"documentation": "https://opensearch.org/docs/opensearch/query-dsl/full-text/#multi-match"
"documentation": "https://opensearch.org/docs/latest/opensearch/query-dsl/full-text/#multi-match"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ export function addHelpMenuToAppChrome(
links: [
{
linkType: 'documentation',
// TODO: [RENAMEME] Need prod urls.
// issue: https://github.com/opensearch-project/OpenSearch-Dashboards/issues/335#issuecomment-868294864
href: `${docLinks.links.opensearchDashboards}`,
href: `${docLinks.links.opensearchDashboards.introduction}`,
},
],
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function escapeRegExp(str: string) {
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
}

// See https://www.opensearch.org/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html#_reserved_characters
// See https://opensearch.org/docs/latest/opensearch/query-dsl/index/
function escapeQueryString(str: string) {
return str.replace(/[+-=&|><!(){}[\]^"~*?:\\/]/g, '\\$&'); // $& means the whole matched string
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ interface Props {

export function QueryLanguageSwitcher(props: Props) {
const opensearchDashboards = useOpenSearchDashboards();
const kueryQuerySyntaxDocs = opensearchDashboards.services.docLinks!.links.query.kueryQuerySyntax;
const kueryQuerySyntaxDocs = opensearchDashboards.services.docLinks!.links.opensearchDashboards.dql;
const [isPopoverOpen, setIsPopoverOpen] = useState(false);
const luceneLabel = (
<FormattedMessage id="data.query.queryBar.luceneLanguageName" defaultMessage="Lucene" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export default function QueryBarTopRow(props: QueryBarTopRowProps) {
const opensearchDashboards = useOpenSearchDashboards<IDataPluginServices>();
const { uiSettings, notifications, storage, appName, docLinks } = opensearchDashboards.services;

const kueryQuerySyntaxLink: string = docLinks!.links.query.kueryQuerySyntax;
const kueryQuerySyntaxLink: string = docLinks!.links.opensearchDashboards.dql;

const queryLanguage = props.query && props.query.language;
const persistedLog: PersistedLog | undefined = React.useMemo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ export default class QueryStringInputUI extends Component<Props, State> {
Learn more in our {link}."
values={{
link: (
<EuiLink href={docLinks.links.query.kueryQuerySyntax} target="_blank">
<EuiLink href={docLinks.links.opensearchDashboards.dql} target="_blank">
<FormattedMessage
id="data.query.queryBar.DQLNestedQuerySyntaxInfoDocLinkText"
defaultMessage="docs"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ async function getBody(
boolFilter: Filter[] = []
) {
const isFieldObject = (f: any): f is IFieldType => Boolean(f && f.name);

// https://www.opensearch.org/guide/en/elasticsearch/reference/current/query-dsl-regexp-query.html#_standard_operators
// See https://opensearch.org/docs/latest/opensearch/query-dsl/index/
const getEscapedQuery = (q: string = '') =>
q.replace(/[.?+*|{}[\]()"\\#@&<>~]/g, (match) => `\\${match}`);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export enum OpenSearchRequestState {

/**
* helper function to build a query body for OpenSearch
* https://www.opensearch.org/guide/en/elasticsearch/reference/current//query-dsl-ids-query.html
* https://opensearch.org/docs/latest/opensearch/query-dsl/index/
*/
export function buildSearchBody(id: string, indexPattern: IndexPattern): Record<string, any> {
const computedFields = indexPattern.getComputedFields();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ export function addHelpMenuToAppChrome(chrome) {
links: [
{
linkType: 'documentation',
// TODO: [RENAMEME] Need prod urls.
// issue: https://github.com/opensearch-project/OpenSearch-Dashboards/issues/335#issuecomment-868294864
href: `${docLinks.links.opensearchDashboards}`,
href: `${docLinks.links.opensearchDashboards.introduction}`,
},
],
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import { ControlParams } from '../editor_utils';
import { InputControlSettings, InputControlVisDependencies } from '../plugin';

function getEscapedQuery(query = '') {
// https://www.opensearch.org/guide/en/elasticsearch/reference/current/query-dsl-regexp-query.html#_standard_operators
// https://opensearch.org/docs/latest/opensearch/query-dsl/index/
return query.replace(/[.?+*|{}[\]()"\\#@&<>~]/g, (match) => `\\${match}`);
}

Expand Down

0 comments on commit 1330f20

Please sign in to comment.