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

fix: add new route not adding double routes in pa app #796

Merged
merged 4 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions .changeset/pr-796-2093375130.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

---
"fusion-project-portal": patch
---
fixing the route creation in the portal admin app
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import styled from 'styled-components';
import { PortalApp, PortalApplication } from '../../types';
import { PortalApplication } from '../../types';
import { Typography } from '@equinor/eds-core-react';
import { useAddPortalApps, useRemovePortalApps } from '../../hooks/use-portal-apps';
import { usePortalContext } from '../../context/PortalContext';
Expand All @@ -11,7 +11,6 @@ import { RemoveAppsButton } from '../Actions/RemoveAppsButton';
import { EditSelectedButton } from '../Actions/EditSelectedButton';
import { ActivateSelectedWithContextButton } from '../Actions/ActivateSelectedWithContextButton';
import { useQueryClient } from '@tanstack/react-query';
import { useRemoveAppWithContexts } from '../../hooks/use-add-app-with-context';

const Styles = {
Wrapper: styled.div`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,6 @@ export const RouterConfigContextComponent = ({ children }: PropsWithChildren) =>
route,
},
});
if (activePortalId && state.routes && state.root) {
updatePortalConfig({
id: activePortalId,
router: { root: state.root, routes: addRoute(route, state.routes) || [] },
});
}
};
const removeRouteById = (id: string) => {
dispatch({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ export const updateRouteByField = (id: string, value: string, route?: Route): Ro
}
if (id.toLowerCase().includes('message')) {
return {
description: '',
...route,
messages: { ...route.messages, [id]: value },
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('updateRoute', () => {
const routes: Route[] = [
{
id: '1',
description: undefined,
description: '',
path: '/home',
pageKey: 'home',
messages: {
Expand All @@ -22,7 +22,7 @@ describe('updateRoute', () => {
},
{
id: '2',
description: undefined,
description: '',
path: '/about',
pageKey: 'about',
messages: {
Expand All @@ -40,7 +40,7 @@ describe('updateRoute', () => {
{
children: [],
id: '1',
description: undefined,
description: '',
path: '/about',
pageKey: 'about',
messages: {
Expand All @@ -49,7 +49,7 @@ describe('updateRoute', () => {
},
{
id: '2',
description: undefined,
description: '',
path: '/about',
pageKey: 'about',
messages: {
Expand All @@ -59,7 +59,7 @@ describe('updateRoute', () => {
{
children: undefined,
id: '3',
description: undefined,
description: '',
path: '/about',
pageKey: 'about',
messages: {
Expand All @@ -72,7 +72,7 @@ describe('updateRoute', () => {
const newRoute = {
children: undefined,
id: '3',
description: undefined,
description: '',
path: '/3',
pageKey: '3',
messages: {
Expand All @@ -83,7 +83,7 @@ describe('updateRoute', () => {
{
children: [],
id: '1',
description: undefined,
description: '',
path: '/about',
pageKey: 'about',
messages: {
Expand All @@ -92,7 +92,7 @@ describe('updateRoute', () => {
},
{
id: '2',
description: undefined,
description: '',
path: '/about',
pageKey: 'about',
messages: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,61 +1,62 @@
import { describe, it, expect } from "vitest";
import { updateRouteByField } from "./router-actions";

describe("updateRouteByField", () => {
it("should return a new route object with the specified field updated", () => {
const route = {
id: "123",
messages: {
errorMessage: "Error",
},
path: "/home",
pageKey: "home",
};

const updatedRoute = updateRouteByField("id", "456", route);

expect(updatedRoute).toEqual({
id: "456",
messages: {
errorMessage: "Error",
},
path: "/home",
pageKey: "home",
});
});

it("should return a new route object with the specified message field updated", () => {
const route = {
id: "123",
messages: {
errorMessage: "Error",
},
path: "/home",
pageKey: "home",
};

const updatedRoute = updateRouteByField("errorMessage", "New Error", route);

expect(updatedRoute).toEqual({
id: "123",
messages: {
errorMessage: "New Error",
},
path: "/home",
pageKey: "home",
});
});

it("should return a new route object with the specified field added if route is not provided", () => {
const updatedRoute = updateRouteByField("id", "123");

expect(updatedRoute).toEqual({
id: "123",
messages: {
errorMessage: "",
},
path: "",
pageKey: "",
});
});
import { describe, it, expect } from 'vitest';
import { updateRouteByField } from './router-actions';

describe('updateRouteByField', () => {
it('should return a new route object with the specified field updated', () => {
const route = {
id: '123',
messages: {
errorMessage: 'Error',
},
path: '/home',
pageKey: 'home',
};

const updatedRoute = updateRouteByField('id', '456', route);

expect(updatedRoute).toEqual({
id: '456',
messages: {
errorMessage: 'Error',
},
path: '/home',
pageKey: 'home',
});
});

it('should return a new route object with the specified message field updated', () => {
const route = {
id: '123',
messages: {
errorMessage: 'Error',
},
path: '/home',
pageKey: 'home',
};

const updatedRoute = updateRouteByField('errorMessage', 'New Error', route);

expect(updatedRoute).toEqual({
id: '123',
messages: {
errorMessage: 'New Error',
},
path: '/home',
pageKey: 'home',
});
});

it('should return a new route object with the specified field added if route is not provided', () => {
const updatedRoute = updateRouteByField('id', '123');

expect(updatedRoute).toEqual({
id: '123',
description: '',
messages: {
errorMessage: '',
},
path: '',
pageKey: '',
});
});
});
Loading