Skip to content

Commit ac48265

Browse files
authored
Add offline filters (#1505)
* feat(online-offline): Online Offline in progress * fix(online-offline): Change text * fix(query): Simplify query * fix(build): Build UI * fix(create-quest): Hide filter from create quest
1 parent e9db24d commit ac48265

File tree

16 files changed

+229
-99
lines changed

16 files changed

+229
-99
lines changed

tavern/internal/www/build/asset-manifest.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tavern/internal/www/build/index.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tavern/internal/www/build/static/js/main.46704686.js renamed to tavern/internal/www/build/static/js/main.050eee30.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tavern/internal/www/build/static/js/main.46704686.js.LICENSE.txt renamed to tavern/internal/www/build/static/js/main.050eee30.js.LICENSE.txt

File renamed without changes.

tavern/internal/www/build/static/js/main.46704686.js.map renamed to tavern/internal/www/build/static/js/main.050eee30.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tavern/internal/www/src/components/beacon-filter-bar/BeaconFilterBar.tsx

Lines changed: 45 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,47 +7,56 @@ type Props = {
77
filtersSelected?: any;
88
initialFilters?: any;
99
isDisabled?: boolean;
10+
hideStatusFilter?: boolean; // Some views may default to only online hosts/beacons
1011
}
1112
export const BeaconFilterBar = (props: Props) => {
1213
const { data } = useTags();
13-
const { beacons, groupTags, serviceTags, hosts, principals, primaryIPs, platforms, transports } = data;
14+
const { beacons, groupTags, serviceTags, hosts, principals, primaryIPs, platforms, transports, onlineOfflineStatus } = data;
1415

15-
const { setFiltersSelected, filtersSelected, isDisabled, initialFilters } = props;
16+
const { setFiltersSelected, filtersSelected, isDisabled, initialFilters, hideStatusFilter } = props;
1617

17-
const options = useMemo(() => [
18-
{
19-
label: "Platform",
20-
options: platforms
21-
},
22-
{
23-
label: "Transport",
24-
options: transports
25-
},
26-
{
27-
label: "Service",
28-
options: serviceTags
29-
},
30-
{
31-
label: "Group",
32-
options: groupTags
33-
},
34-
{
35-
label: "Principal",
36-
options: principals
37-
},
38-
{
39-
label: "PrimaryIPs",
40-
options: primaryIPs
41-
},
42-
{
43-
label: "Host",
44-
options: hosts
45-
},
46-
{
47-
label: "Beacon",
48-
options: beacons
49-
}
50-
], [platforms, serviceTags, groupTags, principals, primaryIPs, hosts, beacons]);
18+
const options = useMemo(() => {
19+
const allOptions = [
20+
{
21+
label: "Platform",
22+
options: platforms
23+
},
24+
{
25+
label: "Transport",
26+
options: transports
27+
},
28+
...!hideStatusFilter ? [{
29+
label: "Status",
30+
options: onlineOfflineStatus
31+
}] : [],
32+
{
33+
label: "Service",
34+
options: serviceTags
35+
},
36+
{
37+
label: "Group",
38+
options: groupTags
39+
},
40+
{
41+
label: "Principal",
42+
options: principals
43+
},
44+
{
45+
label: "PrimaryIPs",
46+
options: primaryIPs
47+
},
48+
{
49+
label: "Host",
50+
options: hosts
51+
},
52+
{
53+
label: "Beacon",
54+
options: beacons
55+
}
56+
];
57+
58+
return allOptions;
59+
}, [platforms, serviceTags, groupTags, principals, primaryIPs, hosts, beacons, transports, onlineOfflineStatus, hideStatusFilter]);
5160

5261

5362
return (

tavern/internal/www/src/context/TagContext.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,20 @@ import { GET_TAG_FILTERS } from "../utils/queries";
44
import { BeaconEdge, BeaconNode, HostEdge, HostNode, TagContextQueryResponse, TagEdge, TagNode } from "../utils/interfacesQuery";
55
import { FilterBarOption, TagContextProps } from "../utils/interfacesUI";
66
import { SupportedPlatforms, SupportedTransports } from "../utils/enums";
7+
import { OnlineOfflineOptions } from "../utils/utils";
78

89
type TagContextType = {
910
data: TagContextProps;
1011
isLoading: boolean;
1112
error: ApolloError | undefined;
13+
lastFetchedTimestamp: Date;
1214
};
1315

1416
export const TagContext = createContext<TagContextType | undefined>(undefined);
1517

1618
export const TagContextProvider = ({ children }: { children: React.ReactNode }) => {
19+
const [lastFetchedTimestamp, setLastFetchedTimestamp] = useState<Date>(new Date());
20+
1721
const [tags, setTags] = useState<TagContextProps>({
1822
beacons: [],
1923
groupTags: [],
@@ -23,6 +27,7 @@ export const TagContextProvider = ({ children }: { children: React.ReactNode })
2327
primaryIPs: [],
2428
platforms: [],
2529
transports: [],
30+
onlineOfflineStatus: [],
2631
});
2732

2833
const PARAMS = {
@@ -137,7 +142,8 @@ export const TagContextProvider = ({ children }: { children: React.ReactNode })
137142
principals,
138143
primaryIPs,
139144
platforms,
140-
transports
145+
transports,
146+
onlineOfflineStatus: OnlineOfflineOptions
141147
};
142148
setTags(tags);
143149
}, []);
@@ -152,12 +158,13 @@ export const TagContextProvider = ({ children }: { children: React.ReactNode })
152158
useEffect(() => {
153159
if (data) {
154160
getTags(data)
161+
setLastFetchedTimestamp(new Date());
155162
}
156163
}, [data, getTags])
157164

158165

159166
return (
160-
<TagContext.Provider value={{ data: tags, isLoading, error }}>
167+
<TagContext.Provider value={{ data: tags, isLoading, error, lastFetchedTimestamp }}>
161168
{children}
162169
</TagContext.Provider>
163170
);

tavern/internal/www/src/pages/create-quest/components/BeaconStep.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ const BeaconStep = (props: Props) => {
9797
<StackItem>
9898
<div className="grid grid-cols-1 md:grid-cols-3 gap-4">
9999
<div className="col-span-1 md:col-span-2">
100-
<BeaconFilterBar initialFilters={typeFilters} setFiltersSelected={setTypeFilters} />
100+
<BeaconFilterBar initialFilters={typeFilters} setFiltersSelected={setTypeFilters} hideStatusFilter={true} />
101101
</div>
102102
<div className="flex-1 flex flex-col gap-2">
103103
<div className="flex flex-row-reverse md:flex-row gap-1 justify-end">

tavern/internal/www/src/pages/host-details/useHostTasks.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,18 @@ import { useFilters } from "../../context/FilterContext";
66
import { constructHostTaskFilterQuery } from "../../utils/constructQueryUtils";
77
import { Cursor } from "../../utils/interfacesQuery";
88
import { useSorts } from "../../context/SortContext";
9+
import { useTags } from "../../context/TagContext";
910

1011
export const useHostTasks = (id?: string) => {
1112
const [page, setPage] = useState<number>(1);
1213
const {filters} = useFilters();
1314
const { sorts } = useSorts();
15+
const {lastFetchedTimestamp} = useTags();
1416
const taskSort = sorts[PageNavItem.tasks];
1517

1618
const constructDefaultQuery = useCallback((afterCursor?: Cursor, beforeCursor?: Cursor) => {
1719
const defaultRowLimit = TableRowLimit.TaskRowLimit;
18-
const filterQueryFields = (filters && filters.filtersEnabled) && constructHostTaskFilterQuery(filters);
20+
const filterQueryFields = (filters && filters.filtersEnabled) && constructHostTaskFilterQuery(filters, lastFetchedTimestamp);
1921

2022
const query = {
2123
"where": {
@@ -34,7 +36,7 @@ export const useHostTasks = (id?: string) => {
3436
} as any;
3537

3638
return query;
37-
},[id, filters, taskSort]);
39+
},[id, filters, taskSort, lastFetchedTimestamp]);
3840

3941

4042
const { loading, error, data, refetch} = useQuery(GET_TASK_QUERY, {variables: constructDefaultQuery(), notifyOnNetworkStatusChange: true});

tavern/internal/www/src/pages/host-list/useHosts.ts

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { Filters, useFilters } from "../../context/FilterContext";
66
import { constructBeaconFilterQuery, } from "../../utils/constructQueryUtils";
77
import { Cursor, HostQueryTopLevel, OrderByField } from "../../utils/interfacesQuery";
88
import { useSorts } from "../../context/SortContext";
9+
import { useTags } from "../../context/TagContext";
910

1011
interface HostsHook {
1112
data: HostQueryTopLevel
@@ -20,11 +21,12 @@ export const useHosts = (pagination: boolean, id?: string): HostsHook => {
2021
const [page, setPage] = useState<number>(1);
2122
const {filters} = useFilters();
2223
const {sorts} = useSorts();
24+
const {lastFetchedTimestamp} = useTags();
2325
const hostSort = sorts[PageNavItem.hosts];
2426

2527
const constructDefaultQuery = useCallback((afterCursor?: Cursor, beforeCursor?: Cursor) => {
26-
return getDefaultHostQuery(pagination, afterCursor, beforeCursor, id, filters, hostSort);
27-
},[pagination, id, filters, hostSort]);
28+
return getDefaultHostQuery(pagination, afterCursor, beforeCursor, id, filters, hostSort, lastFetchedTimestamp);
29+
},[pagination, id, filters, hostSort, lastFetchedTimestamp]);
2830

2931
const { loading, data, error, refetch } = useQuery(
3032
GET_HOST_QUERY, {variables: constructDefaultQuery(), notifyOnNetworkStatusChange: true}
@@ -59,28 +61,20 @@ export const useHosts = (pagination: boolean, id?: string): HostsHook => {
5961
}
6062
};
6163

62-
const getDefaultHostQuery = (pagination: boolean, afterCursor?: Cursor, beforeCursor?: Cursor, id?: string | undefined, filters?: Filters, sort?: OrderByField) => {
64+
const getDefaultHostQuery = (pagination: boolean, afterCursor?: Cursor, beforeCursor?: Cursor, id?: string | undefined, filters?: Filters, sort?: OrderByField, currentTimestamp?: Date) => {
6365
const defaultRowLimit = TableRowLimit.HostRowLimit;
64-
const filterInfo = (filters && filters.filtersEnabled) && constructBeaconFilterQuery(filters.beaconFields);
66+
const filterInfo = (filters && filters.filtersEnabled) && constructBeaconFilterQuery(filters.beaconFields, currentTimestamp);
6567

66-
const hasBeaconsWithFilter: Record<string, any> = {};
67-
if (filterInfo) {
68-
if (filterInfo.hasBeaconWith.nameIn) {
69-
hasBeaconsWithFilter.nameIn = filterInfo.hasBeaconWith.nameIn;
70-
}
71-
if (filterInfo.hasBeaconWith.principalIn) {
72-
hasBeaconsWithFilter.principalIn = filterInfo.hasBeaconWith.principalIn;
73-
}
74-
if (filterInfo.hasBeaconWith.transportIn) {
75-
hasBeaconsWithFilter.transportIn = filterInfo.hasBeaconWith.transportIn;
76-
}
77-
}
68+
// Separate host fields from beacon fields
69+
const hostFields = (filterInfo && filterInfo.hasBeaconWith?.hasHostWith) || {};
70+
const beaconFields = (filterInfo && filterInfo.hasBeaconWith) ? { ...filterInfo.hasBeaconWith } : {};
71+
delete beaconFields.hasHostWith; // Remove host fields from beacon fields
7872

7973
const query = {
8074
"where": {
8175
...id && {"id": id},
82-
...filterInfo && filterInfo.hasBeaconWith.hasHostWith,
83-
...(Object.keys(hasBeaconsWithFilter).length > 0) && {"hasBeaconsWith": hasBeaconsWithFilter},
76+
...hostFields,
77+
...(Object.keys(beaconFields).length > 0) && {"hasBeaconsWith": beaconFields}
8478
},
8579
...(sort && {orderBy: [sort]})
8680
} as any;

0 commit comments

Comments
 (0)