Skip to content

Commit 9c095ba

Browse files
committed
refactor(compass-schema): replace reflux with redux COMPASS-8797
1 parent e0836b5 commit 9c095ba

File tree

5 files changed

+25
-17
lines changed

5 files changed

+25
-17
lines changed

packages/compass-schema/src/components/compass-schema.tsx

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import { useConnectionInfo } from '@mongodb-js/compass-connections/provider';
3535
import { getAtlasPerformanceAdvisorLink } from '../utils';
3636
import { useIsLastAppliedQueryOutdated } from '@mongodb-js/compass-query-bar';
3737
import { useTelemetry } from '@mongodb-js/compass-telemetry/provider';
38-
import type { RootState } from '../stores/store';
38+
import type { RootState, SchemaThunkDispatch } from '../stores/store';
3939
import { startAnalysis, stopAnalysis } from '../stores/reducer';
4040

4141
const rootStyles = css({
@@ -373,20 +373,27 @@ const Schema: React.FunctionComponent<{
373373
schema: MongodbSchema | null;
374374
count?: number;
375375
resultId?: number;
376-
startAnalysis: () => Promise<void>;
377-
stopAnalysis: () => void;
378-
}> = ({ analysisState, errorMessage, schema, resultId }) => {
376+
onStartAnalysis: () => Promise<void>;
377+
onStopAnalysis: () => void;
378+
}> = ({
379+
analysisState,
380+
errorMessage,
381+
schema,
382+
resultId,
383+
onStartAnalysis,
384+
onStopAnalysis,
385+
}) => {
379386
const onApplyClicked = useCallback(() => {
380-
startAnalysis();
381-
}, []);
387+
void onStartAnalysis();
388+
}, [onStartAnalysis]);
382389

383390
const onCancelClicked = useCallback(() => {
384-
stopAnalysis();
385-
}, []);
391+
onStopAnalysis();
392+
}, [onStopAnalysis]);
386393

387394
const onResetClicked = useCallback(() => {
388-
startAnalysis();
389-
}, []);
395+
onStopAnalysis();
396+
}, [onStopAnalysis]);
390397

391398
const outdated = useIsLastAppliedQueryOutdated('schema');
392399

packages/compass-schema/src/components/coordinates-minichart/coordinates-minichart.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ CoordinatesMinichart.propTypes = {
333333
onQueryChanged: PropTypes.func,
334334
};
335335

336-
const ConnectedCoordinatesMinichart = connect(() => {}, {
336+
const ConnectedCoordinatesMinichart = connect(() => ({}), {
337337
geoLayerAdded,
338338
geoLayersEdited,
339339
geoLayersDeleted,

packages/compass-schema/src/components/minichart/minichart.jsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import CoordinatesMinichart from '../coordinates-minichart';
77
import D3Component from '../d3-component';
88
import vizFns from '../../modules';
99
import CONSTANTS from '../../constants/schema';
10-
import { connect } from 'react-redux';
1110

1211
class MiniChart extends PureComponent {
1312
static displayName = 'MiniChartComponent';
@@ -36,12 +35,12 @@ class MiniChart extends PureComponent {
3635
this.resizeListener();
3736
window.addEventListener('resize', this.resizeListener);
3837
// this.unsubscribeMiniChartResize =
39-
// this.props.actions.resizeMiniCharts.listen(this.resizeListener);
38+
// this.props.actions.resizeMiniCharts.listen(this.resizeListener); // TODO: what was this doing?
4039
}
4140

4241
componentWillUnmount() {
4342
window.removeEventListener('resize', this.resizeListener);
44-
this.unsubscribeMiniChartResize();
43+
// this.unsubscribeMiniChartResize();
4544
}
4645

4746
/**
@@ -150,4 +149,4 @@ class MiniChart extends PureComponent {
150149
}
151150
}
152151

153-
export default connect(() => {}, {})(MiniChart);
152+
export default MiniChart;

packages/compass-schema/src/stores/reducer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ export const handleSchemaShare = (): SchemaThunkAction<void> => {
155155

156156
export const _trackSchemaShared = (
157157
hasSchema: boolean
158-
): SchemaThunkAction<undefined> => {
158+
): SchemaThunkAction<void> => {
159159
return (dispatch, getState, { track, connectionInfoRef }) => {
160160
const { schema } = getState();
161161
// Use a function here to a) ensure that the calculations here

packages/compass-schema/src/stores/store.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Logger } from '@mongodb-js/compass-logging';
22
import { createStore, applyMiddleware, type AnyAction } from 'redux';
3-
import thunk, { type ThunkAction } from 'redux-thunk';
3+
import thunk, { type ThunkDispatch, type ThunkAction } from 'redux-thunk';
44
import type { CollectionTabPluginMetadata } from '@mongodb-js/compass-collection';
55
import type {
66
ConnectionInfoRef,
@@ -40,6 +40,8 @@ export type SchemaThunkAction<R, A extends AnyAction = AnyAction> = ThunkAction<
4040
SchemaExtraArgs,
4141
A
4242
>;
43+
export type SchemaThunkDispatch<A extends AnyAction = AnyAction> =
44+
ThunkDispatch<RootState, SchemaExtraArgs, A>;
4345

4446
/**
4547
* Configure a store with the provided options.

0 commit comments

Comments
 (0)