Skip to content

Commit

Permalink
CR Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jennypavlova committed May 16, 2024
1 parent 26b7c86 commit 4ab66b1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import type { SerializableRecord } from '@kbn/utility-types';
import rison from '@kbn/rison';
import { LocatorDefinition, LocatorPublic } from '@kbn/share-plugin/common';
import querystring from 'querystring';

export type InventoryLocator = LocatorPublic<InventoryLocatorParams>;

Expand Down Expand Up @@ -69,8 +70,8 @@ export class InventoryLocatorDefinition implements LocatorDefinition<InventoryLo
boundsOverride: { max: 1, min: 0 },
}
),
customMetrics: params.customMetrics || rison.encodeUnknown(''),
customOptions: params.customOptions || rison.encodeUnknown(''),
customMetrics: params.customMetrics,
customOptions: params.customOptions,
groupBy: rison.encodeUnknown(params.groupBy ?? {}),
legend: rison.encodeUnknown(
params.legend ?? { palette: 'cool', reverseColors: false, steps: 10 }
Expand All @@ -83,9 +84,10 @@ export class InventoryLocatorDefinition implements LocatorDefinition<InventoryLo
view: rison.encodeUnknown(params.view ?? 'map'),
};

const queryStringParams = querystring.stringify(paramsWithDefaults);
return {
app: 'metrics',
path: `/inventory?waffleFilter=${paramsWithDefaults.waffleFilter}&waffleTime=${paramsWithDefaults.waffleTime}&waffleOptions=${paramsWithDefaults.waffleOptions}&customMetrics=${paramsWithDefaults.customMetrics}&customOptions=${paramsWithDefaults.customOptions}&groupBy=${paramsWithDefaults.groupBy}&legend=${paramsWithDefaults.legend}&metric=${paramsWithDefaults.metric}&nodeType=${paramsWithDefaults.nodeType}&region=${paramsWithDefaults.region}&sort=${paramsWithDefaults.sort}&timelineOpen=${paramsWithDefaults.timelineOpen}&view=${paramsWithDefaults.view}`,
path: `/inventory?${queryStringParams}`,
state: params.state ? params.state : {},
};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { AssetDetailsLocatorDefinition } from './asset_details_locator';
import { AssetDetailsFlyoutLocatorDefinition } from './asset_details_flyout_locator';
import { HostsLocatorDefinition } from './hosts_locator';
import { InventoryLocatorDefinition } from './inventory_locator';
import querystring from 'querystring';

const setupAssetDetailsLocator = async () => {
const assetDetailsLocator = new AssetDetailsLocatorDefinition();
Expand Down Expand Up @@ -184,8 +185,8 @@ describe('Infra Locators', () => {
autoBounds: true,
boundsOverride: { max: 1, min: 0 },
},
customMetrics: '',
customOptions: '',
customMetrics: undefined,
customOptions: undefined,
groupBy: { field: 'cloud.provider' },
legend: { palette: 'cool', reverseColors: false, steps: 10 },
metric: '(type:cpu)',
Expand All @@ -196,28 +197,21 @@ describe('Infra Locators', () => {
view: 'map' as const,
};

const waffleFilter = rison.encodeUnknown(params.waffleFilter);
const waffleTime = rison.encodeUnknown(params.waffleTime);
const waffleOptions = rison.encodeUnknown(params.waffleOptions);
const customMetrics = rison.encodeUnknown(params.customMetrics);
const customOptions = rison.encodeUnknown(params.customOptions);
const groupBy = rison.encodeUnknown(params.groupBy);
const legend = rison.encodeUnknown(params.legend);
const metric = params.metric;
const nodeType = rison.encodeUnknown(params.nodeType);
const region = rison.encodeUnknown(params.region);
const sort = rison.encodeUnknown(params.sort);
const timelineOpen = rison.encodeUnknown(params.timelineOpen);
const view = rison.encodeUnknown(params.view);
const expected = Object.keys(params).reduce((acc, key) => {
acc[key] =
key === 'metric' || key === 'customOptions' || key === 'customMetrics'
? params[key]
: rison.encodeUnknown(params[key]);
return acc;
}, {});
const queryStringParams = querystring.stringify(expected);

it('should create a link to Inventory with no state', async () => {
const { inventoryLocator } = await setupInventoryLocator();
const { app, path, state } = await inventoryLocator.getLocation(params);

expect(app).toBe('metrics');
expect(path).toBe(
`/inventory?waffleFilter=${waffleFilter}&waffleTime=${waffleTime}&waffleOptions=${waffleOptions}&customMetrics=${customMetrics}&customOptions=${customOptions}&groupBy=${groupBy}&legend=${legend}&metric=${metric}&nodeType=${nodeType}&region=${region}&sort=${sort}&timelineOpen=${timelineOpen}&view=${view}`
);
expect(path).toBe(`/inventory?${queryStringParams}`);
expect(state).toBeDefined();
expect(Object.keys(state)).toHaveLength(0);
});
Expand All @@ -227,9 +221,7 @@ describe('Infra Locators', () => {
const { app, path, state } = await inventoryLocator.getLocation(params);

expect(app).toBe('metrics');
expect(path).toBe(
`/inventory?waffleFilter=${waffleFilter}&waffleTime=${waffleTime}&waffleOptions=${waffleOptions}&customMetrics=${customMetrics}&customOptions=${customOptions}&groupBy=${groupBy}&legend=${legend}&metric=${metric}&nodeType=${nodeType}&region=${region}&sort=${sort}&timelineOpen=${timelineOpen}&view=${view}`
);
expect(path).toBe(`/inventory?${queryStringParams}`);
expect(state).toBeDefined();
expect(Object.keys(state)).toHaveLength(0);
});
Expand Down

0 comments on commit 4ab66b1

Please sign in to comment.