🔢 Shared with me filters (#79)

 feat: shared with me filters
🐛 Fix try to access the service with init
🌐 feat: shared with me i18n
🌐russian translation

---------

Co-authored-by: Anton SHEPILOV <ashepilov@linagora.com>
This commit is contained in:
Montassar Ghanmy
2023-06-17 15:37:33 +01:00
committed by GitHub
parent fddd3b4ebd
commit 441c2b780f
19 changed files with 482 additions and 404 deletions
@@ -17,6 +17,10 @@ export type SearchDocumentsBody = {
creator?: string;
added?: string;
};
export type sharedWithMeFilterBody = {
mime_type?: string;
creator?: string;
};
let publicLinkToken: null | string = null;
let tdriveTabToken: null | string = null;
@@ -132,12 +136,12 @@ export class DriveApiClient {
);
}
static async search(searchString: string, view?: string,options?: BaseSearchOptions) {
static async search(searchString: string, view?: string, options?: BaseSearchOptions) {
const companyId = options?.company_id ? options.company_id : Workspace.currentGroupId;
const query = `/internal/services/documents/v1/companies/${companyId}/search`;
const searchData = {
search: searchString,
view: view
view: view,
};
const res = await Api.post<SearchDocumentsBody, { entities: DriveItem[] }>(query, searchData);
this.logger.debug(
@@ -149,11 +153,14 @@ export class DriveApiClient {
return res;
}
static async sharedWithMe(options?: BaseSearchOptions) {
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 = {};
const res = await Api.post<SearchDocumentsBody, { entities: DriveItem[] }>(query, filterData);
const filterData = { mime_type: filter.mimeType, creator: filter.creator, view: "shared_with_me" };
const res = await Api.post<sharedWithMeFilterBody, { entities: DriveItem[] }>(
query,
filterData,
);
this.logger.debug(
`Drive shared with me by filter "${JSON.stringify(filterData)}". Found`,
res.entities.length,
@@ -4,7 +4,7 @@ import { useCallback } from 'react';
import { useRecoilCallback } from 'recoil';
import { DriveApiClient } from '../api-client/api-client';
import { DriveItemAtom, DriveItemChildrenAtom } from '../state/store';
import { DriveItem, DriveItemDetails, DriveItemVersion } from '../types';
import { DriveItem, DriveItemVersion } from '../types';
/**
* Returns the children of a drive item
@@ -18,59 +18,20 @@ export const useDriveActions = () => {
({ set, snapshot }) =>
async (parentId: string) => {
if (parentId) {
if (parentId == "shared-with-me") {
const details = {
path: [
{
id: "shared-with-me",
name: "Shared with me"
}
],
item: {
id: "root",
parent_id: "",
company_id: "",
workspace_id: "",
name: "Shared with me",
size: 0,
description: "",
tags: [],
in_trash: false,
is_directory: true,
extension: "",
added: "",
last_modified: "",
last_version_cache: {},
access_info: {},
},
versions: [],
children: [],
access: "manage",
websockets: [
{
room: "/companies/aa7ffdd0-fadb-11ed-b891-510fe3501b2b/documents/item/root",
token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhYTU0Y2YyMC1mYWRiLTExZWQtYjg5MS01MTBmZTM1MDFiMmIiLCJuYW1lIjoiL2NvbXBhbmllcy9hYTdmZmRkMC1mYWRiLTExZWQtYjg5MS01MTBmZTM1MDFiMmIvZG9jdW1lbnRzL2l0ZW0vcm9vdCIsImlhdCI6MTY4ODk1MDk2OCwibmJmIjoxNjg2MjcyNTA4fQ.H6BFRcLG3Op32sqKi45Pf1s2YKcVbMxGZGPJal06l1g"
}
]
};
try {
const details = await DriveApiClient.get(companyId, parentId);
set(DriveItemChildrenAtom(parentId), details.children);
return details;
} else {
try {
const details = await DriveApiClient.get(companyId, parentId);
set(DriveItemChildrenAtom(parentId), details.children);
set(DriveItemAtom(parentId), details);
for (const child of details.children) {
const currentValue = snapshot.getLoadable(DriveItemAtom(child.id)).contents;
if (!currentValue) {
//only update if not already in cache to avoid concurrent updates
set(DriveItemAtom(child.id), { item: child });
}
set(DriveItemAtom(parentId), details);
for (const child of details.children) {
const currentValue = snapshot.getLoadable(DriveItemAtom(child.id)).contents;
if (!currentValue) {
//only update if not already in cache to avoid concurrent updates
set(DriveItemAtom(child.id), { item: child });
}
return details;
} catch (e) {
ToasterService.error('Unable to load your files.');
}
return details;
} catch (e) {
ToasterService.error('Unable to load your files.');
}
}
},
@@ -7,16 +7,16 @@ import _ from 'lodash';
import { useRecoilState, useRecoilValue } from 'recoil';
import { SharedWithMeDriveItemsResultsState } from '../state/shared-with-me-drive-items-result';
import { SearchInputState } from '../../search/state/search-input';
import { SharedWithMeFilterState } from '../state/shared-with-me-filter';
export const useSharedWithMeDriveItemsLoading = () => {
return useRecoilValue(LoadingState('useSearchDriveItems'));
};
let currentQuery = '';
export const useSharedWithMeDriveItems = () => {
const companyId = useRouterCompany();
const searchInput = useRecoilValue(SearchInputState);
const sharedFilter = useRecoilValue(SharedWithMeFilterState);
const [loading, setLoading] = useRecoilState(LoadingState('useSearchDriveItems'));
const [items, setItems] = useRecoilState(SharedWithMeDriveItemsResultsState(companyId));
@@ -34,11 +34,24 @@ export const useSharedWithMeDriveItems = () => {
const refresh = async () => {
setLoading(true);
const query = searchInput.query;
currentQuery = query;
let filter:any = {...sharedFilter};
if (filter.date) {
if (filter.date === "today") {
filter = { ...filter, added_lt: '', added_gt: '' };
}
if (filter.date === "last_week") {
const today = new Date();
const lastWeek = new Date(today.getFullYear(), today.getMonth(), today.getDate() - 7);
filter = { ...filter, added_lt: lastWeek.toISOString(), added_gt: '' };
}
if (filter.date === "last_month") {
const today = new Date();
const lastMonth = new Date(today.getFullYear(), today.getMonth() - 1, today.getDate());
filter = { ...filter, added_lt: lastMonth.toISOString(), added_gt: '' };
}
}
const response = await DriveApiClient.sharedWithMe(opt);
console.log("response is: ", response);
const response = await DriveApiClient.sharedWithMe(filter, opt);
const results = response.entities || [];
const update = {
@@ -47,9 +60,6 @@ export const useSharedWithMeDriveItems = () => {
// nextPage: response.next_page_token,
};
if (currentQuery !== query) {
return;
}
setItems(update);
setLoading(false);
};
@@ -62,18 +72,18 @@ export const useSharedWithMeDriveItems = () => {
useGlobalEffect(
'useSearchDriveItems',
() => {
(async () => {
setLoading(true);
if (searchInput.query) {
delayRequest('useSearchDriveItems', async () => {
await refresh();
});
} else {
refresh();
}
})();
(async () => {
setLoading(true);
if (sharedFilter.mimeType) {
delayRequest('useSearchDriveItems', async () => {
await refresh();
});
} else {
refresh();
}
})();
},
[searchInput.channelId, searchInput.workspaceId],
[sharedFilter, searchInput.channelId, searchInput.workspaceId],
);
return { loading, driveItems: [...items.results], loadMore, refresh };
@@ -0,0 +1,17 @@
import { string } from 'prop-types';
import { atom } from 'recoil';
export type SharedWithMeFilter = {
mimeType: string;
creator: string;
date: string;
};
export const SharedWithMeFilterState = atom<SharedWithMeFilter>({
key: 'SharedWithMeFilterState',
default: {
mimeType: '',
creator: '',
date: '',
},
});