Skip to content

Commit

Permalink
refactor(ui): use named functions for better tracing (#12062)
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 f26f5ee commit 5896f75
Show file tree
Hide file tree
Showing 27 changed files with 73 additions and 71 deletions.
4 changes: 2 additions & 2 deletions ui/src/app/app-router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const loginUrl = uiUrl('login');
const timelineUrl = uiUrl('timeline');
const reportsUrl = uiUrl('reports');

export const AppRouter = ({popupManager, history, notificationsManager}: {popupManager: PopupManager; history: H.History; notificationsManager: NotificationsManager}) => {
export function AppRouter({popupManager, history, notificationsManager}: {popupManager: PopupManager; history: H.History; notificationsManager: NotificationsManager}) {
const [popupProps, setPopupProps] = useState<PopupProps>();
const [modals, setModals] = useState<{string: boolean}>();
const [version, setVersion] = useState<Version>();
Expand Down Expand Up @@ -186,4 +186,4 @@ export const AppRouter = ({popupManager, history, notificationsManager}: {popupM
</Router>
</>
);
};
}
4 changes: 2 additions & 2 deletions ui/src/app/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {ContextApis, Provider} from './shared/context';

const history = createBrowserHistory();

export const App = () => {
export function App() {
const popupManager: PopupManager = new PopupManager();
const notificationsManager: NotificationsManager = new NotificationsManager();
const navigationManager: NavigationManager = new NavigationManager(history);
Expand All @@ -24,4 +24,4 @@ export const App = () => {
<AppRouter history={history} notificationsManager={notificationsManager} popupManager={popupManager} />
</Provider>
);
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {exampleClusterWorkflowTemplate} from '../../shared/examples';
import {services} from '../../shared/services';
import {ClusterWorkflowTemplateEditor} from './cluster-workflow-template-editor';

export const ClusterWorkflowTemplateCreator = ({onCreate}: {onCreate: (workflow: ClusterWorkflowTemplate) => void}) => {
export function ClusterWorkflowTemplateCreator({onCreate}: {onCreate: (workflow: ClusterWorkflowTemplate) => void}) {
const [template, setTemplate] = useState<ClusterWorkflowTemplate>(exampleClusterWorkflowTemplate());
const [error, setError] = useState<Error>();
return (
Expand All @@ -34,4 +34,4 @@ export const ClusterWorkflowTemplateCreator = ({onCreate}: {onCreate: (workflow:
</div>
</>
);
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {services} from '../../shared/services';
import {Utils} from '../../shared/utils';
import {CronWorkflowEditor} from './cron-workflow-editor';

export const CronWorkflowCreator = ({onCreate, namespace}: {namespace: string; onCreate: (cronWorkflow: CronWorkflow) => void}) => {
export function CronWorkflowCreator({onCreate, namespace}: {namespace: string; onCreate: (cronWorkflow: CronWorkflow) => void}) {
const [cronWorkflow, setCronWorkflow] = useState<CronWorkflow>(exampleCronWorkflow(Utils.getNamespaceWithDefault(namespace)));
const [error, setError] = useState<Error>();
return (
Expand All @@ -35,4 +35,4 @@ export const CronWorkflowCreator = ({onCreate, namespace}: {namespace: string; o
</p>
</>
);
};
}
6 changes: 3 additions & 3 deletions ui/src/app/cron-workflows/components/cron-workflow-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {ObjectEditor} from '../../shared/components/object-editor/object-editor'
import {CronWorkflowSpecEditor} from './cron-workflow-spec-editior';
import {CronWorkflowStatusViewer} from './cron-workflow-status-viewer';

export const CronWorkflowEditor = ({
export function CronWorkflowEditor({
selectedTabKey,
onTabSelected,
onError,
Expand All @@ -21,7 +21,7 @@ export const CronWorkflowEditor = ({
onError: (error: Error) => void;
onTabSelected?: (tab: string) => void;
selectedTabKey?: string;
}) => {
}) {
return (
<Tabs
key='tabs'
Expand Down Expand Up @@ -82,4 +82,4 @@ export const CronWorkflowEditor = ({
]}
/>
);
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {NumberInput} from '../../shared/components/number-input';
import {TextInput} from '../../shared/components/text-input';
import {ScheduleValidator} from './schedule-validator';

export const CronWorkflowSpecEditor = ({onChange, spec}: {spec: CronWorkflowSpec; onChange: (spec: CronWorkflowSpec) => void}) => {
export function CronWorkflowSpecEditor({onChange, spec}: {spec: CronWorkflowSpec; onChange: (spec: CronWorkflowSpec) => void}) {
return (
<div className='white-box'>
<div className='white-box__details'>
Expand Down Expand Up @@ -89,4 +89,4 @@ export const CronWorkflowSpecEditor = ({onChange, spec}: {spec: CronWorkflowSpec
</div>
</div>
);
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {ConditionsPanel} from '../../shared/conditions-panel';
import {WorkflowLink} from '../../workflows/components/workflow-link';
import {PrettySchedule} from './pretty-schedule';

export const CronWorkflowStatusViewer = ({spec, status}: {spec: CronWorkflowSpec; status: CronWorkflowStatus}) => {
export function CronWorkflowStatusViewer({spec, status}: {spec: CronWorkflowSpec; status: CronWorkflowStatus}) {
if (status === null) {
return null;
}
Expand Down Expand Up @@ -34,7 +34,7 @@ export const CronWorkflowStatusViewer = ({spec, status}: {spec: CronWorkflowSpec
</div>
</div>
);
};
}

function getCronWorkflowActiveWorkflowList(active: kubernetes.ObjectReference[]) {
return active.reverse().map(activeWf => <WorkflowLink key={activeWf.uid} namespace={activeWf.namespace} name={activeWf.name} />);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ import {icons as phaseIcons} from '../../../workflows/components/workflow-dag/ic
import {icons} from './icons';
import {ID} from './id';

const status = (r: {status?: {conditions?: Condition[]}}) => {
function status(r: {status?: {conditions?: Condition[]}}) {
if (!r.status || !r.status.conditions) {
return '';
}
if (!!r.status.conditions.find(c => c.status === 'False')) {
return 'Failed';
}
return !!r.status.conditions.find(c => c.status !== 'True') ? 'Pending' : 'Ready';
};
}

const numNodesToHide = 2;
export const buildGraph = (eventSources: EventSource[], sensors: Sensor[], workflows: Workflow[], flow: {[p: string]: {count: number; timeout?: any}}, expanded: boolean) => {
export function buildGraph(eventSources: EventSource[], sensors: Sensor[], workflows: Workflow[], flow: {[p: string]: {count: number; timeout?: any}}, expanded: boolean) {
const edgeLabel = (id: Node, label?: string) => (!!flow[id] ? (label || '') + ' (' + flow[id].count + ')' : label);
const edgeClassNames = (id: Node) => (!!flow[id] && flow[id].timeout ? 'flow' : '');
const graph = new Graph();
Expand Down Expand Up @@ -110,4 +110,4 @@ export const buildGraph = (eventSources: EventSource[], sensors: Sensor[], workf
});

return graph;
};
}
4 changes: 2 additions & 2 deletions ui/src/app/event-sources/components/event-source-creator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {services} from '../../shared/services';
import {Utils} from '../../shared/utils';
import {EventSourceEditor} from './event-source-editor';

export const EventSourceCreator = ({onCreate, namespace}: {namespace: string; onCreate: (eventSource: EventSource) => void}) => {
export function EventSourceCreator({onCreate, namespace}: {namespace: string; onCreate: (eventSource: EventSource) => void}) {
const [eventSource, setEventSource] = useState<EventSource>(exampleEventSource(Utils.getNamespaceWithDefault(namespace)));
const [error, setError] = useState<Error>();
return (
Expand All @@ -36,4 +36,4 @@ export const EventSourceCreator = ({onCreate, namespace}: {namespace: string; on
</p>
</>
);
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {EventsPanel} from '../../../workflows/components/events-panel';
import {EventSourceEditor} from '../event-source-editor';
import {EventSourceLogsViewer} from '../event-source-log-viewer';

export const EventSourceDetails = ({history, location, match}: RouteComponentProps<any>) => {
export function EventSourceDetails({history, location, match}: RouteComponentProps<any>) {
// boiler-plate
const {notifications, navigation, popup} = useContext(Context);
const queryParams = new URLSearchParams(location.search);
Expand Down Expand Up @@ -172,4 +172,4 @@ export const EventSourceDetails = ({history, location, match}: RouteComponentPro
</SlidingPanel>
</Page>
);
};
}
6 changes: 3 additions & 3 deletions ui/src/app/event-sources/components/event-source-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {EventSource} from '../../../models';
import {MetadataEditor} from '../../shared/components/editors/metadata-editor';
import {ObjectEditor} from '../../shared/components/object-editor/object-editor';

export const EventSourceEditor = ({
export function EventSourceEditor({
onChange,
onError,
onTabSelected,
Expand All @@ -17,7 +17,7 @@ export const EventSourceEditor = ({
onError: (error: Error) => void;
onTabSelected?: (tab: string) => void;
selectedTabKey?: string;
}) => {
}) {
return (
<Tabs
key='tabs'
Expand All @@ -39,4 +39,4 @@ export const EventSourceEditor = ({
]}
/>
);
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {EventSourceLogsViewer} from '../event-source-log-viewer';

const learnMore = <a href='https://argoproj.github.io/argo-events/concepts/event_source/'>Learn more</a>;

export const EventSourceList = ({match, location, history}: RouteComponentProps<any>) => {
export function EventSourceList({match, location, history}: RouteComponentProps<any>) {
// boiler-plate
const queryParams = new URLSearchParams(location.search);
const {navigation} = useContext(Context);
Expand Down Expand Up @@ -187,4 +187,4 @@ export const EventSourceList = ({match, location, history}: RouteComponentProps<
</SlidingPanel>
</Page>
);
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function identity<T>(value: T) {
return () => value;
}

export const EventSourceLogsViewer = ({
export function EventSourceLogsViewer({
namespace,
selectedEvent: selectedEvent,
eventSource,
Expand All @@ -22,7 +22,7 @@ export const EventSourceLogsViewer = ({
selectedEvent: string;
eventSource: EventSource;
onClick: (selectedNode: string) => void;
}) => {
}) {
const [error, setError] = useState<Error>();
const [logsObservable, setLogsObservable] = useState<Observable<string>>();
const [logLoaded, setLogLoaded] = useState(false);
Expand Down Expand Up @@ -106,4 +106,4 @@ export const EventSourceLogsViewer = ({
</div>
</div>
);
};
}
4 changes: 2 additions & 2 deletions ui/src/app/help/components/help.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {uiUrl} from '../../shared/base';
import {useCollectEvent} from '../../shared/components/use-collect-event';
require('./help.scss');

export const Help = () => {
export function Help() {
useCollectEvent('openedHelp');
return (
<Page title='Help'>
Expand Down Expand Up @@ -42,4 +42,4 @@ export const Help = () => {
</div>
</Page>
);
};
}
17 changes: 9 additions & 8 deletions ui/src/app/login/components/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,24 @@ import {useCollectEvent} from '../../shared/components/use-collect-event';

require('./login.scss');

const logout = () => {
function logout() {
document.cookie = 'authorization=;Max-Age=0';
document.location.reload();
};
const user = (token: string) => {
}
function user(token: string) {
const path = uiUrl('');
document.cookie = 'authorization=' + token + ';SameSite=Strict;path=' + path;
document.location.href = path;
};
const getRedirect = (): string => {
}
function getRedirect(): string {
const urlParams = new URLSearchParams(new URL(document.location.href).search);
if (urlParams.has('redirect')) {
return 'redirect=' + urlParams.get('redirect');
}
return 'redirect=' + window.location.origin + '/workflows';
};
export const Login = () => {
}

export function Login() {
useCollectEvent('openedLogin');
return (
<Page title='Login' toolbar={{breadcrumbs: [{title: 'Login'}]}}>
Expand Down Expand Up @@ -77,4 +78,4 @@ export const Login = () => {
</div>
</Page>
);
};
}
4 changes: 2 additions & 2 deletions ui/src/app/modals/modal-switch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {FirstTimeUserModal} from './first-time-user/first-time-user-modal';
import {NewVersionModal} from './new-version/new-version-modal';
import {majorMinor} from './version';

export const ModalSwitch = ({version, modals}: {version: string; modals: {[key: string]: boolean}}) => {
export function ModalSwitch({version, modals}: {version: string; modals: {[key: string]: boolean}}) {
const localStorage = new ScopedLocalStorage('modal');
const [ftu, setFtu] = useState<string>(localStorage.getItem('ftu', ''));
useEffect(() => localStorage.setItem('ftu', ftu, ''), [ftu]);
Expand All @@ -32,4 +32,4 @@ export const ModalSwitch = ({version, modals}: {version: string; modals: {[key:
return <NewVersionModal dismiss={() => setLastVersion(majorMinorVersion)} version={version} />;
}
return <></>;
};
}
4 changes: 2 additions & 2 deletions ui/src/app/plugins/components/plugin-list/plugin-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {ZeroState} from '../../../shared/components/zero-state';
import {historyUrl} from '../../../shared/history';
import {Utils} from '../../../shared/utils';

export const PluginList = ({match, history}: RouteComponentProps<any>) => {
export function PluginList({match, history}: RouteComponentProps<any>) {
// state for URL and query parameters
const [namespace] = useState(Utils.getNamespace(match.params.namespace) || '');
useEffect(
Expand Down Expand Up @@ -39,4 +39,4 @@ export const PluginList = ({match, history}: RouteComponentProps<any>) => {
</ZeroState>
</Page>
);
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {SensorSidePanel} from '../sensor-side-panel';

require('../../../workflows/components/workflow-details/workflow-details.scss');

export const SensorDetails = ({match, location, history}: RouteComponentProps<any>) => {
export function SensorDetails({match, location, history}: RouteComponentProps<any>) {
// boiler-plate
const {navigation, notifications, popup} = useContext(Context);
const queryParams = new URLSearchParams(location.search);
Expand Down Expand Up @@ -141,4 +141,4 @@ export const SensorDetails = ({match, location, history}: RouteComponentProps<an
)}
</Page>
);
};
}
4 changes: 2 additions & 2 deletions ui/src/app/shared/components/graph/label.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';

export const formatLabel = (label: string) => {
export function formatLabel(label: string) {
if (!label) {
return;
}
Expand Down Expand Up @@ -54,4 +54,4 @@ export const formatLabel = (label: string) => {
</tspan>
</>
);
};
}
4 changes: 2 additions & 2 deletions ui/src/app/shared/components/graph/pretty-layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as dagre from 'dagre';
import {Graph, Node} from './types';

const minSize = 1;
export const layoutGraphPretty = (graph: Graph, nodeSize: number, horizontal: boolean, hidden: (id: Node) => boolean) => {
export function layoutGraphPretty(graph: Graph, nodeSize: number, horizontal: boolean, hidden: (id: Node) => boolean) {
const gap = nodeSize * 1.25;
const g = new dagre.graphlib.Graph();
g.setGraph({rankdir: horizontal ? 'LR' : 'TB', ranksep: gap, nodesep: gap, edgesep: gap});
Expand Down Expand Up @@ -39,4 +39,4 @@ export const layoutGraphPretty = (graph: Graph, nodeSize: number, horizontal: bo
});
}
});
};
}
Loading

0 comments on commit 5896f75

Please sign in to comment.