Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ui): Added Sync failed filter option to Sync Status filters #21291

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {AppsListPreferences, services} from '../../../shared/services';
import {Filter, FiltersGroup} from '../filter/filter';
import * as LabelSelector from '../label-selector';
import {ComparisonStatusIcon, getAppDefaultSource, HealthStatusIcon} from '../utils';
import {COLORS} from '../../../shared/components';

export interface FilterResult {
repos: boolean;
Expand Down Expand Up @@ -35,7 +36,10 @@ export function getFilterResults(applications: Application[], pref: AppsListPref
...app,
filterResult: {
repos: pref.reposFilter.length === 0 || pref.reposFilter.includes(getAppDefaultSource(app).repoURL),
sync: pref.syncFilter.length === 0 || pref.syncFilter.includes(app.status.sync.status),
sync:
pref.syncFilter.length === 0 ||
pref.syncFilter.includes(app.status.sync.status) ||
(pref.syncFilter.includes('Sync failed') && app.status.operationState?.phase === 'Failed'),
autosync: pref.autoSyncFilter.length === 0 || pref.autoSyncFilter.includes(getAutoSyncStatus(app.spec.syncPolicy)),
health: pref.healthFilter.length === 0 || pref.healthFilter.includes(app.status.health.status),
namespaces: pref.namespacesFilter.length === 0 || pref.namespacesFilter.some(ns => app.spec.destination.namespace && minimatch(app.spec.destination.namespace, ns)),
Expand Down Expand Up @@ -96,22 +100,31 @@ const getOptions = (apps: FilteredApp[], filterType: keyof FilterResult, filter:
});
};

const SyncFilter = (props: AppFilterProps) => (
<Filter
label='SYNC STATUS'
selected={props.pref.syncFilter}
setSelected={s => props.onChange({...props.pref, syncFilter: s})}
options={getOptions(
props.apps,
'sync',
app => app.status.sync.status,
Object.keys(SyncStatuses),
s => (
<ComparisonStatusIcon status={s as SyncStatusCode} noSpin={true} />
)
)}
/>
);
const SyncFilter = (props: AppFilterProps) => {
const failedSyncOption = 'Sync failed';
const options = [...Object.keys(SyncStatuses), failedSyncOption];

// counts for sync statuses
const counts = getCounts(props.apps, 'sync', app => app.status.sync.status, options);

// counting failed operation phase separately
const failedCount = props.apps.filter(
app => app.status.operationState?.phase === 'Failed' && Object.keys(app.filterResult).every((key: keyof FilterResult) => key === 'sync' || app.filterResult[key])
).length;

const filterOptions = options.map(status => ({
label: status,
icon:
status === failedSyncOption ? (
<i className='fa fa-times-circle' title='Sync failed' style={{color: COLORS.operation.failed}} />
) : (
<ComparisonStatusIcon status={status as SyncStatusCode} noSpin={true} />
),
count: status === failedSyncOption ? failedCount : counts.get(status)
}));

return <Filter label='SYNC STATUS' selected={props.pref.syncFilter} setSelected={s => props.onChange({...props.pref, syncFilter: s})} options={filterOptions} />;
};

const HealthFilter = (props: AppFilterProps) => (
<Filter
Expand Down
Loading