From 491e7880b708f64313a64d92a3841b24f5b477ee Mon Sep 17 00:00:00 2001 From: Conrad S Date: Fri, 17 Feb 2017 13:50:55 -0500 Subject: [PATCH 1/2] Call document service to get link to folder --- src/components/BuildingOverview/index.js | 6 ++++-- src/components/DocumentCardViewer/index.js | 4 +++- src/containers/Building/actions.js | 1 + src/containers/Building/index.js | 7 +++++-- src/containers/Documents/actions.js | 16 ++++++++++++++++ src/containers/Documents/constants.js | 2 ++ src/containers/Documents/propTypes.js | 1 + src/containers/Documents/reducer.js | 15 +++++++++++++++ src/containers/Documents/sagas.js | 19 +++++++++++++++++++ 9 files changed, 66 insertions(+), 5 deletions(-) diff --git a/src/components/BuildingOverview/index.js b/src/components/BuildingOverview/index.js index df9a359b..65e2d9ec 100644 --- a/src/components/BuildingOverview/index.js +++ b/src/components/BuildingOverview/index.js @@ -8,9 +8,9 @@ export default class BuildingOverview extends Component { constructor(props) { super(props); - const { building, buildingId } = this.props; + const { building } = this.props; this.state = { - documentPath: `/Buildings/${buildingId}_${building.address}/`, + documentPath: `/Buildings/${building.building_id}_${building.address}/`, fileKey: 'building', }; } @@ -39,6 +39,7 @@ export default class BuildingOverview extends Component { documents={this.props.documents} getDocuments={this.props.getDocuments} uploadDocument={this.props.uploadDocument} + getFolderUrl={this.props.getFolderUrl} /> ); @@ -58,4 +59,5 @@ BuildingOverview.propTypes = { documents: documentsPropType, getDocuments: PropTypes.func, uploadDocument: PropTypes.func, + getFolderUrl: PropTypes.func, }; diff --git a/src/components/DocumentCardViewer/index.js b/src/components/DocumentCardViewer/index.js index a17ec11a..a39f696b 100644 --- a/src/components/DocumentCardViewer/index.js +++ b/src/components/DocumentCardViewer/index.js @@ -17,6 +17,7 @@ export default class DocumentCardViewer extends Component { componentDidMount() { this.props.getDocuments(this.props.documentPath, this.props.fileKey); + this.props.getFolderUrl(this.props.documentPath); } uploadHandler = (event) => { @@ -94,7 +95,7 @@ export default class DocumentCardViewer extends Component { />
Documents {/* eslint-disable jsx-a11y/href-no-hash */} - View all + View all
{ this.renderUploadButton() }
{ this.renderDocuments() }
@@ -110,4 +111,5 @@ DocumentCardViewer.propTypes = { documents: documentsPropType.isRequired, getDocuments: PropTypes.func.isRequired, uploadDocument: PropTypes.func.isRequired, + getFolderUrl: PropTypes.func.isRequired, }; diff --git a/src/containers/Building/actions.js b/src/containers/Building/actions.js index 28840a22..0cabd1f1 100644 --- a/src/containers/Building/actions.js +++ b/src/containers/Building/actions.js @@ -22,6 +22,7 @@ import { * passing the building detail */ export function loadBuildingDetail(buildingID) { + console.log('In loadbuildingDetail'); return { type: LOAD_BUILDING_DETAIL, payload: buildingID, diff --git a/src/containers/Building/index.js b/src/containers/Building/index.js index 63b5d823..29eabeb3 100644 --- a/src/containers/Building/index.js +++ b/src/containers/Building/index.js @@ -6,7 +6,7 @@ import buildingDetailPropTypes from './propTypes'; import { loadBuildingDetail } from './actions'; import documentsPropType from '../Documents/propTypes'; -import { loadDocuments, uploadDocument } from '../Documents/actions'; +import { loadDocuments, uploadDocument, loadFolderUrl } from '../Documents/actions'; import SideBarDetail from '../../components/SideBarDetail'; import './styles.css'; @@ -14,6 +14,7 @@ import './styles.css'; class Building extends Component { componentDidMount() { + console.log('In buildings calling loadBuildingDetail'); this.props.loadBuildingDetail(this.props.buildingId); } @@ -22,11 +23,11 @@ class Building extends Component { let mainContent =
; if (this.props.children && !error && !loading && address !== undefined) { mainContent = React.cloneElement(this.props.children, { - buildingId: this.props.buildingId, building: this.props.buildingDetail.overview, documents: this.props.documents, getDocuments: this.props.loadDocuments, uploadDocument: this.props.uploadDocument, + getFolderUrl: this.props.loadFolderUrl, }); } @@ -57,6 +58,7 @@ Building.propTypes = { documents: documentsPropType, loadDocuments: PropTypes.func, uploadDocument: PropTypes.func, + loadFolderUrl: PropTypes.func, }; function mapDispatchToProps(dispatch) { @@ -64,6 +66,7 @@ function mapDispatchToProps(dispatch) { loadBuildingDetail, loadDocuments, uploadDocument, + loadFolderUrl, }, dispatch); } diff --git a/src/containers/Documents/actions.js b/src/containers/Documents/actions.js index 3c8c901d..1048416b 100644 --- a/src/containers/Documents/actions.js +++ b/src/containers/Documents/actions.js @@ -5,6 +5,8 @@ import { UPLOAD_DOCUMENT, UPLOAD_DOCUMENT_SUCCESS, UPLOAD_DOCUMENT_ERROR, + LOAD_FOLDER_URL, + LOAD_FOLDER_URL_SUCCESS, } from './constants'; export function loadDocuments(documentPath, fileKey) { @@ -57,3 +59,17 @@ export function documentUploadError(error) { error, }; } + +export function loadFolderUrl(folderPath) { + return { + type: LOAD_FOLDER_URL, + folderPath, + }; +} + +export function folderUrlLoaded(url) { + return { + type: LOAD_FOLDER_URL_SUCCESS, + payload: url, + }; +} diff --git a/src/containers/Documents/constants.js b/src/containers/Documents/constants.js index ef186ca8..5e8ab2d6 100644 --- a/src/containers/Documents/constants.js +++ b/src/containers/Documents/constants.js @@ -4,3 +4,5 @@ export const LOAD_DOCUMENTS_ERROR = 'LOAD_DOCUMENTS_ERROR'; export const UPLOAD_DOCUMENT = 'UPLOAD_DOCUMENT'; export const UPLOAD_DOCUMENT_SUCCESS = 'UPLOAD_DOCUMENT_SUCCESS'; export const UPLOAD_DOCUMENT_ERROR = 'UPLOAD_DOCUMENT_ERROR'; +export const LOAD_FOLDER_URL = 'LOAD_FOLDER_URL'; +export const LOAD_FOLDER_URL_SUCCESS = 'LOAD_FOLDER_URL_SUCCESS'; diff --git a/src/containers/Documents/propTypes.js b/src/containers/Documents/propTypes.js index f6f413be..185bf293 100644 --- a/src/containers/Documents/propTypes.js +++ b/src/containers/Documents/propTypes.js @@ -23,6 +23,7 @@ export default shape({ bool, string, ]), + folderUrl: string, files: shape({ building: arrayOf(documentProps), utilityBills: arrayOf(documentProps), diff --git a/src/containers/Documents/reducer.js b/src/containers/Documents/reducer.js index 0829c6a5..7959494a 100644 --- a/src/containers/Documents/reducer.js +++ b/src/containers/Documents/reducer.js @@ -5,6 +5,8 @@ import { UPLOAD_DOCUMENT, UPLOAD_DOCUMENT_SUCCESS, UPLOAD_DOCUMENT_ERROR, + LOAD_FOLDER_URL, + LOAD_FOLDER_URL_SUCCESS, } from './constants'; const initState = { @@ -12,6 +14,7 @@ const initState = { error: false, uploading: false, uploadError: false, + documentUrl: '#', files: { building: [], // Root Directory utilityBills: [], // Utility_Bills @@ -72,6 +75,18 @@ export default function (state = initState, action) { uploadError: action.error, }; + case LOAD_FOLDER_URL: + return { + ...state, + folderUrl: '#', + }; + + case LOAD_FOLDER_URL_SUCCESS: + return { + ...state, + folderUrl: action.payload, + }; + default: return state; } diff --git a/src/containers/Documents/sagas.js b/src/containers/Documents/sagas.js index d6f28455..8234b189 100644 --- a/src/containers/Documents/sagas.js +++ b/src/containers/Documents/sagas.js @@ -5,6 +5,7 @@ import { getHeaders, documentURL } from '../../utils/restServices'; import { LOAD_DOCUMENTS, UPLOAD_DOCUMENT, + LOAD_FOLDER_URL, } from './constants'; import { @@ -12,6 +13,7 @@ import { documentsLoadingError, documentUploaded, documentUploadError, + folderUrlLoaded, } from './actions'; @@ -58,7 +60,24 @@ function* uploadDocument(action) { } } +function* getFolderUrl(action) { + const { folderPath } = action; + + const res = yield call( + request, + `${documentURL}?path=${folderPath}&folder=true`, { + method: 'GET', + headers: getHeaders(), + } + ); + + if (!res.err) { + yield put(folderUrlLoaded(res.data[0].url_box)); + } +} + export default function* () { yield takeLatest(LOAD_DOCUMENTS, getDocuments); yield takeLatest(UPLOAD_DOCUMENT, uploadDocument); + yield takeLatest(LOAD_FOLDER_URL, getFolderUrl); } -- GitLab From dac7f8428411f00be247c94c642fe94886a0ef60 Mon Sep 17 00:00:00 2001 From: Alessandro DiMarco Date: Mon, 20 Feb 2017 13:43:42 -0500 Subject: [PATCH 2/2] Use building id from route instead of redux --- src/components/BuildingOverview/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/BuildingOverview/index.js b/src/components/BuildingOverview/index.js index 1810edbe..01099f0e 100644 --- a/src/components/BuildingOverview/index.js +++ b/src/components/BuildingOverview/index.js @@ -13,9 +13,9 @@ export default class BuildingOverview extends Component { constructor(props) { super(props); - const { building } = this.props; + const { building, buildingId } = this.props; this.state = { - documentPath: `/Buildings/${building.building_id}_${building.address}/`, + documentPath: `/Buildings/${buildingId}_${building.address}/`, fileKey: 'building', }; } -- GitLab