support filter in HomePageVisitedByType
Signed-off-by: shmaram <shaharshmaram@gmail.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-home': minor
|
||||
---
|
||||
|
||||
Added filter support for HomePageVisitedByType in order to enable filtering entites from the list
|
||||
@@ -117,6 +117,25 @@ describe('<Content kind="recent"/>', () => {
|
||||
expect(container.querySelectorAll('li')[0]).toBeVisible();
|
||||
expect(container.querySelectorAll('li')[1]).not.toBeVisible();
|
||||
});
|
||||
|
||||
it('allows items to be filtered', async () => {
|
||||
const { getByText, queryByText } = await renderInTestApp(
|
||||
<TestApiProvider apis={[[visitsApiRef, mockVisitsApi]]}>
|
||||
<ContextProvider>
|
||||
<Content
|
||||
kind="recent"
|
||||
filterBy={[
|
||||
{ field: 'pathname', operator: '==', value: '/explore' },
|
||||
]}
|
||||
/>
|
||||
</ContextProvider>
|
||||
</TestApiProvider>,
|
||||
);
|
||||
await waitFor(() =>
|
||||
expect(getByText('Explore Backstage')).toBeInTheDocument(),
|
||||
);
|
||||
await waitFor(() => expect(queryByText('Tech Radar')).toBeNull());
|
||||
});
|
||||
});
|
||||
|
||||
describe('<Content kind="top"/>', () => {
|
||||
|
||||
@@ -31,6 +31,11 @@ export type VisitedByTypeProps = {
|
||||
numVisitsTotal?: number;
|
||||
loading?: boolean;
|
||||
kind: VisitedByTypeKind;
|
||||
filterBy?: Array<{
|
||||
field: keyof Visit;
|
||||
operator: '<' | '<=' | '==' | '!=' | '>' | '>=' | 'contains';
|
||||
value: string | number;
|
||||
}>;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -43,6 +48,7 @@ export const Content = ({
|
||||
numVisitsTotal,
|
||||
loading,
|
||||
kind,
|
||||
filterBy,
|
||||
}: VisitedByTypeProps) => {
|
||||
const { setContext, setVisits, setLoading } = useContext();
|
||||
// Allows behavior override from properties
|
||||
@@ -65,18 +71,34 @@ export const Content = ({
|
||||
const { loading: reqLoading } = useAsync(async () => {
|
||||
if (!visits && !loading && kind === 'recent') {
|
||||
return await visitsApi
|
||||
.list({
|
||||
limit: numVisitsTotal ?? 8,
|
||||
orderBy: [{ field: 'timestamp', direction: 'desc' }],
|
||||
})
|
||||
.list(
|
||||
filterBy
|
||||
? {
|
||||
limit: numVisitsTotal ?? 8,
|
||||
orderBy: [{ field: 'timestamp', direction: 'desc' }],
|
||||
filterBy,
|
||||
}
|
||||
: {
|
||||
limit: numVisitsTotal ?? 8,
|
||||
orderBy: [{ field: 'timestamp', direction: 'desc' }],
|
||||
},
|
||||
)
|
||||
.then(setVisits);
|
||||
}
|
||||
if (!visits && !loading && kind === 'top') {
|
||||
return await visitsApi
|
||||
.list({
|
||||
limit: numVisitsTotal ?? 8,
|
||||
orderBy: [{ field: 'hits', direction: 'desc' }],
|
||||
})
|
||||
.list(
|
||||
filterBy
|
||||
? {
|
||||
limit: numVisitsTotal ?? 8,
|
||||
orderBy: [{ field: 'hits', direction: 'desc' }],
|
||||
filterBy,
|
||||
}
|
||||
: {
|
||||
limit: numVisitsTotal ?? 8,
|
||||
orderBy: [{ field: 'hits', direction: 'desc' }],
|
||||
},
|
||||
)
|
||||
.then(setVisits);
|
||||
}
|
||||
return undefined;
|
||||
|
||||
Reference in New Issue
Block a user