Skip to content

Commit

Permalink
build(ui): code-split ApiDocs and Reports components (#12061)
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Gilgur <[email protected]>
  • Loading branch information
Anton Gilgur authored Oct 23, 2023
1 parent 7f2ac5c commit 12c9aa2
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 26 deletions.
19 changes: 16 additions & 3 deletions ui/src/app/apidocs/components/apiDocs.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
import {Page} from 'argo-ui';
import * as React from 'react';
import SwaggerUI from 'swagger-ui-react';
import 'swagger-ui-react/swagger-ui.css';
import {uiUrl} from '../../shared/base';
import {Loading} from '../../shared/components/loading';
import {useCollectEvent} from '../../shared/components/use-collect-event';

export const ApiDocs = () => {
useCollectEvent('openedApiDocs');
return (
<Page title='Swagger'>
<div className='argo-container'>
<SwaggerUI url={uiUrl('assets/openapi-spec/swagger.json')} defaultModelExpandDepth={0} />
<SuspenseSwaggerUI url={uiUrl('assets/openapi-spec/swagger.json')} defaultModelExpandDepth={0} />
</div>
</Page>
);
};

// lazy load SwaggerUI as it is infrequently used and imports very large components (which can be split into a separate bundle)
const LazySwaggerUI = React.lazy(() => {
import('swagger-ui-react/swagger-ui.css');
return import('swagger-ui-react');
});

function SuspenseSwaggerUI(props: any) {
return (
<React.Suspense fallback={<Loading />}>
<LazySwaggerUI {...props} />
</React.Suspense>
);
}
10 changes: 5 additions & 5 deletions ui/src/app/cron-workflows/components/pretty-schedule.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React = require('react');
import {WarningIcon} from '../../shared/components/fa-icons';
import x from 'cronstrue';
import * as React from 'react';

const x = require('cronstrue');
import {WarningIcon} from '../../shared/components/fa-icons';

/*
https://github.com/bradymholt/cRonstrue
Expand All @@ -12,7 +12,7 @@ const x = require('cronstrue');
sometime it'll not work as expected. Therefore, we must let the user know about this.
*/

export const PrettySchedule = ({schedule}: {schedule: string}) => {
export function PrettySchedule({schedule}: {schedule: string}) {
try {
if (schedule.split(' ').length >= 6) {
throw new Error('cron schedules must consist of 5 values only');
Expand All @@ -26,4 +26,4 @@ export const PrettySchedule = ({schedule}: {schedule: string}) => {
</span>
);
}
};
}
10 changes: 5 additions & 5 deletions ui/src/app/cron-workflows/components/schedule-validator.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React = require('react');
import {SuccessIcon, WarningIcon} from '../../shared/components/fa-icons';
import x from 'cronstrue';
import * as React from 'react';

const x = require('cronstrue');
import {SuccessIcon, WarningIcon} from '../../shared/components/fa-icons';

export const ScheduleValidator = ({schedule}: {schedule: string}) => {
export function ScheduleValidator({schedule}: {schedule: string}) {
try {
if (schedule.split(' ').length >= 6) {
throw new Error('cron schedules must consist of 5 values only');
Expand All @@ -20,4 +20,4 @@ export const ScheduleValidator = ({schedule}: {schedule: string}) => {
</span>
);
}
};
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Page, SlidingPanel, Tabs} from 'argo-ui';
import {useContext, useEffect, useState} from 'react';
import React = require('react');
import * as React from 'react';
import {RouteComponentProps} from 'react-router-dom';
import {Observable} from 'rxjs';
import {filter, map} from 'rxjs/operators';
Expand Down Expand Up @@ -34,7 +34,7 @@ import {ID} from './id';

require('./event-flow-page.scss');

export const EventFlowPage = ({history, location, match}: RouteComponentProps<any>) => {
export function EventFlowPage({history, location, match}: RouteComponentProps<any>) {
// boiler-plate
const {navigation} = useContext(Context);
const queryParams = new URLSearchParams(location.search);
Expand Down Expand Up @@ -355,4 +355,4 @@ export const EventFlowPage = ({history, location, match}: RouteComponentProps<an
</SlidingPanel>
</Page>
);
};
}
15 changes: 13 additions & 2 deletions ui/src/app/reports/components/report-container.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
import * as React from 'react';
import {Route, RouteComponentProps, Switch} from 'react-router';
import {Reports} from './reports';
import {Loading} from '../../shared/components/loading';

export const ReportsContainer = (props: RouteComponentProps<any>) => (
<Switch>
<Route exact={true} path={`${props.match.path}/:namespace?`} component={Reports} />
<Route exact={true} path={`${props.match.path}/:namespace?`} component={SuspenseReports} />
</Switch>
);

// lazy load Reports as it is infrequently used and imports large Chart components (which can be split into a separate bundle)
const LazyReports = React.lazy(() => import('./reports'));

function SuspenseReports(props: RouteComponentProps<any>) {
return (
<React.Suspense fallback={<Loading />}>
<LazyReports {...props} />
</React.Suspense>
);
}
2 changes: 2 additions & 0 deletions ui/src/app/reports/components/reports.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,5 @@ export function Reports({match, location, history}: RouteComponentProps<any>) {
</Page>
);
}

export default Reports;
6 changes: 3 additions & 3 deletions ui/src/app/shared/components/chat-button.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React = require('react');
import * as React from 'react';
import {useEffect, useState} from 'react';
import {Link} from '../../../models';
import {services} from '../services';

export const ChatButton = () => {
export function ChatButton() {
const [link, setLink] = useState<Link>();

useEffect(() => {
Expand All @@ -27,4 +27,4 @@ export const ChatButton = () => {
</a>
</div>
);
};
}
2 changes: 1 addition & 1 deletion ui/src/app/shared/components/links.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {ObjectMeta} from 'argo-ui/src/models/kubernetes';
import {useEffect, useState} from 'react';
import React = require('react');
import * as React from 'react';
import {Link, Workflow} from '../../../models';
import {services} from '../services';
import {Button} from './button';
Expand Down
2 changes: 1 addition & 1 deletion ui/src/app/shared/components/object-parser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import jsyaml = require('js-yaml');
import jsyaml from 'js-yaml';

export function parse<T>(value: string) {
if (value.startsWith('{')) {
Expand Down
2 changes: 1 addition & 1 deletion ui/src/app/shared/cron.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import parser = require('cron-parser');
import parser from 'cron-parser';

export function getNextScheduledTime(schedule: string, tz: string): Date {
let out: Date;
Expand Down
3 changes: 2 additions & 1 deletion ui/src/app/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"outDir": "./../../dist/app",
"sourceMap": true,
"noImplicitAny": true,
"module": "commonjs",
"module": "ES2020", // must be ES2020+ for dynamic imports: https://github.com/Microsoft/TypeScript/issues/16675, https://github.com/webpack/webpack/issues/5703#issuecomment-357512412
"moduleResolution": "node",
"esModuleInterop": true,
"target": "es5",
"jsx": "react",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';
import {useContext, useEffect, useState} from 'react';

import {Autocomplete} from 'argo-ui';
import moment = require('moment-timezone');
import moment from 'moment-timezone';
import {Observable} from 'rxjs';
import {map, publishReplay, refCount} from 'rxjs/operators';
import * as models from '../../../../models';
Expand Down

0 comments on commit 12c9aa2

Please sign in to comment.