Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[data views] REST endpoint for swapping saved object references #157665

Merged
merged 13 commits into from Jul 6, 2023

Conversation

mattkime
Copy link
Contributor

@mattkime mattkime commented May 14, 2023

Summary

Managing large number of saved objects can be cumbersome. This api endpoint allows the management of references without clicking through a lot of different UIs.

For example -

This swaps all data view id abcd-efg references to xyz-123

POST /api/data_views/swap_references
{
     "from_id" : "abcd-efg",
     "to_id" : "xyz-123",
     "preview" : false, // optional, necessary to save changes
     "delete" : true // optional, removes data view which is no longer referenced
}

returns 
{
  preview: false,
  result: [{ id: "123", type: "visualization" }],
  deleteSuccess: true
}

Additional params -

from_type: string - specify the saved object type. Default is `index-pattern` for data view
for_id: string | string[] - limit the affected saved objects to one or more by id
for_type: string - limit the affected saved objects by type

Closes #153806

@mattkime mattkime changed the title Data views swap references [data views] REST endpoint for swapping saved object references Jun 27, 2023
@mattkime mattkime self-assigned this Jun 27, 2023
@mattkime mattkime added Feature:Data Views Data Views code and UI - index patterns before 8.0 release_note:skip Skip the PR/issue when compiling release notes Feature:Kibana Management Feature label for Data Views, Advanced Setting, Saved Object management pages release_note:feature Makes this part of the condensed release notes Team:DataDiscovery Discover App Team (Document Explorer, Saved Search, Surrounding documents, Graph) and removed release_note:skip Skip the PR/issue when compiling release notes labels Jun 27, 2023
@mattkime mattkime marked this pull request as ready for review June 30, 2023 02:47
@mattkime mattkime requested a review from a team as a code owner June 30, 2023 02:47
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-data-discovery (Team:DataDiscovery)

Copy link
Contributor

@jughosta jughosta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very helpful addition!

request: {
body: schema.object({
from_id: idSchema,
from_type: schema.maybe(schema.string()),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What other types are supported? It could be that this endpoint should not be under data_views path then.

body: schema.object({
from_id: idSchema,
from_type: schema.maybe(schema.string()),
to: idSchema,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to_id for consistency with from_id

Comment on lines 63 to 64
search_id: schema.maybe(schema.oneOf([idSchema, schema.arrayOf(idSchema)])),
search_type: schema.maybe(schema.string()),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about for_id and for_type? search can be confused with a search query.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, that does clarify things.

Comment on lines 84 to 92
const res2 = await supertest
.post(DATA_VIEW_SWAP_REFERENCES_PATH)
.set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION)
.send({
from_id: dataViewId,
to: dataViewId,
});

expect(res2.body.result.length).to.equal(1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part does not save changes, right? Does it fit to the test description?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this.

test/api_integration/apis/index.ts Outdated Show resolved Hide resolved
@kibana-ci
Copy link
Collaborator

💛 Build succeeded, but was flaky

Failed CI Steps

Metrics [docs]

Unknown metric groups

API count

id before after diff
dataViews 1048 1049 +1

ESLint disabled line counts

id before after diff
enterpriseSearch 14 16 +2
securitySolution 410 414 +4
total +6

Total ESLint disabled count

id before after diff
enterpriseSearch 15 17 +2
securitySolution 489 493 +4
total +6

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @mattkime

Copy link
Contributor

@jughosta jughosta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job! LGTM 👍

@mattkime mattkime merged commit c843c97 into elastic:main Jul 6, 2023
21 checks passed
@kibanamachine kibanamachine added v8.10.0 backport:skip This commit does not require backporting labels Jul 6, 2023
mattkime added a commit that referenced this pull request Aug 12, 2023
## Summary

Some simple dev UX improvements to the swap_references data views api - 

```
POST /api/data_views/swap_references/_preview
{
     "fromId" : "abcd-efg",
     "toId" : "xyz-123"
}

returns 
{
  result: [{ id: "123", type: "visualization" }],
}
```


```
POST /api/data_views/swap_references
{
     "fromId" : "abcd-efg",
     "toId" : "xyz-123",
     "delete" : true // optional, removes data view which is no longer referenced
}

returns 
{
  result: [{ id: "123", type: "visualization" }],
  deleteStatus: {
    remainingRefs: 0,
    deletePerformed: true
}
```

Additional params - 

```
fromType: string - specify the saved object type. Default is `index-pattern` for data view
forId: string | string[] - limit the affected saved objects to one or more by id
forType: string - limit the affected saved objects by type
```

Improves upon #157665

Docs will be created in follow up PR
jughosta pushed a commit to jughosta/kibana that referenced this pull request Aug 14, 2023
## Summary

Some simple dev UX improvements to the swap_references data views api - 

```
POST /api/data_views/swap_references/_preview
{
     "fromId" : "abcd-efg",
     "toId" : "xyz-123"
}

returns 
{
  result: [{ id: "123", type: "visualization" }],
}
```


```
POST /api/data_views/swap_references
{
     "fromId" : "abcd-efg",
     "toId" : "xyz-123",
     "delete" : true // optional, removes data view which is no longer referenced
}

returns 
{
  result: [{ id: "123", type: "visualization" }],
  deleteStatus: {
    remainingRefs: 0,
    deletePerformed: true
}
```

Additional params - 

```
fromType: string - specify the saved object type. Default is `index-pattern` for data view
forId: string | string[] - limit the affected saved objects to one or more by id
forType: string - limit the affected saved objects by type
```

Improves upon elastic#157665

Docs will be created in follow up PR
benakansara pushed a commit to benakansara/kibana that referenced this pull request Aug 14, 2023
## Summary

Some simple dev UX improvements to the swap_references data views api - 

```
POST /api/data_views/swap_references/_preview
{
     "fromId" : "abcd-efg",
     "toId" : "xyz-123"
}

returns 
{
  result: [{ id: "123", type: "visualization" }],
}
```


```
POST /api/data_views/swap_references
{
     "fromId" : "abcd-efg",
     "toId" : "xyz-123",
     "delete" : true // optional, removes data view which is no longer referenced
}

returns 
{
  result: [{ id: "123", type: "visualization" }],
  deleteStatus: {
    remainingRefs: 0,
    deletePerformed: true
}
```

Additional params - 

```
fromType: string - specify the saved object type. Default is `index-pattern` for data view
forId: string | string[] - limit the affected saved objects to one or more by id
forType: string - limit the affected saved objects by type
```

Improves upon elastic#157665

Docs will be created in follow up PR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting Feature:Data Views Data Views code and UI - index patterns before 8.0 Feature:Kibana Management Feature label for Data Views, Advanced Setting, Saved Object management pages release_note:feature Makes this part of the condensed release notes Team:DataDiscovery Discover App Team (Document Explorer, Saved Search, Surrounding documents, Graph) v8.10.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[data views] provide means of switching saved object references
5 participants