Skip to content

Commit 5a9e105

Browse files
author
Elliot
authored
Action List: Close Actions Menu on Action click (#697)
* Changing children property in ActionListColumn interface to title * Updated ActionListItemAction to close Action menu on click / enter key press * Removed unnecessary MenuContext import * Updated ActionList test suite to reflect change to ActionListColumn interface and new Action click behavior * Updated sort_utils.test * Updated sort_utils snapshots * Updated icons in ActionListDemo * Removed unnecessary state in ActionListItem
1 parent 5e7998c commit 5a9e105

File tree

9 files changed

+38
-30
lines changed

9 files changed

+38
-30
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
- `TextArea` component was created with documentation and tests
1313
- `FieldTextArea` component was created with documentation and tests
1414
- `ArrowLeft`, `EditOutline`, `ExploreOutline` Icons added
15+
- `ActionList` supports sorting
1516
- `ModalHeader` add support for `iconClose` option
1617

1718
### Change
@@ -20,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2021
- update InputSearch to display search icon
2122
- `ArrowDropDown` and `ArrowDropUp` Icons renamed to `ArrowUp` and `ArrowDown`
2223
- `CacheRefesh` Icon update
24+
- `ActionList` closes Actions menu on `ActionListItemAction` click
2325
- `Confirm` no longer displays a `Close` `IconButton` in the header
2426

2527

packages/components/src/ActionList/ActionList.test.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,21 @@ import {
3939
const columns: ActionListColumns = [
4040
{
4141
canSort: true,
42-
children: 'ID',
4342
id: 'id',
4443
primaryKey: true,
44+
title: 'ID',
4545
type: 'number',
4646
widthPercent: 10,
4747
},
4848
{
49-
children: 'Name',
5049
id: 'name',
50+
title: 'Name',
5151
type: 'string',
5252
widthPercent: 45,
5353
},
5454
{
55-
children: 'Role',
5655
id: 'role',
56+
title: 'Role',
5757
type: 'string',
5858
widthPercent: 45,
5959
},
@@ -218,7 +218,6 @@ describe('ActionList', () => {
218218
fireEvent.click(viewProfileAction)
219219
expect(handleActionClick.mock.calls.length).toBe(1)
220220

221-
fireEvent.click(listItemButton)
222221
expect(queryByText('View Profile')).not.toBeInTheDocument()
223222
})
224223
})

packages/components/src/ActionList/ActionList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import { ActionListHeaderColumn } from './ActionListHeader/ActionListHeaderColum
3737

3838
export type ActionListColumns = ActionListColumn[]
3939
export interface ActionListColumn {
40-
children: ReactNode
40+
title: ReactNode
4141
/**
4242
* A unique identifier for a given column
4343
* Note: A column object's id should match a key in your data object template

packages/components/src/ActionList/ActionListHeader/generate.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import { ActionListHeaderColumn } from './ActionListHeaderColumn'
44
import { ActionListHeader } from './ActionListHeader'
55

66
export const generateActionListHeaderColumns = (columns: ActionListColumns) =>
7-
columns.map(({ children, id }) => (
7+
columns.map(({ id, title }) => (
88
<ActionListHeaderColumn key={id} id={id}>
9-
{children}
9+
{title}
1010
</ActionListHeaderColumn>
1111
))
1212

packages/components/src/ActionList/ActionListItemAction.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626

2727
import { CompatibleHTMLProps } from '@looker/design-tokens'
2828
import { IconNames } from '@looker/icons'
29-
import React, { ReactNode } from 'react'
30-
import { MenuItem } from '../Menu/'
29+
import React, { ReactNode, useContext } from 'react'
30+
import { MenuItem, MenuContext } from '../Menu'
3131

3232
export interface ActionListItemActionProps
3333
extends CompatibleHTMLProps<HTMLElement> {
@@ -41,6 +41,13 @@ export interface ActionListItemActionProps
4141
* MenuItem may undergo a refactor soon. Creating a proxy in the form of ActionListItemAction
4242
* allows us to adapt to any changes to MenuItem or its interface.
4343
* */
44-
export const ActionListItemAction = (props: ActionListItemActionProps) => (
45-
<MenuItem {...props} />
46-
)
44+
export const ActionListItemAction = (props: ActionListItemActionProps) => {
45+
const { setOpen } = useContext(MenuContext)
46+
const handleActionClick = (
47+
event: React.MouseEvent<HTMLElement, MouseEvent>
48+
) => {
49+
setOpen && setOpen(false)
50+
props.onClick && props.onClick(event)
51+
}
52+
return <MenuItem {...props} onClick={handleActionClick} />
53+
}

packages/components/src/ActionList/utils/__snapshots__/sort_utils.test.ts.snap

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ Object {
55
"columns": Array [
66
Object {
77
"canSort": true,
8-
"children": "ID",
98
"id": "id",
109
"primaryKey": true,
1110
"sortDirection": "asc",
11+
"title": "ID",
1212
"type": "number",
1313
"widthPercent": 20,
1414
},
1515
Object {
1616
"canSort": true,
17-
"children": "Name",
1817
"id": "name",
18+
"title": "Name",
1919
"type": "string",
2020
"widthPercent": 80,
2121
},
@@ -38,17 +38,17 @@ Object {
3838
"columns": Array [
3939
Object {
4040
"canSort": true,
41-
"children": "ID",
4241
"id": "id",
4342
"primaryKey": true,
4443
"sortDirection": "desc",
44+
"title": "ID",
4545
"type": "number",
4646
"widthPercent": 20,
4747
},
4848
Object {
4949
"canSort": true,
50-
"children": "Name",
5150
"id": "name",
51+
"title": "Name",
5252
"type": "string",
5353
"widthPercent": 80,
5454
},
@@ -71,17 +71,17 @@ Object {
7171
"columns": Array [
7272
Object {
7373
"canSort": true,
74-
"children": "ID",
7574
"id": "id",
7675
"primaryKey": true,
76+
"title": "ID",
7777
"type": "number",
7878
"widthPercent": 20,
7979
},
8080
Object {
8181
"canSort": true,
82-
"children": "Name",
8382
"id": "name",
8483
"sortDirection": "asc",
84+
"title": "Name",
8585
"type": "string",
8686
"widthPercent": 80,
8787
},
@@ -104,17 +104,17 @@ Object {
104104
"columns": Array [
105105
Object {
106106
"canSort": true,
107-
"children": "ID",
108107
"id": "id",
109108
"primaryKey": true,
109+
"title": "ID",
110110
"type": "number",
111111
"widthPercent": 20,
112112
},
113113
Object {
114114
"canSort": true,
115-
"children": "Name",
116115
"id": "name",
117116
"sortDirection": "desc",
117+
"title": "Name",
118118
"type": "string",
119119
"widthPercent": 80,
120120
},

packages/components/src/ActionList/utils/sort_utils.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,16 @@ describe('Action List Sort Utils', () => {
5454
const columns: ActionListColumns = [
5555
{
5656
canSort: true,
57-
children: 'ID',
5857
id: 'id',
5958
primaryKey: true,
59+
title: 'ID',
6060
type: 'number',
6161
widthPercent: 20,
6262
},
6363
{
6464
canSort: true,
65-
children: 'Name',
6665
id: 'name',
66+
title: 'Name',
6767
type: 'string',
6868
widthPercent: 80,
6969
},

packages/playground/src/ActionList/ActionListDemo.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,33 +61,33 @@ const data = [
6161

6262
const columns: ActionListColumns = [
6363
{
64-
children: 'PDT Name',
6564
id: 'pdt_name',
6665
primaryKey: true,
66+
title: 'PDT Name',
6767
type: 'string',
6868
widthPercent: 27,
6969
},
7070
{
71-
children: 'Status',
7271
id: 'status',
72+
title: 'Status',
7373
type: 'string',
7474
widthPercent: 13,
7575
},
7676
{
77-
children: 'Model',
7877
id: 'model',
78+
title: 'Model',
7979
type: 'string',
8080
widthPercent: 20,
8181
},
8282
{
83-
children: 'Persistance Type',
8483
id: 'persistance_type',
84+
title: 'Persistance Type',
8585
type: 'string',
8686
widthPercent: 20,
8787
},
8888
{
89-
children: 'Last Successful Build',
9089
id: 'last_successful_build',
90+
title: 'Last Successful Build',
9191
type: 'string',
9292
widthPercent: 20,
9393
},
@@ -144,7 +144,7 @@ export const ActionListDemo: FC = () => {
144144
}
145145
indicator={
146146
<Icon
147-
name={status === 'Success' ? 'ArrowUp' : 'ArrowDown'}
147+
name={status === 'Success' ? 'CircleCheck' : 'CircleCancel'}
148148
color={
149149
status === 'Success' ? 'palette.green300' : 'palette.red300'
150150
}

packages/playground/src/ActionList/SortableActionListDemo.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,16 @@ export const SortableActionListDemo: FC = () => {
4949
const columns: ActionListColumns = [
5050
{
5151
canSort: true,
52-
children: 'ID',
5352
id: 'id',
5453
primaryKey: true,
54+
title: 'ID',
5555
type: 'number',
5656
widthPercent: 20,
5757
},
5858
{
5959
canSort: true,
60-
children: 'Name',
6160
id: 'name',
61+
title: 'Name',
6262
type: 'string',
6363
widthPercent: 80,
6464
},

0 commit comments

Comments
 (0)