-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(contexts): Simplify
state
context (#80674)
See #80420 Also removes the deprecated redux state files 9/13
- Loading branch information
Showing
10 changed files
with
131 additions
and
200 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
76 changes: 76 additions & 0 deletions
76
static/app/components/events/contexts/knownContext/state.spec.tsx
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,76 @@ | ||
import {EventFixture} from 'sentry-fixture/event'; | ||
|
||
import {render, screen} from 'sentry-test/reactTestingLibrary'; | ||
|
||
import ContextCard from 'sentry/components/events/contexts/contextCard'; | ||
import { | ||
getStateContextData, | ||
type StateContext, | ||
} from 'sentry/components/events/contexts/knownContext/state'; | ||
|
||
const MOCK_STATE_CONTEXT: StateContext = { | ||
state: { | ||
type: 'redux', | ||
value: { | ||
a: 'abc', | ||
}, | ||
}, | ||
// Extra data is still valid and preserved | ||
extra_data: 'something', | ||
unknown_key: 123, | ||
}; | ||
|
||
const MOCK_REDACTION = { | ||
extra_data: { | ||
'': { | ||
rem: [['organization:0', 's', 0, 0]], | ||
len: 5, | ||
}, | ||
}, | ||
}; | ||
|
||
describe('StateContext', function () { | ||
it('returns values and according to the parameters', function () { | ||
expect(getStateContextData({data: MOCK_STATE_CONTEXT})).toEqual([ | ||
{ | ||
key: 'state', | ||
subject: 'State (Redux)', | ||
value: {a: 'abc'}, | ||
meta: undefined, | ||
}, | ||
{ | ||
key: 'extra_data', | ||
subject: 'extra_data', | ||
value: 'something', | ||
meta: undefined, | ||
}, | ||
{ | ||
key: 'unknown_key', | ||
subject: 'unknown_key', | ||
value: 123, | ||
meta: undefined, | ||
}, | ||
]); | ||
}); | ||
|
||
it('renders with meta annotations correctly', function () { | ||
const event = EventFixture({ | ||
_meta: {contexts: {state: MOCK_REDACTION}}, | ||
}); | ||
|
||
render( | ||
<ContextCard | ||
event={event} | ||
type={'default'} | ||
alias={'state'} | ||
value={{...MOCK_STATE_CONTEXT, extra_data: ''}} | ||
/> | ||
); | ||
|
||
expect(screen.getByText('Application State')).toBeInTheDocument(); | ||
expect(screen.getByText('State (Redux)')).toBeInTheDocument(); | ||
expect(screen.getByRole('button', {name: '1 item'})).toBeInTheDocument(); | ||
expect(screen.getByText('extra_data')).toBeInTheDocument(); | ||
expect(screen.getByText(/redacted/)).toBeInTheDocument(); | ||
}); | ||
}); |
43 changes: 43 additions & 0 deletions
43
static/app/components/events/contexts/knownContext/state.tsx
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,43 @@ | ||
import upperFirst from 'lodash/upperFirst'; | ||
|
||
import {getContextKeys} from 'sentry/components/events/contexts/utils'; | ||
import {t} from 'sentry/locale'; | ||
import type {KeyValueListData} from 'sentry/types/group'; | ||
|
||
enum StateContextKeys { | ||
STATE = 'state', | ||
} | ||
|
||
export interface StateContext { | ||
// Any custom keys users may set | ||
[key: string]: any; | ||
[StateContextKeys.STATE]: Record<string, any>; | ||
} | ||
|
||
export function getStateContextData({ | ||
data, | ||
meta, | ||
}: { | ||
data: StateContext; | ||
meta?: Record<keyof StateContext, any>; | ||
}): KeyValueListData { | ||
return getContextKeys({data}).map(ctxKey => { | ||
switch (ctxKey) { | ||
case StateContextKeys.STATE: | ||
return { | ||
key: ctxKey, | ||
subject: `${t('State')}${data.state.type ? ` (${upperFirst(data.state.type)})` : ''}`, | ||
// TODO(TS): Objects cannot be rendered to dom | ||
value: data.state.value as string, | ||
meta: meta?.state?.value?.[''], | ||
}; | ||
default: | ||
return { | ||
key: ctxKey, | ||
subject: ctxKey, | ||
value: data[ctxKey], | ||
meta: meta?.[ctxKey]?.[''], | ||
}; | ||
} | ||
}); | ||
} |
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 was deleted.
Oops, something went wrong.
81 changes: 0 additions & 81 deletions
81
static/app/components/events/contexts/state/index.spec.tsx
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.