Update device filtering.

This commit is contained in:
Mike Cao 2020-08-06 19:37:19 -07:00
parent e17c9da3d5
commit 9d09d89aef
5 changed files with 32 additions and 26 deletions

View file

@ -1,4 +1,4 @@
import { BROWSERS, ISO_COUNTRIES } from './constants';
import { BROWSERS, ISO_COUNTRIES, DEVICES } from './constants';
export const browserFilter = data =>
data.map(({ x, ...props }) => ({ x: BROWSERS[x] || x, ...props }));
@ -8,28 +8,8 @@ export const urlFilter = data => data.filter(({ x }) => x !== '' && !x.startsWit
export const refFilter = data =>
data.filter(({ x }) => x !== '' && !x.startsWith('/') && !x.startsWith('#'));
export const deviceFilter = data => {
if (data.length === 0) return [];
const devices = data.reduce(
(obj, { x, y }) => {
const [width] = x.split('x');
if (width >= 1920) {
obj.Desktop += +y;
} else if (width >= 1024) {
obj.Laptop += +y;
} else if (width >= 767) {
obj.Tablet += +y;
} else {
obj.Mobile += +y;
}
return obj;
},
{ Desktop: 0, Laptop: 0, Tablet: 0, Mobile: 0 },
);
return percentFilter(Object.keys(devices).map(key => ({ x: key, y: devices[key] })));
};
export const deviceFilter = data =>
data.map(({ x, ...props }) => ({ x: DEVICES[x] || x, ...props }));
export const countryFilter = data =>
data.map(({ x, ...props }) => ({ x: ISO_COUNTRIES[x] || x, ...props }));