Skip to content

Commit

Permalink
Merge pull request #7883 from invincibleJai/odc-5354
Browse files Browse the repository at this point in the history
Bug 1918318: show kameletbinding in eventsource list and filters
  • Loading branch information
openshift-merge-robot committed Jan 20, 2021
2 parents 16ef2d5 + 0a8770d commit 5daa524
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,25 +1,37 @@
import * as React from 'react';
import { useTranslation } from 'react-i18next';
import { useFlag } from '@console/shared';
import { MultiListPage } from '@console/internal/components/factory';
import { K8sResourceKind, referenceFor, referenceForModel } from '@console/internal/module/k8s';
import {
K8sResourceKind,
modelFor,
referenceFor,
referenceForModel,
} from '@console/internal/module/k8s';
import { RowFilter } from '@console/internal/components/filter-toolbar';
import EventSourceList from './EventSourceList';
import {
getDynamicEventSourceModel,
useEventSourceModels,
} from '../../../utils/fetch-dynamic-eventsources-utils';
import { CamelKameletBindingModel } from '../../../models';
import { FLAG_CAMEL_KAMELETS } from '../../../const';

const EventSourceListPage: React.FC<React.ComponentProps<typeof MultiListPage>> = (props) => {
const { t } = useTranslation();
const { loaded: modelsLoaded, eventSourceModels } = useEventSourceModels();
const isKameletEnabled = useFlag(FLAG_CAMEL_KAMELETS);
const sourcesModel = isKameletEnabled
? [...eventSourceModels, CamelKameletBindingModel]
: eventSourceModels;
const flatten = (resources) =>
modelsLoaded
? eventSourceModels.flatMap((model) => resources[referenceForModel(model)]?.data ?? [])
? sourcesModel.flatMap((model) => resources[referenceForModel(model)]?.data ?? [])
: [];
const resources = React.useMemo(
() =>
modelsLoaded
? eventSourceModels.map((model) => {
? sourcesModel.map((model) => {
const { namespaced } = model;

return {
Expand All @@ -31,11 +43,11 @@ const EventSourceListPage: React.FC<React.ComponentProps<typeof MultiListPage>>
};
})
: [],
[eventSourceModels, modelsLoaded],
[sourcesModel, modelsLoaded],
);
const getModelId = React.useCallback((obj: K8sResourceKind) => {
const reference = referenceFor(obj);
const model = getDynamicEventSourceModel(reference);
const model = getDynamicEventSourceModel(reference) || modelFor(reference);
return model.id;
}, []);

Expand All @@ -50,12 +62,12 @@ const EventSourceListPage: React.FC<React.ComponentProps<typeof MultiListPage>>
{
filterGroupName: 'Type',
type: 'event-source-type',
items: eventSourceModels.map(({ id, label }) => ({ id, title: label })),
items: sourcesModel.map(({ id, label }) => ({ id, title: label })),
reducer: getModelId,
filter: rowFilterReducer,
},
],
[eventSourceModels, getModelId, rowFilterReducer],
[sourcesModel, getModelId, rowFilterReducer],
);
return (
<MultiListPage
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import { TableRow, TableData, RowFunction } from '@console/internal/components/factory';
import { Kebab, ResourceKebab, ResourceLink, Timestamp } from '@console/internal/components/utils';
import { referenceFor } from '@console/internal/module/k8s';
import { modelFor, referenceFor } from '@console/internal/module/k8s';
import { NamespaceModel } from '@console/internal/models';
import { getDynamicEventSourceModel } from '../../../utils/fetch-dynamic-eventsources-utils';
import { EventSourceKind, EventSourceConditionTypes } from '../../../types';
Expand All @@ -12,7 +12,7 @@ const EventSourceRow: RowFunction<EventSourceKind> = ({ obj, index, key, style }
metadata: { name, namespace, creationTimestamp, uid },
} = obj;
const objReference = referenceFor(obj);
const kind = getDynamicEventSourceModel(objReference);
const kind = getDynamicEventSourceModel(objReference) || modelFor(objReference);
const menuActions = [...Kebab.getExtensionsActionsForKind(kind), ...Kebab.factory.common];
const readyCondition = obj.status
? getCondition(obj.status.conditions, EventSourceConditionTypes.Ready)
Expand Down

0 comments on commit 5daa524

Please sign in to comment.