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

Feature view mode #60

Open
wants to merge 3 commits 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
42 changes: 22 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ function App() {
clientId: "xxxxxxxxxxxxxxxxx",
developerKey: "xxxxxxxxxxxx",
viewId: "DOCS",
viewMode: "LIST",
// token: token, // pass oauth token in case you already have one
showUploadView: true,
showUploadFolders: true,
Expand Down Expand Up @@ -66,26 +67,27 @@ export default App;

## Picker Props

| params | value | default value | description |
|------------------|----------|------------------|-------------------------------|
| callbackFunction |function | REQUIRED |Callback function that will be called on picker action |
| clientId | string | REQUIRED | Google client id |
| developerKey | string | REQUIRED | Google developer key |
| disableDefaultView | boolean | false | disables default view |
| viewId | string | DOCS | ViewIdOptions |
| viewMimeTypes | string | optional |Comma separated mimetypes. Use this in place of viewId if you need to filter multiple type of files. list: https://developers.google.com/drive/api/v3/mime-types.|
|setIncludeFolders| boolean | false |Show folders in the view items.|
|setSelectFolderEnabled|boolean| false |Allows the user to select a folder in Google Drive.|
| token | string | optional | access_token to skip auth part|
| setOrigin | string | optional | Sets the origin of the Google Picker dialog |
| multiselect | boolean | false | Enable picker multiselect |
| supportDrives | boolean | false | Support shared drives |
| showUploadView | boolean | false | Enable upload view |
| showUploadFolders| boolean | false |Enable folder selection(upload)|
| setParentFolder | string | disabled | Drive folder id to upload |
| customViews |ViewClass[]| optional | Array of custom views you want to add to the picker|
| customScopes |string[]| ['https://www.googleapis.com/auth/drive.readonly'] | Array of custom scopes you want to add to the picker|
| locale |string | en | List of supported locales https://developers.google.com/picker/docs#i18n|
| params | value | default value | description |
|------------------------|----------|------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| callbackFunction |function | REQUIRED | Callback function that will be called on picker action |
| clientId | string | REQUIRED | Google client id |
| developerKey | string | REQUIRED | Google developer key |
| disableDefaultView | boolean | false | disables default view |
| viewId | string | DOCS | ViewIdOptions |
| viewMimeTypes | string | optional | Comma separated mimetypes. Use this in place of viewId if you need to filter multiple type of files. list: https://developers.google.com/drive/api/v3/mime-types. |
| viewMode | string | optional | Accepts `GRID` or `LIST` but defaults to `GRID` (changes display view). |
| setIncludeFolders | boolean | false | Show folders in the view items. |
| setSelectFolderEnabled |boolean| false | Allows the user to select a folder in Google Drive. |
| token | string | optional | access_token to skip auth part |
| setOrigin | string | optional | Sets the origin of the Google Picker dialog |
| multiselect | boolean | false | Enable picker multiselect |
| supportDrives | boolean | false | Support shared drives |
| showUploadView | boolean | false | Enable upload view |
| showUploadFolders | boolean | false | Enable folder selection(upload) |
| setParentFolder | string | disabled | Drive folder id to upload |
| customViews |ViewClass[]| optional | Array of custom views you want to add to the picker |
| customScopes |string[]| ['https://www.googleapis.com/auth/drive.readonly'] | Array of custom scopes you want to add to the picker |
| locale |string | en | List of supported locales https://developers.google.com/picker/docs#i18n |


## viewId options
Expand Down
1 change: 1 addition & 0 deletions demo/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ function App() {
developerKey: process.env.REACT_APP_DEVELOPER_KEY!,
viewId: 'DOCUMENTS',
viewMimeTypes: 'application/vnd.google-apps.spreadsheet',
viewMode: 'LIST',
setIncludeFolders: true,
setSelectFolderEnabled: true,
// customViews: customView,
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export default function useDrivePicker(): [
)
const [pickerApiLoaded, setpickerApiLoaded] = useState(false)
const [openAfterAuth, setOpenAfterAuth] = useState(false)
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [authWindowVisible, setAuthWindowVisible] = useState(false)
const [config, setConfig] =
useState<PickerConfiguration>(defaultConfiguration)
Expand Down Expand Up @@ -113,6 +114,7 @@ export default function useDrivePicker(): [
showUploadFolders,
setParentFolder = '',
viewMimeTypes,
viewMode,
customViews,
locale = 'en',
setIncludeFolders,
Expand All @@ -124,6 +126,7 @@ export default function useDrivePicker(): [

const view = new google.picker.DocsView(google.picker.ViewId[viewId])
if (viewMimeTypes) view.setMimeTypes(viewMimeTypes)
if (viewMode) view.setMode(google.picker.DocsViewMode[viewMode])
if (setIncludeFolders) view.setIncludeFolders(true)
if (setSelectFolderEnabled) view.setSelectFolderEnabled(true)

Expand Down
16 changes: 9 additions & 7 deletions src/typeDefs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ export type PickerCallback = {
docs: CallbackDoc[]
}

export type authResult = {
access_token: string;
token_type: string;
expires_in: number;
scope: string;
authuser: string;
prompt: string;
export type authResult = {
access_token: string
token_type: string
expires_in: number
scope: string
authuser: string
prompt: string
}

type ViewIdOptions =
Expand All @@ -50,6 +50,7 @@ export type PickerConfiguration = {
developerKey: string
viewId?: ViewIdOptions
viewMimeTypes?: string
viewMode?: string
setIncludeFolders?: boolean
setSelectFolderEnabled?: boolean
disableDefaultView?: boolean
Expand All @@ -66,6 +67,7 @@ export type PickerConfiguration = {
customViews?: any[]
locale?: string
customScopes?: string[]
// eslint-disable-next-line @typescript-eslint/no-explicit-any
callbackFunction: (data: PickerCallback) => any
}

Expand Down