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

fixed request type strings to match database #464

Merged
merged 3 commits into from
Mar 25, 2020
Merged
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
5 changes: 2 additions & 3 deletions src/components/PinMap/PinMap.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,11 @@ class PinMap extends Component {
address,
ncname,
} = pinsInfo[srnumber] || {};
const { color, abbrev } = REQUEST_TYPES.find(req => req.type === requesttype
|| req.fullType === requesttype);
const { displayName, color, abbrev } = REQUEST_TYPES[requesttype];

const popup = (
<PinPopup
requestType={requesttype}
displayName={displayName}
color={color}
abbrev={abbrev}
address={address}
Expand Down
8 changes: 4 additions & 4 deletions src/components/PinMap/PinPopup.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import moment from 'moment';
import { Popup } from 'react-leaflet';

const PinPopup = ({
requestType,
displayName,
color,
abbrev,
address,
Expand All @@ -28,7 +28,7 @@ const PinPopup = ({
{ createdDate ? (
<>
<p className="pin-popup-type has-text-weight-bold">
{requestType}
{displayName}
&nbsp;
[
<span className="pin-popup-type-abbrev" style={{ color }}>
Expand Down Expand Up @@ -77,7 +77,7 @@ const PinPopup = ({
export default PinPopup;

PinPopup.propTypes = {
requestType: PropTypes.string,
displayName: PropTypes.string,
color: PropTypes.string,
abbrev: PropTypes.string,
address: PropTypes.string,
Expand All @@ -89,7 +89,7 @@ PinPopup.propTypes = {
};

PinPopup.defaultProps = {
requestType: undefined,
displayName: undefined,
color: 'black',
abbrev: undefined,
address: undefined,
Expand Down
2 changes: 1 addition & 1 deletion src/components/Visualizations/Frequency.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const Frequency = ({
const chartData = {
labels: bins.slice(0, -1).map(bin => moment(bin).format('MMM D')),
datasets: Object.keys(counts).map(key => {
const requestType = REQUEST_TYPES.find(t => t.type === key);
const requestType = REQUEST_TYPES[key];
return {
data: counts[key],
label: requestType?.abbrev,
Expand Down
10 changes: 7 additions & 3 deletions src/components/Visualizations/Legend.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,25 @@ import { REQUEST_TYPES } from '@components/common/CONSTANTS';
const Legend = ({
requestTypes,
}) => {
const selectedTypes = REQUEST_TYPES.filter(el => requestTypes[el.type]);
const selectedTypes = (
Object.keys(requestTypes)
.filter(type => type !== 'All' && requestTypes[type])
.map(type => REQUEST_TYPES[type])
);

return (
<div className="legend">
<h1 className="has-text-centered">Legend</h1>
<div className="outline">
{
selectedTypes.length > 0
? selectedTypes.map(({ type, color, abbrev }) => (
? selectedTypes.map(({ displayName, color, abbrev }) => (
<span key={abbrev} className="legend-item">
<div
className="circle"
style={{ backgroundColor: color }}
/>
{ type }
{ displayName }
{' '}
[
<span style={{ color }}>{abbrev}</span>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Visualizations/TimeToClose.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const TimeToClose = ({
// // DATA ////

const boxes = Object.keys(timeToClose).map(key => {
const requestType = REQUEST_TYPES.find(t => t.type === key);
const requestType = REQUEST_TYPES[key];
return {
abbrev: requestType?.abbrev,
color: requestType?.color,
Expand Down
2 changes: 1 addition & 1 deletion src/components/Visualizations/TotalRequests.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const TotalRequests = ({
const chartData = {
labels: bins.slice(0, -1).map(bin => moment(bin).format('MMM D')),
datasets: Object.keys(counts).map(key => {
const requestType = REQUEST_TYPES.find(t => t.type === key);
const requestType = REQUEST_TYPES[key];
return {
data: counts[key],
label: requestType?.abbrev,
Expand Down
4 changes: 2 additions & 2 deletions src/components/Visualizations/TypeOfRequest.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ const TypeOfRequest = ({
typeCounts,
}) => {
const sectors = Object.keys(typeCounts).map(key => ({
label: key,
label: REQUEST_TYPES[key]?.displayName,
value: typeCounts[key],
color: REQUEST_TYPES.find(t => t.type === key)?.color,
color: REQUEST_TYPES[key]?.color,
}));

return (
Expand Down
91 changes: 24 additions & 67 deletions src/components/common/CONSTANTS.js
Original file line number Diff line number Diff line change
@@ -1,91 +1,62 @@
export default {};

export const YEARS = [
'2015',
'2016',
'2017',
'2018',
'2019',
];

export const MONTHS = [
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December',
];

export const REQUEST_TYPES = [
{
type: 'Dead Animal',
fullType: 'Dead Animal Removal',
export const REQUEST_TYPES = {
'Dead Animal Removal': {
displayName: 'Dead Animal',
abbrev: 'DAN',
color: '#4FEFEF',
},
{
type: 'Homeless Encampment',
'Homeless Encampment': {
displayName: 'Homeless Encampment',
abbrev: 'HLE',
color: '#ECB800',
},
{
type: 'Single Streetlight',
fullType: 'Single Streetlight Issue',
'Single Streetlight Issue': {
displayName: 'Single Streetlight',
abbrev: 'SSL',
color: '#AD7B56',
},
{
type: 'Multiple Streetlight',
fullType: 'Multiple Streetlight Issue',
'Multiple Streetlight Issue': {
displayName: 'Multiple Streetlight',
abbrev: 'MSL',
color: '#F7ADAD',
},
{
type: 'Feedback',
Feedback: {
displayName: 'Feedback',
abbrev: 'FBK',
color: '#FFE6B7',
},
{
type: 'Bulky Items',
'Bulky Items': {
displayName: 'Bulky Items',
abbrev: 'BLK',
color: '#FF0000',
},
{
type: 'E-Waste',
fullType: 'Electronic Waste',
'Electronic Waste': {
displayName: 'E-Waste',
abbrev: 'EWT',
color: '#DDEC9F',
},
{
type: 'Metal/Household Appliances',
'Metal/Household Appliances': {
displayName: 'Metal/Household Appliances',
abbrev: 'MHA',
color: '#B8D0FF',
},
{
type: 'Graffiti',
fullType: 'Graffiti Removal',
'Graffiti Removal': {
displayName: 'Graffiti',
abbrev: 'GFT',
color: '#2368D0',
},
{
type: 'Illegal Dumping',
fullType: 'Illegal Dumping Pickup',
'Illegal Dumping Pickup': {
displayName: 'Illegal Dumping',
abbrev: 'ILD',
color: '#6A8011',
},
{
type: 'Other',
Other: {
displayName: 'Other',
abbrev: 'OTH',
color: '#6D7C93',
},
];
};

export const REQUEST_SOURCES = [
{
Expand Down Expand Up @@ -114,20 +85,6 @@ export const REQUEST_SOURCES = [
},
];

export const REQUESTS = [
'Bulky Items',
'Dead Animal Removal',
'Electronic Waste',
'Graffiti Removal',
'Homeless Encampment',
'Illegal Dumping Pickup',
'Metal/Household Appliances',
'Single Streetlight Issue',
'Multiple Streetlight Issue',
'Report Water Waste',
'Other',
];

export const COUNCILS = [
'ARLETA NC',
'ARROYO SECO NC',
Expand Down
37 changes: 23 additions & 14 deletions src/components/main/menu/RequestTypeSelector.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,21 @@ const checkboxStyle = {
paddingLeft: '3px',
};

const types = Object.keys(REQUEST_TYPES);

const midIndex = (list => {
if (list.length / 2 === 0) {
return (list.length / 2);
}
return Math.floor(list.length / 2);
})(REQUEST_TYPES);
})(types);

const leftColumnItems = REQUEST_TYPES.slice(0, midIndex);
const rightColumnItems = REQUEST_TYPES.slice(midIndex);
const leftColumnItems = types.slice(0, midIndex);
const rightColumnItems = types.slice(midIndex);

const RequestItem = ({
type,
displayName,
abbrev,
selected,
color,
Expand Down Expand Up @@ -66,7 +69,7 @@ const RequestItem = ({
/>
</span>
<span>
{`${type} [${abbrev}]`}
{`${displayName} [${abbrev}]`}
</span>
</div>
);
Expand All @@ -82,16 +85,20 @@ const RequestTypeSelector = ({
selectType(type);
};

const renderRequestItems = items => items.map(item => (
<RequestItem
key={item.type}
type={item.type}
abbrev={item.abbrev}
handleClick={handleItemClick}
selected={requestTypes[item.type]}
color={item.color}
/>
));
const renderRequestItems = items => items.map(type => {
const item = REQUEST_TYPES[type];
return (
<RequestItem
key={type}
type={type}
displayName={item.displayName}
abbrev={item.abbrev}
handleClick={handleItemClick}
selected={requestTypes[type]}
color={item.color}
/>
);
});

return (
<div id="type-selector-container" style={{ color: COLORS.FONTS }}>
Expand Down Expand Up @@ -166,6 +173,7 @@ export default connect(

RequestItem.propTypes = {
type: PropTypes.string,
displayName: PropTypes.string,
abbrev: PropTypes.string,
color: PropTypes.string,
selected: PropTypes.bool,
Expand All @@ -174,6 +182,7 @@ RequestItem.propTypes = {

RequestItem.defaultProps = {
type: null,
displayName: null,
abbrev: null,
color: null,
selected: false,
Expand Down
Loading