Skip to content

Commit 4b89729

Browse files
authored
Merge pull request #1 from ushahidi/USH-2130
Adding a check to only include datasources when looking through categories-list
2 parents 9cc04ef + 551da09 commit 4b89729

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

src/components/SimplePanel.tsx

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ import twitterIcon from '../img/twitter.svg';
88
import youtubeIcon from '../img/youtube.svg';
99

1010
interface Props extends PanelProps<SimpleOptions> {}
11-
11+
enum DataSource {
12+
PLATFORM = 'platform',
13+
FACEBOOK = 'facebook',
14+
TWITTER = 'twitter',
15+
YOUTUBE = 'youtube'
16+
}
1217
export const SimplePanel: React.FC<Props> = ({ options, data, width, height }) => {
1318
const {
1419
totalVoicesCount,
@@ -25,20 +30,20 @@ export const SimplePanel: React.FC<Props> = ({ options, data, width, height }) =
2530
const getCategoryStyle = (categoryName: string) => {
2631
const normalized = categoryName?.toLowerCase().trim() || '';
2732
switch (normalized) {
28-
case 'platform':
29-
return { icon: ushahidiIcon, color: '#EFC44C' };
33+
case DataSource.PLATFORM:
34+
return { icon: ushahidiIcon, color: '#EFC44C' };
3035

31-
case 'facebook':
32-
return { icon: facebookIcon, color: '#8B9DC3' };
36+
case DataSource.FACEBOOK:
37+
return { icon: facebookIcon, color: '#8B9DC3' };
3338

34-
case 'twitter':
35-
return { icon: twitterIcon, color: '#1DA1F2' };
39+
case DataSource.TWITTER:
40+
return { icon: twitterIcon, color: '#1DA1F2' };
3641

37-
case 'youtube':
38-
return { icon: youtubeIcon, color: '#CC181E' };
42+
case DataSource.YOUTUBE:
43+
return { icon: youtubeIcon, color: '#CC181E' };
3944

4045
default:
41-
return { icon: '', color: '#8e8e8e' };
46+
return { icon: '', color: '#8e8e8e' };
4247
}
4348
};
4449

@@ -69,9 +74,8 @@ export const SimplePanel: React.FC<Props> = ({ options, data, width, height }) =
6974
const platformRows = [];
7075
for (let i = 0; i < length; i++) {
7176
const category = getValue(fieldCategory, i);
72-
73-
// only add to list if category exists
74-
if (category) {
77+
// only add to list if data-source category exists
78+
if (category && Object.values(DataSource).includes(category.toLowerCase().trim() as DataSource)) {
7579
const style = getCategoryStyle(category);
7680

7781
platformRows.push({

0 commit comments

Comments
 (0)