Skip to content

Commit 0d8db19

Browse files
author
Antonio Contreras LEMONCODE
committed
Create project list component, project list container, project list mappers, project row component and fix others components
1 parent 42f1cb2 commit 0d8db19

8 files changed

Lines changed: 136 additions & 19 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './project-row.component';
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import React from 'react';
2+
import {
3+
RowRendererProps,
4+
RowComponent,
5+
CellComponent,
6+
} from 'common/components';
7+
import Checkbox from '@material-ui/core/Checkbox';
8+
import IconButton from '@material-ui/core/IconButton';
9+
import EditIcon from '@material-ui/icons/Edit';
10+
import DeleteIcon from '@material-ui/icons/Delete';
11+
import { Project } from '../project-list.vm';
12+
13+
type Props = RowRendererProps<Project>;
14+
15+
export const ProjectRowComponent: React.FunctionComponent<Props> = ({
16+
row,
17+
onEdit,
18+
onDelete,
19+
}) => {
20+
return (
21+
<RowComponent>
22+
<CellComponent>
23+
<Checkbox checked={row.active} disabled />
24+
</CellComponent>
25+
<CellComponent>{row.code}</CellComponent>
26+
<CellComponent>{row.projectName}</CellComponent>
27+
<CellComponent>{row.lastDateIncurred}</CellComponent>
28+
<CellComponent>
29+
{row.creationDate}
30+
<IconButton onClick={() => onEdit(row.id)}>
31+
<EditIcon />
32+
</IconButton>
33+
<IconButton onClick={() => onDelete(row)}>
34+
<DeleteIcon />
35+
</IconButton>
36+
</CellComponent>
37+
</RowComponent>
38+
);
39+
};

src/pods/project-list/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export * from './project-list.component';
1+
export * from './project-list.container';
Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,44 @@
11
import React from 'react';
2-
import { useHistory } from 'react-router-dom';
3-
import { routes } from 'core/router';
2+
import {
3+
TableContainer,
4+
RowRendererProps,
5+
useSearchBar,
6+
} from 'common/components';
7+
import { Project } from './project-list.vm';
8+
import { ProjectRowComponent } from './components';
49

5-
export const ProjectListComponent: React.FunctionComponent = () => {
6-
const history = useHistory();
7-
const goToProject = (
8-
event: React.MouseEvent<HTMLParagraphElement, MouseEvent>
9-
) => {
10-
event.preventDefault();
11-
history.push({
12-
pathname: routes.editProject('1'),
13-
});
14-
};
10+
interface Props {
11+
projectList: Project[];
12+
}
13+
14+
export const ProjectListComponent: React.FunctionComponent<Props> = ({
15+
projectList,
16+
}) => {
17+
const { filteredList, onSearch, search } = useSearchBar(projectList, [
18+
'projectName',
19+
]);
1520
return (
16-
<>
17-
<h1>Hello Project list component</h1>
18-
<p onClick={goToProject}>Go to edit project component</p>
19-
</>
21+
<TableContainer
22+
columns={[
23+
'Activo',
24+
'Código',
25+
'Proyecto',
26+
'Fecha Ultimo incurrido',
27+
'Fecha creación',
28+
]}
29+
rows={filteredList}
30+
rowRenderer={(rowProps: RowRendererProps<Project>) => (
31+
<ProjectRowComponent {...rowProps} />
32+
)}
33+
labels={{
34+
searchPlaceholder: 'Buscar proyecto',
35+
createButton: 'Nuevo proyecto',
36+
}}
37+
enableSearch={true}
38+
search={search}
39+
onSearch={onSearch}
40+
enablePagination={true}
41+
pageSize={5}
42+
/>
2043
);
2144
};
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import React from 'react';
2+
import { ProjectListComponent } from './project-list.component';
3+
import { getProjectList, deleteProject } from './api';
4+
import { Project } from './project-list.vm';
5+
import { useSnackbarContext } from 'common/components';
6+
import { trackPromise } from 'react-promise-tracker';
7+
import { mapProjectLIstFromApiToVm } from './project-list.mappers';
8+
import { routes } from 'core/router';
9+
import { useHistory } from 'react-router-dom';
10+
11+
export const ProjectListContainer: React.FunctionComponent = () => {
12+
const [projectes, setProjects] = React.useState<Project[]>([]);
13+
const { showMessage } = useSnackbarContext();
14+
const history = useHistory();
15+
16+
const onLoadProjectList = async () => {
17+
try {
18+
const apiProjectList = await trackPromise(getProjectList());
19+
const viewModelProjectList = mapProjectLIstFromApiToVm(apiProjectList);
20+
setProjects(viewModelProjectList);
21+
} catch (error) {
22+
error &&
23+
showMessage('Ha ocurrido un error al cargar los proyectos', 'error');
24+
}
25+
};
26+
27+
React.useEffect(() => {
28+
onLoadProjectList();
29+
}, []);
30+
31+
return <ProjectListComponent projectList={projectes} />;
32+
};
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { mapToCollection } from 'common/mappers';
2+
import * as apiModel from './api/project-list.api-model';
3+
import * as viewModel from './project-list.vm';
4+
5+
const mapProjectFromApiToVm = (
6+
project: apiModel.Project
7+
): viewModel.Project => ({
8+
...project,
9+
});
10+
11+
export const mapProjectLIstFromApiToVm = (
12+
projectList: apiModel.Project[]
13+
): viewModel.Project[] =>
14+
mapToCollection(projectList, p => mapProjectFromApiToVm(p));
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export interface Project {
2+
id: string;
3+
active: boolean;
4+
code: string;
5+
projectName: string;
6+
lastDateIncurred: string;
7+
creationDate: string;
8+
}

src/scenes/project-list.scene.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import React from 'react';
22
import { AppLayout } from 'layouts';
3-
import { ProjectListComponent } from 'pods/project-list';
3+
import { ProjectListContainer } from 'pods/project-list';
44

55
export const ProjectListScene: React.FunctionComponent = () => {
66
return (
77
<AppLayout>
8-
<ProjectListComponent />
8+
<ProjectListContainer />
99
</AppLayout>
1010
);
1111
};

0 commit comments

Comments
 (0)