Skip to content

Commit 9598f26

Browse files
committed
wip
1 parent 4dd8116 commit 9598f26

File tree

7 files changed

+171
-130
lines changed

7 files changed

+171
-130
lines changed

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

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, { useCallback } from 'react';
2-
2+
import type { Schema as MongodbSchema } from 'mongodb-schema';
3+
import { connect } from 'react-redux';
34
import type { AnalysisState } from '../constants/analysis-states';
45
import {
56
ANALYSIS_STATE_INITIAL,
@@ -29,12 +30,13 @@ import {
2930
Badge,
3031
Icon,
3132
} from '@mongodb-js/compass-components';
32-
import type { configureActions } from '../actions';
3333
import { usePreference } from 'compass-preferences-model/provider';
3434
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';
39+
import { startAnalysis, stopAnalysis } from '../stores/reducer';
3840

3941
const rootStyles = css({
4042
width: '100%',
@@ -296,10 +298,9 @@ const AnalyzingScreen: React.FunctionComponent<{
296298
};
297299

298300
const FieldList: React.FunctionComponent<{
299-
schema: any;
301+
schema: MongodbSchema | null;
300302
analysisState: AnalysisState;
301-
actions: Record<string, any>;
302-
}> = ({ schema, analysisState, actions }) => {
303+
}> = ({ schema, analysisState }) => {
303304
const darkMode = useDarkMode();
304305

305306
if (analysisState !== ANALYSIS_STATE_COMPLETE) {
@@ -327,7 +328,7 @@ const FieldList: React.FunctionComponent<{
327328
>
328329
<div data-testid="schema-field-list">
329330
{fields.map((field: any) => (
330-
<Field key={field.name} actions={actions} {...field} />
331+
<Field key={field.name} {...field} />
331332
))}
332333
</div>
333334
</div>
@@ -366,25 +367,26 @@ const PerformanceAdvisorBanner = () => {
366367
};
367368

368369
const Schema: React.FunctionComponent<{
369-
actions: ReturnType<typeof configureActions>;
370370
analysisState: AnalysisState;
371371
errorMessage?: string;
372372
maxTimeMS?: number;
373-
schema?: any;
373+
schema: MongodbSchema | null;
374374
count?: number;
375-
resultId?: string;
376-
}> = ({ actions, analysisState, errorMessage, schema, resultId }) => {
375+
resultId?: number;
376+
startAnalysis: () => Promise<void>;
377+
stopAnalysis: () => void;
378+
}> = ({ analysisState, errorMessage, schema, resultId }) => {
377379
const onApplyClicked = useCallback(() => {
378-
actions.startAnalysis();
379-
}, [actions]);
380+
startAnalysis();
381+
}, []);
380382

381383
const onCancelClicked = useCallback(() => {
382-
actions.stopAnalysis();
383-
}, [actions]);
384+
stopAnalysis();
385+
}, []);
384386

385387
const onResetClicked = useCallback(() => {
386-
actions.startAnalysis();
387-
}, [actions]);
388+
startAnalysis();
389+
}, []);
388390

389391
const outdated = useIsLastAppliedQueryOutdated('schema');
390392

@@ -403,7 +405,7 @@ const Schema: React.FunctionComponent<{
403405
errorMessage={errorMessage || ''}
404406
isOutdated={!!outdated}
405407
sampleSize={schema ? schema.count : 0}
406-
schemaResultId={resultId || ''}
408+
schemaResultId={String(resultId) || ''}
407409
/>
408410
}
409411
>
@@ -416,16 +418,23 @@ const Schema: React.FunctionComponent<{
416418
<AnalyzingScreen onCancelClicked={onCancelClicked} />
417419
)}
418420
{analysisState === ANALYSIS_STATE_COMPLETE && (
419-
<FieldList
420-
schema={schema}
421-
analysisState={analysisState}
422-
actions={actions}
423-
/>
421+
<FieldList schema={schema} analysisState={analysisState} />
424422
)}
425423
</div>
426424
</WorkspaceContainer>
427425
</div>
428426
);
429427
};
430428

431-
export default Schema;
429+
export default connect(
430+
(state: RootState) => ({
431+
analysisState: state.analysisState,
432+
errorMessage: state.errorMessage,
433+
schema: state.schema,
434+
resultId: state.resultId,
435+
}),
436+
{
437+
onStartAnalysis: startAnalysis,
438+
onStopAnalysis: stopAnalysis,
439+
}
440+
)(Schema);

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

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, { PureComponent, useCallback } from 'react';
22
import PropTypes from 'prop-types';
3+
import { connect } from 'react-redux';
34

45
import L from 'leaflet';
56

@@ -17,6 +18,11 @@ import GeoscatterMapItem from './marker';
1718
import { LIGHTMODE_TILE_URL, DARKMODE_TILE_URL } from './constants';
1819
import { getHereAttributionMessage } from './utils';
1920
import { debounce } from 'lodash';
21+
import {
22+
geoLayerAdded,
23+
geoLayersDeleted,
24+
geoLayersEdited,
25+
} from '../../stores/reducer';
2026

