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: remove error div from studio search #14414

Merged
merged 6 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
13 changes: 5 additions & 8 deletions backend/src/Designer/Controllers/AppDevelopmentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -547,17 +547,14 @@ public ActionResult GetWidgetSettings(string org, string app)
[Route("option-list-ids")]
public ActionResult GetOptionListIds(string org, string app)
{
try
{
string developer = AuthenticationHelper.GetDeveloperUserName(HttpContext);
AltinnAppGitRepository altinnAppGitRepository = _altinnGitRepositoryFactory.GetAltinnAppGitRepository(org, app, developer);
string[] optionListIds = altinnAppGitRepository.GetOptionsListIds();
return Ok(optionListIds);
}
catch (LibGit2Sharp.NotFoundException)
string developer = AuthenticationHelper.GetDeveloperUserName(HttpContext);
AltinnAppGitRepository altinnAppGitRepository = _altinnGitRepositoryFactory.GetAltinnAppGitRepository(org, app, developer);
string[] optionListIds = altinnAppGitRepository.GetOptionsListIds();
if (optionListIds.Length == 0)
{
return NoContent();
}
return Ok(optionListIds);
}

[HttpGet("app-version")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ public string[] GetOptionsListIds()
string optionsFolder = Path.Combine(OptionsFolderPath);
if (!DirectoryExistsByRelativePath(optionsFolder))
{
throw new NotFoundException("Options folder not found.");
return [];
}

string[] fileNames = GetFilesByRelativeDirectoryAscSorted(optionsFolder, "*.json");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System.Collections.Generic;
using System.IO;
using System.Net.Http;
using System.Text.Json;
using System.Threading.Tasks;
using Altinn.Studio.Designer.Models.Dto;
using Designer.Tests.Controllers.ApiTests;
using Designer.Tests.Utils;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.Testing;
using Xunit;
Expand All @@ -14,6 +16,7 @@ public class GetOptionListsReferencesTests : DesignerEndpointsTestsBase<GetOptio
{
const string RepoWithUsedOptions = "app-with-options";
const string RepoWithUnusedOptions = "app-with-layoutsets";
const string RepoWithoutOptions = "empty-app";

public GetOptionListsReferencesTests(WebApplicationFactory<Program> factory) : base(factory)
{
Expand Down Expand Up @@ -85,4 +88,25 @@ public async Task GetOptionListsReferences_Returns200Ok_WithEmptyOptionsReferenc
Assert.Equal(StatusCodes.Status200OK, (int)response.StatusCode);
Assert.Equivalent("[]", responseBody);
}

[Fact]
public async Task GetOptionListsReferences_Returns200Ok_WithEmptyOptionsReferences_WhenAppDoesNotHaveOptions()
{
string targetRepository = TestDataHelper.GenerateTestRepoName();
await CopyRepositoryForTest("ttd", RepoWithoutOptions, "testUser", targetRepository);
string repoPath = TestDataHelper.GetTestDataRepositoryDirectory("ttd", targetRepository, "testUser");
string exampleLayout = @"{ ""data"": {""layout"": []}}";
string filePath = Path.Combine(repoPath, "App/ui/form/layouts");
Directory.CreateDirectory(filePath);
await File.WriteAllTextAsync(Path.Combine(filePath, "exampleLayout.json"), exampleLayout);

string apiUrl = $"/designer/api/ttd/{targetRepository}/options/usage";
using HttpRequestMessage httpRequestMessage = new(HttpMethod.Get, apiUrl);

using HttpResponseMessage response = await HttpClient.SendAsync(httpRequestMessage);
string responseBody = await response.Content.ReadAsStringAsync();

Assert.Equal(StatusCodes.Status200OK, (int)response.StatusCode);
Assert.Equivalent("[]", responseBody);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.studioSearch [id^='search-error'] {
display: none;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { forwardRef, useId } from 'react';
import { Label, Search, type SearchProps } from '@digdir/designsystemet-react';
import type { WithoutAsChild } from '../../types/WithoutAsChild';
import classes from './StudioSearch.module.css';

export type StudioSearchProps = WithoutAsChild<SearchProps>;

Expand All @@ -17,7 +18,7 @@ const StudioSearch = forwardRef<HTMLInputElement, StudioSearchProps>(
{label}
</Label>
)}
<Search {...rest} id={searchId} size={size} ref={ref} />
<Search {...rest} className={classes.studioSearch} id={searchId} size={size} ref={ref} />
</div>
);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,3 @@
gap: var(--fds-spacing-3);
justify-content: flex-start;
}

.searchField {
display: flex;
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ export function CodeListsActionsBar({

return (
<div className={classes.actionsBar}>
<StudioSearch
className={classes.searchField}
label={t('app_content_library.code_lists.search_label')}
/>
<StudioSearch label={t('app_content_library.code_lists.search_label')} />
<CreateNewCodeListModal onUpdateCodeList={onUpdateCodeList} codeListNames={codeListNames} />
<StudioFileUploader
accept='.json'
Expand Down
4 changes: 2 additions & 2 deletions frontend/packages/text-editor/src/TextEditor.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
border-bottom: 1px solid #bcc7cc;
padding: var(--fds-spacing-6);
display: flex;
align-items: center;
align-items: flex-end;
justify-content: space-between;
}

.filterAndSearch {
display: flex;
flex-direction: row;
align-items: center;
align-items: flex-end;
gap: var(--fds-spacing-4);
}

Expand Down
Loading