Skip to content

Commit

Permalink
Merge pull request #87 from cesarhenrq/qa
Browse files Browse the repository at this point in the history
Qa
  • Loading branch information
katiene-souza authored Oct 14, 2023
2 parents 457266a + 4fa3e95 commit 3bb1bed
Show file tree
Hide file tree
Showing 36 changed files with 456 additions and 251 deletions.
13 changes: 8 additions & 5 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@ import Router from '@routes/Router';

import FiltersProvider from '@contexts/filters';
import UserProvider from '@contexts/user';
import QueryProvider from '@contexts/query';

export default function App() {
return (
<div className="App">
<GlobalStyle />
<FiltersProvider>
<UserProvider>
<Router />
</UserProvider>
</FiltersProvider>
<QueryProvider>
<FiltersProvider>
<UserProvider>
<Router />
</UserProvider>
</FiltersProvider>
</QueryProvider>
</div>
);
}
80 changes: 45 additions & 35 deletions src/components/Chart/Chart.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,55 @@
/* eslint-disable indent */
import { useContext } from 'react';

import { BarChart, Bar, ResponsiveContainer, XAxis, YAxis } from 'recharts';

import Text from '@components/Text';
import Button from '@components/Button';

import { userContext } from '@contexts/user';

import * as S from './styles';

type Data = {
name: string;
qty: number;
};

type ChartProps = {
data: Data[];
label: React.ReactElement;
};

const Chart = ({ data, label }: ChartProps) => {
const { user } = useContext(userContext);

return (
<S.ChartWrapper>
<S.Chart isLogged={Boolean(user)}>
<Text label={label} />
<ResponsiveContainer width="100%" height="100%">
<BarChart data={data} margin={{ top: 24 }}>
<XAxis
dataKey="name"
axisLine={false}
tickLine={false}
allowDataOverflow
/>
<YAxis axisLine={false} tickLine={false} allowDataOverflow />
<Bar
dataKey="qty"
fill="#6950A1"
barSize={20}
shape={<RoundedTopBar />}
/>
</BarChart>
</ResponsiveContainer>
</S.Chart>
{!user && <Button label="Cadastre-se para visualizar" />}
</S.ChartWrapper>
);
};

type RoundedTopBarProps = {
fill?: string;
x?: number;
Expand Down Expand Up @@ -36,39 +81,4 @@ const RoundedTopBar = (props: RoundedTopBarProps) => {
);
};

type Data = {
name: string;
qtd: number;
};

type ChartProps = {
data: Data[];
label: React.ReactElement;
};

const Chart = ({ data, label }: ChartProps) => {
return (
<S.Chart>
<Text label={label} />
<ResponsiveContainer width="100%" height="100%">
<BarChart width={150} height={40} data={data} margin={{ top: 24 }}>
<XAxis
dataKey="name"
axisLine={false}
tickLine={false}
allowDataOverflow
/>
<YAxis axisLine={false} tickLine={false} allowDataOverflow />
<Bar
dataKey="qtd"
fill="#6950A1"
barSize={20}
shape={<RoundedTopBar />}
/>
</BarChart>
</ResponsiveContainer>
</S.Chart>
);
};

export default Chart;
22 changes: 20 additions & 2 deletions src/components/Chart/styles.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import styled from 'styled-components';

export const Chart = styled.div`
type ChartProps = {
isLogged: boolean;
};

export const Chart = styled.div<ChartProps>`
display: flex;
flex-direction: column;
padding: 1.5rem 0rem;
width: 50%;
width: 100%;
height: 269px;
background: #f3f3f3;
border-radius: 16px;
border: 1px #ecf1f4 solid;
filter: ${props => (props.isLogged ? 'blur(0px)' : 'blur(3.5px)')};
.text {
justify-content: flex-start;
Expand All @@ -28,3 +33,16 @@ export const Chart = styled.div`
text-overflow: ellipsis;
}
`;

export const ChartWrapper = styled.div`
position: relative;
button {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 300px;
z-index: 1;
}
`;
47 changes: 47 additions & 0 deletions src/components/CityTechTrendsChart/CityTechTrendsChart.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { useContext } from 'react';

import Chart from '@components/Chart';

import useResource from '@hooks/useResource';
import useFetchResource from '@hooks/useFetchResource';

import { filtersContext } from '@contexts/filters';

const CityTechTrendsChart = () => {
const { filters } = useContext(filtersContext);

const url = filters.technologies[0]
? `vacancies?technologies=${filters.technologies[0]}`
: 'vacancies?technologies=React';

const label = (
<span>
Cidades quem mais procuram por{' '}
<span>{filters.technologies[0] ? filters.technologies[0] : 'React'}</span>
</span>
);

const [vacancies, vacanciesService] = useResource<Vacancy>(url);

useFetchResource(vacanciesService, [url]);

const cityCounts = vacancies.reduce<{ [key: string]: number }>(
(acc, vacancy) => {
const city = vacancy.location;
acc[city] = (acc[city] || 0) + 1;
return acc;
},
{},
);

const cityData = Object.entries(cityCounts).map(([city, count]) => ({
name: city,
qty: count,
}));

cityData.sort((a, b) => b.qty - a.qty);

return <Chart label={label} data={cityData} />;
};

export default CityTechTrendsChart;
1 change: 1 addition & 0 deletions src/components/CityTechTrendsChart/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './CityTechTrendsChart';
44 changes: 44 additions & 0 deletions src/components/CountryTechTrends/CountryTechTrends.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import Chart from '@components/Chart';

import useResource from '@hooks/useResource';
import useFetchResource from '@hooks/useFetchResource';

const CountryTechTrends = () => {
const [vacancies, vacanciesService] = useResource<Vacancy>('vacancies');

useFetchResource(vacanciesService);

const label = (
<span>
Tecnologias mais procuradas em <span>Brasil</span>
</span>
);

const allTechnologies = vacancies.reduce<string[]>((acc, vacancy) => {
vacancy.technologies.forEach(tech => {
acc.push(tech.tecName);
});
return acc;
}, []);

const technologyCount = allTechnologies.reduce<{ [key: string]: number }>(
(acc, techName) => {
acc[techName] = (acc[techName] || 0) + 1;
return acc;
},
{},
);

const mostUsedTechnologies = Object.keys(technologyCount).map(techName => ({
name: techName,
qty: technologyCount[techName],
}));

mostUsedTechnologies.sort((a, b) => b.qty - a.qty);

const top5Technologies = mostUsedTechnologies.slice(0, 5);

return <Chart label={label} data={top5Technologies} />;
};

export default CountryTechTrends;
1 change: 1 addition & 0 deletions src/components/CountryTechTrends/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './CountryTechTrends';
13 changes: 0 additions & 13 deletions src/components/Filter/Filter.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';

import Filter from './Filter';

Expand Down Expand Up @@ -61,16 +60,4 @@ describe('<Filter />', () => {
it('should render <Button /> with text "Filtar"', () => {
screen.getByText('Filtrar');
});

it('should render text "Ver mais..." by default', () => {
screen.getByText('Ver mais...');
});

it('should render text "Ver menos..." when click on "Ver mais..."', async () => {
const button = screen.getByText('Ver mais...');

await userEvent.click(button);

screen.getByText('Ver menos...');
});
});
Loading

0 comments on commit 3bb1bed

Please sign in to comment.