Skip to content
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

My Libraries #336

Merged
merged 39 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
20e9af3
Biblib API
shinyichen Sep 7, 2023
a470f86
My Libraries landing page
shinyichen Sep 21, 2023
5fc3cc4
My libraries landing page for delete, add, operations
shinyichen Sep 21, 2023
cb287c3
pagination
shinyichen Sep 21, 2023
b004e81
Add new library
shinyichen Sep 21, 2023
221eb39
Remove delete library
shinyichen Sep 21, 2023
35a3ec3
Apply sorting
shinyichen Sep 22, 2023
cdefedd
Only clear cache when neccessary
shinyichen Sep 22, 2023
57df9ae
temporarily disable column sort until implemented
shinyichen Sep 22, 2023
8ef8a3b
Library Operations
shinyichen Sep 26, 2023
b32c77c
Libraries landing page test
shinyichen Oct 2, 2023
e7a75e6
API for bigquery search
shinyichen Oct 3, 2023
062d153
Library page
shinyichen Oct 3, 2023
357310a
Library settings
shinyichen Oct 12, 2023
79951d3
Clean up
shinyichen Oct 16, 2023
f8819b1
Use store page size
shinyichen Oct 17, 2023
38d2351
Public library view
shinyichen Oct 17, 2023
91d58c5
Show library creation and modified date
shinyichen Oct 17, 2023
66e9461
Prevent paint flashing
shinyichen Oct 18, 2023
80875d3
Libraries responsiveness
shinyichen Oct 18, 2023
3f05da0
Add documents to library
shinyichen Oct 20, 2023
23bc4d0
Disable delete library if not owner
shinyichen Oct 24, 2023
b78d851
Delete documents from library
shinyichen Oct 25, 2023
658a02b
Prefetch library
shinyichen Oct 25, 2023
de58696
Clean up
shinyichen Oct 25, 2023
f6d2565
Clean up comment
shinyichen Oct 27, 2023
cee3480
Bug fixes on libraries
shinyichen Oct 27, 2023
a8a81cd
Clean up errors and warnings
shinyichen Oct 27, 2023
9c72787
Move pagination control so that it isn't showing when no libraries found
shinyichen Nov 1, 2023
ba574e4
Keep modals open if error after submission
shinyichen Nov 1, 2023
fe06e3e
some style updates
shinyichen Nov 1, 2023
0a46a19
no caching for libraries so the table is always up to date with any c…
shinyichen Nov 1, 2023
7ecc9f2
change date last modified format in libraries table
shinyichen Nov 1, 2023
9731c06
clean up and some error handling
shinyichen Nov 1, 2023
1f096a3
add auto focus
shinyichen Nov 1, 2023
12b57ce
Requested changes for libraries
shinyichen Nov 2, 2023
96fe31d
indicate where the back link in library settings should go to
shinyichen Nov 2, 2023
a5b0e40
include <MathJaxProvider> in test
shinyichen Nov 2, 2023
9add16f
revert code
shinyichen Nov 2, 2023
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
1 change: 1 addition & 0 deletions src/api/biblib/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './types';
export * from './libraries';
358 changes: 358 additions & 0 deletions src/api/biblib/libraries.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,358 @@
import api, {
ADSMutation,
ADSQuery,
ApiRequestConfig,
ApiTargets,
IADSApiLibraryAddParams,
IADSApiLibraryAddResponse,
IADSApiLibraryDeleteParams,
IADSApiLibraryDeleteResponse,
IADSApiLibraryDocumentParams,
IADSApiLibraryDocumentResponse,
IADSApiLibraryEditMetaParams,
IADSApiLibraryEditMetaResponse,
IADSApiLibraryEntityParams,
IADSApiLibraryEntityResponse,
IADSApiLibraryOperationParams,
IADSApiLibraryOperationResponse,
IADSApiLibraryParams,
IADSApiLibraryPermissionParams,
IADSApiLibraryPermissionResponse,
IADSApiLibraryPermissionUpdateParams,
IADSApiLibraryPermissionUpdateResponse,
IADSApiLibraryQueryParams,
IADSApiLibraryQueryResponse,
IADSApiLibraryQueryUpdateParams,
IADSApiLibraryQueryUpdateResponse,
IADSApiLibraryResponse,
IADSApiLibraryTransferParams,
IADSApiLibraryTransferResponse,
} from '@api';
import { MutationFunction, QueryFunction, useMutation, useQuery } from '@tanstack/react-query';
import { omit } from 'ramda';

export enum LIBRARY_API_KEYS {
LIBRARIES = 'library/libraries',
LIBRARY = 'library/library',
ADD = 'library/add',
DELETE = 'library/delete',
EDIT = 'library/edit',
OPERATION = 'library/operation',
DOCUMENT = 'library/document',
QUERY = 'library/query',
QUERY_UPDATE = 'library/query-update',
PERMISSION = 'library/permission',
PERMISSION_UPDATE = 'library/permission-update',
TRANSFER = 'library/transfer',
}

