Convert gr-documentation-search to typescript
The change converts the following files to typescript: * elements/documentation/gr-documentation-search/gr-documentation-search.ts Change-Id: Idb7aba008dccaeb9c5c4c4cfbd9837e4a16f6aa8
This commit is contained in:
@@ -14,84 +14,91 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
import '../../../styles/gr-table-styles.js';
|
import '../../../styles/gr-table-styles';
|
||||||
import '../../../styles/shared-styles.js';
|
import '../../../styles/shared-styles';
|
||||||
import '../../shared/gr-list-view/gr-list-view.js';
|
import '../../shared/gr-list-view/gr-list-view';
|
||||||
import '../../shared/gr-rest-api-interface/gr-rest-api-interface.js';
|
import '../../shared/gr-rest-api-interface/gr-rest-api-interface';
|
||||||
import {GestureEventListeners} from '@polymer/polymer/lib/mixins/gesture-event-listeners.js';
|
import {GestureEventListeners} from '@polymer/polymer/lib/mixins/gesture-event-listeners';
|
||||||
import {LegacyElementMixin} from '@polymer/polymer/lib/legacy/legacy-element-mixin.js';
|
import {LegacyElementMixin} from '@polymer/polymer/lib/legacy/legacy-element-mixin';
|
||||||
import {PolymerElement} from '@polymer/polymer/polymer-element.js';
|
import {PolymerElement} from '@polymer/polymer/polymer-element';
|
||||||
import {htmlTemplate} from './gr-documentation-search_html.js';
|
import {htmlTemplate} from './gr-documentation-search_html';
|
||||||
import {ListViewMixin} from '../../../mixins/gr-list-view-mixin/gr-list-view-mixin.js';
|
import {
|
||||||
import {getBaseUrl} from '../../../utils/url-util.js';
|
ListViewMixin,
|
||||||
|
ListViewParams,
|
||||||
|
} from '../../../mixins/gr-list-view-mixin/gr-list-view-mixin';
|
||||||
|
import {getBaseUrl} from '../../../utils/url-util';
|
||||||
|
import {customElement, property} from '@polymer/decorators';
|
||||||
|
import {GrRestApiInterface} from '../../shared/gr-rest-api-interface/gr-rest-api-interface';
|
||||||
|
import {DocResult} from '../../../types/common';
|
||||||
|
|
||||||
/**
|
export interface GrDocumentationSearch {
|
||||||
* @extends PolymerElement
|
$: {
|
||||||
*/
|
restAPI: GrRestApiInterface;
|
||||||
class GrDocumentationSearch extends ListViewMixin(GestureEventListeners(
|
};
|
||||||
LegacyElementMixin(
|
}
|
||||||
PolymerElement))) {
|
@customElement('gr-documentation-search')
|
||||||
static get template() { return htmlTemplate; }
|
export class GrDocumentationSearch extends ListViewMixin(
|
||||||
|
GestureEventListeners(LegacyElementMixin(PolymerElement))
|
||||||
|
) {
|
||||||
|
static get template() {
|
||||||
|
return htmlTemplate;
|
||||||
|
}
|
||||||
|
|
||||||
static get is() { return 'gr-documentation-search'; }
|
|
||||||
|
|
||||||
static get properties() {
|
|
||||||
return {
|
|
||||||
/**
|
/**
|
||||||
* URL params passed from the router.
|
* URL params passed from the router.
|
||||||
*/
|
*/
|
||||||
params: {
|
@property({type: Object, observer: '_paramsChanged'})
|
||||||
type: Object,
|
params?: ListViewParams;
|
||||||
observer: '_paramsChanged',
|
|
||||||
},
|
|
||||||
|
|
||||||
_path: {
|
@property({type: String, readOnly: true})
|
||||||
type: String,
|
_path = '/Documentation';
|
||||||
readOnly: true,
|
|
||||||
value: '/Documentation',
|
|
||||||
},
|
|
||||||
_documentationSearches: Array,
|
|
||||||
|
|
||||||
_loading: {
|
@property({type: Array})
|
||||||
type: Boolean,
|
_documentationSearches?: DocResult[];
|
||||||
value: true,
|
|
||||||
},
|
@property({type: Boolean})
|
||||||
_filter: {
|
_loading = true;
|
||||||
type: String,
|
|
||||||
value: '',
|
@property({type: String})
|
||||||
},
|
_filter = '';
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @override */
|
/** @override */
|
||||||
attached() {
|
attached() {
|
||||||
super.attached();
|
super.attached();
|
||||||
this.dispatchEvent(
|
this.dispatchEvent(
|
||||||
new CustomEvent('title-change', {title: 'Documentation Search'}));
|
new CustomEvent('title-change', {detail: {title: 'Documentation Search'}})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
_paramsChanged(params) {
|
_paramsChanged(params: ListViewParams) {
|
||||||
this._loading = true;
|
this._loading = true;
|
||||||
this._filter = this.getFilterValue(params);
|
this._filter = this.getFilterValue(params);
|
||||||
|
|
||||||
return this._getDocumentationSearches(this._filter);
|
return this._getDocumentationSearches(this._filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
_getDocumentationSearches(filter) {
|
_getDocumentationSearches(filter: string) {
|
||||||
this._documentationSearches = [];
|
this._documentationSearches = [];
|
||||||
return this.$.restAPI.getDocumentationSearches(filter)
|
return this.$.restAPI.getDocumentationSearches(filter).then(searches => {
|
||||||
.then(searches => {
|
|
||||||
// Late response.
|
// Late response.
|
||||||
if (filter !== this._filter || !searches) { return; }
|
if (filter !== this._filter || !searches) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
this._documentationSearches = searches;
|
this._documentationSearches = searches;
|
||||||
this._loading = false;
|
this._loading = false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
_computeSearchUrl(url) {
|
_computeSearchUrl(url?: string) {
|
||||||
if (!url) { return ''; }
|
if (!url) {
|
||||||
return getBaseUrl() + '/' + url;
|
return '';
|
||||||
|
}
|
||||||
|
return `${getBaseUrl()}/${url}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
customElements.define(GrDocumentationSearch.is, GrDocumentationSearch);
|
declare global {
|
||||||
|
interface HTMLElementTagNameMap {
|
||||||
|
'gr-documentation-search': GrDocumentationSearch;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -121,6 +121,7 @@ import {
|
|||||||
PluginInfo,
|
PluginInfo,
|
||||||
GpgKeyInfo,
|
GpgKeyInfo,
|
||||||
GpgKeysInput,
|
GpgKeysInput,
|
||||||
|
DocResult,
|
||||||
} from '../../../types/common';
|
} from '../../../types/common';
|
||||||
import {
|
import {
|
||||||
CancelConditionCallback,
|
CancelConditionCallback,
|
||||||
@@ -3438,7 +3439,7 @@ export class GrRestApiInterface
|
|||||||
}) as Promise<DashboardInfo | undefined>;
|
}) as Promise<DashboardInfo | undefined>;
|
||||||
}
|
}
|
||||||
|
|
||||||
getDocumentationSearches(filter: string) {
|
getDocumentationSearches(filter: string): Promise<DocResult[] | undefined> {
|
||||||
filter = filter.trim();
|
filter = filter.trim();
|
||||||
const encodedFilter = encodeURIComponent(filter);
|
const encodedFilter = encodeURIComponent(filter);
|
||||||
|
|
||||||
@@ -3447,7 +3448,7 @@ export class GrRestApiInterface
|
|||||||
return this._fetchSharedCacheURL({
|
return this._fetchSharedCacheURL({
|
||||||
url: `/Documentation/?q=${encodedFilter}`,
|
url: `/Documentation/?q=${encodedFilter}`,
|
||||||
anonymizedUrl: '/Documentation/?*',
|
anonymizedUrl: '/Documentation/?*',
|
||||||
});
|
}) as Promise<DocResult[] | undefined>;
|
||||||
}
|
}
|
||||||
|
|
||||||
getMergeable(changeNum: ChangeNum) {
|
getMergeable(changeNum: ChangeNum) {
|
||||||
|
|||||||
@@ -1957,3 +1957,12 @@ export interface PluginInfo {
|
|||||||
export interface PluginInput {
|
export interface PluginInput {
|
||||||
url: string;
|
url: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The DocResult entity contains information about a document.
|
||||||
|
* https://gerrit-review.googlesource.com/Documentation/rest-api-documentation.html#doc-result
|
||||||
|
*/
|
||||||
|
export interface DocResult {
|
||||||
|
title: string;
|
||||||
|
url: string;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user