Skip to content

Commit

Permalink
initial linting and isInvokedFromApp=false
Browse files Browse the repository at this point in the history
Signed-off-by: reggie <[email protected]>
  • Loading branch information
reggie-k committed Sep 29, 2023
1 parent 5202333 commit ff93e4c
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { ResourceDetails } from '../resource-details/resource-details';
import * as AppUtils from '../utils';
import { ApplicationResourceList } from './application-resource-list';
import { AbstractFiltersProps, Filters } from './application-resource-filter';
import { getAppDefaultSource, urlPattern, helpTip, isApp, isFromAppComponents } from '../utils';
import { getAppDefaultSource, urlPattern, helpTip, isApp, isInvokedFromApps } from '../utils';
import { ChartDetails, ResourceStatus } from '../../../shared/models';
import { ApplicationsDetailsAppDropdown } from './application-details-app-dropdown';
import { useSidebarTarget } from '../../../sidebar/sidebar';
Expand Down Expand Up @@ -152,7 +152,7 @@ export class ApplicationDetails extends React.Component<RouteComponentProps<{ ap
}

private getPageTitle(view: string) {
if (isFromAppComponents()) {
if (isInvokedFromApps()) {
const { Tree, Pods, Network, List } = AppsDetailsViewKey;
switch (view) {
case Tree:
Expand Down Expand Up @@ -182,8 +182,8 @@ export class ApplicationDetails extends React.Component<RouteComponentProps<{ ap
<ObservableQuery>
{q => (
<DataLoader
errorRenderer={error => <Page title={isFromAppComponents() ? 'Application Details' : 'ApplicationSet Details'}>{error}</Page>}
loadingRenderer={() => <Page title={isFromAppComponents() ? 'Application Details' : 'Application Set Details'}>Loading...</Page>}
errorRenderer={error => <Page title={isInvokedFromApps() ? 'Application Details' : 'ApplicationSet Details'}>{error}</Page>}
loadingRenderer={() => <Page title={isInvokedFromApps() ? 'Application Details' : 'Application Set Details'}>Loading...</Page>}
input={this.props.match.params.name}
load={name =>
combineLatest([this.loadAppInfo(name, this.appNamespace), services.viewPreferences.getPreferences(), q]).pipe(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { useSidebarTarget } from '../../../sidebar/sidebar';

import './applications-list.scss';
import './flex-top-bar.scss';
import { isApp, isFromAppComponents } from '../utils';
import { isApp, isInvokedFromApps } from '../utils';
import { AbstractApplication, Application, ApplicationSet } from '../../../shared/models';

const EVENTS_BUFFER_TIMEOUT = 500;
Expand Down Expand Up @@ -61,8 +61,8 @@ const APPSET_FIELDS = [
'spec',
];

const APP_LIST_FIELDS = AppUtils.isFromAppComponents() ? ['metadata.resourceVersion', ...APP_FIELDS.map(field => `items.${field}`)] : ['metadata.resourceVersion', ...APPSET_FIELDS.map(field => `items.${field}`)];
const APP_WATCH_FIELDS = AppUtils.isFromAppComponents() ? ['result.type', ...APP_FIELDS.map(field => `result.application.${field}`)] : ['result.type', ...APPSET_FIELDS.map(field => `result.application.${field}`)];
const APP_LIST_FIELDS = AppUtils.isInvokedFromApps() ? ['metadata.resourceVersion', ...APP_FIELDS.map(field => `items.${field}`)] : ['metadata.resourceVersion', ...APPSET_FIELDS.map(field => `items.${field}`)];
const APP_WATCH_FIELDS = AppUtils.isInvokedFromApps() ? ['result.type', ...APP_FIELDS.map(field => `result.application.${field}`)] : ['result.type', ...APPSET_FIELDS.map(field => `result.application.${field}`)];

function loadApplications(projects: string[], appNamespace: string): Observable<models.AbstractApplication[]> {
return from(services.applications.list(projects, { appNamespace, fields: APP_LIST_FIELDS })).pipe(
Expand Down Expand Up @@ -100,7 +100,7 @@ function loadApplications(projects: string[], appNamespace: string): Observable<
})
)
.pipe(filter(item => item.updated))
.pipe(map(item => isFromAppComponents() ? item.applications as models.Application[] : item.applications as models.ApplicationSet[]))
.pipe(map(item => isInvokedFromApps() ? item.applications as models.Application[] : item.applications as models.ApplicationSet[]))
);
})
);
Expand All @@ -115,7 +115,7 @@ const ViewPref = ({ children }: { children: (pref: AbstractAppsListPreferences &
map(items => {
const params = items[1];
const viewPref: AbstractAppsListPreferences = { ...items[0] };
if (isFromAppComponents()) {
if (isInvokedFromApps()) {
// App specific filters
// TODO: the knowledge about what is relevant for Apps and what for AppSets should be elsewhere and not here
if (params.get('proj') != null) {
Expand Down Expand Up @@ -183,7 +183,7 @@ const ViewPref = ({ children }: { children: (pref: AbstractAppsListPreferences &
function filterApps(applications: AbstractApplication[], pref: AbstractAppsListPreferences, search: string): { filteredApps: AbstractApplication[]; filterResults: AbstractFilteredApp[] } {
applications = applications.map(app => {
let isAppOfAppsPattern = false;
if (!isFromAppComponents()) { // AppSet behaves like an app of apps
if (!isInvokedFromApps()) { // AppSet behaves like an app of apps
isAppOfAppsPattern = true;
}
else { // It is an App and may or may not be app-of-apps pattern
Expand All @@ -196,7 +196,7 @@ function filterApps(applications: AbstractApplication[], pref: AbstractAppsListP
}
return { ...app, isAppOfAppsPattern };
});
const filterResults = isFromAppComponents() ? getFilterResults(applications as Application[], pref as AppsListPreferences) : getFilterResults(applications as ApplicationSet[], pref as AppSetsListPreferences);
const filterResults = isInvokedFromApps() ? getFilterResults(applications as Application[], pref as AppsListPreferences) : getFilterResults(applications as ApplicationSet[], pref as AppSetsListPreferences);
return {
filterResults,
filteredApps: filterResults.filter(
Expand Down Expand Up @@ -225,7 +225,7 @@ const SearchBar = (props: { content: string; ctx: ContextApis; apps: models.Abst
const [isFocused, setFocus] = React.useState(false);
const useAuthSettingsCtx = React.useContext(AuthSettingsCtx);

const placeholderText = isFromAppComponents() ? 'Search applications...' : 'Search application sets...'
const placeholderText = isInvokedFromApps() ? 'Search applications...' : 'Search application sets...'

useKeybinding({
keys: Key.SLASH,
Expand Down Expand Up @@ -367,20 +367,20 @@ export const ApplicationsList = (props: RouteComponentProps<{}>) => {
'.',

{
proj: isFromAppComponents() ? (newPref as AppsListPreferences).projectsFilter.join(',') : '',
sync: isFromAppComponents() ? (newPref as AppsListPreferences).syncFilter.join(',') : '',
autoSync: isFromAppComponents() ? (newPref as AppsListPreferences).autoSyncFilter.join(',') : '',
proj: isInvokedFromApps() ? (newPref as AppsListPreferences).projectsFilter.join(',') : '',
sync: isInvokedFromApps() ? (newPref as AppsListPreferences).syncFilter.join(',') : '',
autoSync: isInvokedFromApps() ? (newPref as AppsListPreferences).autoSyncFilter.join(',') : '',
health: newPref.healthFilter.join(','),
namespace: isFromAppComponents() ? (newPref as AppsListPreferences).namespacesFilter.join(',') : '',
cluster: isFromAppComponents() ? (newPref as AppsListPreferences).clustersFilter.join(',') : '',
namespace: isInvokedFromApps() ? (newPref as AppsListPreferences).namespacesFilter.join(',') : '',
cluster: isInvokedFromApps() ? (newPref as AppsListPreferences).clustersFilter.join(',') : '',
labels: newPref.labelsFilter.map(encodeURIComponent).join(',')
},
{ replace: true }

);
}

const pageTitlePrefix = isFromAppComponents() ? "Applications " : "ApplicationSets "
const pageTitlePrefix = isInvokedFromApps() ? "Applications " : "ApplicationSets "

function getPageTitle(view: string) {
switch (view) {
Expand All @@ -397,7 +397,7 @@ export const ApplicationsList = (props: RouteComponentProps<{}>) => {

const sidebarTarget = useSidebarTarget();

const getEmptyStateText = isFromAppComponents() ? 'No matching applications found' : 'No matching application sets found'
const getEmptyStateText = isInvokedFromApps() ? 'No matching applications found' : 'No matching application sets found'

const applicationTilesProps = (ctx: ContextApis, data: models.Application[]): ApplicationTilesProps => {
return {
Expand Down Expand Up @@ -429,7 +429,7 @@ export const ApplicationsList = (props: RouteComponentProps<{}>) => {
}

function getProjectsFilter(pref: AbstractAppsListPreferences): string[] {
return isFromAppComponents() ? (pref as AppsListPreferences & { page: number, search: string }).projectsFilter : []
return isInvokedFromApps() ? (pref as AppsListPreferences & { page: number, search: string }).projectsFilter : []
}

return (
Expand All @@ -443,20 +443,20 @@ export const ApplicationsList = (props: RouteComponentProps<{}>) => {
key={pref.view}
title={getPageTitle(pref.view)}
useTitleOnly={true}
toolbar={isFromAppComponents() ? { breadcrumbs: [{ title: 'Applications', path: '/applications' }] } : { breadcrumbs: [{ title: 'Settings', path: '/settings' }, { title: 'ApplicationSets' }] }}
toolbar={isInvokedFromApps() ? { breadcrumbs: [{ title: 'Applications', path: '/applications' }] } : { breadcrumbs: [{ title: 'Settings', path: '/settings' }, { title: 'ApplicationSets' }] }}
hideAuth={true}>
<DataLoader
input={isFromAppComponents() ? (pref as AppsListPreferences & { page: number, search: string }).projectsFilter?.join(',') : ''}
input={isInvokedFromApps() ? (pref as AppsListPreferences & { page: number, search: string }).projectsFilter?.join(',') : ''}
ref={loaderRef}
load={() => AppUtils.handlePageVisibility(() => loadApplications(isFromAppComponents() ? (pref as AppsListPreferences & { page: number, search: string }).projectsFilter : [], query.get('appNamespace')))}
load={() => AppUtils.handlePageVisibility(() => loadApplications(isInvokedFromApps() ? (pref as AppsListPreferences & { page: number, search: string }).projectsFilter : [], query.get('appNamespace')))}
loadingRenderer={() => (
<div className='argo-container'>
<MockupList height={100} marginTop={30} />
</div>
)}>
{(applications: models.AbstractApplication[]) => {
const healthBarPrefs = pref.statusBarView || ({} as HealthStatusBarPreferences);
const { filteredApps, filterResults } = filterApps(isFromAppComponents() ? applications as Application[] : applications as ApplicationSet[], isFromAppComponents() ? (pref as AppsListPreferences & { page: number, search: string }) : (pref as AppSetsListPreferences & { page: number, search: string }), pref.search);
const { filteredApps, filterResults } = filterApps(isInvokedFromApps() ? applications as Application[] : applications as ApplicationSet[], isInvokedFromApps() ? (pref as AppsListPreferences & { page: number, search: string }) : (pref as AppSetsListPreferences & { page: number, search: string }), pref.search);
return (
<React.Fragment>
<FlexTopBar
Expand Down Expand Up @@ -558,7 +558,7 @@ export const ApplicationsList = (props: RouteComponentProps<{}>) => {
<ApplicationsFilter
apps={filterResults}
onChange={newPrefs => onFilterPrefChanged(ctx, newPrefs)}
pref={isFromAppComponents() ? pref as AppsListPreferences & { page: number; search: string; } : pref as AppSetsListPreferences}
pref={isInvokedFromApps() ? pref as AppsListPreferences & { page: number; search: string; } : pref as AppSetsListPreferences}
collapsed={allpref.hideSidebar}
/>
)}
Expand All @@ -579,7 +579,7 @@ export const ApplicationsList = (props: RouteComponentProps<{}>) => {
Change filter criteria or&nbsp;
<a
onClick={() => {
if (isFromAppComponents()) {
if (isInvokedFromApps()) {
AppsListPreferences.clearFilters(pref as AppsListPreferences & { page: number; search: string; });
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Consumer } from '../../../shared/context';
import * as models from '../../../shared/models';

import './applications-status-bar.scss';
import { getAppSetHealthStatus, isFromAppComponents } from '../utils';
import { getAppSetHealthStatus, isInvokedFromApps } from '../utils';
import { Application, ApplicationSet } from '../../../shared/models';

export interface ApplicationsStatusBarProps {
Expand All @@ -14,7 +14,7 @@ export interface ApplicationsStatusBarProps {

export const ApplicationsStatusBar = ({ applications }: ApplicationsStatusBarProps) => {
const readings: any[] = [];
if (isFromAppComponents()) {
if (isInvokedFromApps()) {
readings.push({
name: 'Healthy',
value: applications.filter(app => (app as Application).status.health.status === 'Healthy').length,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const PieChart = require('react-svg-piechart').default;
import { COLORS } from '../../../shared/components';
import * as models from '../../../shared/models';
import { Application, ApplicationSet, HealthStatusCode, SyncStatusCode } from '../../../shared/models';
import { ComparisonStatusIcon, HealthStatusIcon, getAppSetHealthStatus, isFromAppComponents } from '../utils';
import { ComparisonStatusIcon, HealthStatusIcon, getAppSetHealthStatus, isInvokedFromApps } from '../utils';

const healthColors = new Map<models.HealthStatusCode, string>();
healthColors.set('Unknown', COLORS.health.unknown);
Expand All @@ -29,15 +29,15 @@ export const ApplicationsSummary = ({ applications }: { applications: models.Abs
const health = new Map<string, number>();

// if (isApp(applications[0])) {
if (isFromAppComponents()) {
if (isInvokedFromApps()) {
applications.forEach(app => sync.set((app as Application).status.sync.status, (sync.get((app as Application).status.sync.status) || 0) + 1));
applications.forEach(app => health.set((app as Application).status.health.status, (health.get((app as Application).status.health.status) || 0) + 1));
}
else {
applications.forEach(app => health.set(getAppSetHealthStatus((app as ApplicationSet).status), (health.get(getAppSetHealthStatus((app as ApplicationSet).status)) || 0) + 1));
}

const attributes = isFromAppComponents() ? ([{
const attributes = isInvokedFromApps() ? ([{
title: 'APPLICATIONS',
value: applications.length
},
Expand Down Expand Up @@ -69,7 +69,7 @@ export const ApplicationsSummary = ({ applications }: { applications: models.Abs



const charts = isFromAppComponents() ? ([
const charts = isInvokedFromApps() ? ([
{
title: 'Sync',
data: Array.from(sync.keys()).map(key => ({ title: key, value: sync.get(key), color: syncColors.get(key as models.SyncStatusCode) })),
Expand Down Expand Up @@ -123,7 +123,7 @@ export const ApplicationsSummary = ({ applications }: { applications: models.Abs
<ul>
{Array.from(chart.legend.keys()).map(key => (
<li style={{ listStyle: 'none', whiteSpace: 'nowrap' }} key={key}>
{isFromAppComponents() && chart.title === 'Health' && <HealthStatusIcon state={{ status: key as HealthStatusCode, message: '' }} noSpin={true} />}
{isInvokedFromApps() && chart.title === 'Health' && <HealthStatusIcon state={{ status: key as HealthStatusCode, message: '' }} noSpin={true} />}
{/* {chart.title === 'Health' && <AppSetHealthStatusIcon state={{conditions : key as ApplicationSetConditionStatus}} noSpin={true} />} */}
{chart.title === 'Sync' && <ComparisonStatusIcon status={key as SyncStatusCode} noSpin={true} />}
{` ${key} (${getLegendValue(key)})`}
Expand Down
4 changes: 2 additions & 2 deletions ui/src/app/applications/components/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1287,7 +1287,7 @@ export function isApp(abstractApp: appModels.AbstractApplication): abstractApp i
return abstractApp.kind === "Application";
}

export function isFromAppComponents(): boolean {
export function isInvokedFromApps(): boolean {
// console.log("*** ctx.history.location.pathname *** " + ctx.history.location.pathname)
const isInvokedFromApp = false //ctx.history.location.pathname.includes("applicationsets") ? true : false
return isInvokedFromApp
Expand All @@ -1307,7 +1307,7 @@ ctxh: ContextApis & {
*/

export function getRootPath(): string {
return isFromAppComponents() ? '/applications' : '/applicationsets'
return isInvokedFromApps() ? '/applications' : '/applicationsets'
}


Expand Down
Loading

0 comments on commit ff93e4c

Please sign in to comment.