Skip to content

Commit

Permalink
[Infra] Inventory-view saved object schema fix (elastic#210023)
Browse files Browse the repository at this point in the history
fixes [elastic#209996](elastic#209996) 

## Summary

Fix the `inventory-view` schema. The wrong schema was causing an error
when trying to create/update a saved view on Infra Inventory UI


![inventory-saved-view](https://github.com/user-attachments/assets/682533c0-1893-47a6-9f87-99a2390bb19a)

### How to test

- Run on dev tools the request below, it should return a 400 containing
the message: `"[attributes.legend.steps]: Value must be equal to or
lower than [18].: Bad Request"`
```
POST kbn:/api/saved_objects/inventory-view
{
  "attributes": {
    "metric": {
      "type": "cpuV2"
    },
    "sort": {
      "by": "name",
      "direction": "desc"
    },
    "groupBy": [],
    "nodeType": "host",
    "view": "map",
    "customOptions": [],
    "customMetrics": [],
    "boundsOverride": {
      "max": 1,
      "min": 0
    },
    "autoBounds": true,
    "accountId": "",
    "region": "",
    "time": 1738848614746,
    "autoReload": false,
    "filterQuery": {
      "expression": "",
      "kind": "kuery"
    },
    "legend": {
      "palette": "cool",
      "steps": 20,
      "reverseColors": false
    },
    "timelineOpen": false,
    "name": "sss"
  }
}
```
- Navigate to Infra > Inventory
- Create a new saved view
  • Loading branch information
crespocarlos authored Feb 7, 2025
1 parent 02c3373 commit e21e748
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@ const getInventoryViewTitle = (savedObject: SavedObject<unknown>) =>
);

const schemaV1 = schema.object({}, { unknowns: 'allow' });
const schemaV2 = schema.object({
legend: schema.object({ steps: schema.number({ max: 18, min: 2 }) }),
});
const schemaV2 = schema.object(
{
legend: schema.maybe(
schema.object({ steps: schema.number({ max: 18, min: 2 }) }, { unknowns: 'allow' })
),
},
{ unknowns: 'allow' }
);

export const inventoryViewSavedObjectType: SavedObjectsType = {
name: inventoryViewSavedObjectName,
Expand Down Expand Up @@ -64,7 +69,7 @@ export const inventoryViewSavedObjectType: SavedObjectsType = {
},
],
schemas: {
forwardCompatibility: schemaV2.extends({}, { unknowns: 'ignore' }),
forwardCompatibility: schemaV2,
create: schemaV2,
},
},
Expand Down

0 comments on commit e21e748

Please sign in to comment.