Skip to content

Commit 8e1d707

Browse files
author
Mingze
authored
feat(api): Add file collaborators fetch action (#479)
* feat(api): Add file collaborators fetch action * feat(api): Address comments and add tests * feat(api): Address comments
1 parent 471ab57 commit 8e1d707

File tree

23 files changed

+165
-6
lines changed

23 files changed

+165
-6
lines changed

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module.exports = {
77
'flowtype/no-types-missing-file-annotation': 'off', // Allows types in TS files
88
'import/no-extraneous-dependencies': ['error', { devDependencies: ['scripts/**/*.js', '**/*-test.[j|t]s*'] }],
99
'import/no-unresolved': 'off', // Allows JS files to import TS files
10+
'import/prefer-default-export': 'off',
1011
'prefer-destructuring': ['error', { object: true, array: false }],
1112
},
1213
overrides: [

src/@types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ export * from './events';
66
export * from './i18n';
77
export * from './model';
88
export * from './new';
9+
export * from './users';

src/@types/users.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
export type Collaborator = {
2+
id: string;
3+
item?: UserMini | GroupMini;
4+
name: string;
5+
};
6+
7+
export type UserMini = {
8+
avatar_url?: string;
9+
email?: string;
10+
id: string;
11+
login?: string;
12+
name: string;
13+
type: 'user';
14+
};
15+
16+
export type GroupMini = {
17+
id: string;
18+
name: string;
19+
type: 'group';
20+
};

src/api/APIFactory.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Annotations from 'box-ui-elements/es/api/Annotations';
2+
import FileCollaborators from 'box-ui-elements/es/api/FileCollaborators';
23
import { DEFAULT_HOSTNAME_API } from 'box-ui-elements/es/constants';
3-
import { AnnotationsAPI, APIOptions } from './types';
4+
import { AnnotationsAPI, CollaboratorsAPI, APIOptions } from './types';
45

56
export default class APIFactory {
67
options: APIOptions;
@@ -16,4 +17,8 @@ export default class APIFactory {
1617
getAnnotationsAPI(): AnnotationsAPI {
1718
return new Annotations(this.options);
1819
}
20+
21+
getCollaboratorsAPI(): CollaboratorsAPI {
22+
return new FileCollaborators(this.options);
23+
}
1924
}

src/api/types.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { Annotation, NewAnnotation, Token } from '../@types';
1+
import { Annotation, Collaborator, NewAnnotation, Token } from '../@types';
22

33
export type APICollection<R> = {
44
entries: R[];
55
limit: number;
66
next_marker: string | null;
7+
previous_marker: string | null;
78
};
89

910
export type APIError = {
@@ -42,3 +43,19 @@ export interface AnnotationsAPI {
4243

4344
destroy(): void;
4445
}
46+
47+
export interface CollaboratorsAPI {
48+
getFileCollaborators(
49+
fileId: string | null,
50+
successCallback: (result: APICollection<Collaborator>) => void,
51+
errorCallback: (error: APIError) => void,
52+
requestData?: {
53+
filter_term?: string;
54+
include_groups?: boolean;
55+
include_uploader_collabs?: boolean;
56+
},
57+
limit?: number,
58+
): Promise<void>;
59+
60+
destroy(): void;
61+
}

src/common/BaseAnnotator.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ export default class BaseAnnotator {
9494
// Redux dispatch method signature doesn't seem to like async actions
9595
// eslint-disable-next-line @typescript-eslint/no-explicit-any
9696
this.store.dispatch<any>(store.fetchAnnotationsAction());
97+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
98+
this.store.dispatch<any>(store.fetchCollaboratorsAction());
9799
}
98100

99101
// Called by box-content-preview

src/common/__tests__/BaseAnnotator-test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ jest.mock('../../api');
1111
jest.mock('../../store', () => ({
1212
createStore: jest.fn(() => ({ dispatch: jest.fn() })),
1313
fetchAnnotationsAction: jest.fn(),
14+
fetchCollaboratorsAction: jest.fn(),
1415
setActiveAnnotationIdAction: jest.fn(),
1516
setVisibilityAction: jest.fn(),
1617
toggleAnnotationModeAction: jest.fn(),

src/components/Popups/ReplyField/ReplyField.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import classnames from 'classnames';
33
import { getActiveMentionForEditorState } from 'box-ui-elements/es/components/form-elements/draft-js-mention-selector';
44
import { ContentState, Editor, EditorState, SelectionState } from 'draft-js';
55
import PopupList from './PopupList';
6+
import { Collaborator } from '../../../@types';
67
import { VirtualElement } from '../Popper';
78
import './ReplyField.scss';
89

@@ -16,6 +17,7 @@ export type Mention = {
1617

1718
export type Props = {
1819
className?: string;
20+
collaborators: Collaborator[];
1921
cursorPosition: number;
2022
isDisabled?: boolean;
2123
onChange: (text?: string) => void;

src/components/Popups/ReplyField/ReplyFieldContainer.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import { connect } from 'react-redux';
2-
import { AppState, getCreatorCursor, setCursorAction } from '../../../store';
2+
import { AppState, getCollaborators, getCreatorCursor, setCursorAction } from '../../../store';
33
import ReplyField from './ReplyField';
4+
import { Collaborator } from '../../../@types';
45

56
export type Props = {
7+
collaborators: Collaborator[];
68
cursorPosition: number;
79
};
810

911
export const mapStateToProps = (state: AppState): Props => ({
12+
collaborators: getCollaborators(state),
1013
cursorPosition: getCreatorCursor(state),
1114
});
1215

src/components/Popups/ReplyField/__tests__/ReplyField-test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ jest.mock('box-ui-elements/es/components/form-elements/draft-js-mention-selector
2020
describe('components/Popups/ReplyField', () => {
2121
const defaults: Props = {
2222
className: 'ba-Popup-field',
23+
collaborators: [],
2324
cursorPosition: 0,
2425
isDisabled: false,
2526
onChange: jest.fn(),

0 commit comments

Comments
 (0)