Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Commit

Permalink
Add facility type & other facility type fields
Browse files Browse the repository at this point in the history
- add facility_type field & choices for facility claim
- add other_facility_type field for facility claim
- update profile form and details screen to show facility type data
  • Loading branch information
Kelly Innes committed Jul 8, 2019
1 parent b25e320 commit 8d93c74
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/app/src/actions/claimedFacilityDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,7 @@ export const updateClaimedFacilityOfficePhone =
createAction('UPDATE_CLAIMED_FACILITY_OFFICE_PHONE');
export const updateClaimedFacilityParentCompany =
createAction('UPDATE_CLAIMED_FACILITY_PARENT_COMPANY');
export const updateClaimedFacilityFacilityType =
createAction('UPDATE_CLAIMED_FACILITY_FACILITY_TYPE');
export const updateClaimedFacilityOtherFacilityType =
createAction('UPDATE_CLAIMED_FACILITY_OTHER_FACILITY_TYPE');
28 changes: 28 additions & 0 deletions src/app/src/components/ClaimedFacilitiesDetails.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import memoize from 'lodash/memoize';
import find from 'lodash/find';
import stubFalse from 'lodash/stubFalse';
import isEmpty from 'lodash/isEmpty';
import isEqual from 'lodash/isEqual';
import get from 'lodash/get';
import isNull from 'lodash/isNull';
import Select from 'react-select';
Expand Down Expand Up @@ -40,6 +41,8 @@ import {
updateClaimedFacilityDescription,
updateClaimedFacilityMinimumOrder,
updateClaimedFacilityAverageLeadTime,
updateClaimedFacilityFacilityType,
updateClaimedFacilityOtherFacilityType,
updateClaimedFacilityContactPersonName,
updateClaimedFacilityContactEmail,
updateClaimedFacilityPointOfContactVisibility,
Expand Down Expand Up @@ -256,6 +259,8 @@ function ClaimedFacilitiesDetails({
errorUpdating,
updateParentCompany,
contributorOptions,
updateFacilityType,
updateFacilityOtherType,
}) {
/* eslint-disable react-hooks/exhaustive-deps */
// disabled because we want to use this as just
Expand Down Expand Up @@ -378,6 +383,22 @@ function ClaimedFacilitiesDetails({
{get(data, 'facility_parent_company.name', null)}
</Typography>
</ShowOnly>
<InputSection
label="Facility Type"
value={get(data, 'facility_type', null)}
onChange={updateFacilityType}
disabled={updating}
isSelect
selectOptions={mapDjangoChoiceTuplesToSelectOptions(data.facility_types)}
/>
<ShowOnly when={isEqual(get(data, 'facility_type', null), 'Other')}>
<InputSection
label="Other Facility Type"
value={get(data, 'other_facility_type', null)}
onChange={updateFacilityOtherType}
disabled={updating}
/>
</ShowOnly>
<InputSection
label="Minimum order quantity"
value={data.facility_minimum_order_quantity}
Expand Down Expand Up @@ -583,6 +604,8 @@ ClaimedFacilitiesDetails.propTypes = {
updateContactVisibility: func.isRequired,
updateOfficeVisibility: func.isRequired,
contributorOptions: contributorOptionsPropType,
updateFacilityType: func.isRequired,
updateFacilityOtherType: func.isRequired,
};

function mapStateToProps({
Expand Down Expand Up @@ -664,6 +687,11 @@ function mapDispatchToProps(
updateFacilityDescription: makeDispatchValueFn(
updateClaimedFacilityDescription,
),
updateFacilityType: ({ value }) =>
dispatch(updateClaimedFacilityFacilityType(value)),
updateFacilityOtherType: makeDispatchValueFn(
updateClaimedFacilityOtherFacilityType,
),
updateFacilityMinimumOrder: makeDispatchValueFn(
updateClaimedFacilityMinimumOrder,
),
Expand Down
8 changes: 8 additions & 0 deletions src/app/src/components/FacilityDetailSidebarClaimedInfo.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ export default function FacilityDetailsSidebarClaimedInfo({
label="Description"
value={facility.description}
/>
<ClaimInfoSection
label="Facility Type"
value={facility.facility_type}
/>
<ClaimInfoSection
label="Other Facility Type"
value={facility.other_facility_type}
/>
<ClaimInfoSection
value={facility.website}
label="Website"
Expand Down
18 changes: 18 additions & 0 deletions src/app/src/reducers/ClaimedFacilityDetailsReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import {
updateClaimedFacilityOfficeCountry,
updateClaimedFacilityOfficePhone,
updateClaimedFacilityParentCompany,
updateClaimedFacilityFacilityType,
updateClaimedFacilityOtherFacilityType,
} from '../actions/claimedFacilityDetails';

const initialState = Object.freeze({
Expand Down Expand Up @@ -205,6 +207,22 @@ export default createReducer({
facility_average_lead_time: { $set: avgLeadTime },
},
}),
[updateClaimedFacilityFacilityType]: (state, type) => update(state, {
updateData: {
error: { $set: initialState.updateData.error },
},
data: {
facility_type: { $set: type },
},
}),
[updateClaimedFacilityOtherFacilityType]: (state, otherType) => update(state, {
updateData: {
error: { $set: initialState.updateData.error },
},
data: {
other_facility_type: { $set: otherType },
},
}),
[updateClaimedFacilityContactPersonName]: (state, person) => update(state, {
updateData: {
error: { $set: initialState.updateData.error },
Expand Down
3 changes: 3 additions & 0 deletions src/app/src/util/propTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,4 +278,7 @@ export const approvedFacilityClaimPropType = shape({
office_phone_number: string.isRequired,
office_info_publicly_visible: bool.isRequired,
facility: facilityDetailsPropType.isRequired,
facility_type: string.isRequired,
other_facility_type: string.isRequired,
facility_types: arrayOf(arrayOf(string)).isRequired,
});
33 changes: 33 additions & 0 deletions src/django/api/migrations/0022_auto_20190708_2040.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Generated by Django 2.0.13 on 2019-07-08 20:40

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('api', '0021_auto_20190708_1947'),
]

operations = [
migrations.AddField(
model_name='facilityclaim',
name='facility_type',
field=models.CharField(blank=True, choices=[('Cut and Sew / RMG', 'Cut and Sew / RMG'), ('Fabric Mill', 'Fabric Mill'), ('Dyehouse', 'Dyehouse'), ('Laundry', 'Laundry'), ('Finishing', 'Finishing'), ('Tannery', 'Tannery'), ('Spinning', 'Spinning'), ('Ginning', 'Ginning'), ('Other', 'Other')], help_text='The editable facility type for this claim.', max_length=17, null=True),
),
migrations.AddField(
model_name='facilityclaim',
name='other_facility_type',
field=models.CharField(blank=True, help_text='Editable alternate text when facility type is OTHER.', max_length=200, null=True),
),
migrations.AddField(
model_name='historicalfacilityclaim',
name='facility_type',
field=models.CharField(blank=True, choices=[('Cut and Sew / RMG', 'Cut and Sew / RMG'), ('Fabric Mill', 'Fabric Mill'), ('Dyehouse', 'Dyehouse'), ('Laundry', 'Laundry'), ('Finishing', 'Finishing'), ('Tannery', 'Tannery'), ('Spinning', 'Spinning'), ('Ginning', 'Ginning'), ('Other', 'Other')], help_text='The editable facility type for this claim.', max_length=17, null=True),
),
migrations.AddField(
model_name='historicalfacilityclaim',
name='other_facility_type',
field=models.CharField(blank=True, help_text='Editable alternate text when facility type is OTHER.', max_length=200, null=True),
),
]
33 changes: 33 additions & 0 deletions src/django/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,28 @@ class FacilityClaim(models.Model):
(REVOKED, REVOKED),
)

CUT_AND_SEW = 'Cut and Sew / RMG'
FABRIC_MILL = 'Fabric Mill'
DYEHOUSE = 'Dyehouse'
LAUNDRY = 'Laundry'
FINISHING = 'Finishing'
TANNERY = 'Tannery'
SPINNING = 'Spinning'
GINNING = 'Ginning'
OTHER = 'Other'

FACILITY_TYPE_CHOICES = (
(CUT_AND_SEW, CUT_AND_SEW),
(FABRIC_MILL, FABRIC_MILL),
(DYEHOUSE, DYEHOUSE),
(LAUNDRY, LAUNDRY),
(FINISHING, FINISHING),
(TANNERY, TANNERY),
(SPINNING, SPINNING),
(GINNING, GINNING),
(OTHER, OTHER),
)

contributor = models.ForeignKey(
'Contributor',
null=False,
Expand Down Expand Up @@ -521,6 +543,17 @@ class FacilityClaim(models.Model):
choices=[(i, i) for i in range(0, 101)],
help_text=('Integer value indicating the facility\'s percentage of '
'female workers.'))
facility_type = models.CharField(
max_length=len(CUT_AND_SEW),
null=True,
blank=True,
choices=FACILITY_TYPE_CHOICES,
help_text='The editable facility type for this claim.')
other_facility_type = models.CharField(
max_length=200,
null=True,
blank=True,
help_text='Editable alternate text when facility type is OTHER.')
point_of_contact_person_name = models.CharField(
max_length=200,
null=True,
Expand Down
9 changes: 8 additions & 1 deletion src/django/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,8 @@ def get_claim_info(self, facility):
'workers_count': claim.facility_workers_count,
'female_workers_percentage': claim
.facility_female_workers_percentage,
'facility_type': claim.facility_type,
'other_facility_type': claim.other_facility_type,
},
'contact': {
'name': claim.point_of_contact_person_name,
Expand Down Expand Up @@ -571,6 +573,7 @@ class ApprovedFacilityClaimSerializer(ModelSerializer):
facility = SerializerMethodField()
countries = SerializerMethodField()
contributors = SerializerMethodField()
facility_types = SerializerMethodField()
facility_parent_company = SerializerMethodField()

class Meta:
Expand All @@ -588,7 +591,8 @@ class Meta:
'office_country_code', 'office_phone_number',
'office_info_publicly_visible',
'facility', 'countries', 'facility_parent_company',
'contributors', 'facility_website_publicly_visible')
'contributors', 'facility_website_publicly_visible',
'facility_types', 'facility_type', 'other_facility_type')

def get_facility(self, claim):
return FacilityDetailsSerializer(claim.facility).data
Expand All @@ -603,6 +607,9 @@ def get_contributors(self, claim):
in Contributor.objects.all().order_by('name')
]

def get_facility_types(self, claim):
return FacilityClaim.FACILITY_TYPE_CHOICES

def get_facility_parent_company(self, claim):
if not claim.parent_company:
return None
Expand Down
11 changes: 9 additions & 2 deletions src/django/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2033,6 +2033,13 @@ def get_claimed_details(self, request, pk=None):
.objects \
.get(pk=parent_company_data['id'])

facility_type = request.data.get('facility_type')

if facility_type == FacilityClaim.OTHER:
other_facility_type = request.data.get('other_facility_type')
else:
other_facility_type = None

FacilityClaim.objects.filter(pk=pk).update(
facility_description=request.data.get('facility_description'),
facility_name_english=request.data
Expand All @@ -2047,8 +2054,8 @@ def get_claimed_details(self, request, pk=None):
facility_website=request.data.get('facility_website'),
facility_website_publicly_visible=request.data
.get('facility_website_publicly_visible'),
facility_minimum_order_quantity=request.data
.get('facility_minimum_order_quantity'),
facility_type=facility_type,
other_facility_type=other_facility_type,
facility_average_lead_time=request.data
.get('facility_average_lead_time'),
facility_workers_count=request.data
Expand Down

0 comments on commit 8d93c74

Please sign in to comment.