-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Security Solution][Detections] Adds loading states to export/delete …
…on modal (#72562) * Add loading spinners to Value Lists modal While export or a delete is pending, we display a loading spinner instead of the button that was clicked. Since state is controlled in the parent, we must pass this additional state in the same way; the table component simply reacts to this state. * Fix bug with useAsync and multiple calls Multiple calls to start() would not previously reset the hook's state, where useEffect on the hook's state would fire improperly as subsequent calls would not travel the same undefined -> result path. * Fix style of loading spinner This fits the size of the button it's replacing, so no shifting occurs when replacing elements. * Better styling of spinner Keep it roughly the same size as the icons themselves, and fill the space with margin. * Fix circular dependency in value lists modal Moves our shared types into a separate module to prevent a circular dependency.
- Loading branch information
Showing
7 changed files
with
185 additions
and
67 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
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
98 changes: 98 additions & 0 deletions
98
...rity_solution/public/detections/components/value_lists_management_modal/table_helpers.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,98 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
/* eslint-disable react/display-name */ | ||
|
||
import React from 'react'; | ||
import styled from 'styled-components'; | ||
import { EuiButtonIcon, IconType, EuiLoadingSpinner, EuiToolTip } from '@elastic/eui'; | ||
|
||
import { ListSchema } from '../../../../../lists/common/schemas/response'; | ||
import { FormattedDate } from '../../../common/components/formatted_date'; | ||
import * as i18n from './translations'; | ||
import { TableItem, TableItemCallback, TableProps } from './types'; | ||
|
||
const AlignedSpinner = styled(EuiLoadingSpinner)` | ||
margin: ${({ theme }) => theme.eui.euiSizeXS}; | ||
vertical-align: middle; | ||
`; | ||
|
||
const ActionButton: React.FC<{ | ||
content: string; | ||
dataTestSubj: string; | ||
icon: IconType; | ||
isLoading: boolean; | ||
item: TableItem; | ||
onClick: TableItemCallback; | ||
}> = ({ content, dataTestSubj, icon, item, onClick, isLoading }) => ( | ||
<EuiToolTip content={content}> | ||
{isLoading ? ( | ||
<AlignedSpinner size="m" /> | ||
) : ( | ||
<EuiButtonIcon | ||
aria-label={content} | ||
data-test-subj={dataTestSubj} | ||
iconType={icon} | ||
onClick={() => onClick(item)} | ||
/> | ||
)} | ||
</EuiToolTip> | ||
); | ||
|
||
export const buildColumns = ( | ||
onExport: TableItemCallback, | ||
onDelete: TableItemCallback | ||
): TableProps['columns'] => [ | ||
{ | ||
field: 'name', | ||
name: i18n.COLUMN_FILE_NAME, | ||
truncateText: true, | ||
}, | ||
{ | ||
field: 'created_at', | ||
name: i18n.COLUMN_UPLOAD_DATE, | ||
render: (value: ListSchema['created_at']) => ( | ||
<FormattedDate value={value} fieldName="created_at" /> | ||
), | ||
width: '30%', | ||
}, | ||
{ | ||
field: 'created_by', | ||
name: i18n.COLUMN_CREATED_BY, | ||
truncateText: true, | ||
width: '20%', | ||
}, | ||
{ | ||
name: i18n.COLUMN_ACTIONS, | ||
actions: [ | ||
{ | ||
render: (item) => ( | ||
<ActionButton | ||
content={i18n.ACTION_EXPORT_DESCRIPTION} | ||
dataTestSubj="action-export-value-list" | ||
icon="exportAction" | ||
item={item} | ||
onClick={onExport} | ||
isLoading={item.isExporting} | ||
/> | ||
), | ||
}, | ||
{ | ||
render: (item) => ( | ||
<ActionButton | ||
content={i18n.ACTION_DELETE_DESCRIPTION} | ||
dataTestSubj="action-delete-value-list" | ||
icon="trash" | ||
item={item} | ||
onClick={onDelete} | ||
isLoading={item.isDeleting} | ||
/> | ||
), | ||
}, | ||
], | ||
width: '15%', | ||
}, | ||
]; |
16 changes: 16 additions & 0 deletions
16
...gins/security_solution/public/detections/components/value_lists_management_modal/types.ts
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,16 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { EuiBasicTableProps } from '@elastic/eui'; | ||
|
||
import { ListSchema } from '../../../../../lists/common/schemas/response'; | ||
|
||
export interface TableItem extends ListSchema { | ||
isDeleting: boolean; | ||
isExporting: boolean; | ||
} | ||
export type TableProps = EuiBasicTableProps<TableItem>; | ||
export type TableItemCallback = (item: TableItem) => void; |