Skip to content

Commit

Permalink
fix(ui): revert changes (#245)
Browse files Browse the repository at this point in the history
  • Loading branch information
bouassaba authored Jul 28, 2024
1 parent c30bc7a commit c195d5f
Show file tree
Hide file tree
Showing 33 changed files with 491 additions and 162 deletions.
66 changes: 62 additions & 4 deletions ui/src/client/api/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,33 @@
// by the GNU Affero General Public License v3.0 only, included in the file
// licenses/AGPL.txt.
import useSWR, { SWRConfiguration } from 'swr'
import { paramsFromListOptions } from '@/client/api/query-helpers'
import { FileType, ListOptions } from '@/client/api/types/queries'
import { apiFetcher } from '@/client/fetcher'
import { User } from '@/client/idp/user'
import { getConfig } from '@/config/config'
import { getAccessTokenOrRedirect } from '@/infra/token'
import { encodeQuery } from '@/lib/helpers/query'
import { Group } from './group'
import { PermissionType } from './permission'
import { Snapshot } from './snapshot'

export enum FileType {
File = 'file',
Folder = 'folder',
}

export enum SortBy {
Name = 'name',
Kind = 'kind',
Size = 'size',
DateCreated = 'date_created',
DateModified = 'date_modified',
}

export enum SortOrder {
Asc = 'asc',
Desc = 'desc',
}

export type File = {
id: string
workspaceId: string
Expand Down Expand Up @@ -61,6 +78,15 @@ export type Query = {
updateTimeBefore?: number
}

export type ListOptions = {
size?: number
page?: number
type?: FileType
sortBy?: SortBy
sortOrder?: SortOrder
query?: Query
}

export type MoveManyOptions = {
sourceIds: string[]
targetId: string
Expand Down Expand Up @@ -129,6 +155,15 @@ export type PatchOptions = {
onProgress?: (value: number) => void
}

type ListQueryParams = {
page?: string
size?: string
sort_by?: string
sort_order?: string
type?: string
query?: string
}

export default class FileAPI {
static async create({
type,
Expand Down Expand Up @@ -217,7 +252,7 @@ export default class FileAPI {

static async list(id: string, options: ListOptions) {
return apiFetcher({
url: `/files/${id}/list?${paramsFromListOptions(options)}`,
url: `/files/${id}/list?${this.paramsFromListOptions(options)}`,
method: 'GET',
}) as Promise<List>
}
Expand All @@ -227,14 +262,37 @@ export default class FileAPI {
options: ListOptions,
swrOptions?: SWRConfiguration,
) {
const url = `/files/${id}/list?${paramsFromListOptions(options)}`
const url = `/files/${id}/list?${this.paramsFromListOptions(options)}`
return useSWR<List | undefined>(
id ? url : null,
() => apiFetcher({ url, method: 'GET' }),
swrOptions,
)
}

static paramsFromListOptions(options?: ListOptions): URLSearchParams {
const params: ListQueryParams = {}
if (options?.page) {
params.page = options.page.toString()
}
if (options?.size) {
params.size = options.size.toString()
}
if (options?.sortBy) {
params.sort_by = options.sortBy.toString()
}
if (options?.sortOrder) {
params.sort_order = options.sortOrder.toString()
}
if (options?.type) {
params.type = options.type
}
if (options?.query) {
params.query = encodeQuery(JSON.stringify(options.query))
}
return new URLSearchParams(params)
}

static useGetPath(
id: string | null | undefined,
swrOptions?: SWRConfiguration,
Expand Down
56 changes: 53 additions & 3 deletions ui/src/client/api/group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,20 @@
// by the GNU Affero General Public License v3.0 only, included in the file
// licenses/AGPL.txt.
import useSWR, { SWRConfiguration } from 'swr'
import { paramsFromListOptions } from '@/client/api/query-helpers'
import { ListOptions } from '@/client/api/types/queries'
import { apiFetcher } from '@/client/fetcher'
import { Organization } from './organization'

export enum SortBy {
Name = 'name',
DateCreated = 'date_created',
DateModified = 'date_modified',
}

export enum SortOrder {
Asc = 'asc',
Desc = 'desc',
}

export type Group = {
id: string
name: string
Expand All @@ -30,6 +39,15 @@ export type List = {
size: number
}

export type ListOptions = {
query?: string
organizationId?: string
size?: number
page?: number
sortBy?: SortBy
sortOrder?: SortOrder
}

export type CreateOptions = {
name: string
image?: string
Expand All @@ -48,6 +66,15 @@ export type RemoveMemberOptions = {
userId: string
}

type ListQueryParams = {
page?: string
size?: string
sort_by?: string
sort_order?: string
query?: string
organization_id?: string
}

export default class GroupAPI {
static create(options: CreateOptions) {
return apiFetcher({
Expand Down Expand Up @@ -75,14 +102,37 @@ export default class GroupAPI {
}

static useList(options?: ListOptions, swrOptions?: SWRConfiguration) {
const url = `/groups?${paramsFromListOptions(options)}`
const url = `/groups?${this.paramsFromListOptions(options)}`
return useSWR<List>(
url,
() => apiFetcher({ url, method: 'GET' }) as Promise<List>,
swrOptions,
)
}

static paramsFromListOptions(options?: ListOptions): URLSearchParams {
const params: ListQueryParams = {}
if (options?.query) {
params.query = encodeURIComponent(options.query.toString())
}
if (options?.organizationId) {
params.organization_id = options.organizationId.toString()
}
if (options?.page) {
params.page = options.page.toString()
}
if (options?.size) {
params.size = options.size.toString()
}
if (options?.sortBy) {
params.sort_by = options.sortBy.toString()
}
if (options?.sortOrder) {
params.sort_order = options.sortOrder.toString()
}
return new URLSearchParams(params)
}

static delete(id: string) {
return apiFetcher({
url: `/groups/${id}`,
Expand Down
42 changes: 39 additions & 3 deletions ui/src/client/api/insights.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
// by the GNU Affero General Public License v3.0 only, included in the file
// licenses/AGPL.txt.
import useSWR, { SWRConfiguration } from 'swr'
import { paramsFromListOptions } from '@/client/api/query-helpers'
import { SortBy, SortOrder } from '@/client/api/types/queries'
import { apiFetcher } from '@/client/fetcher'
import { Snapshot } from './snapshot'

Expand Down Expand Up @@ -51,6 +49,24 @@ export type ListEntitiesOptions = {
sortOrder?: SortOrder
}

export enum SortBy {
Name = 'name',
Frequency = 'frequency',
}

export enum SortOrder {
Asc = 'asc',
Desc = 'desc',
}

type ListEntitiesQueryParams = {
page?: string
size?: string
sort_by?: string
sort_order?: string
query?: string
}

export default class InsightsAPI {
static create(id: string, options: CreateOptions, showError = true) {
return apiFetcher({
Expand Down Expand Up @@ -113,11 +129,31 @@ export default class InsightsAPI {
options?: ListEntitiesOptions,
swrOptions?: SWRConfiguration,
) {
const url = `/insights/${id}/entities?${paramsFromListOptions(options)}`
const url = `/insights/${id}/entities?${this.paramsFromListOptions(options)}`
return useSWR<EntityList>(
id ? url : null,
() => apiFetcher({ url, method: 'GET' }) as Promise<EntityList>,
swrOptions,
)
}

static paramsFromListOptions(options?: ListEntitiesOptions): URLSearchParams {
const params: ListEntitiesQueryParams = {}
if (options?.query) {
params.query = encodeURIComponent(options.query.toString())
}
if (options?.page) {
params.page = options.page.toString()
}
if (options?.size) {
params.size = options.size.toString()
}
if (options?.sortBy) {
params.sort_by = options.sortBy.toString()
}
if (options?.sortOrder) {
params.sort_order = options.sortOrder.toString()
}
return new URLSearchParams(params)
}
}
54 changes: 50 additions & 4 deletions ui/src/client/api/invitation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,21 @@
// by the GNU Affero General Public License v3.0 only, included in the file
// licenses/AGPL.txt.
import useSWR, { SWRConfiguration } from 'swr'
import { paramsFromListOptions } from '@/client/api/query-helpers'
import { ListOptions } from '@/client/api/types/queries'
import { apiFetcher } from '@/client/fetcher'
import { User } from '@/client/idp/user'
import { Organization } from './organization'

export enum SortBy {
Email = 'email',
DateCreated = 'date_created',
DateModified = 'date_modified',
}

export enum SortOrder {
Asc = 'asc',
Desc = 'desc',
}

export type InvitationStatus = 'pending' | 'accepted' | 'declined'

export type Invitation = {
Expand All @@ -39,6 +48,23 @@ export type CreateOptions = {
emails: string[]
}

export type ListOptions = {
organizationId?: string
size?: number
page?: number
sortBy?: SortBy
sortOrder?: SortOrder
}

type ListQueryParams = {
page?: string
size?: string
sort_by?: string
sort_order?: string
query?: string
organization_id?: string
}

export default class InvitationAPI {
static async create(options: CreateOptions) {
return apiFetcher({
Expand All @@ -49,7 +75,7 @@ export default class InvitationAPI {
}

static useGetIncoming(options?: ListOptions, swrOptions?: SWRConfiguration) {
const url = `/invitations/incoming?${paramsFromListOptions(options)}`
const url = `/invitations/incoming?${this.paramsFromListOptions(options)}`
return useSWR<List>(
url,
() => apiFetcher({ url, method: 'GET' }) as Promise<List>,
Expand All @@ -67,14 +93,34 @@ export default class InvitationAPI {
}

static useGetOutgoing(options?: ListOptions, swrOptions?: SWRConfiguration) {
const url = `/invitations/outgoing?${paramsFromListOptions(options)}`
const url = `/invitations/outgoing?${this.paramsFromListOptions(options)}`
return useSWR<List>(
options?.organizationId ? url : null,
() => apiFetcher({ url, method: 'GET' }) as Promise<List>,
swrOptions,
)
}

static paramsFromListOptions(options?: ListOptions): URLSearchParams {
const params: ListQueryParams = {}
if (options?.organizationId) {
params.organization_id = options.organizationId.toString()
}
if (options?.page) {
params.page = options.page.toString()
}
if (options?.size) {
params.size = options.size.toString()
}
if (options?.sortBy) {
params.sort_by = options.sortBy.toString()
}
if (options?.sortOrder) {
params.sort_order = options.sortOrder.toString()
}
return new URLSearchParams(params)
}

static async delete(id: string) {
return apiFetcher({
url: `/invitations/${id}`,
Expand Down
Loading

0 comments on commit c195d5f

Please sign in to comment.