Skip to content

Commit

Permalink
Merge branch 'main' into 12848-upload-static-images-to-be-used-by-the…
Browse files Browse the repository at this point in the history
…-image-component
  • Loading branch information
standeren authored Sep 26, 2024
2 parents c82ee58 + e9f45d8 commit 21e3a4f
Show file tree
Hide file tree
Showing 60 changed files with 7,776 additions and 1,765 deletions.
47 changes: 27 additions & 20 deletions backend/src/Designer/Controllers/RepositoryController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,43 +9,39 @@
using Altinn.Studio.Designer.Configuration;
using Altinn.Studio.Designer.Enums;
using Altinn.Studio.Designer.Helpers;
using Altinn.Studio.Designer.Hubs.SyncHub;
using Altinn.Studio.Designer.Models;
using Altinn.Studio.Designer.RepositoryClient.Model;
using Altinn.Studio.Designer.Services.Interfaces;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR;
using RepositoryModel = Altinn.Studio.Designer.RepositoryClient.Model.Repository;

namespace Altinn.Studio.Designer.Controllers
{
/// <summary>
/// This is the API controller for functionality related to repositories.
/// </summary>
/// <remarks>
/// Initializes a new instance of the <see cref="RepositoryController"/> class.
/// </remarks>
/// <param name="giteaWrapper">the gitea wrapper</param>
/// <param name="sourceControl">the source control</param>
/// <param name="repository">the repository control</param>
/// <param name="userRequestsSynchronizationService">An <see cref="IUserRequestsSynchronizationService"/> used to control parallel execution of user requests.</param>
/// <param name="syncHub">websocket syncHub</param>
[Authorize]
[AutoValidateAntiforgeryToken]
[Route("designer/api/repos")]
public class RepositoryController : ControllerBase
public class RepositoryController(IGitea giteaWrapper, ISourceControl sourceControl, IRepository repository, IUserRequestsSynchronizationService userRequestsSynchronizationService, IHubContext<SyncHub, ISyncClient> syncHub) : ControllerBase
{
private readonly IGitea _giteaApi;
private readonly ISourceControl _sourceControl;
private readonly IRepository _repository;
private readonly IUserRequestsSynchronizationService _userRequestsSynchronizationService;

/// <summary>
/// Initializes a new instance of the <see cref="RepositoryController"/> class.
/// </summary>
/// <param name="giteaWrapper">the gitea wrapper</param>
/// <param name="sourceControl">the source control</param>
/// <param name="repository">the repository control</param>
/// <param name="userRequestsSynchronizationService">An <see cref="IUserRequestsSynchronizationService"/> used to control parallel execution of user requests.</param>
public RepositoryController(IGitea giteaWrapper, ISourceControl sourceControl, IRepository repository, IUserRequestsSynchronizationService userRequestsSynchronizationService)
{
_giteaApi = giteaWrapper;
_sourceControl = sourceControl;
_repository = repository;
_userRequestsSynchronizationService = userRequestsSynchronizationService;
}
private readonly IGitea _giteaApi = giteaWrapper;
private readonly ISourceControl _sourceControl = sourceControl;
private readonly IRepository _repository = repository;
private readonly IUserRequestsSynchronizationService _userRequestsSynchronizationService = userRequestsSynchronizationService;
private readonly IHubContext<SyncHub, ISyncClient> _syncHub = syncHub;

/// <summary>
/// Returns a list over repositories
Expand Down Expand Up @@ -323,6 +319,17 @@ public async Task CommitAndPushRepo([FromBody] CommitInfo commitInfo)
{
await _sourceControl.PushChangesForRepository(commitInfo);
}
catch (LibGit2Sharp.NonFastForwardException)
{
RepoStatus repoStatus = await _sourceControl.PullRemoteChanges(commitInfo.Org, commitInfo.Repository);
await _sourceControl.Push(commitInfo.Org, commitInfo.Repository);
foreach (RepositoryContent repoContent in repoStatus?.ContentStatus)
{
Source source = new(Path.GetFileName(repoContent.FilePath), repoContent.FilePath);
SyncSuccess syncSuccess = new(source);
await _syncHub.Clients.Group(developer).FileSyncSuccess(syncSuccess);
}
}
finally
{
semaphore.Release();
Expand Down
12 changes: 11 additions & 1 deletion backend/src/Designer/Services/Implementation/SourceControlSI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ public async Task<string> CloneRemoteRepository(string org, string repository, s
/// <inheritdoc />
public async Task<RepoStatus> PullRemoteChanges(string org, string repository)
{
RepoStatus status = new();
RepoStatus status = new()
{
ContentStatus = []
};
using (var repo = new LibGit2Sharp.Repository(FindLocalRepoLocation(org, repository)))
{
PullOptions pullOptions = new()
Expand All @@ -99,11 +102,18 @@ public async Task<RepoStatus> PullRemoteChanges(string org, string repository)

try
{
Tree head = repo.Head.Tip.Tree;
MergeResult mergeResult = Commands.Pull(
repo,
new LibGit2Sharp.Signature("my name", "my email", DateTimeOffset.Now), // I dont want to provide these
pullOptions);

TreeChanges treeChanges = repo.Diff.Compare<TreeChanges>(head, mergeResult.Commit?.Tree);
foreach (TreeEntryChanges change in treeChanges.Modified)
{
status.ContentStatus.Add(new RepositoryContent { FilePath = change.Path, FileStatus = Enums.FileStatus.ModifiedInWorkdir });
}

if (mergeResult.Status == MergeStatus.Conflicts)
{
status.RepositoryStatus = Enums.RepositoryStatus.MergeConflict;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,18 +187,18 @@ public async Task GetBranches_And_Branch_ShouldBehaveAsExpected(string org)

[Theory]
[InlineData(GiteaConstants.TestOrgUsername)]
public async Task Commit_AndPush_NonPulled_ShouldReturnConflict(string org)
public async Task PushWithConflictingChangesRemotely_ShouldReturnConflict(string org)
{
string targetRepo = TestDataHelper.GenerateTestRepoName("-gitea");
await CreateAppUsingDesigner(org, targetRepo);

// Create a file in gitea
using var createFileContent = new StringContent(GenerateCommitJsonPayload("I am a new file created in gitea", "test commit"), Encoding.UTF8, MediaTypeNames.Application.Json);
using HttpResponseMessage createFileResponse = await GiteaFixture.GiteaClient.Value.PostAsync($"repos/{org}/{targetRepo}/contents/test2.txt", createFileContent);
using HttpResponseMessage createFileResponse = await GiteaFixture.GiteaClient.Value.PostAsync($"repos/{org}/{targetRepo}/contents/fileAlreadyInRepository.txt", createFileContent);
createFileResponse.StatusCode.Should().Be(HttpStatusCode.Created);

// Add a file to local repo and try to push with designer
await File.WriteAllTextAsync($"{CreatedFolderPath}/test.txt", "I am a new file from studio.");
await File.WriteAllTextAsync($"{CreatedFolderPath}/fileAlreadyInRepository.txt", "I am a new file from studio.");
using var commitAndPushContent = new StringContent(GetCommitInfoJson("test commit", org, targetRepo), Encoding.UTF8, MediaTypeNames.Application.Json);
using HttpResponseMessage commitAndPushResponse = await HttpClient.PostAsync($"designer/api/repos/repo/{org}/{targetRepo}/commit-and-push", commitAndPushContent);
commitAndPushResponse.StatusCode.Should().Be(HttpStatusCode.Conflict);
Expand Down
2 changes: 1 addition & 1 deletion eidlogger/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.3</version>
<version>3.3.4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>no.altinn</groupId>
Expand Down
2 changes: 1 addition & 1 deletion frontend/app-development/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"devDependencies": {
"cross-env": "7.0.3",
"jest": "29.7.0",
"typescript": "5.5.4",
"typescript": "5.6.2",
"webpack": "5.94.0",
"webpack-dev-server": "5.1.0"
},
Expand Down
2 changes: 1 addition & 1 deletion frontend/app-preview/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"devDependencies": {
"cross-env": "7.0.3",
"jest": "29.7.0",
"typescript": "5.5.4",
"typescript": "5.6.2",
"webpack": "5.94.0",
"webpack-dev-server": "5.1.0"
},
Expand Down
2 changes: 1 addition & 1 deletion frontend/dashboard/components/OrgRepoList/OrgReposList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const OrgReposList = ({ user, organizations }: OrgReposListProps) => {
uid: uid as number,
keyword: DATA_MODEL_REPO_IDENTIFIER,
});
const totalRows = repoResults?.totalCount - dataModelsResults?.totalCount ?? 0;
const totalRows = repoResults?.totalCount - dataModelsResults?.totalCount || 0;

const { data: starredRepos = [], isPending: hasPendingStarredRepos } = useStarredReposQuery();
const reposIncludingStarredData = useAugmentReposWithStarred({
Expand Down
2 changes: 1 addition & 1 deletion frontend/dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"devDependencies": {
"cross-env": "7.0.3",
"jest": "29.7.0",
"typescript": "5.5.4",
"typescript": "5.6.2",
"webpack": "5.94.0",
"webpack-dev-server": "5.1.0"
},
Expand Down
2 changes: 1 addition & 1 deletion frontend/libs/studio-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@
"jest-environment-jsdom": "^29.7.0",
"storybook": "^8.0.4",
"ts-jest": "^29.1.1",
"typescript": "^5.2.2"
"typescript": "5.6.2"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from 'react';
import type { Meta, StoryFn } from '@storybook/react';
import { StudioBetaTag } from './StudioBetaTag';

type Story = StoryFn<typeof StudioBetaTag>;

const meta: Meta = {
title: 'Components/StudioBetaTag',
component: StudioBetaTag,
argTypes: {
size: {
control: 'radio',
options: ['sm', 'md', 'lg'],
},
},
};

export const Preview: Story = (args): React.ReactElement => <StudioBetaTag {...args} />;

Preview.args = {
size: 'sm',
};

export default meta;
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import { StudioBetaTag, type StudioBetaTagProps } from './StudioBetaTag';
import { testRootClassNameAppending } from '../../test-utils/testRootClassNameAppending';

describe('StudioBetaTag', () => {
it('should render the "Beta" text', () => {
renderStudioBetaTag();
expect(screen.getByText('Beta')).toBeInTheDocument();
});

it('Appends given classname to the component', () => {
testRootClassNameAppending((className) => renderStudioBetaTag({ className }));
});
});

const renderStudioBetaTag = (props: Partial<StudioBetaTagProps> = {}) => {
return render(<StudioBetaTag {...props} />);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from 'react';
import { StudioTag, type StudioTagProps } from '../StudioTag';

export type StudioBetaTagProps = Omit<StudioTagProps, 'color' | 'children'>;

export const StudioBetaTag = ({ size = 'sm', ...rest }: StudioBetaTagProps) => {
return (
<StudioTag color='info' size={size} {...rest}>
Beta
</StudioTag>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { StudioBetaTag, type StudioBetaTagProps } from './StudioBetaTag';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { Tag as StudioTag, type TagProps as StudioTagProps } from '@digdir/designsystemet-react';
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
align-items: center;
color: var(--fds-semantic-text-neutral-default);
width: 100%;
gap: var(--fds-spacing-1);
}

.textContainer,
Expand Down
2 changes: 2 additions & 0 deletions frontend/libs/studio-components/src/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './StudioAnimateHeight';
export * from './StudioBetaTag';
export * from './StudioBlobDownloader';
export * from './StudioBooleanToggleGroup';
export * from './StudioButton';
Expand Down Expand Up @@ -35,6 +36,7 @@ export * from './StudioCombobox';
export * from './StudioTableLocalPagination';
export * from './StudioTableRemotePagination';
export * from './StudioTabs';
export * from './StudioTag';
export * from './StudioTextarea';
export * from './StudioTextfield';
export * from './StudioToggleableTextfield';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useTableSorting } from './useTableSorting';
import { renderHook, waitFor } from '@testing-library/react';
import { act, renderHook } from '@testing-library/react';
import type { Rows } from '../components';

describe('useTableSorting', () => {
Expand Down Expand Up @@ -28,7 +28,7 @@ describe('useTableSorting', () => {

it('should sort rows in ascending order when a column is clicked', async () => {
const { result } = renderHook(() => useTableSorting(rows, { enable: true }));
await waitFor(() => result.current.handleSorting('creator'));
act(() => result.current.handleSorting('creator'));

const creatorsAscending: string[] = [];
result.current.sortedRows.forEach((row) => {
Expand All @@ -42,8 +42,8 @@ describe('useTableSorting', () => {

it('should sort rows in descending order when the same column is clicked again', async () => {
const { result } = renderHook(() => useTableSorting(rows, { enable: true }));
await waitFor(() => result.current.handleSorting('creator'));
await waitFor(() => result.current.handleSorting('creator'));
act(() => result.current.handleSorting('creator'));
act(() => result.current.handleSorting('creator'));

const creatorsDescending: string[] = [];
result.current.sortedRows.forEach((row) => {
Expand All @@ -57,8 +57,8 @@ describe('useTableSorting', () => {

it('should reset the sort direction to ascending when a different column is clicked', async () => {
const { result } = renderHook(() => useTableSorting(rows, { enable: true }));
await waitFor(() => result.current.handleSorting('creator'));
await waitFor(() => result.current.handleSorting('id'));
act(() => result.current.handleSorting('creator'));
act(() => result.current.handleSorting('id'));
expect(result.current.sortedRows).toEqual(rows);
});

Expand Down
2 changes: 1 addition & 1 deletion frontend/libs/studio-hooks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"ts-jest": "^29.1.1",
"typescript": "^5.2.2"
"typescript": "5.6.2"
}
}
2 changes: 1 addition & 1 deletion frontend/libs/studio-icons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"ts-jest": "^29.1.1",
"typescript": "^5.2.2"
"typescript": "5.6.2"
}
}
2 changes: 1 addition & 1 deletion frontend/libs/studio-pure-functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"ts-jest": "^29.1.1",
"typescript": "^5.2.2"
"typescript": "5.6.2"
}
}
2 changes: 1 addition & 1 deletion frontend/packages/policy-editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
"peerDependencies": {
"react": "18.3.1",
"react-dom": "18.3.1",
"typescript": "5.5.4"
"typescript": "5.6.2"
}
}
2 changes: 1 addition & 1 deletion frontend/packages/process-editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"peerDependencies": {
"react": "18.3.1",
"react-dom": "18.3.1",
"typescript": "5.5.4"
"typescript": "5.6.2"
},
"dependencies": {
"bpmn-js": "^13.2.2"
Expand Down
2 changes: 1 addition & 1 deletion frontend/packages/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"devDependencies": {
"@types/react": "18.3.5",
"jest": "29.7.0",
"typescript": "5.5.4"
"typescript": "5.6.2"
},
"license": "3-Clause BSD",
"private": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ export const FetchChangesPopover = (): React.ReactElement => {

const [popoverOpen, setPopoverOpen] = useState(false);

const displayNotification: boolean = (repoStatus?.behindBy > 0 ?? false) && !hasMergeConflict;
const displayNotification: boolean =
repoStatus?.behindBy !== undefined &&
repoStatus?.behindBy !== null &&
repoStatus.behindBy > 0 &&
!hasMergeConflict;

const handleClosePopover = () => setPopoverOpen(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const ShareChangesPopover = () => {

const fetchCompleted: boolean = !isLoading && !hasChangesToPush;
const displayNotification: boolean =
(repoStatus?.contentStatus?.length > 0 ?? false) && !hasMergeConflict;
repoStatus?.contentStatus && repoStatus?.contentStatus?.length > 0 && !hasMergeConflict;

const fileChanges: RepoContentStatus[] = repoStatus?.contentStatus;

Expand Down
2 changes: 1 addition & 1 deletion frontend/packages/text-editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"peerDependencies": {
"react": "18.3.1",
"react-dom": "18.3.1",
"typescript": "5.5.4"
"typescript": "5.6.2"
},
"scripts": {
"test": "jest"
Expand Down
2 changes: 1 addition & 1 deletion frontend/packages/ux-editor-v3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"react-modal": "3.16.1",
"react-redux": "9.1.2",
"redux": "5.0.1",
"typescript": "5.5.4",
"typescript": "5.6.2",
"uuid": "10.0.0"
},
"devDependencies": {
Expand Down
Loading

0 comments on commit 21e3a4f

Please sign in to comment.