Skip to content

Commit 6ea93f4

Browse files
committed
null/undefined cleanup
1 parent 0be9d1a commit 6ea93f4

File tree

12 files changed

+148
-155
lines changed

12 files changed

+148
-155
lines changed

src/platform/plugins/shared/discover/public/embeddable/utils/serialization_utils.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ describe('Serialization utils', () => {
223223
...mockedSavedSearchAttributes,
224224
managed: false,
225225
searchSource,
226+
projectRouting: undefined,
226227
};
227228

228229
const serializedState = serializeState({
@@ -269,6 +270,7 @@ describe('Serialization utils', () => {
269270
...mockedSavedSearchAttributes,
270271
managed: false,
271272
searchSource,
273+
projectRouting: undefined,
272274
};
273275

274276
test('equal state', () => {

src/platform/plugins/shared/discover/public/embeddable/utils/serialization_utils.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,8 @@ export const deserializeState = async ({
4747
// what is this??
4848
const rawSavedObjectAttributes = pick(so, EDITABLE_SAVED_SEARCH_KEYS);
4949
const savedObjectOverride = pick(serializedState.rawState, EDITABLE_SAVED_SEARCH_KEYS);
50-
// Filter out null projectRouting for type safety (runtime already filtered by fromSavedSearchAttributes)
51-
const { projectRouting, ...soWithoutTimeRangeAndProjectRouting } = omit(so, 'timeRange');
5250
return {
53-
...soWithoutTimeRangeAndProjectRouting,
54-
// Only include projectRouting if it's not null (SearchEmbeddableRuntimeState doesn't allow null)
55-
...(projectRouting !== null && projectRouting !== undefined && { projectRouting }),
51+
...omit(so, 'timeRange'),
5652
savedObjectId,
5753
savedObjectTitle: so.title,
5854
savedObjectDescription: so.description,
@@ -71,12 +67,8 @@ export const deserializeState = async ({
7167
serializedState.rawState as SearchEmbeddableByValueState,
7268
true
7369
);
74-
// Filter out null projectRouting for type safety (runtime already filtered by fromSavedSearchAttributes)
75-
const { projectRouting, ...savedSearchWithoutProjectRouting } = savedSearch;
7670
return {
77-
...savedSearchWithoutProjectRouting,
78-
// Only include projectRouting if it's not null (SearchEmbeddableRuntimeState doesn't allow null)
79-
...(projectRouting !== null && projectRouting !== undefined && { projectRouting }),
71+
...savedSearch,
8072
...panelState,
8173
nonPersistedDisplayOptions: serializedState.rawState.nonPersistedDisplayOptions,
8274
};

src/platform/plugins/shared/saved_search/common/saved_searches_utils.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ export const fromSavedSearchAttributes = <
5050
visContext: attributes.visContext,
5151
controlGroupJson: attributes.controlGroupJson,
5252
density: attributes.density,
53-
// Only include projectRouting if it's not null/undefined (saved state allows null, runtime doesn't)
54-
...(projectRouting !== null && projectRouting !== undefined && { projectRouting }),
53+
projectRouting: projectRouting ?? undefined,
5554
tabs,
5655
managed,
5756
} as ReturnType;

src/platform/plugins/shared/saved_search/common/service/get_discover_session.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ export const getDiscoverSession = async (
5050
visContext: tab.attributes.visContext,
5151
controlGroupJson: tab.attributes.controlGroupJson,
5252
})),
53-
// Session-level projectRouting - normalize null to undefined for runtime usage
54-
projectRouting:
55-
so.item.attributes.projectRouting === null ? undefined : so.item.attributes.projectRouting,
53+
projectRouting: so.item.attributes.projectRouting ?? undefined,
5654
managed: Boolean(so.item.managed),
5755
tags: deps.savedObjectsTagging
5856
? deps.savedObjectsTagging.ui.getTagIdsFromReferences(so.item.references)

src/platform/plugins/shared/saved_search/common/service/get_saved_searches.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ describe('getSavedSearch', () => {
9393
"id": "ccf1af80-2297-11ec-86e0-1155ffb9c7a7",
9494
"isTextBasedQuery": undefined,
9595
"managed": false,
96+
"projectRouting": undefined,
9697
"references": Array [
9798
Object {
9899
"id": "ff959d40-b880-11e8-a6d9-e546fe2bba5f",
@@ -244,6 +245,7 @@ describe('getSavedSearch', () => {
244245
"id": "ccf1af80-2297-11ec-86e0-1155ffb9c7a7",
245246
"isTextBasedQuery": true,
246247
"managed": false,
248+
"projectRouting": undefined,
247249
"references": Array [
248250
Object {
249251
"id": "ff959d40-b880-11e8-a6d9-e546fe2bba5f",

src/platform/plugins/shared/saved_search/common/service/saved_searches_utils.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ describe('saved_searches_utils', () => {
7979
"id": "id",
8080
"isTextBasedQuery": false,
8181
"managed": false,
82+
"projectRouting": undefined,
8283
"references": Array [],
8384
"refreshInterval": undefined,
8485
"rowHeight": undefined,
@@ -165,7 +166,7 @@ describe('saved_searches_utils', () => {
165166
};
166167

167168
const result = toSavedSearchAttributes(savedSearch, '{}');
168-
expect(result).toEqual({
169+
expect(result).toMatchObject({
169170
kibanaSavedObjectMeta: {
170171
searchSourceJSON: '{}',
171172
},
@@ -178,6 +179,7 @@ describe('saved_searches_utils', () => {
178179
isTextBasedQuery: true,
179180
usesAdHocDataView: false,
180181
timeRestore: false,
182+
projectRouting: null,
181183
tabs: [
182184
{
183185
id: expect.any(String),
@@ -193,6 +195,7 @@ describe('saved_searches_utils', () => {
193195
isTextBasedQuery: true,
194196
usesAdHocDataView: false,
195197
timeRestore: false,
198+
projectRouting: null,
196199
},
197200
},
198201
],

src/platform/plugins/shared/saved_search/common/service/saved_searches_utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ export const toSavedSearchAttributes = (
5252
timeRestore: savedSearch.timeRestore ?? false,
5353
timeRange: savedSearch.timeRange ? pick(savedSearch.timeRange, ['from', 'to']) : undefined,
5454
refreshInterval: savedSearch.refreshInterval,
55-
projectRouting: savedSearch.projectRouting ?? undefined,
55+
// Convert undefined to null for storage (null explicitly signals "no value" in saved objects)
56+
projectRouting: savedSearch.projectRouting ?? null,
5657
rowsPerPage: savedSearch.rowsPerPage,
5758
sampleSize: savedSearch.sampleSize,
5859
density: savedSearch.density,

src/platform/plugins/shared/saved_search/common/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ export type SavedSearch = Partial<SavedSearchAttributes> & {
9898
aliasPurpose?: SavedObjectsResolveResponse['alias_purpose'];
9999
errorJSON?: string;
100100
};
101+
projectRouting?: ProjectRouting;
101102
};
102103

103104
/** @internal **/

src/platform/plugins/shared/saved_search/public/service/save_discover_session.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,9 @@ export const saveDiscoverSession = async (
136136
...tabs[0].attributes,
137137
sort: tabs[0].attributes.sort as SortOrder[],
138138
density: tabs[0].attributes.density as DataGridDensity,
139+
projectRouting: discoverSession.projectRouting ?? null,
139140
};
140141

141-
// Only include projectRouting if explicitly provided (even if null to clear)
142-
if ('projectRouting' in discoverSession) {
143-
attributes.projectRouting = discoverSession.projectRouting ?? null;
144-
}
145-
146142
const references = savedObjectsTagging
147143
? savedObjectsTagging.ui.updateTagsReferences(tabReferences, discoverSession.tags ?? [])
148144
: tabReferences;
@@ -156,8 +152,7 @@ export const saveDiscoverSession = async (
156152

157153
return {
158154
...discoverSession,
159-
projectRouting:
160-
discoverSession.projectRouting === null ? undefined : discoverSession.projectRouting,
155+
projectRouting: discoverSession.projectRouting ?? undefined,
161156
id,
162157
references,
163158
managed: false,

0 commit comments

Comments
 (0)