-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Infra] Add collapsible sections (#176048)
Closes #175558 ## Summary This PR makes all asset details overview sections collapsible. All sections will be always open by default and the user should be able to expand/collapse a section. <img width="300" alt="Screenshot 2024-02-01 at 12 04 24" src="https://github.com/elastic/kibana/assets/14139027/b91a190a-eaec-4031-8591-f11a3a04f201"> <img width="300" alt="Screenshot 2024-02-01 at 12 03 50" src="https://github.com/elastic/kibana/assets/14139027/9d8c20fc-3a27-481c-89ad-1fd7f0e6df47"> ## Testing 1. Open Host view 2. Open the hosts flyout and go to the overview tab - All sections should be collapsible - All section buttons should be clickable https://github.com/elastic/kibana/assets/14139027/27a6df67-c560-42d6-9166-a8f45880cf8e 3. Open the asset details page and go to the overview tab - All sections should be collapsible - All section buttons should be clickable https://github.com/elastic/kibana/assets/14139027/f7225ddd-c2a3-4a7b-b520-22acb41e9080
- Loading branch information
1 parent
5104183
commit 5221756
Showing
8 changed files
with
200 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
...ugins/infra/public/components/asset_details/tabs/overview/section/collapsible_section.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { | ||
EuiAccordion, | ||
EuiFlexGroup, | ||
EuiFlexItem, | ||
useGeneratedHtmlId, | ||
type EuiAccordionProps, | ||
} from '@elastic/eui'; | ||
import React, { useState } from 'react'; | ||
|
||
export const CollapsibleSection = ({ | ||
title, | ||
closedSectionContent, | ||
extraAction, | ||
children, | ||
collapsible, | ||
['data-test-subj']: dataTestSubj, | ||
id, | ||
}: { | ||
title: React.FunctionComponent; | ||
closedSectionContent?: React.ReactNode; | ||
extraAction?: React.ReactNode; | ||
dependsOn?: string[]; | ||
children: React.ReactNode; | ||
collapsible: boolean; | ||
['data-test-subj']: string; | ||
id: string; | ||
}) => { | ||
const [trigger, setTrigger] = useState<EuiAccordionProps['forceState']>('open'); | ||
|
||
const Title = title; | ||
const ButtonContent = () => | ||
closedSectionContent && trigger === 'closed' ? ( | ||
<EuiFlexGroup gutterSize="m"> | ||
<EuiFlexItem grow={false}> | ||
<Title /> | ||
</EuiFlexItem> | ||
<EuiFlexItem grow={false}>{closedSectionContent}</EuiFlexItem> | ||
</EuiFlexGroup> | ||
) : ( | ||
<Title /> | ||
); | ||
const collapsibleSectionAccordionId = useGeneratedHtmlId({ | ||
prefix: id, | ||
}); | ||
|
||
const onToggle = (isOpen: boolean) => { | ||
const newState = isOpen ? 'open' : 'closed'; | ||
setTrigger(newState); | ||
}; | ||
|
||
return collapsible ? ( | ||
<EuiAccordion | ||
id={collapsibleSectionAccordionId} | ||
data-section-id={id} | ||
buttonElement="div" | ||
element="fieldset" | ||
buttonContent={<ButtonContent />} | ||
buttonProps={{ 'data-test-subj': dataTestSubj }} | ||
paddingSize="s" | ||
initialIsOpen={true} | ||
extraAction={extraAction ?? undefined} | ||
forceState={trigger} | ||
onToggle={onToggle} | ||
data-section-state={trigger} | ||
data-test-subj="infraAssetDetailsCollapseExpandSection" | ||
> | ||
{children} | ||
</EuiAccordion> | ||
) : ( | ||
<EuiFlexGroup gutterSize="m" direction="column"> | ||
<EuiFlexItem grow={false}> | ||
<Title /> | ||
</EuiFlexItem> | ||
<EuiFlexItem grow={false}>{children}</EuiFlexItem> | ||
</EuiFlexGroup> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters