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

Make collapsed section header clickable #20317

Merged
merged 5 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 18 additions & 14 deletions graylog2-web-interface/src/components/common/Section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* along with this program. If not, see
* <http://www.mongodb.com/licensing/server-side-public-license>.
*/

import * as React from 'react';
import styled, { css } from 'styled-components';
import { useDisclosure } from '@mantine/hooks';
Expand All @@ -24,21 +23,25 @@ import Icon from './Icon';

import { Button } from '../bootstrap';

const Container = styled.div(({ theme }) => css`
const Container = styled.div<{ $collapsible: boolean, $opened: boolean}>(({ $collapsible, $opened, theme }) => css`
background-color: ${theme.colors.section.filled.background};
border: 1px solid ${theme.colors.section.filled.border};
border-radius: 10px;
padding: 15px;
padding: ${($collapsible && !$opened) ? 0 : theme.spacings.md};
margin-bottom: ${theme.spacings.xxs};
`);

const Header = styled.div(({ theme }) => css`
const Header = styled.div<{ $collapsible: boolean, $opened: boolean}>(({ $collapsible, $opened, theme }) => css`
display: flex;
justify-content: space-between;
gap: ${theme.spacings.xs};
align-items: center;
margin-bottom: ${theme.spacings.xs};
border-radius: 10px;
padding: ${($collapsible && !$opened) ? theme.spacings.md : 0};
flex-wrap: wrap;
&:hover {
background-color: ${($collapsible && !$opened) ? theme.colors.table.row.backgroundHover : 'initial'};
}
`);

const FlexWrapper = styled.div(({ theme }) => css`
Expand All @@ -62,24 +65,25 @@ type Props = React.PropsWithChildren<{
*/
const Section = ({ title, actions, headerLeftSection, collapsible, defaultClosed, disableCollapseButton, children }: Props) => {
const [opened, { toggle }] = useDisclosure(!defaultClosed);
const onHeaderClick = () => (!disableCollapseButton && toggle());

return (
<Container>
<Header>
<Container $opened={opened} $collapsible={collapsible}>
<Header $opened={opened} $collapsible={collapsible} onClick={onHeaderClick}>
<FlexWrapper>
<h2>{title}</h2>
{headerLeftSection && <FlexWrapper>{headerLeftSection}</FlexWrapper>}
</FlexWrapper>
<FlexWrapper>
{actions && <div>{actions}</div>}
{collapsible && (
<Button bsSize="sm"
bsStyle={opened ? 'primary' : 'default'}
onClick={toggle}
data-testid="collapseButton"
disabled={disableCollapseButton}>
<Icon size="sm" name={opened ? 'keyboard_arrow_up' : 'keyboard_arrow_down'} />
</Button>
<Button bsSize="sm"
bsStyle={opened ? 'primary' : 'default'}
onClick={toggle}
data-testid="collapseButton"
disabled={disableCollapseButton}>
<Icon size="sm" name={opened ? 'keyboard_arrow_up' : 'keyboard_arrow_down'} />
</Button>
)}
</FlexWrapper>
</Header>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import * as React from 'react';
import { PluginStore } from 'graylog-web-plugin/plugin';
import styled, { css } from 'styled-components';

import { IfPermitted } from 'components/common';
import type { Stream } from 'stores/streams/StreamsStore';
import useSingleIndexSet from 'components/indices/hooks/useSingleIndexSet';
import DestinationOutputs from 'components/streams/StreamDetails/routing-destination/DestinationOutputs';
Expand All @@ -43,7 +44,9 @@ const StreamDataRoutingDestinations = ({ stream }: Props) => {
<Container>
{isSuccess && <DestinationIndexSetSection indexSet={indexSet} stream={stream} />}
{StreamDataWarehouseComponent && <StreamDataWarehouseComponent />}
<DestinationOutputs stream={stream} />
<IfPermitted permissions="outputs:edit">
<DestinationOutputs stream={stream} />
</IfPermitted>
</Container>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* along with this program. If not, see
* <http://www.mongodb.com/licensing/server-side-public-license>.
*/

import * as React from 'react';
import { useState } from 'react';
import styled, { css } from 'styled-components';
Expand All @@ -27,13 +26,13 @@ import { LinkContainer } from 'components/common/router';
import Routes from 'routing/Routes';
import { useStore } from 'stores/connect';
import type { Stream } from 'stores/streams/StreamsStore';
import NumberUtils from 'util/NumberUtils';
import useStreamOutputFilters from 'components/streams/hooks/useStreamOutputFilters';
import IndexSetArchivingCell from 'components/streams/StreamDetails/routing-destination/IndexSetArchivingCell';
import IndexSetUpdateForm from 'components/streams/StreamDetails/routing-destination/IndexSetUpdateForm';
import IndexSetFilters from 'components/streams/StreamDetails/routing-destination/IndexSetFilters';
import SectionCountLabel from 'components/streams/StreamDetails/SectionCountLabel';
import useIndexSetStats from 'hooks/useIndexSetStats';
import NumberUtils from 'util/NumberUtils';
import { DEFAULT_PAGINATION } from 'stores/PaginationTypes';

type Props = {
Expand Down Expand Up @@ -73,6 +72,7 @@ const DestinationIndexSetSection = ({ indexSet, stream }: Props) => {
return (
<Section title="Index Set"
collapsible
defaultClosed
headerLeftSection={(
<>
<StyledSwitch aria-label="Toggle index set"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,11 @@ const StreamActions = ({

return (
<ButtonToolbar>
<LinkContainer to={Routes.stream_view(stream.id)}>
<Button disabled={isNotEditable} bsStyle="primary" bsSize="xsmall">View details</Button>
</LinkContainer>
<IfPermitted permissions={`streams:edit:${stream.id}`}>
<LinkContainer to={Routes.stream_view(stream.id)}>
<Button disabled={isNotEditable} bsStyle="primary" bsSize="xsmall">Data Routing</Button>
</LinkContainer>
</IfPermitted>
<ShareButton entityId={stream.id}
entityType="stream"
onClick={toggleEntityShareModal}
Expand Down
Loading