[Lens] Add internal CRUD api routes#223296
Conversation
nickofthyme
left a comment
There was a problem hiding this comment.
A few thoughts to consider.
| perPage: schema.maybe( | ||
| schema.number({ | ||
| meta: { | ||
| description: | ||
| 'The number of dashboards to display on each page (max 1000). Default is "20".', | ||
| }, | ||
| defaultValue: 20, | ||
| min: 1, | ||
| max: 1000, | ||
| }) | ||
| ), | ||
| perPage: schema.number({ | ||
| meta: { | ||
| description: | ||
| 'The number of dashboards to display on each page (max 1000). Default is "20".', | ||
| }, | ||
| defaultValue: 20, | ||
| min: 1, | ||
| max: 1000, | ||
| }), |
There was a problem hiding this comment.
Using a defaultValue is enough to treat this as optional, but when also paired with schema.maybe the resulting validated value of perPage will be undefined instead of 20.
x-pack/platform/plugins/shared/lens/server/api/routes/visualizations/create.ts
Show resolved
Hide resolved
x-pack/platform/plugins/shared/lens/server/api/routes/visualizations/create.ts
Outdated
Show resolved
Hide resolved
| try { | ||
| ({ result } = await client.create(data, options)); | ||
| } catch (e) { | ||
| // TODO prevent duplicate titles? | ||
|
|
||
| if (e.isBoom && e.output.statusCode === 403) { | ||
| return res.forbidden(); | ||
| } |
There was a problem hiding this comment.
Do we want to prohibit duplicate titles at the API level? Currently we block this in the UI.
There was a problem hiding this comment.
do we today ? (on the UI level ? )
There was a problem hiding this comment.
Good question.
@nickpeihl do you have an existing logic for that in presentation? I would like consistency on the API side with the UI, hence keep the title validation as well, but let's sync with the entire API ecosystem as I think it has priority over UI.
@ppisljar yes we do. It is not possible to save a visualisation with an existing title.
There was a problem hiding this comment.
We don't have that logic to prohibit duplicate titles on the API. We also don't prohibit it in the UI. We first warn users that saving a dashboard will create a duplicate title. But they can click the save button again to create the dashboard.
It is my understanding that Lens also allows creating a duplicative title in the same way.
There was a problem hiding this comment.
Interesting, I never realized that was the flow. I figured the save was disabled.
x-pack/platform/plugins/shared/lens/server/content_management/lens_storage.ts
Show resolved
Hide resolved
x-pack/platform/plugins/shared/lens/server/content_management/v1/cm_services.ts
Outdated
Show resolved
Hide resolved
src/platform/test/api_integration/apis/lens/visualizations/create/index.ts
Show resolved
Hide resolved
src/platform/test/api_integration/fixtures/kbn_archiver/saved_objects/lens.json
Show resolved
Hide resolved
- fix paths - update files after move - move fixtures - add lens test config - update CO file with move
jbudz
left a comment
There was a problem hiding this comment.
.buildkite/ftr_platform_stateful_configs.yml LGTM
|
Starting backport for target branches: 8.19 https://github.com/elastic/kibana/actions/runs/15884860731 |
💚 Build Succeeded
Metrics [docs]Public APIs missing comments
History
|
💔 All backports failed
Manual backportTo create the backport manually run: Questions ?Please refer to the Backport tool documentation |
💚 All backports created successfully
Note: Successful backport PRs will be merged automatically after passing CI. Questions ?Please refer to the Backport tool documentation |
|
Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync. |
1 similar comment
|
Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync. |
|
Friendly reminder: Looks like this PR hasn’t been backported yet. |
Summary
This adds basic Lens CRUD api routes using the Content Management system.
POST api/lens/visualizationsGET api/lens/visualizations/{id}GET api/lens/visualizations?query=testPUT api/lens/visualizations/{id}DELETE api/lens/visualizations/{id}Changes to Lens Content Management
The custom
updatemethod usessoClient.createunder the hood for reasons (i.e. #160116). However, doing this acts as an update or create method with the providedid. I changed this behavior so now any update where the id is not found will return a404error.Closes #221941
Closes #221942 - OpenAPI docs auto generate from route schema
Testing
You can testing this locally in kibana dev console like so...
Checklist
release_note:breakinglabel should be applied in these situations.