refactor(site): generalize UserCell component (#484)

Summary:

This is a first step in porting over v1 AuditLog in a refactored/cleaned
up fashion. The existing `UserCell` component was generalized for re-use
across various tables (AuditLog, Users, Orgs).

Details:

- Move UserCell to `components/Table/Cells`
- Add tests and stories for UserCell


Impact:

This unblocks future work in list views like the audit log, user management
panel and organizations management panel.

Relations:

- This commit relates to https://github.com/coder/coder/issues/472, but does not finish it.
- This commit should not merge until after https://github.com/coder/coder/pull/465 and https://github.com/coder/coder/pull/483 because it's
based on them.
This commit is contained in:
G r e y
2022-03-23 10:28:34 -04:00
committed by GitHub
parent 038dd54ab3
commit 6560f2e340
10 changed files with 222 additions and 20 deletions
+11
View File
@@ -0,0 +1,11 @@
import { firstLetter } from "./first-letter"
describe("first-letter", () => {
it.each<[string, string]>([
["", ""],
["User", "U"],
["test", "T"],
])(`firstLetter(%p) returns %p`, (input, expected) => {
expect(firstLetter(input)).toBe(expected)
})
})
+10
View File
@@ -0,0 +1,10 @@
/**
* firstLetter extracts the first character and returns it, uppercased.
*/
export const firstLetter = (str: string): string => {
if (str.length > 0) {
return str[0].toLocaleUpperCase()
}
return ""
}