Skip to content

Commit

Permalink
Removed redux (#13193)
Browse files Browse the repository at this point in the history
* Remove redux

* Cleanup

* Cleanup

* Rename WithMockStore methods

* Cleanup code

* Cleanup imports

* Fix README.md

* Fix after cr

* Test to trigger github actions
  • Loading branch information
mlqn authored Jul 31, 2024
1 parent eb3da0d commit 5577d89
Show file tree
Hide file tree
Showing 62 changed files with 406 additions and 1,508 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ The current build is deployed in Kubernetes on Azure. Automated CI/CD using Azur

## Built With

- [React](https://reactjs.org/)/[Redux](https://redux.js.org/) - The front-end framework
- [React](https://reactjs.org/) - The front-end framework
- [.NET Core](https://docs.microsoft.com/en-us/dotnet/core/)/[C#](https://docs.microsoft.com/en-us/dotnet/csharp/) - The back-end framework
- [yarn](https://yarnpkg.com/) - Package management
- [Docker](https://www.docker.com/) - Container platform
Expand Down Expand Up @@ -194,7 +194,6 @@ This project is licensed under the 3-Clause BSD License - see the [LICENSE.md](L
[9]: https://github.com/Altinn/altinn-studio
[10]: http://studio.localhost
[11]: https://reactjs.org/
[12]: https://redux.js.org/
[13]: https://docs.microsoft.com/en-us/dotnet/core/
[14]: https://docs.microsoft.com/en-us/dotnet/csharp/
[15]: https://yarnpkg.com/
Expand Down
39 changes: 1 addition & 38 deletions backend/src/Designer/Controllers/TextController.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Altinn.Studio.Designer.Configuration;
using Altinn.Studio.Designer.Helpers;
using Altinn.Studio.Designer.Models;
using Altinn.Studio.Designer.Services.Interfaces;
Expand All @@ -14,7 +12,6 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;

using Newtonsoft.Json;
using IRepository = Altinn.Studio.Designer.Services.Interfaces.IRepository;

namespace Altinn.Studio.Designer.Controllers
Expand All @@ -30,7 +27,6 @@ public class TextController : Controller
{
private readonly IWebHostEnvironment _hostingEnvironment;
private readonly IRepository _repository;
private readonly ServiceRepositorySettings _settings;
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly ILogger _logger;
private readonly ITextsService _textsService;
Expand All @@ -40,15 +36,13 @@ public class TextController : Controller
/// </summary>
/// <param name="hostingEnvironment">The hosting environment service.</param>
/// <param name="repositoryService">The app repository service.</param>
/// <param name="repositorySettings">The repository settings.</param>
/// <param name="httpContextAccessor">The http context accessor.</param>
/// <param name="logger">the log handler.</param>
/// <param name="textsService">The texts service</param>
public TextController(IWebHostEnvironment hostingEnvironment, IRepository repositoryService, ServiceRepositorySettings repositorySettings, IHttpContextAccessor httpContextAccessor, ILogger<TextController> logger, ITextsService textsService)
public TextController(IWebHostEnvironment hostingEnvironment, IRepository repositoryService, IHttpContextAccessor httpContextAccessor, ILogger<TextController> logger, ITextsService textsService)
{
_hostingEnvironment = hostingEnvironment;
_repository = repositoryService;
_settings = repositorySettings;
_httpContextAccessor = httpContextAccessor;
_logger = logger;
_textsService = textsService;
Expand Down Expand Up @@ -271,36 +265,5 @@ public IActionResult GetResourceSchema()
string schema = System.IO.File.ReadAllText(_hostingEnvironment.WebRootPath + "/designer/json/schema/resource-schema.json");
return Content(schema, "application/json", Encoding.UTF8);
}

/// <summary>
/// Method to retrieve service name from textresources file
/// </summary>
/// <param name="org">Unique identifier of the organisation responsible for the app.</param>
/// <param name="app">Application identifier which is unique within an organisation.</param>
/// <returns>The service name of the service</returns>
[HttpGet]
[Route("service-name")]
public IActionResult GetServiceName(string org, string app)
{
string defaultLang = "nb";
string filename = $"resource.{defaultLang}.json";
string serviceResourceDirectoryPath = _settings.GetLanguageResourcePath(org, app, AuthenticationHelper.GetDeveloperUserName(_httpContextAccessor.HttpContext)) + filename;

try
{
if (System.IO.File.Exists(serviceResourceDirectoryPath))
{
string textResource = System.IO.File.ReadAllText(serviceResourceDirectoryPath, Encoding.UTF8);
ResourceCollection textResourceObject = JsonConvert.DeserializeObject<ResourceCollection>(textResource);
return Content(textResourceObject?.Resources?.FirstOrDefault(r => r.Id == "appName" || r.Id == "ServiceName")?.Value ?? string.Empty);
}

return Problem($"Working directory does not exist for {org}/{app}");
}
catch (JsonException ex)
{
return Problem(title: $"Failed to parse App/config/texts/{filename} as JSON", instance: $"App/config/texts/{filename}", detail: $"Failed to parse App/config/texts/{filename} as JSON\n" + ex.Message);
}
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { DeployProps } from './Deploy';
import { Deploy } from './Deploy';
import { screen, waitForElementToBeRemoved } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { renderWithMockStore } from 'app-development/test/mocks';
import { renderWithProviders } from 'app-development/test/mocks';
import { textMock } from '@studio/testing/mocks/i18nMock';
import type { ServicesContextProps } from 'app-shared/contexts/ServicesContext';
import type { AppRelease } from 'app-shared/types/AppRelease';
Expand Down Expand Up @@ -60,18 +60,15 @@ const imageOptions = [
];

const render = (props?: Partial<DeployProps>, queries?: Partial<ServicesContextProps>) => {
return renderWithMockStore(
{},
{
getDeployPermissions: jest.fn().mockImplementation(() => Promise.resolve(['tt02'])),
getAppReleases: jest.fn().mockImplementation(() =>
Promise.resolve({
results: appReleases,
}),
),
...queries,
},
)(<Deploy {...defaultProps} {...props} />);
return renderWithProviders({
getDeployPermissions: jest.fn().mockImplementation(() => Promise.resolve(['tt02'])),
getAppReleases: jest.fn().mockImplementation(() =>
Promise.resolve({
results: appReleases,
}),
),
...queries,
})(<Deploy {...defaultProps} {...props} />);
};
describe('DeploymentActions', () => {
it('renders a spinner while loading data', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { DeployDropdownProps } from './DeployDropdown';
import { DeployDropdown } from './DeployDropdown';
import { textMock } from '@studio/testing/mocks/i18nMock';
import type { ServicesContextProps } from 'app-shared/contexts/ServicesContext';
import { renderWithMockStore } from 'app-development/test/mocks';
import { renderWithProviders } from 'app-development/test/mocks';
import type { AppRelease } from 'app-shared/types/AppRelease';
import { BuildResult } from 'app-shared/types/Build';
import { appRelease } from 'app-shared/mocks/mocks';
Expand Down Expand Up @@ -304,15 +304,12 @@ describe('DeployDropdown', () => {
});

const render = (props?: Partial<DeployDropdownProps>, queries?: Partial<ServicesContextProps>) => {
return renderWithMockStore(
{},
{
getAppReleases: jest.fn().mockImplementation(() =>
Promise.resolve({
results: appReleases,
}),
),
...queries,
},
)(<DeployDropdown {...defaultProps} {...props} />);
return renderWithProviders({
getAppReleases: jest.fn().mockImplementation(() =>
Promise.resolve({
results: appReleases,
}),
),
...queries,
})(<DeployDropdown {...defaultProps} {...props} />);
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import type { DeploymentEnvironmentLogListProps } from './DeploymentEnvironmentLogList';
import { DeploymentEnvironmentLogList } from './DeploymentEnvironmentLogList';
import { screen } from '@testing-library/react';
import { renderWithMockStore } from 'app-development/test/mocks';
import { renderWithProviders } from 'app-development/test/mocks';
import { textMock } from '@studio/testing/mocks/i18nMock';
import type { ServicesContextProps } from 'app-shared/contexts/ServicesContext';
import { BuildResult, BuildStatus } from 'app-shared/types/Build';
Expand Down Expand Up @@ -34,10 +34,9 @@ const render = (
props?: Partial<DeploymentEnvironmentLogListProps>,
queries?: Partial<ServicesContextProps>,
) => {
return renderWithMockStore(
{},
queries,
)(<DeploymentEnvironmentLogList {...defaultProps} {...props} />);
return renderWithProviders(queries)(
<DeploymentEnvironmentLogList {...defaultProps} {...props} />,
);
};
describe('DeploymentEnvironmentLogList', () => {
it('renders with no history', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { screen, waitForElementToBeRemoved } from '@testing-library/react';
import { DeploymentContainer } from './DeploymentContainer';
import { textMock } from '@studio/testing/mocks/i18nMock';
import type { ServicesContextProps } from 'app-shared/contexts/ServicesContext';
import { renderWithMockStore } from 'app-development/test/mocks';
import { renderWithProviders } from 'app-development/test/mocks';
import { environment } from 'app-shared/mocks/mocks';
import type { DeploymentsResponse } from 'app-shared/types/api/DeploymentsResponse';
import { org } from '@studio/testing/testids';
Expand Down Expand Up @@ -54,5 +54,5 @@ describe('DeploymentContainer', () => {
});

const render = (queries?: Partial<ServicesContextProps>) => {
return renderWithMockStore({}, queries)(<DeploymentContainer />);
return renderWithProviders(queries)(<DeploymentContainer />);
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { screen, waitForElementToBeRemoved } from '@testing-library/react';
import { DeployPage } from './DeployPage';
import { textMock } from '@studio/testing/mocks/i18nMock';
import type { ServicesContextProps } from 'app-shared/contexts/ServicesContext';
import { renderWithMockStore } from 'app-development/test/mocks';
import { renderWithProviders } from 'app-development/test/mocks';
import { org } from '@studio/testing/testids';

describe('DeployPage', () => {
Expand Down Expand Up @@ -71,5 +71,5 @@ describe('DeployPage', () => {
});

const render = (queries?: Partial<ServicesContextProps>) => {
return renderWithMockStore({}, queries)(<DeployPage />);
return renderWithProviders(queries)(<DeployPage />);
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { LandingPagePanel } from './LandingPagePanel';
import userEvent from '@testing-library/user-event';
import { fileSelectorInputId } from '@studio/testing/testids';
import { textMock } from '@studio/testing/mocks/i18nMock';
import { renderWithMockStore } from '../../../test/mocks';
import { renderWithProviders } from '../../../test/mocks';

const user = userEvent.setup();

Expand Down Expand Up @@ -45,4 +45,4 @@ describe('LandingPagePanel', () => {
});

const renderLandingPagePanel = (props: Partial<LandingPagePanelProps> = {}) =>
renderWithMockStore()(<LandingPagePanel {...landingPagePropsMock} {...props} />);
renderWithProviders()(<LandingPagePanel {...landingPagePropsMock} {...props} />);
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { renderWithMockStore } from '../../../test/mocks';
import { renderWithProviders } from '../../../test/mocks';
import type { SchemaGenerationErrorsPanelProps } from './SchemaGenerationErrorsPanel';
import { SchemaGenerationErrorsPanel } from './SchemaGenerationErrorsPanel';
import type { ServicesContextProps } from 'app-shared/contexts/ServicesContext';
Expand Down Expand Up @@ -77,4 +77,4 @@ describe('SchemaGenerationErrorsPanel', () => {
const render = (
queries: Partial<ServicesContextProps> = {},
props: Partial<SchemaGenerationErrorsPanelProps> = {},
) => renderWithMockStore({}, queries)(<SchemaGenerationErrorsPanel {...defaultProps} {...props} />);
) => renderWithProviders(queries)(<SchemaGenerationErrorsPanel {...defaultProps} {...props} />);
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { renderWithMockStore } from '../../../test/mocks';
import { renderWithProviders } from '../../../test/mocks';
import type { SelectedSchemaEditorProps } from './SelectedSchemaEditor';
import { SelectedSchemaEditor } from './SelectedSchemaEditor';
import type { ServicesContextProps } from 'app-shared/contexts/ServicesContext';
Expand Down Expand Up @@ -183,8 +183,7 @@ const render = (
[QueryKey.DataModelsXsd, org, app],
[model1MetadataXsd, model2MetadataXsd],
);
return renderWithMockStore(
{},
return renderWithProviders(
queries,
queryClient,
)(<SelectedSchemaEditor {...defaultProps} {...props} />);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
import { createQueryClientMock } from 'app-shared/mocks/queryClientMock';
import { QueryKey } from 'app-shared/types/QueryKey';
import { convertMetadataToOption } from '../../../../utils/metadataUtils';
import { renderWithMockStore } from '../../../../test/mocks';
import { renderWithProviders } from '../../../../test/mocks';
import type { QueryClient } from '@tanstack/react-query';
import { app, org } from '@studio/testing/testids';
import { queriesMock } from 'app-shared/mocks/queriesMock';
Expand Down Expand Up @@ -47,11 +47,7 @@ const render = (
[QueryKey.DataModelsMetadata, org, app],
[jsonMetadata1Mock, jsonMetadata2Mock],
);
return renderWithMockStore(
{},
queries,
queryClient,
)(<DeleteWrapper {...defaultProps} {...props} />);
return renderWithProviders(queries, queryClient)(<DeleteWrapper {...defaultProps} {...props} />);
};

describe('DeleteWrapper', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { uiSchemaNodesMock } from '../../../../../packages/schema-editor/test/mo
import type { MetadataOption } from '../../../../types/MetadataOption';
import { convertMetadataToOption } from '../../../../utils/metadataUtils';
import { buildJsonSchema } from '@altinn/schema-model';
import { renderWithMockStore } from '../../../../test/mocks';
import { renderWithProviders } from '../../../../test/mocks';
import { useQueryClient } from '@tanstack/react-query';
import { queriesMock } from 'app-shared/mocks/queriesMock';
import { app, org } from '@studio/testing/testids';
Expand Down Expand Up @@ -53,7 +53,7 @@ const renderToolbar = (
return <TopToolbar {...defaultProps} {...props} />;
};

return renderWithMockStore({}, { ...servicesContextProps })(<TopToolbarWithInitData />);
return renderWithProviders({ ...servicesContextProps })(<TopToolbarWithInitData />);
};

describe('TopToolbar', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { textMock } from '@studio/testing/mocks/i18nMock';
import type { QueryClient } from '@tanstack/react-query';
import { createQueryClientMock } from 'app-shared/mocks/queryClientMock';
import { fileSelectorInputId } from '@studio/testing/testids';
import { renderWithMockStore } from '../../../../test/mocks';
import { renderWithProviders } from '../../../../test/mocks';
import type { ServicesContextProps } from 'app-shared/contexts/ServicesContext';
import { createApiErrorMock } from 'app-shared/mocks/apiErrorMock';

Expand All @@ -33,7 +33,7 @@ const render = ({
}: {
queryClient?: QueryClient;
queries?: Partial<ServicesContextProps>;
} = {}) => renderWithMockStore({}, queries, queryClient)(<XSDUpload />);
} = {}) => renderWithProviders(queries, queryClient)(<XSDUpload />);

describe('XSDUpload', () => {
afterEach(jest.restoreAllMocks);
Expand Down
Loading

0 comments on commit 5577d89

Please sign in to comment.