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

Feature/implement project list #11

Open
wants to merge 40 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
808fa6d
Merge branch 'feature/Implement_validations_to_employee' into feature…
May 14, 2020
87c619a
Create data validations and implement it
May 14, 2020
9f7f7dd
Create report validation to project and implement it
May 14, 2020
8460032
Merge branch 'feature/Implement_validations_to_employee' into feature…
May 18, 2020
5f47d80
Refactor name externalId validation
May 18, 2020
f8dd2d2
Merge branch 'master' into feature/Implement_validations_to_project
Jun 12, 2020
52b9b9d
Remove externalId validation
Jun 17, 2020
c1a335e
config graphql client
nasdan Jun 22, 2020
cee690c
implement delete method
nasdan Jun 22, 2020
f281c07
implement get employee by id
nasdan Jun 22, 2020
c3b7c80
implement employee insert
nasdan Jun 22, 2020
27d1b34
Fix employee api
Jun 22, 2020
0b2c6ec
Refactor employee components and remove mock data
Jun 23, 2020
a5ad030
Implement saveProjectSummaryList and mappers
Jun 23, 2020
6aab104
Fix employee container logic
Jun 24, 2020
7eb5db2
Fix view model and api model
Jun 24, 2020
796779d
Work in progress
Jun 24, 2020
2a6caee
Fix query
Jun 24, 2020
32ed3de
Fix view model and mappers
Jun 24, 2020
eedf56a
Add function to employee view model and fix mappers
Jun 24, 2020
cd89bb5
fix unit test
Jun 24, 2020
3e7044c
Add others unit test
Jun 25, 2020
123e5b5
Fix column name
Jun 25, 2020
22f6251
Delete lastDateIncurred property from employee api
Jun 25, 2020
a59b4de
Remove Project view model interface
Jun 25, 2020
7c4e9d2
Merge branch 'feature/Implement_validations_to_project' into feature/…
Jun 25, 2020
345340a
Merge branch 'feature/implement-employee-list' into feature/implement…
Jun 25, 2020
3d4f9f1
Fix view model and others methods and remove project list mock data
Jun 25, 2020
5c537d9
Fix names
Jun 25, 2020
ce3a4c3
Fix a import
Jun 25, 2020
6dfcb2e
Merge branch 'feature/Implement_validations_to_project' into feature/…
Jun 25, 2020
facc4fe
fix name, from Project to project
Jun 26, 2020
8edbd09
Merge branch 'feature/Implement_validations_to_project' into feature/…
Jun 26, 2020
844f2e6
Implement save project function and mappers and fix project view model
Jun 26, 2020
f4593b1
Fix project view model
Jun 26, 2020
21a2684
Add handleSaveEmployeeSelection function
Jun 26, 2020
cec26e3
Remove project mock data and create project mappers spec and project.…
Jun 29, 2020
a47b8ad
Fix component
Jun 29, 2020
5cf64f9
Fix project component
Jun 29, 2020
151353e
Merge branch 'feature/implement-employee-list' into feature/implement…
Jun 29, 2020
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
3 changes: 3 additions & 0 deletions config/webpack/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ module.exports = merge.strategy({
port: 8080,
stats: 'minimal',
hot: true,
proxy: {
'/graphql': 'http://localhost:8081',
},
},
plugins: [
new Dotenv({
Expand Down
2 changes: 1 addition & 1 deletion dev.env
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
NODE_ENV=development
GRAPHQL_URL=http://localhost:8081/graphql/employee
GRAPHQL_URL=/graphql/admin
2 changes: 1 addition & 1 deletion prod.env
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
NODE_ENV=production
GRAPHQL_URL=/graphql/employee
GRAPHQL_URL=/graphql/admin
4 changes: 4 additions & 0 deletions src/core/api/graphql.client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { GraphQLClient } from 'graphql-request';

const url = process.env.GRAPHQL_URL;
export const graphQLClient = new GraphQLClient(url);
1 change: 1 addition & 0 deletions src/core/api/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './graphql.client';
1 change: 1 addition & 0 deletions src/core/router/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './router.component';
export * from './routes';
export * from './route-params.vm';
3 changes: 3 additions & 0 deletions src/core/router/route-params.vm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface EditParams {
id: string;
}
37 changes: 32 additions & 5 deletions src/pods/employee-list/api/employee-list.api.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,40 @@
import { graphQLClient } from 'core/api';
import { Employee } from './employee-list.api-model';
import { mockEmployeeList } from './employee-list.mock-data';

let employeeList = [...mockEmployeeList];
interface GetEmployeeListResponse {
employees: Employee[];
}

export const getEmployeeList = async (): Promise<Employee[]> => {
return employeeList;
const query = `
query {
employees {
id
name
isActive
email
lastDateIncurred
}
}
`;
const { employees } = await graphQLClient.request<GetEmployeeListResponse>(
query
);
return employees;
};

interface DeleteEmployeeResponse {
deleteEmployee: boolean;
}

export const deleteEmployee = async (id: string): Promise<boolean> => {
employeeList = employeeList.filter(e => e.id !== id);
return true;
const query = `
mutation {
deleteEmployee(id: "${id}")
}
`;
const { deleteEmployee } = await graphQLClient.request<
DeleteEmployeeResponse
>(query);
return deleteEmployee;
};
60 changes: 0 additions & 60 deletions src/pods/employee-list/api/employee-list.mock-data.ts

This file was deleted.

10 changes: 7 additions & 3 deletions src/pods/employee/api/employee.api-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ export interface Employee {
email: string;
isActive: boolean;
temporalPassword?: string;
projects?: ProjectSummary[];
projects?: EmployeeProject[];
}

export interface ProjectSummary {
export interface EmployeeProject {
id: string;
isAssigned?: boolean;
projectName: string;
}

export interface Project {
id: string;
name: string;
}
85 changes: 82 additions & 3 deletions src/pods/employee/api/employee.api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,85 @@
import { Employee } from './employee.api-model';
import { mockEmployee } from './employee.mock-data';
import { Employee, EmployeeProject, Project } from './employee.api-model';
import { graphQLClient } from 'core/api';

interface GetEmployeeResponse {
employee: Employee;
}

export const getEmployeeById = async (id: string): Promise<Employee> => {
return mockEmployee;
const query = `
query {
employee(id: "${id}") {
id
name
isActive
email
projects {
id
isAssigned
}
}
}
`;

const { employee } = await graphQLClient.request<GetEmployeeResponse>(query);

return employee;
};

interface GetProjectListResponse {
projects: Project[];
}

export const getProjects = async (): Promise<Project[]> => {
const query = `
query {
projects {
id
name
}
}
`;
const { projects } = await graphQLClient.request<GetProjectListResponse>(
query
);
return projects;
};

interface SaveEmployeeResponse {
saveEmployee: Employee;
}

export const saveEmployee = async (employee: Employee): Promise<string> => {
const query = `
mutation($employee: EmployeeInput!) {
saveEmployee(employee: $employee) {
id
}
}
`;

const { saveEmployee } = await graphQLClient.request<SaveEmployeeResponse>(
query,
{
employee,
}
);

return saveEmployee.id;
};

export const saveEmployeeProjectList = async (
id: string,
employeeProjectList: EmployeeProject[]
): Promise<void> => {
const query = `mutation($employeeProjectList: [EmployeeProjectInput!]!) {
saveEmployeeProjectList(
id: "${id}",
employeeProjectList: $employeeProjectList,
) {
id
}
}`;

await graphQLClient.request(query, { employeeProjectList });
};
33 changes: 0 additions & 33 deletions src/pods/employee/api/employee.mock-data.ts

This file was deleted.

22 changes: 17 additions & 5 deletions src/pods/employee/components/project-row.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,31 @@ import {
CellComponent,
} from 'common/components';
import Checkbox from '@material-ui/core/Checkbox';
import { ProjectSummary } from '../employee.vm';
import { EmployeeProject } from '../employee.vm';

type Props = RowRendererProps<ProjectSummary>;
interface RowProps extends RowRendererProps<EmployeeProject> {
onChangeProject: (project: EmployeeProject) => void;
}

export const EmployeeRowComponent: React.FunctionComponent<Props> = ({
export const EmployeeRowComponent: React.FunctionComponent<RowProps> = ({
row,
onChangeProject,
}) => {
return (
<RowComponent>
<CellComponent>
<Checkbox checked={row.isAssigned} color="primary" />
<Checkbox
color="primary"
onChange={(_, checked) =>
onChangeProject({
...row,
isAssigned: checked,
})
}
checked={row.isAssigned}
/>
</CellComponent>
<CellComponent>{row.projectName}</CellComponent>
<CellComponent>{row.name}</CellComponent>
</RowComponent>
);
};
41 changes: 31 additions & 10 deletions src/pods/employee/components/project.component.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,52 @@
import React from 'react';
import { TableContainer, RowRendererProps } from 'common/components';
import { ProjectSummary } from '../employee.vm';
import { EmployeeProject } from '../employee.vm';
import { EmployeeRowComponent } from './project-row.component';
import { CommandFooterComponent } from 'common-app/command-footer';

interface Props {
projectSummaryList: ProjectSummary[];
className?: string;
employeeProjectList: EmployeeProject[];
onSave: (project: EmployeeProject[]) => void;
onCancel: () => void;
className?: string;
}

export const ProjectComponent: React.FunctionComponent<Props> = ({
projectSummaryList,
className,
employeeProjectList,
onSave,
onCancel,
className,
}) => {
const [projectList, setProjectList] = React.useState<EmployeeProject[]>(
employeeProjectList
);

React.useEffect(() => {
setProjectList(employeeProjectList);
}, [employeeProjectList]);

const handleChangeProject = (id: string) => (project: EmployeeProject) => {
const updateProjectList = projectList.map(p => (p.id === id ? project : p));
setProjectList(updateProjectList);
};

const handleSave = () => onSave(projectList);
return (
<>
<TableContainer
columns={['Asignado', 'Nombre y Apellido']}
rows={projectSummaryList}
columns={['Asignado', 'Nombre']}
rows={projectList}
className={className}
rowRenderer={(rowProps: RowRendererProps<ProjectSummary>) => (
<EmployeeRowComponent {...rowProps} />
rowRenderer={(rowProps: RowRendererProps<EmployeeProject>) => (
<EmployeeRowComponent
{...rowProps}
onChangeProject={handleChangeProject(rowProps.row.id)}
/>
)}
enablePagination={true}
pageSize={5}
/>
<CommandFooterComponent onCancel={onCancel} />
<CommandFooterComponent onSave={handleSave} onCancel={onCancel} />
</>
);
};
Loading