export const librariesKeys = {
libraries: (params: IADSApiLibraryParams) => [LIBRARY_API_KEYS.LIBRARIES, params] as const,
library: (params: IADSApiLibraryEntityParams) => [LIBRARY_API_KEYS.LIBRARY, params],
add: () => [LIBRARY_API_KEYS.ADD] as const,
delete: () => [LIBRARY_API_KEYS.DELETE] as const,
edit: () => [LIBRARY_API_KEYS.EDIT] as const,
operation: () => [LIBRARY_API_KEYS.OPERATION] as const,
document: () => [LIBRARY_API_KEYS.DOCUMENT] as const,
query: () => [LIBRARY_API_KEYS.QUERY] as const,
query_update: () => [LIBRARY_API_KEYS.QUERY_UPDATE] as const,
permission: (params: IADSApiLibraryPermissionParams) => [LIBRARY_API_KEYS.PERMISSION, params],
permission_update: () => [LIBRARY_API_KEYS.PERMISSION_UPDATE] as const,
transfer: () => [LIBRARY_API_KEYS.TRANSFER] as const,
};

// libraries

export const useGetLibraries: ADSQuery<IADSApiLibraryParams, IADSApiLibraryResponse> = (params, options) => {
return useQuery({
queryKey: librariesKeys.libraries(params),
queryFn: fetchLibraries,
meta: { params },
...options,
});
};

export const fetchLibraries: QueryFunction<IADSApiLibraryResponse> = async ({ meta }) => {
const { params } = meta as { params: IADSApiLibraryParams };
const config: ApiRequestConfig = {
method: 'GET',
url: ApiTargets.LIBRARIES,
params,
};

const { data } = await api.request<IADSApiLibraryResponse>(config);
return data;
};

export const useAddLibrary: ADSMutation<IADSApiLibraryAddResponse, undefined, IADSApiLibraryAddParams> = (
_,
options,
) => {
return useMutation({
mutationKey: librariesKeys.add(),
mutationFn: addLibrary,
...options,
});
};

export const addLibrary: MutationFunction<IADSApiLibraryAddResponse, IADSApiLibraryAddParams> = async (params) => {
const config: ApiRequestConfig = {
method: 'POST',
url: `${ApiTargets.LIBRARIES}`,
data: params,
};

const { data } = await api.request<IADSApiLibraryAddResponse>(config);
return data;
};

export const useGetLibraryEntity: ADSQuery<IADSApiLibraryEntityParams, IADSApiLibraryEntityResponse> = (
params,
options,
) => {
return useQuery({
queryKey: librariesKeys.library(params),
queryFn: fetchLibraryEntity,
meta: { params },
...options,
});
};

export const fetchLibraryEntity: QueryFunction<IADSApiLibraryEntityResponse> = async ({ meta }) => {
const { params } = meta as { params: IADSApiLibraryEntityParams };
const config: ApiRequestConfig = {
method: 'GET',
url: `${ApiTargets.LIBRARIES}/${params.id}`,
params: omit(['id'], params),
};

const { data } = await api.request<IADSApiLibraryEntityResponse>(config);
return data;
};

// documents

export const useDeleteLibrary: ADSMutation<IADSApiLibraryDeleteResponse, undefined, IADSApiLibraryDeleteParams> = (
_,
options,
) => {
return useMutation({
mutationKey: librariesKeys.delete(),
mutationFn: deleteLibrary,
...options,
});
};

export const deleteLibrary: MutationFunction<IADSApiLibraryDeleteResponse, IADSApiLibraryDeleteParams> = async ({
id,
}) => {
const config: ApiRequestConfig = {
method: 'DELETE',
url: `${ApiTargets.DOCUMENTS}/${id}`,
};

const { data } = await api.request<IADSApiLibraryDeleteResponse>(config);
return data;
};

export const useEditLibraryMeta: ADSMutation<IADSApiLibraryEditMetaResponse, undefined, IADSApiLibraryEditMetaParams> =
(_, options) => {
return useMutation({
mutationKey: librariesKeys.edit(),
mutationFn: editLibraryMeta,
...options,
});
};

export const editLibraryMeta: MutationFunction<IADSApiLibraryEditMetaResponse, IADSApiLibraryEditMetaParams> = async (
params,
) => {
const config: ApiRequestConfig = {
method: 'PUT',
url: `${ApiTargets.DOCUMENTS}/${params.id}`,
data: omit(['id'], params),
};

const { data } = await api.request<IADSApiLibraryEditMetaResponse>(config);
return data;
};

export const useEditLibraryDocuments: ADSMutation<
IADSApiLibraryDocumentResponse,
undefined,
IADSApiLibraryDocumentParams
> = (_, options) => {
return useMutation({
mutationKey: librariesKeys.document(),
mutationFn: editLibraryDocuments,
...options,
});
};

