-
Notifications
You must be signed in to change notification settings - Fork 364
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into develop
- Loading branch information
Showing
33 changed files
with
1,035 additions
and
256 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
139 changes: 139 additions & 0 deletions
139
packages/manager/src/components/RemovableSelectionsList/RemovableSelectionsListTable.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,139 @@ | ||
import Close from '@mui/icons-material/Close'; | ||
import * as React from 'react'; | ||
|
||
import { IconButton } from 'src/components/IconButton'; | ||
import { Table } from 'src/components/Table'; | ||
import { TableBody } from 'src/components/TableBody'; | ||
import { TableCell } from 'src/components/TableCell'; | ||
import { TableHead } from 'src/components/TableHead'; | ||
import { TableRow } from 'src/components/TableRow'; | ||
import { determineNoneSingleOrMultipleWithChip } from 'src/utilities/noneSingleOrMultipleWithChip'; | ||
|
||
import { TableRowEmpty } from '../TableRowEmpty/TableRowEmpty'; | ||
import { | ||
SelectedOptionsHeader, | ||
StyledLabel, | ||
} from './RemovableSelectionsList.style'; | ||
|
||
export type RemovableItem = { | ||
id: number; | ||
label: string; | ||
// The remaining key-value pairs must have their values typed | ||
// as 'any' because we do not know what types they could be. | ||
// Trying to type them as 'unknown' led to type errors. | ||
} & { [key: string]: any }; | ||
|
||
export interface RemovableSelectionsListTableProps { | ||
/** | ||
* The descriptive text to display above the list | ||
*/ | ||
headerText: string; | ||
/** | ||
* If false, hide the remove button | ||
*/ | ||
isRemovable?: boolean; | ||
/** | ||
* The text to display if there is no data | ||
*/ | ||
noDataText: string; | ||
/** | ||
* The action to perform when a data item is clicked | ||
*/ | ||
onRemove: (data: RemovableItem) => void; | ||
/** | ||
* Assumes the passed in prop is a key within the selectionData, and that the | ||
* value of this key is a string. | ||
* Displays the value of this key as the label of the data item, rather than data.label | ||
*/ | ||
preferredDataLabel?: string; | ||
/** | ||
* The data to display in the list | ||
*/ | ||
selectionData: RemovableItem[]; | ||
/** | ||
* Headers for the table containing the list of selected options | ||
*/ | ||
tableHeaders: string[]; | ||
} | ||
|
||
export const RemovableSelectionsListTable = ( | ||
props: RemovableSelectionsListTableProps | ||
) => { | ||
const { | ||
headerText, | ||
isRemovable = true, | ||
noDataText, | ||
onRemove, | ||
preferredDataLabel, | ||
selectionData, | ||
tableHeaders, | ||
} = props; | ||
|
||
const handleOnClick = (selection: RemovableItem) => { | ||
onRemove(selection); | ||
}; | ||
|
||
const selectedOptionsJSX = | ||
selectionData.length === 0 ? ( | ||
<TableRowEmpty colSpan={4} message={noDataText} /> | ||
) : ( | ||
selectionData.map((selection) => ( | ||
<TableRow key={selection.id}> | ||
<TableCell> | ||
<StyledLabel> | ||
{preferredDataLabel | ||
? selection[preferredDataLabel] | ||
: selection.label} | ||
</StyledLabel> | ||
</TableCell> | ||
<TableCell>{selection.interfaceData?.ipv4?.vpc ?? null}</TableCell> | ||
<TableCell> | ||
{determineNoneSingleOrMultipleWithChip( | ||
selection.interfaceData?.ip_ranges ?? [] | ||
)} | ||
</TableCell> | ||
<TableCell> | ||
{isRemovable && ( | ||
<IconButton | ||
aria-label={`remove ${ | ||
preferredDataLabel | ||
? selection[preferredDataLabel] | ||
: selection.label | ||
}`} | ||
disableRipple | ||
onClick={() => handleOnClick(selection)} | ||
size="medium" | ||
> | ||
<Close /> | ||
</IconButton> | ||
)} | ||
</TableCell> | ||
</TableRow> | ||
)) | ||
); | ||
|
||
const tableHeadersJSX = tableHeaders.map((thisHeader, idx) => { | ||
const lastHeader = idx === tableHeaders.length - 1; | ||
|
||
return ( | ||
<TableCell | ||
colSpan={lastHeader ? 2 : 1} | ||
key={`removable-selections-list-header-${thisHeader}`} | ||
> | ||
{thisHeader} | ||
</TableCell> | ||
); | ||
}); | ||
|
||
return ( | ||
<> | ||
<SelectedOptionsHeader>{headerText}</SelectedOptionsHeader> | ||
<Table> | ||
<TableHead> | ||
<TableRow>{tableHeadersJSX}</TableRow> | ||
</TableHead> | ||
<TableBody>{selectedOptionsJSX}</TableBody> | ||
</Table> | ||
</> | ||
); | ||
}; |
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
Oops, something went wrong.