Files
graylog2-server/graylog2-web-interface/src/views/components/aggregationwizard/ElementConfigurationContainer.tsx
graylog-internal-actions-access[bot] 3ed1e2cce7 Fix direction radio button losing visual state during DnD reorder (7.0) (#25192) (#25228)
* Fix direction radio button losing visual state during DnD reorder (#25169)

* Rendering grouping configuration in portal while dragging.

* Adding changelog snippet.

(cherry picked from commit f91cb82471)

* Assigning stable ids to direction radio inputs.

---------

(cherry picked from commit ab9c77b63b)

Co-authored-by: Dennis Oelkers <dennis@graylog.com>
2026-03-12 13:58:07 +01:00

110 lines
2.9 KiB
TypeScript

/*
* Copyright (C) 2020 Graylog, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the Server Side Public License, version 1,
* as published by MongoDB, Inc.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Server Side Public License for more details.
*
* You should have received a copy of the Server Side Public License
* along with this program. If not, see
* <http://www.mongodb.com/licensing/server-side-public-license>.
*/
import * as React from 'react';
import { forwardRef } from 'react';
import styled, { css } from 'styled-components';
import { Icon, IconButton } from 'components/common';
import type { DraggableProps, DragHandleProps } from 'components/common/SortableList';
const Container = styled.div(
({ theme }) => css`
display: flex;
padding: 6px 5px 3px 7px;
margin-bottom: 5px;
border-radius: 3px;
border: 1px solid ${theme.colors.variant.lighter.default};
background-color: ${theme.colors.variant.lightest.default};
flex-direction: column;
position: relative;
input {
font-size: ${theme.fonts.size.body};
}
.control-label {
padding-left: 0;
padding-right: 5px;
font-weight: normal;
}
`,
);
const ElementActions = styled.div`
display: flex;
flex-direction: row;
justify-content: end;
align-items: center;
position: absolute;
right: 0;
top: 5px;
`;
const StyledIconButton = styled(IconButton)`
width: fit-content;
height: fit-content;
`;
const ElementConfiguration = styled.div`
flex: 1;
// The min-width is required to avoid an overflow problem with the parent component.
min-width: 0;
`;
const DragHandle = styled.div`
display: flex;
align-items: center;
justify-content: center;
`;
type Props = {
children: React.ReactNode;
onRemove?: () => void;
elementTitle: string;
draggableProps?: DraggableProps;
dragHandleProps?: DragHandleProps;
className?: string;
testIdPrefix?: string;
};
const ElementConfigurationContainer = (
{
children,
onRemove = undefined,
testIdPrefix = 'configuration',
dragHandleProps = undefined,
className = undefined,
draggableProps = undefined,
elementTitle,
}: Props,
ref: React.ForwardedRef<HTMLDivElement>,
) => (
<Container className={className} ref={ref} {...(draggableProps ?? {})}>
<ElementActions>
{dragHandleProps && (
<DragHandle {...dragHandleProps} data-testid={`${testIdPrefix}-drag-handle`}>
<Icon size="sm" name="drag_indicator" />
</DragHandle>
)}
{onRemove && <StyledIconButton size="sm" onClick={onRemove} name="delete" title={`Remove ${elementTitle}`} />}
</ElementActions>
<ElementConfiguration>{children}</ElementConfiguration>
</Container>
);
export default forwardRef(ElementConfigurationContainer);