-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Rename capability gdrive/#7
- Loading branch information
Showing
10 changed files
with
167 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 0 additions & 86 deletions
86
client-react/src/client/connectors/google_drive_v2/capabilities.js
This file was deleted.
Oops, something went wrong.
55 changes: 55 additions & 0 deletions
55
client-react/src/client/connectors/google_drive_v2/capabilities/create-folder.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import api from '../api'; | ||
import sanitizeFilename from 'sanitize-filename'; | ||
import ContextMenuItem from '../../../components/ContextMenuItem'; | ||
import SetNameDialog from '../../../components/SetNameDialog'; | ||
|
||
let createFolderIcon = require('!!raw-loader!@opuscapita/svg-icons/lib/create_new_folder.svg'); | ||
|
||
export default (apiOptions, { showDialog, hideDialog, forceUpdate }) => ({ | ||
id: 'createFolder', | ||
shouldBeAvailable: (apiOptions, { selectedResources }) => selectedResources.length === 1, | ||
contextMenuRenderer: (apiOptions, { | ||
selection, | ||
selectedResources, | ||
resource, | ||
resourceChildren, | ||
resourceLocation | ||
}) => ( | ||
<ContextMenuItem | ||
icon={{ svg: createFolderIcon }} | ||
onClick={() => { | ||
showDialog(( | ||
<SetNameDialog | ||
onHide={hideDialog} | ||
onSubmit={async (folderName) => { | ||
let { resourceChildren } = await api.getChildrenForId(apiOptions, resource.id); | ||
let alreadyExists = resourceChildren.some((o) => o.title === folderName); | ||
if (alreadyExists) { | ||
return `File or folder with name "${folderName}" already exists`; | ||
} else { | ||
hideDialog(); | ||
await api.createFolder(apiOptions, resource.id, folderName); | ||
forceUpdate(); | ||
} | ||
}} | ||
onValidate={async (folderName) => { | ||
if (!folderName) { | ||
return 'Name can\'t be empty'; | ||
} else if (folderName === 'CON') { | ||
return 'We too do not respect Bill ;)'; | ||
} else if (folderName.length >= 255) { | ||
return 'Folder name can\'t contain more than 255 characters'; | ||
} else if (folderName.trim() !== sanitizeFilename(folderName.trim())) { | ||
return 'Folder name contains not allowed characters'; | ||
} | ||
return null; | ||
}} | ||
headerText={`Folder name`} | ||
/> | ||
)); | ||
}} | ||
> | ||
<span>Create folder</span> | ||
</ContextMenuItem> | ||
) | ||
}); |
17 changes: 17 additions & 0 deletions
17
client-react/src/client/connectors/google_drive_v2/capabilities/delete-resource.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import api from '../api'; | ||
import ContextMenuItem from '../../../components/ContextMenuItem'; | ||
|
||
let deleteIcon = require('!!raw-loader!@opuscapita/svg-icons/lib/delete.svg'); | ||
|
||
export default (apiOptions, { showDialog, hideDialog, forceUpdate }) => ({ | ||
id: 'delete', | ||
title: 'Remove', | ||
shouldBeAvailable: (apiOptions, { selectedResources }) => { | ||
return selectedResources.every(resource => resource.capabilities.canDelete); | ||
}, | ||
contextMenuRenderer: (apiOptions, { selectedResources }) => ( | ||
<ContextMenuItem icon={{ svg: deleteIcon }}> | ||
<span>Remove</span> | ||
</ContextMenuItem> | ||
) | ||
}); |
19 changes: 19 additions & 0 deletions
19
client-react/src/client/connectors/google_drive_v2/capabilities/download.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import api from '../api'; | ||
import ContextMenuItem from '../../../components/ContextMenuItem'; | ||
|
||
let downloadIcon = require('!!raw-loader!@opuscapita/svg-icons/lib/file_download.svg'); | ||
|
||
export default (apiOptions, { showDialog, hideDialog, forceUpdate }) => ({ | ||
id: 'download', | ||
shouldBeAvailable: (apiOptions, { selectedResources }) => { | ||
return selectedResources.length === 1 && selectedResources[0].type !== 'dir'; | ||
}, | ||
contextMenuRenderer: (apiOptions, { selectedResources }) => ( | ||
<ContextMenuItem | ||
icon={{ svg: downloadIcon }} | ||
onClick={() => api.downloadResources(selectedResources)} | ||
> | ||
<span>Download</span> | ||
</ContextMenuItem> | ||
) | ||
}); |
11 changes: 11 additions & 0 deletions
11
client-react/src/client/connectors/google_drive_v2/capabilities/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import createFolder from './create-folder'; | ||
import deleteResource from './delete-resource'; | ||
import download from './download'; | ||
import rename from './rename'; | ||
|
||
export default (apiOptions, { showDialog, hideDialog, forceUpdate }) => ([ | ||
createFolder(apiOptions, { showDialog, hideDialog, forceUpdate }), | ||
rename(apiOptions, { showDialog, hideDialog, forceUpdate }), | ||
download(apiOptions, { showDialog, hideDialog, forceUpdate }), | ||
deleteResource(apiOptions, { showDialog, hideDialog, forceUpdate }) | ||
]); |
56 changes: 56 additions & 0 deletions
56
client-react/src/client/connectors/google_drive_v2/capabilities/rename.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import api from '../api'; | ||
import sanitizeFilename from 'sanitize-filename'; | ||
import ContextMenuItem from '../../../components/ContextMenuItem'; | ||
import SetNameDialog from '../../../components/SetNameDialog'; | ||
|
||
let renameIcon = require('!!raw-loader!@opuscapita/svg-icons/lib/title.svg'); | ||
|
||
export default (apiOptions, { showDialog, hideDialog, forceUpdate }) => ({ | ||
id: 'rename', | ||
shouldBeAvailable: (apiOptions, { selectedResources }) => ( | ||
selectedResources.length === 1 && | ||
selectedResources[0].id !== 'root' // root is not mutable | ||
), | ||
contextMenuRenderer: (apiOptions, { | ||
selection, | ||
selectedResources, | ||
resource, | ||
resourceChildren, | ||
resourceLocation | ||
}) => ( | ||
<ContextMenuItem | ||
icon={{ svg: renameIcon }} | ||
onClick={() => { | ||
showDialog(( | ||
<SetNameDialog | ||
onHide={hideDialog} | ||
onSubmit={async (name) => { | ||
let { resourceChildren } = await api.getChildrenForId(apiOptions, resource.id); | ||
let alreadyExists = resourceChildren.some((o) => o.title === name); | ||
if (alreadyExists) { | ||
return `File or folder with name "${name}" already exists`; | ||
} else { | ||
hideDialog(); | ||
await api.renameResource(apiOptions, selectedResources[0].id, name); | ||
forceUpdate(); | ||
} | ||
}} | ||
onValidate={async (name) => { | ||
if (!name) { | ||
return 'Name can\'t be empty'; | ||
} else if (name.length >= 255) { | ||
return 'Name can\'t contain more than 255 characters'; | ||
} else if (name.trim() !== sanitizeFilename(name.trim())) { | ||
return 'Name contains not allowed characters'; | ||
} | ||
return null; | ||
}} | ||
headerText={`New name`} | ||
/> | ||
)); | ||
}} | ||
> | ||
<span>Rename</span> | ||
</ContextMenuItem> | ||
) | ||
}); |
3 changes: 0 additions & 3 deletions
3
client-react/src/client/connectors/google_drive_v2/context-menu-layout.js
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,11 @@ | ||
import api from './api'; | ||
import capabilities from './capabilities'; | ||
import contextMenuLayout from './context-menu-layout'; | ||
import listViewLayout from './list-view-layout'; | ||
import viewLayoutOptions from './view-layout-options'; | ||
|
||
export default { | ||
api, | ||
capabilities, | ||
contextMenuLayout, | ||
listViewLayout, | ||
viewLayoutOptions | ||
}; |