-
Notifications
You must be signed in to change notification settings - Fork 935
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* consolidates state to saved object serialization Signed-off-by: Ashwin P Chandran <[email protected]> * fixes histogram agg Signed-off-by: Ashwin P Chandran <[email protected]> * fixes orderBy Signed-off-by: Ashwin P Chandran <[email protected]> * style fixes Signed-off-by: Ashwin P Chandran <[email protected]> * updates base test Signed-off-by: Ashwin P Chandran <[email protected]> * Updates changelog Signed-off-by: Ashwin P Chandran <[email protected]> Signed-off-by: Ashwin P Chandran <[email protected]> (cherry picked from commit 83f1306) Co-authored-by: Ashwin P Chandran <[email protected]>
- Loading branch information
1 parent
f52ef60
commit 0c808dc
Showing
19 changed files
with
214 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/plugins/wizard/public/saved_visualizations/transforms.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { coreMock } from '../../../../core/public/mocks'; | ||
import { getStubIndexPattern } from '../../../../plugins/data/public/test_utils'; | ||
import { IndexPattern } from '../../../data/public'; | ||
import { RootState } from '../application/utils/state_management'; | ||
import { WizardVisSavedObject } from '../types'; | ||
import { saveStateToSavedObject } from './transforms'; | ||
|
||
const getConfig = (cfg: any) => cfg; | ||
|
||
describe('transforms', () => { | ||
describe('saveStateToSavedObject', () => { | ||
let TEST_INDEX_PATTERN_ID; | ||
let savedObject; | ||
let rootState: RootState; | ||
let indexPattern: IndexPattern; | ||
|
||
beforeEach(() => { | ||
TEST_INDEX_PATTERN_ID = 'test-pattern'; | ||
savedObject = {} as WizardVisSavedObject; | ||
rootState = { | ||
metadata: { editor: { state: 'loading', validity: {} } }, | ||
style: '', | ||
visualization: { | ||
searchField: '', | ||
indexPattern: TEST_INDEX_PATTERN_ID, | ||
activeVisualization: { | ||
name: 'bar', | ||
aggConfigParams: [], | ||
}, | ||
}, | ||
}; | ||
indexPattern = getStubIndexPattern( | ||
TEST_INDEX_PATTERN_ID, | ||
getConfig, | ||
null, | ||
[], | ||
coreMock.createSetup() | ||
); | ||
}); | ||
|
||
test('should save root state information into saved object', async () => { | ||
saveStateToSavedObject(savedObject, rootState, indexPattern); | ||
|
||
expect(savedObject.visualizationState).not.toContain(TEST_INDEX_PATTERN_ID); | ||
expect(savedObject.styleState).toEqual(JSON.stringify(rootState.style)); | ||
expect(savedObject.searchSourceFields?.index?.id).toEqual(TEST_INDEX_PATTERN_ID); | ||
}); | ||
|
||
test('should fail if the index pattern does not match the value on state', () => { | ||
rootState.visualization.indexPattern = 'Some-other-pattern'; | ||
|
||
expect(() => | ||
saveStateToSavedObject(savedObject, rootState, indexPattern) | ||
).toThrowErrorMatchingInlineSnapshot( | ||
`"indexPattern id should match the value in redux state"` | ||
); | ||
}); | ||
}); | ||
}); |
28 changes: 28 additions & 0 deletions
28
src/plugins/wizard/public/saved_visualizations/transforms.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import produce from 'immer'; | ||
import { IndexPattern } from '../../../data/public'; | ||
import { RootState, VisualizationState } from '../application/utils/state_management'; | ||
import { WizardVisSavedObject } from '../types'; | ||
|
||
export const saveStateToSavedObject = ( | ||
obj: WizardVisSavedObject, | ||
state: RootState, | ||
indexPattern: IndexPattern | ||
): WizardVisSavedObject => { | ||
if (state.visualization.indexPattern !== indexPattern.id) | ||
throw new Error('indexPattern id should match the value in redux state'); | ||
|
||
obj.visualizationState = JSON.stringify( | ||
produce(state.visualization, (draft: VisualizationState) => { | ||
delete draft.indexPattern; | ||
}) | ||
); | ||
obj.styleState = JSON.stringify(state.style); | ||
obj.searchSourceFields = { index: indexPattern }; | ||
|
||
return obj; | ||
}; |
Oops, something went wrong.