Skip to content

Commit

Permalink
Add div to ensure grid-display works correctly (#13394)
Browse files Browse the repository at this point in the history
* Add div to ensure grid-display works correctly

* Remove redundant showSpinnerTitle prop and add PageSpinner when entering uiEditor
  • Loading branch information
standeren authored Aug 29, 2024
1 parent 79b2d03 commit bc4ee37
Show file tree
Hide file tree
Showing 14 changed files with 59 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ export function DataModelling({ createPathOption = false }: DataModellingProps):

switch (mergeQueryStatuses(jsonStatus, xsdStatus)) {
case 'pending':
return (
<StudioPageSpinner showSpinnerTitle={false} spinnerTitle={t('data_modelling.loading')} />
);
return <StudioPageSpinner spinnerTitle={t('data_modelling.loading')} />;
case 'error':
return (
<StudioCenter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,7 @@ export const SelectedSchemaEditor = ({ modelPath }: SelectedSchemaEditorProps) =

switch (status) {
case 'pending':
return (
<StudioPageSpinner
showSpinnerTitle={false}
spinnerTitle={t('schema_editor.loading_page')}
/>
);
return <StudioPageSpinner spinnerTitle={t('schema_editor.loading_page')} />;

case 'error':
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export const ProcessEditor = (): React.ReactElement => {
};

if (appLibDataLoading || appMetadataPending) {
return <StudioPageSpinner spinnerTitle={t('process_editor.loading')} showSpinnerTitle />;
return <StudioPageSpinner spinnerTitle={t('process_editor.loading')} />;
}

// TODO: Handle error will be handled better after issue #10735 is resolved
Expand Down
4 changes: 1 addition & 3 deletions frontend/app-development/features/textEditor/TextEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ export const TextEditor = () => {
const { mutate: upsertTextResource } = useUpsertTextResourceMutation(org, app);

if (isInitialLoadingLang || !textResources) {
return (
<StudioPageSpinner showSpinnerTitle={false} spinnerTitle={t('text_editor.loading_page')} />
);
return <StudioPageSpinner spinnerTitle={t('text_editor.loading_page')} />;
}

return (
Expand Down
2 changes: 1 addition & 1 deletion frontend/app-development/layout/PageLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const PageLayout = (): React.ReactNode => {
if (isRepoStatusPending || isUserPending) {
return (
<StudioCenter>
<StudioPageSpinner showSpinnerTitle={false} spinnerTitle={t('repo_status.loading')} />
<StudioPageSpinner spinnerTitle={t('repo_status.loading')} />
</StudioCenter>
);
}
Expand Down
28 changes: 18 additions & 10 deletions frontend/app-development/router/routes.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { app, org } from '@studio/testing/testids';
import { SettingsModalContextProvider } from '../contexts/SettingsModalContext';
import { PreviewContextProvider } from '../contexts/PreviewContext';
import { AppDevelopmentContextProvider } from '../contexts/AppDevelopmentContext';
import { textMock } from '@studio/testing/mocks/i18nMock';
import type { QueryClient } from '@tanstack/react-query';

// Mocks:
jest.mock('@altinn/ux-editor-v3/SubApp', () => ({
Expand All @@ -35,24 +37,30 @@ describe('routes', () => {
it.each(testCases)(
'Renders the %s schema editor page when the app frontend version is %s',
(expectedPackage, frontendVersion) => {
renderUiEditor(frontendVersion);
const appVersion: AppVersion = {
frontendVersion,
backendVersion: '7.0.0',
};
const queryClient = createQueryClientMock();
queryClient.setQueryData([QueryKey.AppVersion, org, app], appVersion);
renderUiEditor(queryClient);
expect(screen.getByTestId(expectedPackage)).toBeInTheDocument();
},
);

const renderUiEditor = (frontendVersion: string | null) =>
renderSubapp(RoutePaths.UIEditor, frontendVersion);
it('renders a loading spinner while fetching frontend version', () => {
renderUiEditor();
expect(screen.getByText(textMock('ux_editor.loading_page'))).toBeInTheDocument();
});

const renderUiEditor = (queryClient: QueryClient = createQueryClientMock()) =>
renderSubapp(RoutePaths.UIEditor, queryClient);
});
});

const renderSubapp = (path: RoutePaths, frontendVersion: string = null) => {
const renderSubapp = (path: RoutePaths, queryClient: QueryClient) => {
const Subapp = routerRoutes.find((route) => route.path === path)!.subapp;
const appVersion: AppVersion = {
frontendVersion,
backendVersion: '7.0.0',
};
const queryClient = createQueryClientMock();
queryClient.setQueryData([QueryKey.AppVersion, org, app], appVersion);

return render(
<ServicesContextProvider {...queriesMock} client={queryClient}>
<SettingsModalContextProvider>
Expand Down
9 changes: 8 additions & 1 deletion frontend/app-development/router/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { useAppVersionQuery } from 'app-shared/hooks/queries';
import React from 'react';
import { usePreviewContext } from '../contexts/PreviewContext';
import { useLayoutContext } from '../contexts/LayoutContext';
import { StudioPageSpinner } from '@studio/components';
import { useTranslation } from 'react-i18next';

interface IRouteProps {
headerTextKey?: string;
Expand All @@ -38,10 +40,15 @@ const isLatestFrontendVersion = (version: AppVersion): boolean =>

const UiEditor = () => {
const { org, app } = useStudioEnvironmentParams();
const { data: version } = useAppVersionQuery(org, app);
const { t } = useTranslation();
const { data: version, isPending: fetchingVersionIsPending } = useAppVersionQuery(org, app);
const { shouldReloadPreview, previewHasLoaded } = usePreviewContext();
const { setSelectedLayoutSetName } = useLayoutContext();

if (fetchingVersionIsPending) {
return <StudioPageSpinner spinnerTitle={t('ux_editor.loading_page')} />;
}

if (!version) return null;

return isLatestFrontendVersion(version) ? (
Expand Down
2 changes: 1 addition & 1 deletion frontend/dashboard/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export const App = (): JSX.Element => {

return (
<div className={classes.appDashboardSpinner}>
<StudioPageSpinner showSpinnerTitle={false} spinnerTitle={t('dashboard.loading')} />
<StudioPageSpinner spinnerTitle={t('dashboard.loading')} />
</div>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('StudioPageSpinner', () => {
afterEach(jest.clearAllMocks);

it('should render default loading message as accessibility title when spinnerText is not provided', () => {
render(<StudioPageSpinner spinnerTitle={mockSpinnerText} showSpinnerTitle={false} />);
render(<StudioPageSpinner spinnerTitle={mockSpinnerText} />);

expect(screen.getByTitle(mockSpinnerText));

Expand Down
2 changes: 1 addition & 1 deletion frontend/packages/ux-editor-v3/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,5 @@ export function App() {
</FormItemContextProvider>
);
}
return <StudioPageSpinner showSpinnerTitle={false} spinnerTitle={t('ux_editor.loading_page')} />;
return <StudioPageSpinner spinnerTitle={t('ux_editor.loading_page')} />;
}
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,5 @@ export const FormDesigner = ({
</DragAndDropTree.Provider>
);
}
return (
<StudioPageSpinner showSpinnerTitle={false} spinnerTitle={t('ux_editor.loading_form_layout')} />
);
return <StudioPageSpinner spinnerTitle={t('ux_editor.loading_form_layout')} />;
};
40 changes: 22 additions & 18 deletions frontend/packages/ux-editor/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,31 +47,36 @@ export function App() {
const t = useText();
const { org, app } = useStudioEnvironmentParams();
const { selectedFormLayoutSetName } = useAppContext();
const { isSuccess: areWidgetsFetched, isError: widgetFetchedError } = useWidgetsQuery(org, app);
const { isSuccess: areLayoutSetsFetched, isError: layoutSetsFetchedError } = useLayoutSetsQuery(
const { status: widgetsStatus, isError: widgetFetchedError } = useWidgetsQuery(org, app);
const { status: layoutSetsStatus, isError: layoutSetsFetchedError } = useLayoutSetsQuery(
org,
app,
);
const { isSuccess: isDataModelFetched, isError: dataModelFetchedError } =
useDataModelMetadataQuery({
org,
app,
layoutSetName: selectedFormLayoutSetName,
hideDefault: true,
});
const { isSuccess: areTextResourcesFetched, data: textResources } = useTextResourcesQuery(
const { status: dataModelStatus, isError: dataModelFetchedError } = useDataModelMetadataQuery({
org,
app,
);
layoutSetName: selectedFormLayoutSetName,
hideDefault: true,
});
const { status: textsStatus, data: textResources } = useTextResourcesQuery(org, app);

const { doReloadPreview } = usePreviewContext();
useEffect(() => {
doReloadPreview();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [textResources]);

const componentIsReady = areWidgetsFetched && isDataModelFetched && areTextResourcesFetched;
const componentHasError = dataModelFetchedError || widgetFetchedError;
const componentIsPending =
widgetsStatus === 'pending' ||
layoutSetsStatus === 'pending' ||
dataModelStatus === 'pending' ||
textsStatus === 'pending';
const componentIsReady =
widgetsStatus === 'success' &&
layoutSetsStatus === 'success' &&
dataModelStatus === 'success' &&
textsStatus === 'success';
const componentHasError = widgetsStatus === 'error' || dataModelStatus === 'error';

const errors: ErrorKinds = {
layoutSetsError: layoutSetsFetchedError,
Expand All @@ -86,10 +91,10 @@ export function App() {
return <StudioPageError title={mappedError.title} message={mappedError.message} />;
}

if (areLayoutSetsFetched) {
if (!componentIsPending) {
// If layoutSets are successfully fetched, show layoutSetsSelector and app
return (
<>
<div>
<FormDesignerToolbar />
{componentHasError && (
<StudioPageError title={mappedError.title} message={mappedError.message} />
Expand All @@ -99,10 +104,9 @@ export function App() {
<FormDesigner />
</FormItemContextProvider>
)}
</>
</div>
);
}

// If any requests are loading show spinner on whole page
return <StudioPageSpinner showSpinnerTitle={false} spinnerTitle={t('ux_editor.loading_page')} />;
return <StudioPageSpinner spinnerTitle={t('ux_editor.loading_page')} />;
}
4 changes: 1 addition & 3 deletions frontend/packages/ux-editor/src/containers/FormDesigner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,5 @@ export const FormDesigner = (): JSX.Element => {
</DragAndDropTree.Provider>
);
}
return (
<StudioPageSpinner showSpinnerTitle={false} spinnerTitle={t('ux_editor.loading_form_layout')} />
);
return <StudioPageSpinner spinnerTitle={t('ux_editor.loading_form_layout')} />;
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useQuery } from '@tanstack/react-query';
import type { MutationMeta, UseQueryResult } from '@tanstack/react-query';
import type { UseQueryResult } from '@tanstack/react-query';
import type { DataModelFieldElement } from 'app-shared/types/DataModelFieldElement';
import { useServicesContext } from 'app-shared/contexts/ServicesContext';
import { QueryKey } from 'app-shared/types/QueryKey';
Expand All @@ -19,7 +19,6 @@ type QueryOptions = {
export const useDataModelMetadataQuery = (
{ org, app, layoutSetName, dataModelName, hideDefault }: UseDataModelMetadataQuery,
options: QueryOptions = {},
meta?: MutationMeta,
): UseQueryResult<DataModelFieldElement[]> => {
const { getDataModelMetadata } = useServicesContext();

Expand Down

0 comments on commit bc4ee37

Please sign in to comment.