Skip to content
This repository has been archived by the owner on Apr 22, 2022. It is now read-only.

Commit

Permalink
Edit company (#18)
Browse files Browse the repository at this point in the history
* Add edit company

* Add edit company

* fix test
  • Loading branch information
carlosthe19916 authored Jan 3, 2021
1 parent 0682076 commit 498a159
Show file tree
Hide file tree
Showing 43 changed files with 1,085 additions and 16 deletions.
2 changes: 1 addition & 1 deletion cypress/integration/companyList.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ context("Test company list", () => {
cy.get(".pf-c-table__action").first().click();
cy.get(".pf-c-dropdown__menu-item").contains("Edit").click();

cy.url().should("eq", Cypress.config().baseUrl + "/companies/company1");
cy.url().should("eq", Cypress.config().baseUrl + "/companies/company1/overview");
});

it("Company list - new", () => {
Expand Down
2 changes: 2 additions & 0 deletions src/Paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export enum Paths {
newCompany = "/companies/~new",

editCompany = "/companies/:company",
editCompany_overview = "/companies/:company/overview",
editCompany_sunat = "/companies/:company/sunat",
}

export interface OptionalCompanyRoute {
Expand Down
4 changes: 4 additions & 0 deletions src/api/rest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,7 @@ export const getCompanies = (
export const deleteCompany = (company: Company): AxiosPromise => {
return APIClient.delete(`${COMPANIES}/${company.name}`);
};

export const getCompany = (name: string): AxiosPromise<Company> => {
return APIClient.get(`${COMPANIES}/${name}`);
};
2 changes: 2 additions & 0 deletions src/pages/companies/companies.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Paths } from "Paths";

const CommpanyList = lazy(() => import("./company-list"));
const NewCompany = lazy(() => import("./new-company"));
const EditCompany = lazy(() => import("./edit-company"));

export const Projects: React.FC = () => {
return (
Expand All @@ -14,6 +15,7 @@ export const Projects: React.FC = () => {
<Switch>
<Route path={Paths.companyList} component={CommpanyList} exact />
<Route path={Paths.newCompany} component={NewCompany} />
<Route path={Paths.editCompany} component={EditCompany} />
</Switch>
</Suspense>
</>
Expand Down
14 changes: 8 additions & 6 deletions src/pages/companies/company-list/company-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
} from "@patternfly/react-table";
import { AddCircleOIcon } from "@patternfly/react-icons";

import { alertActions } from "store/alert";
import { deleteWithMatchModalActions } from "store/delete-with-match-modal";

import {
Expand All @@ -34,17 +35,18 @@ import {
ConditionalRender,
SimplePageSection,
} from "shared/components";
import { useTableControls } from "shared/hooks";
import {
useTableControls,
useFetchCompanies,
useDeleteCompany,
} from "shared/hooks";
import { DeleteWithMatchModalContainer } from "shared/containers";

import { formatPath, Paths } from "Paths";
import { Company, PageQuery, SortByQuery } from "api/models";
import { getAxiosErrorMessage } from "utils/modelUtils";

import { Welcome } from "./components/welcome";
import useFetchCompany from "./hooks/useFetchCompany";
import useDeleteCompany from "./hooks/useDeleteCompany";
import { alertActions } from "store/alert";
import { getAxiosErrorMessage } from "utils/modelUtils";

const columns: ICell[] = [
{ title: "Name", transforms: [sortable] },
Expand Down Expand Up @@ -98,7 +100,7 @@ export const CompanyList: React.FC<CompanyListProps> = ({ history }) => {
fetchError,
fetchCount,
fetchCompanies,
} = useFetchCompany(true);
} = useFetchCompanies(true);

const {
filterText,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { PageHeader } from "./page-header";
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import React from "react";
import {
Stack,
StackItem,
Split,
SplitItem,
TextContent,
Text,
} from "@patternfly/react-core";
import { BreadCrumbPath } from "shared/components/breadcrumb-path";
import { MenuActions } from "shared/components/menu-actions";
import { HorizontalNav } from "shared/components/horizontal-nav/horizontal-nav";

export interface PageHeaderProps {
title: string;
breadcrumbs: { title: string; path: string }[];
menuActions: { label: string; callback: () => void }[];
navItems: { title: string; path: string }[];
}

export const PageHeader: React.FC<PageHeaderProps> = ({
title,
breadcrumbs,
menuActions,
navItems,
}) => {
return (
<Stack hasGutter>
<StackItem>
<BreadCrumbPath breadcrumbs={breadcrumbs} />
</StackItem>
<StackItem>
<Split>
<SplitItem isFilled>
<TextContent>
<Text component="h1">{title}</Text>
</TextContent>
</SplitItem>
<SplitItem>
<MenuActions actions={menuActions} />
</SplitItem>
</Split>
</StackItem>
<StackItem>
<HorizontalNav navItems={navItems} />
</StackItem>
</Stack>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import React from "react";
import { HashRouter } from "react-router-dom";
import { Story, Meta } from "@storybook/react/types-6-0";
import { action } from "@storybook/addon-actions";
import { PageHeader, PageHeaderProps } from "../page-header";

export default {
title: "Edit company / PageHeader",
component: PageHeader,
argTypes: {},
} as Meta;

const Template: Story<PageHeaderProps> = (args) => (
<HashRouter>
<PageHeader {...args} />
</HashRouter>
);
export const Basic = Template.bind({});
Basic.args = {
title: "mycompany",
breadcrumbs: [
{
title: "Companies",
path: "/companies",
},
{
title: "Company details",
path: "/companies/1",
},
],
menuActions: [
{
label: "Edit",
callback: action("Edit"),
},
{
label: "Delete",
callback: action("Delete"),
},
],
navItems: [
{
title: "Overview",
path: "/companies/1/overview",
},
{
title: "YAML",
path: "/companies/1/yaml",
},
{
title: "SUNAT",
path: "/companies/1/sunat",
},
],
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`PageHeader Renders without crashing 1`] = `
<Stack
hasGutter={true}
>
<StackItem>
<BreadCrumbPath
breadcrumbs={
Array [
Object {
"path": "/companies",
"title": "Companies",
},
Object {
"path": "/companies/1",
"title": "Company details",
},
]
}
/>
</StackItem>
<StackItem>
<Split>
<SplitItem
isFilled={true}
>
<TextContent>
<Text
component="h1"
>
mycompany
</Text>
</TextContent>
</SplitItem>
<SplitItem>
<MenuActions
actions={
Array [
Object {
"callback": [MockFunction],
"label": "Edit",
},
Object {
"callback": [MockFunction],
"label": "Delete",
},
]
}
/>
</SplitItem>
</Split>
</StackItem>
<StackItem>
<HorizontalNav
navItems={
Array [
Object {
"path": "/companies/1/overview",
"title": "Overview",
},
Object {
"path": "/companies/1/yaml",
"title": "YAML",
},
Object {
"path": "/companies/1/sunat",
"title": "SUNAT",
},
]
}
/>
</StackItem>
</Stack>
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import React from "react";
import { shallow } from "enzyme";
import { PageHeader } from "../page-header";

describe("PageHeader", () => {
it("Renders without crashing", () => {
const wrapper = shallow(
<PageHeader
title="mycompany"
breadcrumbs={[
{
title: "Companies",
path: "/companies",
},
{
title: "Company details",
path: "/companies/1",
},
]}
menuActions={[
{
label: "Edit",
callback: jest.fn(),
},
{
label: "Delete",
callback: jest.fn(),
},
]}
navItems={[
{
title: "Overview",
path: "/companies/1/overview",
},
{
title: "YAML",
path: "/companies/1/yaml",
},
{
title: "SUNAT",
path: "/companies/1/sunat",
},
]}
/>
);
expect(wrapper).toMatchSnapshot();
});
});
Loading

0 comments on commit 498a159

Please sign in to comment.