kibana/x-pack/plugins/maps/public/classes/util/data_request.ts
Kibana Machine 5dea5bbe5f
[Maps] Add force-refresh toggle (#104691) (#111776)
Adds the ability for users to control whether a layer should refresh on auto-update or when the refresh-button is clicked. This is required to display static layers from geo-data indexed in Elasticsearch.

Co-authored-by: Thomas Neirynck <thomas@elastic.co>
2021-09-09 15:47:11 -04:00

60 lines
1.4 KiB
TypeScript

/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
/* eslint-disable max-classes-per-file */
import { DataRequestDescriptor, DataRequestMeta } from '../../../common/descriptor_types';
export class DataRequest {
private readonly _descriptor: DataRequestDescriptor;
constructor(descriptor: DataRequestDescriptor) {
this._descriptor = {
...descriptor,
};
}
getData(): object | undefined {
return this._descriptor.data;
}
isLoading(): boolean {
return !!this._descriptor.dataRequestToken;
}
getMeta(): DataRequestMeta {
if (this._descriptor.dataRequestMetaAtStart) {
return this._descriptor.dataRequestMetaAtStart;
} else if (this._descriptor.dataRequestMeta) {
return this._descriptor.dataRequestMeta;
} else {
return {};
}
}
hasData(): boolean {
return !!this._descriptor.data;
}
hasDataOrRequestInProgress(): boolean {
return this.hasData() || this.isLoading();
}
getDataId(): string {
return this._descriptor.dataId;
}
getRequestToken(): symbol | undefined {
return this._descriptor.dataRequestToken;
}
}
export class DataRequestAbortError extends Error {
constructor() {
super();
}
}