Skip to content

Commit 8eacbe1

Browse files
committed
feat(critical facilities): add drawer for showing critical facility details
1 parent f685e37 commit 8eacbe1

File tree

4 files changed

+75
-5
lines changed

4 files changed

+75
-5
lines changed

src/GeographicalFeatures/CriticalFacilities/DetailsView/Body.js

Whitespace-only changes.

src/GeographicalFeatures/CriticalFacilities/DetailsView/Header.js

Whitespace-only changes.

src/GeographicalFeatures/CriticalFacilities/DetailsView/styles.css

Whitespace-only changes.

src/GeographicalFeatures/CriticalFacilities/index.js

Lines changed: 75 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { Component } from 'react';
22
import PropTypes from 'prop-types';
33
import { httpActions } from '@codetanzania/ewea-api-client';
44
import { Connect, reduxActions } from '@codetanzania/ewea-api-states';
5-
import { Modal, Row, Col } from 'antd';
5+
import { Modal, Row, Col, Drawer } from 'antd';
66
import { PlusOutlined } from '@ant-design/icons';
77
import isEmpty from 'lodash/isEmpty';
88
import get from 'lodash/get';
@@ -14,6 +14,8 @@ import NotificationForm from '../../components/NotificationForm';
1414
import { notifyError, notifySuccess, truncateString } from '../../util';
1515
import ItemList from '../../components/List';
1616
import ListItem from '../../components/ListItem';
17+
import CriticalFacilityDetailsViewHeader from './DetailsView/Header';
18+
import CriticalFacilityDetailsViewBody from './DetailsView/Body';
1719

1820
/* http actions */
1921
const {
@@ -118,6 +120,7 @@ class FeatureList extends Component {
118120
super(props);
119121
this.state = {
120122
showFilters: false,
123+
showDetails: false,
121124
isEditForm: false,
122125
showNotificationForm: false,
123126
notificationSubject: undefined,
@@ -167,12 +170,12 @@ class FeatureList extends Component {
167170
* @function handleListSearch
168171
* @name handleListSearch
169172
* @description Handle list search
170-
* @param {object} event List search event
173+
* @param {object} feature List search feature
171174
* @version 0.1.0
172175
* @since 0.1.0
173176
*/
174-
handleListSearch = (event) => {
175-
searchFeatures(event.target.value);
177+
handleListSearch = (feature) => {
178+
searchFeatures(feature.target.value);
176179
};
177180

178181
/**
@@ -242,6 +245,7 @@ class FeatureList extends Component {
242245
* @since 0.1.0
243246
*/
244247
handleFormOpen = () => {
248+
selectFeature(null);
245249
openFeatureForm();
246250
};
247251

@@ -265,7 +269,10 @@ class FeatureList extends Component {
265269
* @since 0.1.0
266270
*/
267271
handleAfterFormClose = () => {
268-
selectFeature(null);
272+
const { showDetails } = this.state;
273+
if (!showDetails) {
274+
selectFeature(null);
275+
}
269276
this.setState({ isEditForm: false });
270277
};
271278

@@ -377,6 +384,30 @@ class FeatureList extends Component {
377384
this.setState({ showFilters: false });
378385
};
379386

387+
/**
388+
* @function
389+
* @name handleView
390+
* @description Handle on view item details action for list item
391+
* @param {object} item item to be viewed
392+
* @version 0.1.0
393+
* @since 0.1.0
394+
*/
395+
handleView = (item) => {
396+
selectFeature(item);
397+
this.setState({ showDetails: true });
398+
};
399+
400+
/**
401+
* @function
402+
* @name closeDetails
403+
* @description close feature details drawer
404+
* @version 0.1.0
405+
* @since 0.1.0
406+
*/
407+
closeDetails = () => {
408+
this.setState({ showDetails: false });
409+
};
410+
380411
/**
381412
* @function render
382413
* @name render
@@ -401,6 +432,7 @@ class FeatureList extends Component {
401432
// states
402433
const {
403434
showFilters,
435+
showDetails,
404436
cached,
405437
isEditForm,
406438
showNotificationForm,
@@ -481,6 +513,12 @@ class FeatureList extends Component {
481513
</span>
482514
}
483515
actions={[
516+
{
517+
name: 'View Critical Infrastructure',
518+
title: 'View Critical Infrastructure Details',
519+
onClick: () => this.handleView(item),
520+
icon: 'view',
521+
},
484522
{
485523
name: 'Edit Critical Infrastructure',
486524
title: 'Update critical infrastructure details',
@@ -594,6 +632,38 @@ class FeatureList extends Component {
594632
/>
595633
</Modal>
596634
{/* end: form modal */}
635+
636+
{/* details drawer */}
637+
<Drawer
638+
title={
639+
<CriticalFacilityDetailsViewHeader
640+
number={get(feature, 'number', 'N/A')}
641+
description={get(feature, 'description', 'N/A')}
642+
type={get(feature, 'type.strings.name.en', 'N/A')}
643+
stage={get(feature, 'stage', 'N/A')}
644+
onBack={this.closeDetails}
645+
/>
646+
}
647+
placement="right"
648+
width="100%"
649+
onClose={this.closeDetails}
650+
visible={showDetails}
651+
drawerStyle={{ overflow: 'hidden' }}
652+
headerStyle={{ padding: 0 }}
653+
bodyStyle={{ overflow: 'hidden', height: '100%', padding: '15px' }}
654+
destroyOnClose
655+
>
656+
<CriticalFacilityDetailsViewBody
657+
feature={feature}
658+
onShare={() => {
659+
this.handleShare(feature);
660+
}}
661+
onEdit={() => {
662+
this.handleEdit(feature);
663+
}}
664+
/>
665+
</Drawer>
666+
{/* End details drawer */}
597667
</>
598668
);
599669
}

0 commit comments

Comments
 (0)