mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
This implements a very simple Project Summary page (which lists workspaces):  ...which also has an empty state:  Fixes #66
14 lines
413 B
TypeScript
14 lines
413 B
TypeScript
/**
|
|
* Helper function that, given an array or a single item:
|
|
* - If an array with no elements, returns null
|
|
* - If an array with 1 or more elements, returns the first element
|
|
* - If a single item, returns that item
|
|
*/
|
|
export const firstOrItem = <T>(itemOrItems: T | T[]): T | null => {
|
|
if (Array.isArray(itemOrItems)) {
|
|
return itemOrItems.length > 0 ? itemOrItems[0] : null
|
|
}
|
|
|
|
return itemOrItems
|
|
}
|