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

chore(js-ts): Convert core types to TypeScript #3933

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
154 changes: 0 additions & 154 deletions src/elements/content-sharing/types.js

This file was deleted.

152 changes: 152 additions & 0 deletions src/elements/content-sharing/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
import type {
Access,
BoxItemClassification,
BoxItemPermission,
Collaboration,
GroupMini,
ItemType,
NewCollaboration,
SharedLink as APISharedLink,
UserMini,
} from '../../common/types/core';
import type {
accessLevelsDisabledReasonType,
contactType,
InviteCollaboratorsRequest,
item,
sharedLinkType as USMSharedLinkType,
} from '../../features/unified-share-modal/flowTypes';
import type { RequestOptions } from '../../common/types/api';

// "SLS" denotes values that are used in the Shared Link Settings modal
interface ContentSharingEnterpriseDataType {
enterpriseName?: string;
serverURL?: string; // SLS
}

export interface ContentSharingUserDataType {
id: string;
userEnterpriseData: ContentSharingEnterpriseDataType;
}

// This type is used when an item does not have a shared link.
interface SharedLinkNotCreatedType {
accessLevel?: string;
canChangeExpiration?: boolean;
canInvite: boolean;
expirationTimestamp?: number | null;
isDownloadAvailable?: boolean;
}

// This is the full shared link type, which extends the internal USM shared link with
// data necessary for instantiating the Shared Link Settings modal.
interface SharedLinkCreatedType extends USMSharedLinkType, SharedLinkNotCreatedType {
canChangeDownload: boolean; // SLS
canChangeExpiration: boolean; // SLS
canChangePassword: boolean; // SLS
canChangeVanityName: boolean; // SLS
directLink: string; // SLS
isDirectLinkAvailable: boolean; // SLS
isDownloadAvailable: boolean; // SLS
isDownloadEnabled: boolean; // SLS
isPasswordAvailable: boolean; // SLS
isPasswordEnabled: boolean; // SLS
vanityName: string;
}

export type ContentSharingSharedLinkType = ContentSharingEnterpriseDataType &
(SharedLinkNotCreatedType | SharedLinkCreatedType);

export interface ContentSharingItemDataType {
item: item;
sharedLink: ContentSharingSharedLinkType;
}

export interface ContentSharingItemAPIResponse {
allowed_invitee_roles: Array<string>;
allowed_shared_link_access_levels?: Array<string>;
allowed_shared_link_access_levels_disabled_reasons?: accessLevelsDisabledReasonType;
classification: BoxItemClassification | null;
description: string;
etag: string;
extension: string;
id: string;
name: string;
owned_by: {
id: string;
login: string;
};
permissions: BoxItemPermission;
shared_link?: APISharedLink;
shared_link_features: {
download_url: boolean;
password: boolean;
vanity_name: boolean;
};
type: ItemType;
}

export interface ContentSharingHooksOptions {
handleError?: Function;
handleRemoveSharedLinkError?: Function;
handleRemoveSharedLinkSuccess?: Function;
handleSuccess?: Function;
handleUpdateSharedLinkError?: Function;
handleUpdateSharedLinkSuccess?: Function;
setIsLoading?: Function;
transformAccess?: Function;
transformGroups?: Function;
transformItem?: Function;
transformPermissions?: Function;
transformResponse?: Function;
transformSettings?: Function;
transformUsers?: Function;
}

export interface SharedLinkSettingsOptions {
expirationTimestamp: number;
isDownloadEnabled: boolean;
isExpirationEnabled: boolean;
isPasswordEnabled: boolean;
password: string;
vanityName: string;
}

export interface ContentSharingCollaborationsRequest {
groups: Array<Partial<NewCollaboration>>;
users: Array<Partial<NewCollaboration>>;
}

export interface UseInvitesOptions extends ContentSharingHooksOptions {
transformRequest: (request: InviteCollaboratorsRequest) => ContentSharingCollaborationsRequest;
}

export type SharedLinkUpdateLevelFnType = () => (level: string) => Promise<void>;

export type SharedLinkUpdateSettingsFnType = () => (settings: Partial<APISharedLink>) => Promise<void>;

export type GetContactsFnType = () => (filterTerm: string) => Promise<Array<contactType | GroupMini | UserMini>> | null;

export type ContactByEmailObject = { [key: string]: contactType | UserMini | [] };

export type GetContactsByEmailFnType = () => (filterTerm: {
emails: string[];
}) => Promise<ContactByEmailObject | Array<UserMini>> | null;

export type SendInvitesFnType = () => (request: InviteCollaboratorsRequest) => Promise<null | Array<Function>>;

export type ConnectToItemShareFnType = (options: {
access?: Access;
errorFn?: Function;
requestOptions?: RequestOptions;
successFn?: Function;
}) => Function;

export type AvatarURLMap = { [key: number | string]: string | null };

export interface ConvertCollabOptions {
avatarURLMap?: AvatarURLMap | null;
collab: Collaboration;
isCurrentUserOwner: boolean;
ownerEmail: string | null;
}
Loading