export const editLibraryDocuments: MutationFunction<IADSApiLibraryDocumentResponse, IADSApiLibraryDocumentParams> =
async (params) => {
const config: ApiRequestConfig = {
method: 'POST',
url: `${ApiTargets.DOCUMENTS}/${params.id}`,
data: omit(['id'], params),
};

const { data } = await api.request<IADSApiLibraryDocumentResponse>(config);
return data;
};

// operations

export const useLibraryOperation: ADSMutation<
IADSApiLibraryOperationResponse,
undefined,
IADSApiLibraryOperationParams
> = (_, options) => {
return useMutation({
mutationKey: librariesKeys.operation(),
mutationFn: operation,
...options,
});
};

export const operation: MutationFunction<IADSApiLibraryOperationResponse, IADSApiLibraryOperationParams> = async (
params,
) => {
const config: ApiRequestConfig = {
method: 'POST',
url: `${ApiTargets.LIBRARY_OPERATION}/${params.id}`,
data: omit(['id'], params),
};

const { data } = await api.request<IADSApiLibraryOperationResponse>(config);
return data;
};

// query

export const useAddDocumentsByQuery: ADSMutation<IADSApiLibraryQueryResponse, undefined, IADSApiLibraryQueryParams> = (
_,
options,
) => {
return useMutation({
mutationKey: librariesKeys.query(),
mutationFn: addDocumentsByQuery,
...options,
});
};

export const addDocumentsByQuery: MutationFunction<IADSApiLibraryQueryResponse, IADSApiLibraryQueryParams> = async (
params,
) => {
const config: ApiRequestConfig = {
method: 'POST',
url: `${ApiTargets.LIBRARY_QUERY}/${params.id}`,
data: params,
};

const { data } = await api.request<IADSApiLibraryQueryResponse>(config);
return data;
};

export const useUpdateDocumentsByQuery: ADSMutation<
IADSApiLibraryQueryUpdateResponse,
undefined,
IADSApiLibraryQueryUpdateParams
> = (_, options) => {
return useMutation({
mutationKey: librariesKeys.query_update(),
mutationFn: updateDocumentsByQuery,
...options,
});
};

export const updateDocumentsByQuery: MutationFunction<
IADSApiLibraryQueryUpdateResponse,
IADSApiLibraryQueryUpdateParams
> = async (params) => {
const config: ApiRequestConfig = {
method: 'POST',
url: `${ApiTargets.LIBRARY_QUERY}/${params.id}`,
data: omit(['id'], params),
};

const { data } = await api.request<IADSApiLibraryQueryUpdateResponse>(config);
return data;
};

// permissions

export const useGetPermission: ADSQuery<IADSApiLibraryPermissionParams, IADSApiLibraryPermissionResponse> = (
params,
options,
) => {
return useQuery({
queryKey: librariesKeys.permission(params),
queryFn: getPermission,
meta: { params },
...options,
});
};

export const getPermission: QueryFunction<IADSApiLibraryPermissionResponse> = async ({ meta }) => {
const { params } = meta as { params: IADSApiLibraryPermissionParams };
const config: ApiRequestConfig = {
method: 'GET',
url: `${ApiTargets.PERMISSIONS}/${params.id}`,
};

const { data } = await api.request<IADSApiLibraryPermissionResponse>(config);
return data;
};

export const useModifyPermission: ADSMutation<
IADSApiLibraryPermissionUpdateResponse,
undefined,
IADSApiLibraryPermissionUpdateParams
> = (_, options) => {
return useMutation({
mutationKey: librariesKeys.query_update(),
mutationFn: modifyPermission,
...options,
});
};

export const modifyPermission: MutationFunction<
IADSApiLibraryPermissionUpdateResponse,
IADSApiLibraryPermissionUpdateParams
> = async (params) => {
const config: ApiRequestConfig = {
method: 'POST',
url: `${ApiTargets.PERMISSIONS}/${params.id}`,
data: omit(['id'], params),
};

const { data } = await api.request<IADSApiLibraryPermissionUpdateResponse>(config);
return data;
};

// transfer

export const useTransfer: ADSMutation<IADSApiLibraryTransferResponse, undefined, IADSApiLibraryTransferParams> = (
_,
options,
) => {
return useMutation({
mutationKey: librariesKeys.transfer(),
mutationFn: transfer,
...options,
});
};

export const transfer: MutationFunction<IADSApiLibraryTransferResponse, IADSApiLibraryTransferParams> = async (
params,
) => {
const config: ApiRequestConfig = {
method: 'POST',
url: `${ApiTargets.LIBRARY_TRANSFER}/${params.id}`,
data: omit(['id'], params),
};

const { data } = await api.request<IADSApiLibraryTransferResponse>(config);
return data;
};
Loading
Loading