Skip to content

Commit 9be7319

Browse files
authored
feat(editor-monaco): add ability to use custom markers (#3814)
Refs #3803 BREAKING CHANGE: editor.editorMarkers redux state has been changed to editor.markers. FSA updateEditorMarkers has been renamed to setEditorMarkers. Selector selectEditorMarkers has been renamed to selectMarkers.
1 parent c7387f7 commit 9be7319

File tree

7 files changed

+58
-21
lines changed

7 files changed

+58
-21
lines changed

src/plugins/editor-monaco/actions.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
export const EDITOR_UPDATE_THEME = 'editor_update_theme';
2-
export const EDITOR_ERROR_MARKERS = 'editor_error_markers';
2+
3+
export const EDITOR_SET_MARKERS = 'editor_set_markers';
4+
export const EDITOR_APPEND_MARKERS = 'editor_append_markers';
5+
export const EDITOR_CLEAR_MARKERS = 'editor_clear_markers';
6+
37
export const EDITOR_JUMP_TO_EDITOR_MARKER = 'editor_jump_to_editor_marker';
48
export const EDITOR_CLEAR_JUMP_TO_EDITOR_MARKER = 'editor_clear_jump_to_editor_marker';
59
export const EDITOR_SET_REQUEST_JUMP_TO_EDITOR_MARKER = 'editor_set_request_jump_to_editor_marker';
@@ -12,12 +16,27 @@ export const updateEditorTheme = (theme = 'my-vs-dark') => {
1216
type: EDITOR_UPDATE_THEME,
1317
};
1418
};
15-
export const updateEditorMarkers = (markers = []) => {
19+
20+
export const setMarkers = (markers = []) => {
21+
return {
22+
type: EDITOR_SET_MARKERS,
23+
payload: markers,
24+
};
25+
};
26+
export const appendMarkers = (markers = []) => {
1627
return {
28+
type: EDITOR_APPEND_MARKERS,
1729
payload: markers,
18-
type: EDITOR_ERROR_MARKERS,
1930
};
2031
};
32+
33+
export const clearMarkers = (source = 'apilint') => {
34+
return {
35+
type: EDITOR_CLEAR_MARKERS,
36+
payload: source,
37+
};
38+
};
39+
2140
export const setJumpToEditorMarker = (marker = {}) => {
2241
return {
2342
payload: marker,

src/plugins/editor-monaco/components/MonacoEditor/MonacoEditorContainer.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const MonacoEditorContainer = ({ editorActions, editorSelectors, isReadOnly }) =
3333

3434
const handleEditorMarkersDidChange = useCallback(
3535
(markers) => {
36-
editorActions.updateEditorMarkers(markers);
36+
editorActions.setMarkers(markers);
3737
},
3838
[editorActions]
3939
);
@@ -78,7 +78,7 @@ MonacoEditorContainer.propTypes = {
7878
editorSetup: PropTypes.func.isRequired,
7979
editorTearDown: PropTypes.func.isRequired,
8080
setContentDebounced: PropTypes.func.isRequired,
81-
updateEditorMarkers: PropTypes.func.isRequired,
81+
setMarkers: PropTypes.func.isRequired,
8282
clearJumpToEditorMarker: PropTypes.func.isRequired,
8383
setJumpToEditorMarker: PropTypes.func.isRequired,
8484
clearRequestJumpToEditorMarker: PropTypes.func.isRequired,

src/plugins/editor-monaco/components/ValidationPane/ValidationPane.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const ValidationPane = ({
99
onValidationClick,
1010
alwaysDisplayHeading,
1111
}) => {
12-
const markers = editorSelectors.selectEditorMarkers();
12+
const markers = editorSelectors.selectMarkers();
1313
const columns = React.useMemo(
1414
() => [
1515
{

src/plugins/editor-monaco/components/ValidationPane/ValidationPane.test.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ import * as editorSelectors from '../../selectors.js';
66
import * as editorActions from '../../actions.js';
77

88
jest.mock('../../selectors.js', () => ({
9-
selectEditorMarkers: jest.fn(),
9+
selectMarkers: jest.fn(),
1010
}));
1111

1212
afterAll(() => {
1313
jest.unmock('../../selectors.js');
1414
});
1515

1616
const setup = ({ markerErrorList } = {}) => {
17-
editorSelectors.selectEditorMarkers.mockReturnValue(markerErrorList);
17+
editorSelectors.selectMarkers.mockReturnValue(markerErrorList);
1818
const onValidationClick = jest.fn();
1919
const alwaysDisplayHeading = true;
2020
return { editorSelectors, editorActions, onValidationClick, alwaysDisplayHeading };
@@ -27,7 +27,7 @@ const renderValidationPane = async (props) => {
2727
/>
2828
);
2929

30-
await waitFor(() => expect(editorSelectors.selectEditorMarkers).toBeCalled());
30+
await waitFor(() => expect(editorSelectors.selectMarkers).toBeCalled());
3131
return {
3232
hasTableItem: (selector) => {
3333
const item = screen.queryByText(selector, { exact: false });

src/plugins/editor-monaco/index.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import EditorPaneBarTopWrapper from './wrap-components/EditorPaneBarTopWrapper.j
77
import EditorPaneBarBottomWrapper from './wrap-components/EditorPaneBarBottomWrapper.jsx';
88
import {
99
updateEditorTheme,
10-
updateEditorMarkers,
10+
setMarkers,
11+
appendMarkers,
12+
clearMarkers,
1113
setJumpToEditorMarker,
1214
clearJumpToEditorMarker,
1315
setRequestJumpToEditorMarker,
@@ -16,7 +18,7 @@ import {
1618
import reducers from './reducers.js';
1719
import {
1820
selectEditorTheme,
19-
selectEditorMarkers,
21+
selectMarkers,
2022
selectEditorJumpToMarker,
2123
selectEditorRequestJumpToMarker,
2224
} from './selectors.js';
@@ -44,7 +46,9 @@ const EditorMonacoPlugin = (opts = {}) => {
4446
editor: {
4547
actions: {
4648
updateEditorTheme,
47-
updateEditorMarkers,
49+
setMarkers,
50+
appendMarkers,
51+
clearMarkers,
4852
setJumpToEditorMarker,
4953
clearJumpToEditorMarker,
5054
setRequestJumpToEditorMarker,
@@ -53,7 +57,7 @@ const EditorMonacoPlugin = (opts = {}) => {
5357
reducers,
5458
selectors: {
5559
selectEditorTheme,
56-
selectEditorMarkers,
60+
selectMarkers,
5761
selectEditorJumpToMarker,
5862
selectEditorRequestJumpToMarker,
5963
},

src/plugins/editor-monaco/reducers.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
import { fromJS, List } from 'immutable';
2+
13
import {
24
EDITOR_UPDATE_THEME,
3-
EDITOR_ERROR_MARKERS,
5+
EDITOR_SET_MARKERS,
6+
EDITOR_CLEAR_MARKERS,
7+
EDITOR_APPEND_MARKERS,
48
EDITOR_JUMP_TO_EDITOR_MARKER,
59
EDITOR_CLEAR_JUMP_TO_EDITOR_MARKER,
610
EDITOR_SET_REQUEST_JUMP_TO_EDITOR_MARKER,
@@ -11,8 +15,19 @@ const reducers = {
1115
[EDITOR_UPDATE_THEME]: (state, action) => {
1216
return state.set('editorTheme', action.payload);
1317
},
14-
[EDITOR_ERROR_MARKERS]: (state, action) => {
15-
return state.set('editorMarkers', action.payload);
18+
[EDITOR_SET_MARKERS]: (state, action) => {
19+
return state.set('markers', fromJS(action.payload));
20+
},
21+
[EDITOR_APPEND_MARKERS]: (state, action) => {
22+
const markers = state.get('markers', List());
23+
return state.set('markers', markers.concat(fromJS(action.payload)));
24+
},
25+
[EDITOR_CLEAR_MARKERS]: (state, action) => {
26+
const { payload: source } = action;
27+
const markers = state
28+
.get('markers', List())
29+
.filterNot((marker) => marker.get('source') === source);
30+
return state.set('markers', markers);
1631
},
1732
[EDITOR_JUMP_TO_EDITOR_MARKER]: (state, action) => {
1833
return state.set('editorJumpToMarker', action.payload);

src/plugins/editor-monaco/selectors.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import { createSelector } from 'reselect';
2+
import { List } from 'immutable';
23

34
export const selectEditorTheme = (state) => state.get('editorTheme') || 'my-vs-dark';
45

5-
export const selectEditorMarkers = createSelector(
6-
(state) => state.get('editorMarkers'),
7-
(editorMarkers) => {
8-
return editorMarkers || [];
9-
}
6+
export const selectMarkers = createSelector(
7+
(state) => state.get('markers', List()),
8+
(markers) => markers.toJS()
109
);
1110

1211
export const selectEditorJumpToMarker = createSelector(

0 commit comments

Comments
 (0)