✨ Shared with me browser integration (#84)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import Api from '../../global/framework/api-service';
|
||||
import { DriveItem, DriveItemDetails, DriveItemVersion } from '../types';
|
||||
import { BrowseFilter, DriveItem, DriveItemDetails, DriveItemVersion } from '../types';
|
||||
import Workspace from '@deprecated/workspaces/workspaces';
|
||||
import Logger from 'features/global/framework/logger-service';
|
||||
import { JWTDataType } from 'app/features/auth/jwt-storage-service';
|
||||
@@ -70,6 +70,13 @@ export class DriveApiClient {
|
||||
);
|
||||
}
|
||||
|
||||
static async browse(companyId: string, id: string | 'trash' | '', filter: BrowseFilter) {
|
||||
return await Api.post<BrowseFilter, DriveItemDetails>(
|
||||
`/internal/services/documents/v1/companies/${companyId}/browse/${id}${appendTdriveToken()}`,
|
||||
filter,
|
||||
);
|
||||
}
|
||||
|
||||
static async remove(companyId: string, id: string | 'trash' | '') {
|
||||
return await Api.delete<void>(
|
||||
`/internal/services/documents/v1/companies/${companyId}/item/${id}${appendTdriveToken()}`,
|
||||
@@ -156,7 +163,11 @@ export class DriveApiClient {
|
||||
static async sharedWithMe(filter?: any, options?: BaseSearchOptions) {
|
||||
const companyId = options?.company_id ? options.company_id : Workspace.currentGroupId;
|
||||
const query = `/internal/services/documents/v1/companies/${companyId}/shared-with-me`;
|
||||
const filterData = { mime_type: filter.mimeType, creator: filter.creator, view: "shared_with_me" };
|
||||
const filterData = {
|
||||
mime_type: filter.mimeType,
|
||||
creator: filter.creator,
|
||||
view: 'shared_with_me',
|
||||
};
|
||||
const res = await Api.post<sharedWithMeFilterBody, { entities: DriveItem[] }>(
|
||||
query,
|
||||
filterData,
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { ToasterService } from '@features/global/services/toaster-service';
|
||||
import useRouterCompany from '@features/router/hooks/use-router-company';
|
||||
import { useCallback } from 'react';
|
||||
import { useRecoilCallback } from 'recoil';
|
||||
import { useRecoilValue, useRecoilCallback } from 'recoil';
|
||||
import { DriveApiClient } from '../api-client/api-client';
|
||||
import { DriveItemAtom, DriveItemChildrenAtom } from '../state/store';
|
||||
import { DriveItem, DriveItemVersion } from '../types';
|
||||
|
||||
import { BrowseFilter, DriveItem, DriveItemVersion } from '../types';
|
||||
import { SharedWithMeFilterState } from '../state/shared-with-me-filter';
|
||||
/**
|
||||
* Returns the children of a drive item
|
||||
* @param id
|
||||
@@ -13,13 +13,18 @@ import { DriveItem, DriveItemVersion } from '../types';
|
||||
*/
|
||||
export const useDriveActions = () => {
|
||||
const companyId = useRouterCompany();
|
||||
const sharedFilter = useRecoilValue(SharedWithMeFilterState);
|
||||
|
||||
const refresh = useRecoilCallback(
|
||||
({ set, snapshot }) =>
|
||||
async (parentId: string) => {
|
||||
if (parentId) {
|
||||
const filter:BrowseFilter = {
|
||||
company_id: companyId,
|
||||
mime_type: sharedFilter.mimeType.value,
|
||||
};
|
||||
try {
|
||||
const details = await DriveApiClient.get(companyId, parentId);
|
||||
const details = await DriveApiClient.browse(companyId, parentId, filter);
|
||||
set(DriveItemChildrenAtom(parentId), details.children);
|
||||
set(DriveItemAtom(parentId), details);
|
||||
for (const child of details.children) {
|
||||
|
||||
@@ -71,8 +71,10 @@ export const useDriveItem = (id: string) => {
|
||||
);
|
||||
|
||||
const inTrash = id === 'trash' || item?.path?.some(i => i.parent_id === 'trash');
|
||||
const sharedWithMe = id =="shared_with_me";
|
||||
|
||||
return {
|
||||
sharedWithMe,
|
||||
inTrash,
|
||||
loading: loading,
|
||||
children: children || [],
|
||||
|
||||
@@ -2,16 +2,28 @@ import { string } from 'prop-types';
|
||||
import { atom } from 'recoil';
|
||||
|
||||
export type SharedWithMeFilter = {
|
||||
mimeType: string;
|
||||
mimeType: {
|
||||
key: string;
|
||||
value: string
|
||||
};
|
||||
creator: string;
|
||||
date: string;
|
||||
date: {
|
||||
key: string;
|
||||
value: string;
|
||||
};
|
||||
};
|
||||
|
||||
export const SharedWithMeFilterState = atom<SharedWithMeFilter>({
|
||||
key: 'SharedWithMeFilterState',
|
||||
default: {
|
||||
mimeType: '',
|
||||
mimeType: {
|
||||
key: '',
|
||||
value: ''
|
||||
},
|
||||
creator: '',
|
||||
date: '',
|
||||
date: {
|
||||
key: '',
|
||||
value: ''
|
||||
}
|
||||
},
|
||||
});
|
||||
@@ -1,3 +1,8 @@
|
||||
export type BrowseFilter = {
|
||||
company_id: string;
|
||||
mime_type?: string;
|
||||
}
|
||||
|
||||
export type DriveItemDetails = {
|
||||
item: DriveItem;
|
||||
versions: DriveItemVersion[];
|
||||
|
||||
Reference in New Issue
Block a user