Skip to content

[features] Add NewEvent component, and routing event #24

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

Closed
wants to merge 8 commits into from
7 changes: 7 additions & 0 deletions .env.exmaple
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
SD_BACKEND_URL=""

SD_CLIENT_ID=""
SD_AUTHORITY=""
SD_REDIRECT=""
SD_LOGOUT_REDIRECT=""
SD_AUTH_SECRET=""
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
},
"devDependencies": {
"@farmfe/cli": "^1.0.4",
"@farmfe/core": "^1.4.1",
"@farmfe/core": "^1.4.2",
"@farmfe/js-plugin-postcss": "^1.9.0",
"@farmfe/plugin-react": "^1.2.4",
"@farmfe/plugin-react": "^1.2.6",
"@testing-library/jest-dom": "^6.6.3",
"@testing-library/react": "^16.0.1",
"@types/lodash": "^4.17.13",
Expand Down
230 changes: 115 additions & 115 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

12 changes: 2 additions & 10 deletions src/Components/History/EventItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,6 @@ export function EventItem({ Prev, Curr }: IEventItem) {
}
}, [label.current]);

const status = useMemo(() => {
return chain(Array.from(Curr.Histories))
.orderBy(x => x.Created, "desc")
.map(x => x.Status)
.first()
.value() ?? EventStatus.Investigating;
}, [Curr.Histories]);

const services = useMemo(() => {
return chain(Array.from(Curr.RegionServices))
.map(x => x.Service)
Expand Down Expand Up @@ -73,7 +65,7 @@ export function EventItem({ Prev, Curr }: IEventItem) {

let color: any;

switch (status) {
switch (Curr.Status) {
case EventStatus.Investigating:
case EventStatus.Fixing:
case EventStatus.Monitoring:
Expand Down Expand Up @@ -112,7 +104,7 @@ export function EventItem({ Prev, Curr }: IEventItem) {

<div className="flex gap-x-2.5">
<ScaleTag color={color}>
{status}
{Curr.Status}
</ScaleTag>

{services.slice(0, 3).map(service => (
Expand Down
29 changes: 29 additions & 0 deletions src/Pages/NewEvent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Helmet } from "react-helmet";
import { Authorized } from "~/Components/Auth/With";

/**
* The `NewEvent` component is responsible for rendering the interface
* for creating a new event within the OTC Status Dashboard application.
*
* This component is wrapped with the `Authorized` component to ensure
* that only authorized users can access the functionality provided.
*
* The main content of the component includes a heading that indicates
* the purpose of the page, which is to create a new event.
*
* @author Aloento
* @since 1.0.0
* @version 0.1.0
*/
export function NewEvent() {
return (
<Authorized>
<Helmet>
<title>New Event - OTC Status Dashboard</title>
</Helmet>

<h3 className="text-3xl font-medium text-slate-800">Create New Event</h3>

</Authorized>
)
}
9 changes: 8 additions & 1 deletion src/Pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Availability } from "./Availability";
import { Event } from "./Event";
import { History } from "./History";
import { Home } from "./Home";
import { NewEvent } from "./NewEvent";

/**
* @author Aloento
Expand All @@ -20,9 +21,12 @@ export function Layout() {

const match = useMemo(() => {
switch (path) {
case "Login":
case "signin-oidc":
return <ScaleLoadingSpinner size="large" text="Login Redirecting..." />;

case "signout-callback-oidc":
return <ScaleLoadingSpinner size="large" text="Logout Redirecting..." />;

case "Reload":
return <ScaleLoadingSpinner size="large" text="Reloading..." />;

Expand All @@ -35,6 +39,9 @@ export function Layout() {
case "Availability":
return <Availability />;

case "NewEvent":
return <NewEvent />;

case "":
case undefined:
return <Home />;
Expand Down
6 changes: 2 additions & 4 deletions src/Services/Status.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -184,20 +184,18 @@ export function StatusContext({ children }: { children: JSX.Element }) {
const [db, setDB] = useState(DB);

const url = process.env.SD_BACKEND_URL;
const uri = process.env.SD_BACKEND_API;
const file = process.env.SD_BACKEND_FILE === "true";

useRequest(
async () => {
log.info(`Loading status data from v2...`);

const compLink = file ? "/mock.json" : `${url}${uri}/components`;
const compLink = `${url}/components`;
const compRes = await fetch(compLink);
const compData = await compRes.json();

log.debug("Components Status loaded.", compData);

const eventLink = file ? "/event.json" : `${url}${uri}/incidents`;
const eventLink = `${url}/incidents`;
const eventRes = await fetch(eventLink);
const eventData = (await eventRes.json()).data;

Expand Down
25 changes: 25 additions & 0 deletions test/newevent.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { render } from "@testing-library/react";
import { describe, expect, it } from "vitest";
import { App } from "~/App";

describe("NewEvent", () => {
const url = new URL('http://otc.com/NewEvent');

Object.defineProperty(window, 'location', {
value: {
...window.location,
href: url.href,
hostname: url.hostname,
pathname: url.pathname,
},
writable: true,
});

it("should not render without Auth", async () => {
const { getByRole } = render(<App />);
const mainElement = getByRole('main');

expect(mainElement).toBeInTheDocument();
expect(mainElement).toHaveTextContent('Authenticating...');
}, 6000);
});