2127
// TODO: Disable boxZoom handler for circle lasso.
2228
//
@@ -124,10 +130,12 @@ class UnthemedCoordinatesMinichart extends PureComponent {
124130
unique: PropTypes.number,
125131
values: PropTypes.array,
126132
}),
127-
actions: PropTypes.object.isRequired,
128133
fieldName: PropTypes.string.isRequired,
129134
darkMode: PropTypes.bool,
130135
onGeoQueryChanged: PropTypes.func.isRequired,
136+
geoLayerAdded: PropTypes.func.isRequired,
137+
geoLayersEdited: PropTypes.func.isRequired,
138+
geoLayersDeleted: PropTypes.func.isRequired,
131139
};
132140

133141
state = {
@@ -239,26 +247,23 @@ class UnthemedCoordinatesMinichart extends PureComponent {
239247
}
240248

241249
onCreated = (evt) => {
242-
this.props.actions.geoLayerAdded(
250+
this.props.geoLayerAdded(
243251
this.props.fieldName,
244252
evt.layer,
245253
this.props.onGeoQueryChanged
246254
);
247255
};
248256

249257
onEdited = (evt) => {
250-
this.props.actions.geoLayersEdited(
258+
this.props.geoLayersEdited(
251259
this.props.fieldName,
252260
evt.layers,
253261
this.props.onGeoQueryChanged
254262
);
255263
};
256264

257265
onDeleted = (evt) => {
258-
this.props.actions.geoLayersDeleted(
259-
evt.layers,
260-
this.props.onGeoQueryChanged
261-
);
266+
this.props.geoLayersDeleted(evt.layers, this.props.onGeoQueryChanged);
262267
};
263268

264269
/**
@@ -328,5 +333,10 @@ CoordinatesMinichart.propTypes = {
328333
onQueryChanged: PropTypes.func,
329334
};
330335

331-
export default CoordinatesMinichart;
332-
export { CoordinatesMinichart };
336+
const ConnectedCoordinatesMinichart = connect(() => {}, {
337+
geoLayerAdded,
338+
geoLayersEdited,
339+
geoLayersDeleted,
340+
})(CoordinatesMinichart);
341+
342+
export default ConnectedCoordinatesMinichart;

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import type {
2121
import { FieldType, sortTypes } from './type';
2222
import Minichart from './minichart';
2323
import detectCoordinates from '../modules/detect-coordinates';
24-
import type { configureActions } from '../actions';
2524
import { useQueryBarQuery } from '@mongodb-js/compass-query-bar';
2625
import { useChangeQueryBarQuery } from '@mongodb-js/compass-query-bar';
2726

@@ -110,7 +109,6 @@ const nestedFieldStyles = css({
110109
});
111110

112111
type FieldProps = {
113-
actions: ReturnType<typeof configureActions>;
114112
name: string;
115113
path: string[];
116114
types: SchemaType[];
@@ -196,7 +194,7 @@ export function shouldShowUnboundArrayInsight(
196194
);
197195
}
198196

199-
function Field({ actions, name, path, types, enableMaps }: FieldProps) {
197+
function Field({ name, path, types, enableMaps }: FieldProps) {
200198
const query = useQueryBarQuery();
201199
const changeQuery = useChangeQueryBarQuery();
202200
const [isExpanded, setIsExpanded] = useState(false);
@@ -308,7 +306,6 @@ function Field({ actions, name, path, types, enableMaps }: FieldProps) {
308306
fieldValue={query.filter?.[fieldName]}
309307
type={activeType}
310308
nestedDocType={nestedDocType}
311-
actions={actions}
312309
onQueryChanged={debouncedChangeQuery}
313310
/>
314311
</div>
@@ -326,7 +323,7 @@ function Field({ actions, name, path, types, enableMaps }: FieldProps) {
326323
{(getNestedDocType(types)?.fields || []).map(
327324
(field: SchemaField) => (
328325
<div className={nestedFieldStyles} key={field.name}>
329-
<Field actions={actions} enableMaps={enableMaps} {...field} />
326+
<Field enableMaps={enableMaps} {...field} />
330327
</div>
331328
)
332329
)}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ 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';
1011

1112
class MiniChart extends PureComponent {
1213
static displayName = 'MiniChartComponent';
@@ -34,8 +35,8 @@ class MiniChart extends PureComponent {
3435
// but it is not noticable to the user.
3536
this.resizeListener();
3637
window.addEventListener('resize', this.resizeListener);
37-
this.unsubscribeMiniChartResize =
38-
this.props.actions.resizeMiniCharts.listen(this.resizeListener);
38+
// this.unsubscribeMiniChartResize =
39+
// this.props.actions.resizeMiniCharts.listen(this.resizeListener);
3940
}
4041

4142
componentWillUnmount() {
@@ -149,4 +150,4 @@ class MiniChart extends PureComponent {
149150
}
150151
}
151152

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

packages/compass-schema/src/modules/schema-analysis.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ export const analyzeSchema = async (
5555
ns,
5656
});
5757

58-
console.log({ aggregateOptions });
59-
6058
const docs = await dataService.sample(
6159
ns,
6260
query,

0 commit comments

Comments
 (0)