Skip to content

feat(site): Read users into basic UsersTable #981

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 26 commits into from
Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Set up fake response
  • Loading branch information
presleyp committed Apr 11, 2022
commit 665e21768fde7190e00c3415c376b6ed34b91f1f
11 changes: 8 additions & 3 deletions site/src/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import axios, { AxiosRequestHeaders } from "axios"
import { mutate } from "swr"
import { MockPager, MockUser, MockUser2 } from "../test_helpers"
import * as Types from "./types"

const CONTENT_TYPE_JSON: AxiosRequestHeaders = {
Expand Down Expand Up @@ -69,9 +70,13 @@ export const getApiKey = async (): Promise<Types.APIKeyResponse> => {
return response.data
}

export const getUsers = async (): Promise<Types.UserResponse[]> => {
const response = await axios.get<Types.UserResponse[]>("/api/v2/users")
return response.data
export const getUsers = async (): Promise<Types.PagedUsers> => {
// const response = await axios.get<Types.UserResponse[]>("/api/v2/users")
// return response.data
return Promise.resolve({
page: [MockUser, MockUser2],
pager: MockPager
})
}

export const getBuildInfo = async (): Promise<Types.BuildInfoResponse> => {
Expand Down
20 changes: 20 additions & 0 deletions site/src/api/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import internal from "stream";

/**
* `BuildInfoResponse` must be kept in sync with the go struct in buildinfo.go.
*/
Expand Down Expand Up @@ -74,3 +76,21 @@ export interface UserAgent {
readonly ip_address: string
readonly os: string
}

export interface Cursor {
after: string
before: string
limit: number
total: number
}
export interface Pager {
cursor: Cursor
next: string
previous: string
total: number
}

export interface PagedUsers {
page: UserResponse[]
pager: Pager
}
13 changes: 13 additions & 0 deletions site/src/test_helpers/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
UserAgent,
UserResponse,
Workspace,
Pager
} from "../api/types"

export const MockSessionToken = { session_token: "my-session-token" }
Expand All @@ -31,6 +32,18 @@ export const MockUser2: UserResponse = {
created_at: "",
}

export const MockPager: Pager = {
cursor: {
after: "",
before: "",
limit: 10,
total: 25
},
next: "",
previous: "",
total: 25
}

export const MockOrganization: Organization = {
id: "test-org",
name: "Test Organization",
Expand Down
10 changes: 6 additions & 4 deletions site/src/xServices/users/usersXService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import * as API from "../../api"
import * as Types from "../../api/types"

export interface UsersContext {
users: Types.UserResponse[]
pager: Types.Pager
getUsersError: Error | unknown
}

export type UsersEvent = { type: 'GET_USERS' }
Expand All @@ -16,12 +19,10 @@ export const usersMachine =
events: {} as UsersEvent,
services: {} as {
getUsers: {
data: Types.UserResponse[]
data: Types.PagedUsers
}
},
},
context: {
},
id: "usersState",
initial: "gettingUsers",
states: {
Expand Down Expand Up @@ -62,7 +63,8 @@ export const usersMachine =
},
actions: {
assignUsers: assign({
me: (_, event) => event.data,
users: (_, event) => event.data.page,
pager: (_, event) => event.data.pager
}),
assignGetUsersError: assign({
getUsersError: (_, event) => event.data,
Expand Down