Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(deps): update LG packages COMPASS-8611 #6569

Merged
merged 16 commits into from
Dec 17, 2024
2,326 changes: 1,066 additions & 1,260 deletions package-lock.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,7 @@ export const GroupWithSubset = ({
<>
<TextInput
type="number"
label="Number of records"
addaleax marked this conversation as resolved.
Show resolved Hide resolved
// NOTE: LeafyGreen doesn't support aria-label and only understands "aria-labelledby" and "label".
aria-labelledby=""
aria-label="Number of records"
data-testid="number-of-records-input"
placeholder="Number of records"
className={recordInputStyles}
Expand Down Expand Up @@ -339,7 +337,6 @@ export const GroupWithSubset = ({
className={selectStyles}
allowDeselect={false}
aria-label="Select direction"
usePortal={false}
value={formData.sortDirection}
onChange={(value: string) =>
onChangeValue('sortDirection', value as SortDirection)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,11 @@ export const LookupForm = ({
/>
</div>
<div className={formGroup}>
<Body id="lookup-stage-as-input-label" className={titleStyles}>
<Body
aria-label="Name of the array"
id="lookup-stage-as-input-label"
className={titleStyles}
>
as
</Body>
<div className={inputFieldStyles}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ const MatchConditionForm = ({
allowDeselect={false}
placeholder={LABELS.operatorSelect}
aria-label={LABELS.operatorSelect}
usePortal={true}
value={condition.operator}
onChange={handleOperatorChange}
>
Expand Down Expand Up @@ -197,7 +196,6 @@ const MatchConditionForm = ({
allowDeselect={false}
placeholder={LABELS.typeSelect}
aria-label={LABELS.typeSelect}
usePortal={true}
value={condition.bsonType}
onChange={handleBsonTypeChange}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@ describe('project', function () {
'street',
'city',
]);
const selectedOptions = within(
const comboboxInput = within(
screen.getByTestId('project-form-field')
).getAllByRole('option');
).getByRole('combobox');
const selectedOptions = within(comboboxInput).getAllByRole('option');

expect(selectedOptions).to.have.lengthOf(2);
expect(within(selectedOptions[0]).getByText(/street/i)).to.exist;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,55 +270,60 @@ export const FocusModeModalHeader: React.FunctionComponent<
/>
</div>

<Menu
data-testid="add-stage-menu-content"
className={menuStyles}
open={menuOpen}
setOpen={setMenuOpen}
trigger={({ onClick, children }: any) => {
return (
<div className={controlContainerStyles}>
<Button
data-testid="add-stage-menu-button"
size="xsmall"
leftGlyph={
<Icon
title={null}
role="presentation"
glyph="PlusWithCircle"
></Icon>
}
rightGlyph={
<Icon
title={null}
role="presentation"
glyph="CaretDown"
></Icon>
}
onClick={onClick}
>
Add stage
</Button>
{children}
</div>
);
}}
>
<MenuItem
className={menuItemStyles}
onClick={onAddStageAfter}
data-hotkey={formatHotkey(ADD_STAGE_AFTER_HOTKEY)}
>
Add stage after
</MenuItem>
<MenuItem
className={menuItemStyles}
onClick={onAddStageBefore}
data-hotkey={formatHotkey(ADD_STAGE_BEFORE_HOTKEY)}
{/* Menu popover is rendered inside this div and positioned correctly when it opens. */}
<div>
<Menu
data-testid="add-stage-menu-content"
className={menuStyles}
open={menuOpen}
setOpen={setMenuOpen}
trigger={({ onClick, children }: any) => {
return (
<div className={controlContainerStyles}>
<Button
data-testid="add-stage-menu-button"
size="xsmall"
leftGlyph={
<Icon
title={null}
role="presentation"
glyph="PlusWithCircle"
></Icon>
}
rightGlyph={
<Icon
title={null}
role="presentation"
glyph="CaretDown"
></Icon>
}
onClick={onClick}
>
Add stage
</Button>
{children}
</div>
);
}}
>
Add stage before
</MenuItem>
</Menu>
<MenuItem
className={menuItemStyles}
onClick={onAddStageAfter}
data-hotkey={formatHotkey(ADD_STAGE_AFTER_HOTKEY)}
data-text="Add stage after"
>
Add stage after
</MenuItem>
<MenuItem
className={menuItemStyles}
onClick={onAddStageBefore}
data-hotkey={formatHotkey(ADD_STAGE_BEFORE_HOTKEY)}
data-text="Add stage before"
>
Add stage before
</MenuItem>
</Menu>
</div>

{showInsights && insight && <SignalPopover signals={insight} />}
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react';
import React, { useMemo, useState } from 'react';
import { connect } from 'react-redux';
import {
Menu,
Expand Down Expand Up @@ -39,6 +39,51 @@ export const OptionMenu = ({
}) => {
const [menuOpen, setMenuOpen] = useState(false);

const menuItems = useMemo(() => {
return [
{
label: 'Add stage after',
onClick: () => {
onAddStageClick(index);
setMenuOpen(false);
},
icon: 'PlusWithCircle',
},
{
label: 'Add stage before',
onClick: () => {
onAddStageClick(index - 1);
setMenuOpen(false);
},
icon: 'PlusWithCircle',
},
{
label: 'Delete stage',
onClick: () => {
onDeleteStageClick(index);
setMenuOpen(false);
},
icon: 'Trash',
},
{
label: 'Expand documents',
onClick: () => {
onExpand(index);
setMenuOpen(false);
},
icon: 'ChevronDown',
},
{
label: 'Collapse documents',
onClick: () => {
onCollapse(index);
setMenuOpen(false);
},
icon: 'ChevronUp',
},
];
}, [index, onAddStageClick, onDeleteStageClick, onExpand, onCollapse]);

return (
Comment on lines +42 to +86
Copy link
Contributor

@kraenhansen kraenhansen Dec 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've seen us doing this pattern elsewhere, but why do you see this being advantageous over simply rendering the children? I see possibilities of making the existing code more DRY without falling back on this pattern of building component trees from arrays of "data". In any case, would it make sense to separate this out into its own PR or does it have to be included in this work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this to simply avoid adding data-text prop in the menu item because i did not want to repeat the text.
How would you prefer to clean this?

<Menu
open={menuOpen}
Expand All @@ -60,69 +105,18 @@ export const OptionMenu = ({
);
}}
>
<MenuItem
onClick={() => {
onAddStageClick(index);
setMenuOpen(false);
}}
>
<div className={menuItemStyles}>
<Icon
color={palette.gray.dark2}
glyph="PlusWithCircle"
size="small"
/>
Add stage after
</div>
</MenuItem>
<MenuItem
onClick={() => {
onAddStageClick(index - 1);
setMenuOpen(false);
}}
>
<div className={menuItemStyles}>
<Icon
color={palette.gray.dark2}
glyph="PlusWithCircle"
size="small"
/>
Add stage before
</div>
</MenuItem>
<MenuItem
onClick={() => {
onDeleteStageClick(index);
setMenuOpen(false);
}}
>
<div className={menuItemStyles}>
<Icon color={palette.gray.dark2} glyph="Trash" size="small" />
Delete stage
</div>
</MenuItem>
<MenuItem
onClick={() => {
onExpand(index);
setMenuOpen(false);
}}
>
<div className={menuItemStyles}>
<Icon color={palette.gray.dark2} glyph="ChevronDown" size="small" />
Expand documents
</div>
</MenuItem>
<MenuItem
onClick={() => {
onCollapse(index);
setMenuOpen(false);
}}
>
<div className={menuItemStyles}>
<Icon color={palette.gray.dark2} glyph="ChevronUp" size="small" />
Collapse documents
</div>
</MenuItem>
{menuItems.map((item) => (
<MenuItem
key={item.label}
data-text={item.label}
onClick={item.onClick}
>
<div className={menuItemStyles}>
<Icon color={palette.gray.dark2} glyph={item.icon} size="small" />
{item.label}
</div>
</MenuItem>
))}
</Menu>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,11 @@ const comboboxStyles = css({
minHeight: inputHeight,
},
},
});

const comboboxPortalStyles = css({
position: 'fixed',
top: 0,
// -4px to count for the input focus outline.
left: `${comboboxOptionsLeft - 4}px`,
zIndex: 1,
'> div': {
'> :popover-open': {
width: comboxboxOptionsWidth,
whiteSpace: 'normal',
// -4px to count for the input focus outline.
marginLeft: `${comboboxOptionsLeft - 4}px`,
},
});

Expand Down Expand Up @@ -74,35 +68,28 @@ export const StageOperatorSelect = ({
},
[onChange, index]
);
const portalRef = React.useRef<HTMLDivElement | null>(null);

return (
<React.Fragment>
<div className={comboboxPortalStyles} ref={portalRef} />
<Combobox
value={selectedStage}
disabled={isDisabled}
aria-label="Select a stage operator"
onChange={onStageOperatorSelected}
size="default"
clearable={false}
data-testid="stage-operator-combobox"
className={comboboxStyles}
portalContainer={portalRef.current}
usePortal
>
{stages.map((stage, index) => (
<ComboboxOption
data-testid={`combobox-option-stage-${stage.name}`}
key={`combobox-option-stage-${index}`}
value={stage.name}
description={
(isAtlasOnly(stage.env) ? 'Atlas only. ' : '') + stage.description
}
/>
))}
</Combobox>
</React.Fragment>
<Combobox
value={selectedStage}
disabled={isDisabled}
aria-label="Select a stage operator"
onChange={onStageOperatorSelected}
size="default"
clearable={false}
data-testid="stage-operator-combobox"
className={comboboxStyles}
>
{stages.map((stage, index) => (
<ComboboxOption
data-testid={`combobox-option-stage-${stage.name}`}
key={`combobox-option-stage-${index}`}
value={stage.name}
description={
(isAtlasOnly(stage.env) ? 'Atlas only. ' : '') + stage.description
}
/>
))}
</Combobox>
);
};

Expand Down
Loading
Loading