[data views] Allow data view rename via rest api (#141869)

* allow rename of data view via rest api
This commit is contained in:
Matthew Kime 2022-09-27 06:56:46 -05:00 committed by GitHub
parent fa78386746
commit 3c04a1f212
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
74 changed files with 51 additions and 13 deletions

View file

@ -39,6 +39,7 @@ the data view is updated. The default is `false`.
You can partially update the following fields:
* `title`
* `name`
* `timeFieldName`
* `fields`
* `sourceFilters`
@ -93,6 +94,7 @@ $ curl -X POST api/data_views/data-view/my-view
{
"data_view": {
"title": "...",
"name": "...",
"timeFieldName": "...",
"sourceFilters": [],
"fieldFormats": {},

View file

@ -38,6 +38,7 @@ the index pattern is updated. The default is `false`.
You can partially update the following fields:
* `title`
* `name`
* `timeFieldName`
* `fields`
* `sourceFilters`
@ -90,6 +91,7 @@ $ curl -X POST api/index_patterns/index-pattern/my-pattern
{
"index_pattern": {
"title": "...",
"name": "...",
"timeFieldName": "...",
"sourceFilters": [],
"fieldFormats": {},

View file

@ -37,6 +37,7 @@ const indexPatternUpdateSchema = schema.object({
fields: schema.maybe(schema.recordOf(schema.string(), fieldSpecSchema)),
allowNoIndex: schema.maybe(schema.boolean()),
runtimeFieldMap: schema.maybe(schema.recordOf(schema.string(), runtimeFieldSchema)),
name: schema.maybe(schema.string()),
});
interface UpdateDataViewArgs {
@ -67,6 +68,7 @@ export const updateDataView = async ({
typeMeta,
fields,
runtimeFieldMap,
name,
} = spec;
let changeCount = 0;
@ -102,6 +104,11 @@ export const updateDataView = async ({
dataView.typeMeta = typeMeta;
}
if (name !== undefined) {
changeCount++;
dataView.name = name;
}
if (fields !== undefined) {
changeCount++;
doRefreshFields = true;

View file

@ -10,10 +10,10 @@ import { FtrProviderContext } from '../../../ftr_provider_context';
export default function ({ loadTestFile }: FtrProviderContext) {
describe('index_pattern_crud', () => {
loadTestFile(require.resolve('./create_index_pattern'));
loadTestFile(require.resolve('./get_index_pattern'));
loadTestFile(require.resolve('./delete_index_pattern'));
loadTestFile(require.resolve('./update_index_pattern'));
loadTestFile(require.resolve('./create_data_view'));
loadTestFile(require.resolve('./get_data_view'));
loadTestFile(require.resolve('./delete_data_view'));
loadTestFile(require.resolve('./update_data_view'));
loadTestFile(require.resolve('./get_data_views'));
});
}

View file

@ -16,7 +16,7 @@ export default function ({ getService }: FtrProviderContext) {
describe('main', () => {
configArray.forEach((config) => {
describe(config.name, () => {
it('can update index_pattern title', async () => {
it('can update data view title', async () => {
const title1 = `foo-${Date.now()}-${Math.random()}*`;
const title2 = `bar-${Date.now()}-${Math.random()}*`;
const response1 = await supertest.post(config.path).send({
@ -41,7 +41,34 @@ export default function ({ getService }: FtrProviderContext) {
expect(response3.body[config.serviceKey].title).to.be(title2);
});
it('can update index_pattern timeFieldName', async () => {
it('can update data view name', async () => {
const title = `foo-${Date.now()}-${Math.random()}*`;
const name1 = 'good data view name';
const name2 = 'better data view name';
const response1 = await supertest.post(config.path).send({
[config.serviceKey]: {
title,
name: name1,
},
});
expect(response1.body[config.serviceKey].name).to.be(name1);
const id = response1.body[config.serviceKey].id;
const response2 = await supertest.post(`${config.path}/${id}`).send({
[config.serviceKey]: {
name: name2,
},
});
expect(response2.body[config.serviceKey].name).to.be(name2);
const response3 = await supertest.get(`${config.path}/${id}`);
expect(response3.body[config.serviceKey].name).to.be(name2);
});
it('can update data view timeFieldName', async () => {
const title = `foo-${Date.now()}-${Math.random()}*`;
const response1 = await supertest.post(config.path).send({
[config.serviceKey]: {
@ -66,7 +93,7 @@ export default function ({ getService }: FtrProviderContext) {
expect(response3.body[config.serviceKey].timeFieldName).to.be('timeFieldName2');
});
it('can update index_pattern sourceFilters', async () => {
it('can update data view sourceFilters', async () => {
const title = `foo-${Date.now()}-${Math.random()}*`;
const response1 = await supertest.post(config.path).send({
[config.serviceKey]: {
@ -120,7 +147,7 @@ export default function ({ getService }: FtrProviderContext) {
]);
});
it('can update index_pattern fieldFormats', async () => {
it('can update data view fieldFormats', async () => {
const title = `foo-${Date.now()}-${Math.random()}*`;
const response1 = await supertest.post(config.path).send({
[config.serviceKey]: {
@ -180,7 +207,7 @@ export default function ({ getService }: FtrProviderContext) {
});
});
it('can update index_pattern type', async () => {
it('can update data view type', async () => {
const title = `foo-${Date.now()}-${Math.random()}*`;
const response1 = await supertest.post(config.path).send({
[config.serviceKey]: {
@ -205,7 +232,7 @@ export default function ({ getService }: FtrProviderContext) {
expect(response3.body[config.serviceKey].type).to.be('bar');
});
it('can update index_pattern typeMeta', async () => {
it('can update data view typeMeta', async () => {
const title = `foo-${Date.now()}-${Math.random()}*`;
const response1 = await supertest.post(config.path).send({
[config.serviceKey]: {
@ -230,7 +257,7 @@ export default function ({ getService }: FtrProviderContext) {
expect(response3.body[config.serviceKey].typeMeta).to.eql({ foo: 'baz' });
});
it('can update multiple index pattern fields at once', async () => {
it('can update multiple data view fields at once', async () => {
const title = `foo-${Date.now()}-${Math.random()}*`;
const response1 = await supertest.post(config.path).send({
[config.serviceKey]: {

View file

@ -10,7 +10,7 @@ export default function ({ loadTestFile }) {
describe('index_patterns', () => {
loadTestFile(require.resolve('./es_errors'));
loadTestFile(require.resolve('./fields_for_wildcard_route'));
loadTestFile(require.resolve('./index_pattern_crud'));
loadTestFile(require.resolve('./data_views_crud'));
loadTestFile(require.resolve('./scripted_fields_crud'));
loadTestFile(require.resolve('./fields_api'));
loadTestFile(require.resolve('./default_index_pattern'));

View file

@ -16,7 +16,7 @@ export default function ({ loadTestFile }: FtrProviderContext) {
loadTestFile(require.resolve('./general'));
loadTestFile(require.resolve('./home'));
loadTestFile(require.resolve('./data_view_field_editor'));
loadTestFile(require.resolve('./index_patterns'));
loadTestFile(require.resolve('./data_views'));
loadTestFile(require.resolve('./kql_telemetry'));
loadTestFile(require.resolve('./saved_objects_management'));
loadTestFile(require.resolve('./saved_objects'));