本文整理匯總了TypeScript中ui/chrome.addBasePath函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript addBasePath函數的具體用法?TypeScript addBasePath怎麽用?TypeScript addBasePath使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了addBasePath函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: requestFile
export async function requestFile(
payload: FetchFilePayload,
line?: string
): Promise<FetchFileResponse> {
const { uri, revision, path } = payload;
const url = `/api/code/repo/${uri}/blob/${encodeURIComponent(revision)}/${path}`;
const query: any = {};
if (line) {
query.line = line;
}
const response: Response = await fetch(chrome.addBasePath(Url.format({ pathname: url, query })));
if (response.status >= 200 && response.status < 300) {
const contentType = response.headers.get('Content-Type');
if (contentType && contentType.startsWith('text/')) {
const lang = contentType.split(';')[0].substring('text/'.length);
if (lang === 'big') {
return {
payload,
content: '',
isOversize: true,
};
}
return {
payload,
lang,
content: await response.text(),
isUnsupported: false,
};
} else if (contentType && contentType.startsWith('image/')) {
return {
payload,
isImage: true,
content: '',
url,
isUnsupported: false,
};
} else {
return {
payload,
isImage: false,
content: '',
url,
isUnsupported: true,
};
}
} else if (response.status === 404) {
return {
payload,
isNotFound: true,
};
}
throw new Error('invalid file type');
}
示例2: get
(uiCapabilities: UICapabilities, kbnBaseUrl: string, $route: any, kbnUrl: any) => {
const route = get($route, 'current.$$route') as any;
if (!route.requireUICapability) {
return;
}
if (!get(uiCapabilities, route.requireUICapability)) {
const url = chrome.addBasePath(`${kbnBaseUrl}#/home`);
kbnUrl.redirect(url);
throw uiRoutes.WAIT_FOR_URL_CHANGE_TOKEN;
}
}
示例3: moveToDiscover
export function moveToDiscover(indexPatternId: string, kbnBaseUrl: string) {
const _g = rison.encode({});
// Add the index pattern ID to the appState part of the URL.
const _a = rison.encode({
index: indexPatternId,
});
const baseUrl = chrome.addBasePath(kbnBaseUrl);
const hash = `#/discover?_g=${_g}&_a=${_a}`;
window.location.href = `${baseUrl}${hash}`;
}
示例4: getKibanaHref
export function getKibanaHref({
location,
pathname = '',
hash,
query = {}
}: KibanaHrefArgs): string {
const search = getSearchString(location, pathname, query);
const href = url.format({
pathname: chrome.addBasePath(pathname),
hash: `${hash}?${search}`
});
return href;
}
示例5: getKibanaHref
export function getKibanaHref({
location,
pathname = '',
hash,
query = {}
}: KibanaHrefArgs): string {
const queryWithRisonParams = getQueryWithRisonParams(location, query);
const search = stringifyWithoutEncoding(queryWithRisonParams);
const href = url.format({
pathname: chrome.addBasePath(pathname),
hash: `${hash}?${search}`
});
return href;
}
示例6: trackUiMetric
export function trackUiMetric(appName: string, metricType: string | string[]) {
if (!getCanTrackUiMetrics()) {
return;
}
if (appName.includes(':')) {
throw createErrorMessage(`app name '${appName}'`);
}
if (metricType.includes(':')) {
throw createErrorMessage(`metric type ${metricType}`);
}
const metricTypes = Array.isArray(metricType) ? metricType.join(',') : metricType;
const uri = chrome.addBasePath(`${API_BASE_PATH}/${appName}/${metricTypes}`);
_http.post(uri);
}
示例7: fetchText
private async fetchText(resource: Uri) {
const repo = `${resource.authority}${resource.path}`;
const revision = resource.query;
const file = resource.fragment;
const response = await fetch(
chrome.addBasePath(`/api/code/repo/${repo}/blob/${revision}/${file}`)
);
if (response.status === 200) {
const contentType = response.headers.get('Content-Type');
if (contentType && contentType.startsWith('text/')) {
const lang = contentType.split(';')[0].substring('text/'.length);
const text = await response.text();
return { text, lang };
}
} else {
return null;
}
}
示例8: getRisonHref
export function getRisonHref({
location,
pathname,
hash,
query = {}
}: RisonHrefArgs) {
const currentQuery = toQuery(location.search);
const nextQuery = {
...TIMEPICKER_DEFAULTS,
...pick(currentQuery, PERSISTENT_APM_PARAMS),
...query
};
// Create _g value for non-apm links
const g = createG(nextQuery);
const encodedG = rison.encode(g);
const encodedA = query._a ? rison.encode(query._a) : ''; // TODO: Do we need to url-encode the _a values before rison encoding _a?
const risonQuery: RisonEncoded = {
_g: encodedG
};
if (encodedA) {
risonQuery._a = encodedA;
}
// don't URI-encode the already-encoded rison
const search = qs.stringify(risonQuery, undefined, undefined, {
encodeURIComponent: (v: string) => v
});
const href = url.format({
pathname: chrome.addBasePath(pathname),
hash: `${hash}?${search}`
});
return href;
}
示例9: saveRole
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { omit } from 'lodash';
import chrome from 'ui/chrome';
import { Role } from '../../../common/model/role';
const apiBase = chrome.addBasePath(`/api/security/role`);
export async function saveRole($http: any, role: Role) {
const data = omit(role, 'name', 'transient_metadata', '_unrecognized_applications');
return await $http.put(`${apiBase}/${role.name}`, data);
}
export async function deleteRole($http: any, name: string) {
return await $http.delete(`${apiBase}/${name}`);
}
示例10: createUserActionUri
export function createUserActionUri(appName: string, actionType: string): string {
return chrome.addBasePath(`/api/user_action/${appName}/${actionType}`);
}