mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
moving indexPattern.delete() to indexPatterns.delete(indexPattern) (#70430)
This commit is contained in:
parent
4257afad1b
commit
dfeb60b5ee
8 changed files with 36 additions and 50 deletions
|
@ -1,15 +0,0 @@
|
|||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [IndexPattern](./kibana-plugin-plugins-data-public.indexpattern.md) > [destroy](./kibana-plugin-plugins-data-public.indexpattern.destroy.md)
|
||||
|
||||
## IndexPattern.destroy() method
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
destroy(): Promise<{}> | undefined;
|
||||
```
|
||||
<b>Returns:</b>
|
||||
|
||||
`Promise<{}> | undefined`
|
||||
|
|
@ -39,7 +39,6 @@ export declare class IndexPattern implements IIndexPattern
|
|||
| [\_fetchFields()](./kibana-plugin-plugins-data-public.indexpattern._fetchfields.md) | | |
|
||||
| [addScriptedField(name, script, fieldType, lang)](./kibana-plugin-plugins-data-public.indexpattern.addscriptedfield.md) | | |
|
||||
| [create(allowOverride)](./kibana-plugin-plugins-data-public.indexpattern.create.md) | | |
|
||||
| [destroy()](./kibana-plugin-plugins-data-public.indexpattern.destroy.md) | | |
|
||||
| [getAggregationRestrictions()](./kibana-plugin-plugins-data-public.indexpattern.getaggregationrestrictions.md) | | |
|
||||
| [getComputedFields()](./kibana-plugin-plugins-data-public.indexpattern.getcomputedfields.md) | | |
|
||||
| [getFieldByName(name)](./kibana-plugin-plugins-data-public.indexpattern.getfieldbyname.md) | | |
|
||||
|
|
|
@ -224,7 +224,7 @@ export class IndexPattern implements IIndexPattern {
|
|||
this.sourceFilters = spec.sourceFilters;
|
||||
|
||||
// ignoring this because the same thing happens elsewhere but via _.assign
|
||||
// @ts-ignore
|
||||
// @ts-expect-error
|
||||
this.fields = spec.fields || [];
|
||||
this.typeMeta = spec.typeMeta;
|
||||
this.fieldFormatMap = _.mapValues(fieldFormatMap, (mapping) => {
|
||||
|
@ -473,21 +473,8 @@ export class IndexPattern implements IIndexPattern {
|
|||
async create(allowOverride: boolean = false) {
|
||||
const _create = async (duplicateId?: string) => {
|
||||
if (duplicateId) {
|
||||
const duplicatePattern = new IndexPattern(duplicateId, {
|
||||
getConfig: this.getConfig,
|
||||
savedObjectsClient: this.savedObjectsClient,
|
||||
apiClient: this.apiClient,
|
||||
patternCache: this.patternCache,
|
||||
fieldFormats: this.fieldFormats,
|
||||
onNotification: this.onNotification,
|
||||
onError: this.onError,
|
||||
uiSettingsValues: {
|
||||
shortDotsEnable: this.shortDotsEnable,
|
||||
metaFields: this.metaFields,
|
||||
},
|
||||
});
|
||||
|
||||
await duplicatePattern.destroy();
|
||||
this.patternCache.clear(duplicateId);
|
||||
await this.savedObjectsClient.delete(savedObjectType, duplicateId);
|
||||
}
|
||||
|
||||
const body = this.prepBody();
|
||||
|
@ -634,11 +621,4 @@ export class IndexPattern implements IIndexPattern {
|
|||
toString() {
|
||||
return '' + this.toJSON();
|
||||
}
|
||||
|
||||
destroy() {
|
||||
if (this.id) {
|
||||
this.patternCache.clear(this.id);
|
||||
return this.savedObjectsClient.delete(savedObjectType, this.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,6 +53,7 @@ describe('IndexPatterns', () => {
|
|||
Array<SavedObject<any>>
|
||||
>
|
||||
);
|
||||
savedObjectsClient.delete = jest.fn(() => Promise.resolve({}) as Promise<any>);
|
||||
|
||||
indexPatterns = new IndexPatternsService({
|
||||
uiSettings: ({
|
||||
|
@ -98,4 +99,13 @@ describe('IndexPatterns', () => {
|
|||
await indexPatterns.getFields(['id', 'title'], true);
|
||||
expect(savedObjectsClient.find).toHaveBeenCalledTimes(3);
|
||||
});
|
||||
|
||||
test('deletes the index pattern', async () => {
|
||||
const id = '1';
|
||||
const indexPattern = await indexPatterns.get(id);
|
||||
|
||||
expect(indexPattern).toBeDefined();
|
||||
await indexPatterns.delete(id);
|
||||
expect(indexPattern).not.toBe(await indexPatterns.get(id));
|
||||
});
|
||||
});
|
||||
|
|
|
@ -228,6 +228,15 @@ export class IndexPatternsService {
|
|||
|
||||
return indexPattern.init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes an index pattern from .kibana index
|
||||
* @param indexPatternId: Id of kibana Index Pattern to delete
|
||||
*/
|
||||
async delete(indexPatternId: string) {
|
||||
indexPatternCache.clear(indexPatternId);
|
||||
return this.savedObjectsClient.delete('index-pattern', indexPatternId);
|
||||
}
|
||||
}
|
||||
|
||||
export type IndexPatternsContract = PublicMethodsOf<IndexPatternsService>;
|
||||
|
|
|
@ -988,8 +988,6 @@ export class IndexPattern implements IIndexPattern {
|
|||
// (undocumented)
|
||||
create(allowOverride?: boolean): Promise<string | false>;
|
||||
// (undocumented)
|
||||
destroy(): Promise<{}> | undefined;
|
||||
// (undocumented)
|
||||
_fetchFields(): Promise<void>;
|
||||
// (undocumented)
|
||||
fieldFormatMap: any;
|
||||
|
|
|
@ -83,9 +83,14 @@ const confirmModalOptionsDelete = {
|
|||
|
||||
export const EditIndexPattern = withRouter(
|
||||
({ indexPattern, history, location }: EditIndexPatternProps) => {
|
||||
const { uiSettings, indexPatternManagementStart, overlays, savedObjects, chrome } = useKibana<
|
||||
IndexPatternManagmentContext
|
||||
>().services;
|
||||
const {
|
||||
uiSettings,
|
||||
indexPatternManagementStart,
|
||||
overlays,
|
||||
savedObjects,
|
||||
chrome,
|
||||
data,
|
||||
} = useKibana<IndexPatternManagmentContext>().services;
|
||||
const [fields, setFields] = useState<IndexPatternField[]>(indexPattern.getNonScriptedFields());
|
||||
const [conflictedFields, setConflictedFields] = useState<IndexPatternField[]>(
|
||||
indexPattern.fields.filter((field) => field.type === 'conflict')
|
||||
|
@ -138,10 +143,11 @@ export const EditIndexPattern = withRouter(
|
|||
uiSettings.set('defaultIndex', otherPatterns[0].id);
|
||||
}
|
||||
}
|
||||
|
||||
Promise.resolve(indexPattern.destroy()).then(function () {
|
||||
history.push('');
|
||||
});
|
||||
if (indexPattern.id) {
|
||||
Promise.resolve(data.indexPatterns.delete(indexPattern.id)).then(function () {
|
||||
history.push('');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
overlays.openConfirm('', confirmModalOptionsDelete).then((isConfirmed) => {
|
||||
|
|
|
@ -96,8 +96,7 @@ export class IndexPatternsTestPlugin
|
|||
const [, { data }] = await core.getStartServices();
|
||||
const id = (req.params as Record<string, string>).id;
|
||||
const service = await data.indexPatterns.indexPatternsServiceFactory(req);
|
||||
const ip = await service.get(id);
|
||||
await ip.destroy();
|
||||
await service.delete(id);
|
||||
return res.ok();
|
||||
}
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue