generated from RedHatInsights/frontend-starter-app
-
Notifications
You must be signed in to change notification settings - Fork 43
/
Groups.js
154 lines (143 loc) · 5.23 KB
/
Groups.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import React, { useEffect, useState } from 'react';
import { Bullseye, Flex, Spinner } from '@patternfly/react-core';
import {
PageHeader,
PageHeaderTitle,
} from '@redhat-cloud-services/frontend-components/PageHeader';
import useChrome from '@redhat-cloud-services/frontend-components/useChrome';
import GroupTable from './GroupTable';
import Empty from '../../components/Empty';
import { getGroups } from '../../api/groups';
import CreateGroupModal from './CreateGroupModal';
import RenameGroupModal from './RenameGroupModal';
import DeleteGroupModal from './DeleteGroupModal';
import useApi from '../../hooks/useApi';
import { emptyStateNoFilters, useFeatureFlags } from '../../utils';
import PropTypes from 'prop-types';
import { useLocation } from 'react-router-dom';
import GroupsLinkAccess from './GroupsLinkAccess';
import useInventoryGroups from '../../hooks/useInventoryGroups';
// eslint-disable-next-line react/prop-types
const Groups = ({ locationProp, navigateProp, paramsProp }) => {
const hideCreateGroupsEnabled = useFeatureFlags(
'edge-management.hide-create-group'
);
const [inventoryGroupsEnabled, enforceEdgeGroupCheckReady] =
useInventoryGroups(false);
const { search } = locationProp ? locationProp() : useLocation();
const [response, fetchGroups] = useApi({
api: getGroups,
tableReload: true,
});
const chrome = useChrome();
const { data, isLoading, hasError } = response;
const [modalState, setModalState] = useState({ id: null, name: '' });
const [isCreateModalOpen, setIsCreateModalOpen] = useState(false);
const [isRenameModalOpen, setIsRenameModalOpen] = useState(false);
const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false);
const [hasModalSubmitted, setHasModalSubmitted] = useState(false);
const handleRenameModal = (id, name) => {
setModalState({ id, name });
setIsRenameModalOpen(true);
};
const handleDeleteModal = (id, name) => {
setModalState({ id, name });
setIsDeleteModalOpen(true);
};
const reloadData = async () => {
await fetchGroups();
setHasModalSubmitted(true);
};
useEffect(() => {
chrome?.updateDocumentTitle?.('Groups - Inventory');
}, [chrome]);
return (
<>
{!enforceEdgeGroupCheckReady ? (
<Bullseye>
<Spinner size="xl" />
</Bullseye>
) : inventoryGroupsEnabled ? (
<GroupsLinkAccess />
) : (
<>
<PageHeader className="pf-m-light">
<PageHeaderTitle title="Groups" />
</PageHeader>
<section className="edge-groups pf-l-page__main-section pf-c-page__main-section">
{!emptyStateNoFilters(isLoading, data?.count, search) ? (
<GroupTable
data={data?.data || []}
count={data?.count}
isLoading={isLoading}
hasError={hasError}
handleRenameModal={handleRenameModal}
locationProp={locationProp}
navigateProp={navigateProp}
paramsProp={paramsProp}
handleDeleteModal={handleDeleteModal}
handleCreateModal={() => setIsCreateModalOpen(true)}
hasModalSubmitted={hasModalSubmitted}
setHasModalSubmitted={setHasModalSubmitted}
fetchGroups={fetchGroups}
/>
) : (
<Flex justifyContent={{ default: 'justifyContentCenter' }}>
{hideCreateGroupsEnabled}?{}:
<Empty
icon="plus"
title="Create a system group"
body="Create system groups to help manage your systems more effectively."
primaryAction={{
text: 'Create group',
click: () => setIsCreateModalOpen(true),
}}
secondaryActions={[
{
type: 'link',
title: 'Learn more about system groups',
link: 'https://access.redhat.com/documentation/en-us/edge_management/2022/html-single/working_with_systems_in_the_edge_management_application/index',
},
]}
/>
{}
</Flex>
)}
</section>
{isCreateModalOpen && (
<CreateGroupModal
isModalOpen={isCreateModalOpen}
setIsModalOpen={setIsCreateModalOpen}
reloadData={reloadData}
/>
)}
{isRenameModalOpen && (
<RenameGroupModal
isModalOpen={isRenameModalOpen}
setIsModalOpen={setIsRenameModalOpen}
reloadData={reloadData}
modalState={modalState}
/>
)}
{isDeleteModalOpen && (
<DeleteGroupModal
isModalOpen={isDeleteModalOpen}
setIsModalOpen={setIsDeleteModalOpen}
reloadData={reloadData}
modalState={modalState}
/>
)}
</>
)}
</>
);
};
Groups.propTypes = {
pathPrefix: PropTypes.string,
historyProp: PropTypes.func,
locationProp: PropTypes.func,
navigateProp: PropTypes.func,
notificationProp: PropTypes.object,
paramsProp: PropTypes.func,
};
export default Groups;