Skip to content

Commit f338780

Browse files
authored
feat(compass-aggregations): update pipeline options to Leafy Green components COMPASS-6048 (#3438)
1 parent cd29cd0 commit f338780

File tree

9 files changed

+195
-323
lines changed

9 files changed

+195
-323
lines changed

packages/compass-aggregations/src/components/pipeline-toolbar/pipeline-options/index.spec.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ describe('PipelineOptions', function () {
1717
container = screen.getByTestId('pipeline-options');
1818
});
1919

20-
it('renders legacy collation toolbar', function () {
21-
expect(within(container).getByTestId('legacy-collation-toolbar')).to.exist;
20+
it('renders the collation toolbar', function () {
21+
expect(within(container).getByTestId('collation-toolbar')).to.exist;
2222
});
2323
});
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import React from 'react';
2+
import { render, screen } from '@testing-library/react';
3+
import { expect } from 'chai';
4+
import { Provider } from 'react-redux';
5+
import userEvent from '@testing-library/user-event';
6+
7+
import configureStore from '../../../stores/store';
8+
import PipelineCollation from './pipeline-collation';
9+
10+
describe('PipelineCollation', function () {
11+
let store: ReturnType<typeof configureStore>;
12+
beforeEach(function () {
13+
store = configureStore();
14+
render(
15+
<Provider store={store}>
16+
<PipelineCollation />
17+
</Provider>
18+
);
19+
});
20+
21+
it('renders the collation toolbar', function () {
22+
expect(screen.getByTestId('collation-toolbar')).to.exist;
23+
});
24+
25+
it('updates the store when a new collation value is typed', function() {
26+
userEvent.tab();
27+
expect(screen.getByTestId('collation-string')).to.eq(document.activeElement);
28+
userEvent.keyboard('8');
29+
const storeState = store.getState();
30+
expect(storeState.collationString.value).to.equal(8);
31+
});
32+
33+
it('updates the store when a new max time ms value is typed', function() {
34+
userEvent.tab();
35+
userEvent.tab();
36+
expect(screen.getByTestId('max-time-ms')).to.eq(document.activeElement);
37+
userEvent.keyboard('5');
38+
const storeState = store.getState();
39+
expect(storeState.maxTimeMS).to.equal(5);
40+
});
41+
});

packages/compass-aggregations/src/components/pipeline-toolbar/pipeline-options/pipeline-collation.tsx

Lines changed: 105 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,130 @@
1-
import React from 'react';
1+
import React, { useCallback } from 'react';
22
import { connect } from 'react-redux';
33
import type { ConnectedProps } from 'react-redux';
4+
import { css, cx, Label, spacing, TextInput, uiColors } from '@mongodb-js/compass-components';
45

56
import type { RootState } from '../../../modules';
67
import { collationStringChanged } from '../../../modules/collation-string';
7-
import { openLink } from '../../../modules/link';
88
import { maxTimeMSChanged } from '../../../modules/max-time-ms';
9+
import { DEFAULT_MAX_TIME_MS } from '../../../constants';
910

10-
import LegacyPipelineCollation from '../../pipeline/collation-toolbar';
11+
const pipelineOptionsContainerStyles = css({
12+
paddingTop: spacing[1],
13+
display: 'flex',
14+
alignItems: 'center',
15+
});
16+
17+
const labelStyles = css({
18+
// A bit of vertical padding so users can click the label easier.
19+
padding: `${spacing[2]}px 0`,
20+
marginRight: spacing[2],
21+
});
22+
23+
const collationInputStyles = css({
24+
flexGrow: 1,
25+
marginRight: spacing[2],
26+
});
27+
28+
const inputStyles = css({
29+
input: {
30+
borderColor: 'transparent',
31+
},
32+
});
33+
34+
const inputWithErrorStyles = css({
35+
input: {
36+
borderColor: uiColors.red.base,
37+
},
38+
});
39+
40+
const collationLabelId = 'aggregations-collation-toolbar-input-label';
41+
const collationInputId = 'aggregations-collation-toolbar-input';
42+
43+
const maxTimeMSLabelId = 'aggregations-max-time-ms-toolbar-input-label';
44+
const maxTimeMSInputId = 'aggregations-max-time-ms-toolbar-input';
1145

1246
const PipelineCollation: React.FunctionComponent<PipelineCollationProps> = ({
13-
collationString,
47+
collationValue,
48+
collationHasError,
1449
collationStringChanged,
15-
maxTimeMS,
50+
maxTimeMSValue,
1651
maxTimeMSChanged,
17-
openLink,
1852
}) => {
19-
const props = {
20-
collationString,
21-
collationStringChanged,
22-
maxTimeMS,
23-
maxTimeMSChanged,
24-
openLink,
25-
};
26-
return <LegacyPipelineCollation {...props} />;
53+
const onMaxTimeMSChanged = useCallback((evt: React.ChangeEvent<HTMLInputElement>) => {
54+
if (maxTimeMSChanged) {
55+
maxTimeMSChanged(parseInt(evt.currentTarget.value, 10));
56+
}
57+
}, [ maxTimeMSChanged]);
58+
59+
return (
60+
<div
61+
className={pipelineOptionsContainerStyles}
62+
data-testid="collation-toolbar"
63+
>
64+
<Label
65+
data-testid="collation-toolbar-input-label"
66+
htmlFor={collationInputId}
67+
id={collationLabelId}
68+
className={labelStyles}
69+
>
70+
Collation
71+
</Label>
72+
<TextInput
73+
aria-labelledby={collationLabelId}
74+
id={collationInputId}
75+
data-testid="collation-string"
76+
className={cx(
77+
collationInputStyles,
78+
inputStyles,
79+
collationHasError && inputWithErrorStyles
80+
)}
81+
type="text"
82+
sizeVariant="small"
83+
state={collationHasError ? 'error' : 'none'}
84+
value={`${collationValue}`}
85+
onChange={(evt: React.ChangeEvent<HTMLInputElement>) =>
86+
collationStringChanged(evt.target.value)
87+
}
88+
placeholder="{ locale: 'simple' }"
89+
/>
90+
<Label
91+
data-testid="maxtimems-toolbar-input-label"
92+
htmlFor={maxTimeMSInputId}
93+
id={maxTimeMSLabelId}
94+
className={labelStyles}
95+
>
96+
Max Time MS
97+
</Label>
98+
<TextInput
99+
aria-labelledby={maxTimeMSLabelId}
100+
id={maxTimeMSInputId}
101+
data-testid="max-time-ms"
102+
className={inputStyles}
103+
placeholder={`${DEFAULT_MAX_TIME_MS}`}
104+
type="number"
105+
min="0"
106+
sizeVariant="small"
107+
value={`${maxTimeMSValue ?? ''}`}
108+
onChange={onMaxTimeMSChanged}
109+
/>
110+
</div>
111+
);
27112
};
28113

29114
const mapState = ({
30115
collationString,
31-
settings: { maxTimeMS: defaultMaxTimeMS, isDirty },
116+
settings: { maxTimeMS: defaultMaxTimeMSFromSettings, isDirty },
32117
maxTimeMS,
33118
}: RootState) => ({
34-
collationString,
35-
maxTimeMS: isDirty ? defaultMaxTimeMS : maxTimeMS,
119+
collationValue: collationString.text,
120+
collationHasError: !collationString.isValid,
121+
maxTimeMSValue: maxTimeMS,
122+
maxTimeMS: isDirty ? defaultMaxTimeMSFromSettings : maxTimeMS,
36123
});
124+
37125
const mapDispatch = {
38126
collationStringChanged,
39127
maxTimeMSChanged,
40-
openLink,
41128
};
42129
const connector = connect(mapState, mapDispatch);
43130
type PipelineCollationProps = ConnectedProps<typeof connector>;

packages/compass-aggregations/src/components/pipeline/collation-toolbar.jsx

Lines changed: 0 additions & 124 deletions
This file was deleted.

packages/compass-aggregations/src/components/pipeline/collation-toolbar.module.less

Lines changed: 0 additions & 69 deletions
This file was deleted.

0 commit comments

Comments
 (0)