Skip to content

Commit 460b941

Browse files
author
Amrit Borah
committed
feat: expand/collapse using right/left arrow
1 parent 351a35a commit 460b941

5 files changed

Lines changed: 55 additions & 3 deletions

File tree

src/Shared/Components/CICDHistory/ConflictedResourcesTable.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import './ConflictedResourcesTable.scss'
1010
const Wrapper = ({ children }: TableViewWrapperProps<unknown, FiltersTypeEnum.STATE>) => (
1111
<div className="dc__overflow-hidden flexbox-col flex-grow-1">{children}</div>
1212
)
13-
const filter = () => true
1413

1514
const ConflictedResourcesTable = ({ resourceConflictDetails }: ConflictedResourcesTableProps) => {
1615
const rows: RowsType<ResourceConflictItemType> = useMemo(
@@ -42,7 +41,7 @@ const ConflictedResourcesTable = ({ resourceConflictDetails }: ConflictedResourc
4241
}}
4342
filtersVariant={FiltersTypeEnum.STATE}
4443
ViewWrapper={Wrapper}
45-
filter={filter}
44+
filter={null}
4645
/>
4746
)
4847
}

src/Shared/Components/Table/TableContent.tsx

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
FiltersTypeEnum,
3636
PaginationEnum,
3737
RowType,
38+
SignalEnum,
3839
SignalsType,
3940
TableContentProps,
4041
} from './types'
@@ -189,7 +190,7 @@ const TableContent = <
189190

190191
useEffectAfterMount(() => {
191192
setActiveRowIndex(0)
192-
}, [offset, visibleRows])
193+
}, [offset])
193194

194195
useEffect(() => {
195196
setIdentifiers?.(
@@ -204,6 +205,36 @@ const TableContent = <
204205
handleSorting(newSortBy)
205206
}
206207

208+
useEffect(() => {
209+
if (!isAnyRowExpandable) {
210+
return () => {}
211+
}
212+
213+
const getExpandCollapseRowHandler =
214+
(state: boolean) =>
215+
({ detail: { activeRowData } }) => {
216+
if ((activeRowData as RowType<RowData>).expandableRows) {
217+
setExpandState({
218+
...expandState,
219+
[activeRowData.id]: state,
220+
})
221+
}
222+
}
223+
224+
const handleExpandRow = getExpandCollapseRowHandler(true)
225+
const handleCollapseRow = getExpandCollapseRowHandler(false)
226+
227+
const signals = EVENT_TARGET as SignalsType
228+
229+
signals.addEventListener(SignalEnum.EXPAND_ROW, handleExpandRow)
230+
signals.addEventListener(SignalEnum.COLLAPSE_ROW, handleCollapseRow)
231+
232+
return () => {
233+
signals.removeEventListener(SignalEnum.EXPAND_ROW, handleExpandRow)
234+
signals.removeEventListener(SignalEnum.COLLAPSE_ROW, handleCollapseRow)
235+
}
236+
}, [isAnyRowExpandable])
237+
207238
const toggleExpandAll = (e: MouseEvent<HTMLButtonElement>) => {
208239
e.stopPropagation()
209240

src/Shared/Components/Table/styles.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@
7676
outline: none;
7777
}
7878

79+
&--expanded-row:has(+ .generic-table__row--expanded-row) {
80+
border-bottom: 0px;
81+
}
82+
7983
&:hover,
8084
&:hover > *,
8185
&--active,

src/Shared/Components/Table/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ import { useBulkSelection, UseBulkSelectionProps } from '../BulkSelection'
3333
export interface UseFiltersReturnType extends UseStateFiltersReturnType<string> {}
3434

3535
export enum SignalEnum {
36+
COLLAPSE_ROW = 'collapse-row',
37+
EXPAND_ROW = 'expand-row',
3638
ENTER_PRESSED = 'enter-pressed',
3739
DELETE_PRESSED = 'delete-pressed',
3840
ESCAPE_PRESSED = 'escape-pressed',

src/Shared/Components/Table/useTableWithKeyboardShortcuts.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,20 @@ const useTableWithKeyboardShortcuts = <
101101
)
102102

103103
useEffect(() => {
104+
registerShortcut({
105+
keys: ['ArrowLeft'],
106+
callback: () => {
107+
dispatchEvent(SignalEnum.COLLAPSE_ROW)
108+
},
109+
})
110+
111+
registerShortcut({
112+
keys: ['ArrowRight'],
113+
callback: () => {
114+
dispatchEvent(SignalEnum.EXPAND_ROW)
115+
},
116+
})
117+
104118
registerShortcut({
105119
keys: ['ArrowDown'],
106120
callback: () => {
@@ -142,6 +156,8 @@ const useTableWithKeyboardShortcuts = <
142156
unregisterShortcut(['Enter'])
143157
unregisterShortcut(['Backspace'])
144158
unregisterShortcut(['.'])
159+
unregisterShortcut(['ArrowLeft'])
160+
unregisterShortcut(['ArrowRight'])
145161
}
146162
}, [getMoveFocusToNextRowHandler, getMoveFocusToPreviousRowHandler, dispatchEvent])
147163

0 commit comments

Comments
 (0)