Skip to content

Commit

Permalink
Merge branch 'main' into fix/update-studioResizableLayoutHandle
Browse files Browse the repository at this point in the history
  • Loading branch information
JamalAlabdullah authored Oct 22, 2024
2 parents 9bcd54c + 72389f8 commit f7cce80
Show file tree
Hide file tree
Showing 78 changed files with 1,585 additions and 402 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public async Task<List<Team>> GetTeams()
{
var starredRepos = new List<RepositoryClient.Model.Repository>();

HttpResponseMessage response = await _httpClient.GetAsync("user/starred");
HttpResponseMessage response = await _httpClient.GetAsync("user/starred?limit=100");
if (response.StatusCode == HttpStatusCode.OK)
{
var repos = await response.Content.ReadAsAsync<List<RepositoryClient.Model.Repository>>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const PageHeaderContextProvider = ({
const menuItems = getTopBarMenuItems(repoType, repoOwnerIsOrg);

const docsMenuItem: StudioProfileMenuItem = {
action: { type: 'link', href: altinnDocsUrl('', 'nb'), openInNewTab: true },
action: { type: 'link', href: altinnDocsUrl(), openInNewTab: true },
itemName: t('sync_header.documentation'),
};

Expand Down
3 changes: 3 additions & 0 deletions frontend/app-development/enums/GiteaRoutePaths.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export enum GiteaRoutePaths {
LatestCommit = 'latest-commit',
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ describe('ReleaseContainer', () => {
name: textMock('app_release.release_title_link'),
});
await user.click(latestCommitLink);
expect(mockGetBranchStatus).toHaveBeenCalledTimes(2);
expect(mockGetRepoStatus).toHaveBeenCalledTimes(1);
expect(latestCommitLink).toBeInTheDocument();
});

it('renders status that latest commit fetched from master is the same as commit for latest release', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,21 @@ import { QueryKey } from 'app-shared/types/QueryKey';
import { useRepoStatusQuery } from 'app-shared/hooks/queries';
import { useStudioEnvironmentParams } from 'app-shared/hooks/useStudioEnvironmentParams';
import { Link } from '@digdir/designsystemet-react';
import { PackagesRouter } from 'app-shared/navigation/PackagesRouter';

export function ReleaseContainer() {
const { org, app } = useStudioEnvironmentParams();
const [popoverOpenClick, setPopoverOpenClick] = useState<boolean>(false);
const [popoverOpenHover, setPopoverOpenHover] = useState<boolean>(false);
const packagesRouter = new PackagesRouter({ app, org });

const { data: releases = [] } = useAppReleasesQuery(org, app);
const { data: repoStatus, isPending: isRepoStatusPending } = useRepoStatusQuery(org, app);
const {
data: masterBranchStatus,
isPending: masterBranchStatusIsPending,
refetch: getMasterBranchStatus,
} = useBranchStatusQuery(org, app, 'master');
const { data: masterBranchStatus, isPending: masterBranchStatusIsPending } = useBranchStatusQuery(
org,
app,
'master',
);

const latestRelease: AppReleaseType = releases && releases[0] ? releases[0] : null;

Expand Down Expand Up @@ -146,17 +148,6 @@ export function ReleaseContainer() {
}

function renderCreateReleaseTitle() {
const handleLinkClick = async (event) => {
event.preventDefault(); // Prevent default link behavior
const url = await getLatestCommitOnMaster();
window.open(url, '#', 'noopener,noreferrer');
};

const getLatestCommitOnMaster = async () => {
const { data: newMasterBranchStatus } = await getMasterBranchStatus();
return gitCommitPath(org, app, newMasterBranchStatus.commit.id);
};

if (!masterBranchStatus || !repoStatus?.contentStatus) {
return null;
}
Expand All @@ -169,7 +160,11 @@ export function ReleaseContainer() {
return (
<>
{t('app_release.release_title')}
<a href='#' onClick={handleLinkClick}>
<a
href={packagesRouter.getPackageNavigationUrl('latestCommit')}
target='_blank'
rel='noopener noreferrer'
>
{t('app_release.release_title_link')}
</a>
</>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React from 'react';
import { screen } from '@testing-library/react';
import { textMock } from '@studio/testing/mocks/i18nMock';
import { renderWithProviders } from '../../test/mocks';
import { createQueryClientMock } from 'app-shared/mocks/queryClientMock';
import { QueryKey } from 'app-shared/types/QueryKey';
import { app, org } from '@studio/testing/testids';
import { branchStatus } from 'app-shared/mocks/mocks';
import type { BranchStatus } from 'app-shared/types/BranchStatus';
import { NavigateToLatestCommitInGitea } from './NavigateToLatestCommitInGitea';

describe('NavigateToLatestCommitInGitea', () => {
afterEach(() => jest.clearAllMocks);

it('sets window location when the latest commit is received', async () => {
const commitId = 'some-commit-id';
delete window.location;
window.location = { ...window.location, assign: jest.fn() };
renderLatestCommit({ ...branchStatus, commit: { ...branchStatus.commit, id: commitId } });
expect(window.location.href).toBe(`/repos/${org}/${app}/commit/${commitId}`);
});

it('renders a spinner if master branch status is pending', () => {
renderLatestCommit();
expect(screen.getByText(textMock('general.loading'))).toBeInTheDocument();
});
});

const renderLatestCommit = (branchStatusMock?: BranchStatus) => {
const queryClientMock = createQueryClientMock();
if (branchStatusMock) {
queryClientMock.setQueryData([QueryKey.BranchStatus, org, app, 'master'], branchStatusMock);
}
renderWithProviders({}, queryClientMock)(<NavigateToLatestCommitInGitea />);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React, { useEffect } from 'react';
import { StudioPageSpinner } from '@studio/components';
import { gitCommitPath } from 'app-shared/api/paths';
import { useStudioEnvironmentParams } from 'app-shared/hooks/useStudioEnvironmentParams';
import { useBranchStatusQuery } from 'app-development/hooks/queries';
import { useTranslation } from 'react-i18next';

export const NavigateToLatestCommitInGitea = (): React.ReactElement => {
const { t } = useTranslation();
const { org, app } = useStudioEnvironmentParams();
const { data: masterBranchStatus } = useBranchStatusQuery(org, app, 'master');
const latestCommitId = masterBranchStatus?.commit?.id;

useEffect(() => {
if (latestCommitId) {
window.location.href = gitCommitPath(org, app, latestCommitId);
}
}, [app, latestCommitId, org]);
return <StudioPageSpinner spinnerTitle={t('general.loading')} />;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { NavigateToLatestCommitInGitea } from './NavigateToLatestCommitInGitea';
10 changes: 10 additions & 0 deletions frontend/app-development/router/PageRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import {
NotFoundRouteErrorBoundary,
RouteErrorBoundary,
} from './PageRouterErrorBoundry';
import { GiteaRoutePaths } from '../enums/GiteaRoutePaths';
import { NavigateToLatestCommitInGitea } from '../features/navigateToLatestCommitInGitea';

const BASE_PATH = '/:org/:app';

Expand All @@ -40,6 +42,14 @@ const router = createBrowserRouter(
))}
<Route path='*' element={<NotFoundPage />} errorElement={<NotFoundRouteErrorBoundary />} />
</Route>
<Route path={BASE_PATH}>
{/* Additional BasePath route to avoid using PageLayout around NavigateToLatestCommitInGitea */}
<Route
path={GiteaRoutePaths.LatestCommit}
element={<NavigateToLatestCommitInGitea />}
errorElement={<RouteErrorBoundary />}
/>
</Route>
<Route path='*' element={<NotFoundPage />} errorElement={<NotFoundRouteErrorBoundary />} />
</Route>,
),
Expand Down
2 changes: 0 additions & 2 deletions frontend/app-development/test/mocks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import { queriesMock } from 'app-shared/mocks/queriesMock';
import type { QueryClient } from '@tanstack/react-query';
import { queryClientConfigMock } from 'app-shared/mocks/queryClientMock';

export const textLanguagesMock = ['nb', 'nn', 'en'];

export const renderWithProviders =
(queries: Partial<ServicesContextProps> = {}, queryClient?: QueryClient) =>
(component: ReactNode) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const UserProfileMenu = ({ user, repository }: UserProfileMenuProps): Rea
const { mutate: logout } = useLogoutMutation();

const docsMenuItem: StudioProfileMenuItem = {
action: { type: 'link', href: altinnDocsUrl('', 'nb') },
action: { type: 'link', href: altinnDocsUrl() },
itemName: t('sync_header.documentation'),
};
const logOutMenuItem: StudioProfileMenuItem = {
Expand Down
7 changes: 7 additions & 0 deletions frontend/language/src/nb.json
Original file line number Diff line number Diff line change
Expand Up @@ -1672,6 +1672,13 @@
"ux_editor.properties_panel.options.codelist_switch_to_custom": "Bytt til egendefinert kodeliste",
"ux_editor.properties_panel.options.codelist_switch_to_static": "Bytt til statisk kodeliste",
"ux_editor.properties_panel.options.use_code_list_label": "Bruk kodeliste",
"ux_editor.properties_panel.subform_table_columns.add_column": "Legg til kolonne",
"ux_editor.properties_panel.subform_table_columns.cell_content_default_label": "Default",
"ux_editor.properties_panel.subform_table_columns.cell_content_query_label": "Query",
"ux_editor.properties_panel.subform_table_columns.column_header": "Kolonne {{columnNumber}}",
"ux_editor.properties_panel.subform_table_columns.delete_column": "Slett kolonne {{columnNumber}}",
"ux_editor.properties_panel.subform_table_columns.header_content_label": "Header Content",
"ux_editor.properties_panel.subform_table_columns.heading": "Valg for tabell",
"ux_editor.properties_panel.texts.loading": "Laster inn tekster",
"ux_editor.properties_panel.texts.no_properties": "Det er ingen tekster å konfigurere for denne komponenten.",
"ux_editor.properties_panel.texts.sub_title_images": "Valg for bilde",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,19 @@ export const Preview: Story = {
label: 'Test 1',
value: 'test1',
description: 'Test 1 description',
helpText: 'Test 1 help text',
},
{
label: 'Test 2',
value: 'test2',
description: 'Test 2 description',
helpText: 'Test 2 help text',
},
{
label: 'Test 3',
value: 'test3',
description: 'Test 3 description',
helpText: 'Test 3 help text',
},
],
texts: {
Expand All @@ -35,7 +38,9 @@ export const Preview: Story = {
deleteItem: (number) => `Delete item number ${number}`,
description: 'Description',
emptyCodeList: 'The code list is empty.',
helpText: 'Help text',
itemDescription: (number) => `Description for item number ${number}`,
itemHelpText: (number) => `Help text for item number ${number}`,
itemLabel: (number) => `Label for item number ${number}`,
itemValue: (number) => `Value for item number ${number}`,
label: 'Label',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ const texts: CodeListEditorTexts = {
deleteItem: (number) => `Delete item number ${number}`,
description: 'Description',
emptyCodeList: 'The code list is empty.',
helpText: 'Help text',
itemDescription: (number) => `Description for item number ${number}`,
itemHelpText: (number) => `Help text for item number ${number}`,
itemLabel: (number) => `Label for item number ${number}`,
itemValue: (number) => `Value for item number ${number}`,
label: 'Label',
Expand All @@ -25,16 +27,19 @@ const codeList: CodeList = [
label: 'Test 1',
value: 'test1',
description: 'Test 1 description',
helpText: 'Test 1 help text',
},
{
label: 'Test 2',
value: 'test2',
description: 'Test 2 description',
helpText: 'Test 2 help text',
},
{
label: 'Test 3',
value: 'test3',
description: 'Test 3 description',
helpText: 'Test 3 help text',
},
];
const onChange = jest.fn();
Expand Down Expand Up @@ -63,9 +68,11 @@ describe('StudioCodeListEditor', () => {

it('Renders the given column headers', () => {
renderCodeListEditor();
expect(screen.getByRole('columnheader', { name: texts.label })).toBeInTheDocument();
expect(screen.getByRole('columnheader', { name: texts.value })).toBeInTheDocument();
expect(screen.getByRole('columnheader', { name: texts.label })).toBeInTheDocument();
expect(screen.getByRole('columnheader', { name: texts.description })).toBeInTheDocument();
expect(screen.getByRole('columnheader', { name: texts.helpText })).toBeInTheDocument();
expect(screen.getByRole('columnheader', { name: texts.delete })).toBeInTheDocument();
});

it('Renders a button to add a new code list item', () => {
Expand Down Expand Up @@ -120,6 +127,20 @@ describe('StudioCodeListEditor', () => {
]);
});

it('Calls the onChange callback with the new code list when a help text is changed', async () => {
const user = userEvent.setup();
renderCodeListEditor();
const helpTextInput = screen.getByRole('textbox', { name: texts.itemHelpText(1) });
const newValue = 'new text';
await user.type(helpTextInput, newValue);
expect(onChange).toHaveBeenCalledTimes(newValue.length);
expect(onChange).toHaveBeenLastCalledWith([
{ ...codeList[0], helpText: newValue },
codeList[1],
codeList[2],
]);
});

it('Calls the onChange callback with the new code list when an item is removed', async () => {
const user = userEvent.setup();
renderCodeListEditor();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,10 @@ function Headings(): ReactElement {
return (
<StudioInputTable.Head>
<StudioInputTable.Row>
<StudioInputTable.HeaderCell>{texts.value}</StudioInputTable.HeaderCell>
<StudioInputTable.HeaderCell>{texts.label}</StudioInputTable.HeaderCell>
<StudioInputTable.HeaderCell>{texts.description}</StudioInputTable.HeaderCell>
<StudioInputTable.HeaderCell>{texts.value}</StudioInputTable.HeaderCell>
<StudioInputTable.HeaderCell>{texts.helpText}</StudioInputTable.HeaderCell>
<StudioInputTable.HeaderCell>{texts.delete}</StudioInputTable.HeaderCell>
</StudioInputTable.Row>
</StudioInputTable.Head>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { CodeListItem } from '../types/CodeListItem';
import { StudioInputTable } from '../../StudioInputTable';
import { TrashIcon } from '../../../../../studio-icons';
import React, { useCallback } from 'react';
import { changeDescription, changeLabel, changeValue } from './utils';
import { changeDescription, changeHelpText, changeLabel, changeValue } from './utils';
import { useStudioCodeListEditorContext } from '../StudioCodeListEditorContext';

type StudioCodeListEditorRowProps = {
Expand Down Expand Up @@ -44,8 +44,21 @@ export function StudioCodeListEditorRow({
[item, onChange],
);

const handleHelpTextChange = useCallback(
(helpText: string) => {
const updatedItem = changeHelpText(item, helpText);
onChange(updatedItem);
},
[item, onChange],
);

return (
<StudioInputTable.Row>
<TextfieldCell
label={texts.itemValue(number)}
value={item.value}
onChange={handleValueChange}
/>
<TextfieldCell
label={texts.itemLabel(number)}
value={item.label}
Expand All @@ -57,9 +70,9 @@ export function StudioCodeListEditorRow({
onChange={handleDescriptionChange}
/>
<TextfieldCell
label={texts.itemValue(number)}
value={item.value}
onChange={handleValueChange}
label={texts.itemHelpText(number)}
value={item.helpText}
onChange={handleHelpTextChange}
/>
<DeleteButtonCell onClick={onDeleteButtonClick} number={number} />
</StudioInputTable.Row>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { CodeListItem } from '../types/CodeListItem';
import { ObjectUtils } from '@studio/pure-functions';
import { changeDescription, changeLabel, changeValue } from './utils';
import { changeDescription, changeHelpText, changeLabel, changeValue } from './utils';

// Test data:
const testItem: CodeListItem = {
Expand Down Expand Up @@ -55,4 +55,19 @@ describe('StudioCodeListEditorRow utils', () => {
expect(updatedItem).not.toBe(item);
});
});

describe('changeHelpText', () => {
it('Changes the help text of the code list item', () => {
const item = createTestItem();
const newHelpText = 'Updated help text';
const updatedItem = changeHelpText(item, newHelpText);
expect(updatedItem.helpText).toBe(newHelpText);
});

it('Returns a new instance', () => {
const item = createTestItem();
const updatedItem = changeHelpText(item, 'Updated help text');
expect(updatedItem).not.toBe(item);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ export function changeDescription(item: CodeListItem, description: string): Code
export function changeValue(item: CodeListItem, value: string): CodeListItem {
return { ...item, value };
}

export function changeHelpText(item: CodeListItem, helpText: string): CodeListItem {
return { ...item, helpText };
}
Loading

0 comments on commit f7cce80

Please sign in to comment.