Skip to content

Commit 3c6fa80

Browse files
Merge pull request #1761 from johnduprey/dev
CippTable - Graph filter rewrite
2 parents 8fd42f3 + 6924f35 commit 3c6fa80

File tree

4 files changed

+84
-105
lines changed

4 files changed

+84
-105
lines changed

src/components/tables/CippTable.js

Lines changed: 78 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useRef } from 'react'
1+
import React, { useRef, useMemo, useState } from 'react'
22
import { useSelector } from 'react-redux'
33
import { ExportCsvButton, ExportPDFButton } from 'src/components/buttons'
44
import {
@@ -25,16 +25,9 @@ import { cellGenericFormatter } from './CellGenericFormat'
2525
import { ModalService } from '../utilities'
2626
import { useLazyGenericGetRequestQuery, useLazyGenericPostRequestQuery } from 'src/store/api/app'
2727
import { ConfirmModal } from '../utilities/SharedModal'
28-
import { useState } from 'react'
28+
import { debounce } from 'lodash'
2929

30-
const FilterComponent = ({
31-
filterText,
32-
onFilter,
33-
onClear,
34-
filterlist,
35-
onFilterPreset,
36-
onFilterGraph,
37-
}) => (
30+
const FilterComponent = ({ filterText, onFilter, onClear, filterlist, onFilterPreset }) => (
3831
<>
3932
<CInputGroup>
4033
<CDropdown variant="input-group">
@@ -50,26 +43,17 @@ const FilterComponent = ({
5043
<CDropdownItem
5144
onClick={() => {
5245
onFilterPreset('')
53-
onFilterGraph('')
5446
}}
5547
>
5648
Clear Filter
5749
</CDropdownItem>
5850
{filterlist &&
5951
filterlist.map((item, idx) => {
60-
if (item.hasOwnProperty('graphFilter') && item.graphFilter == true) {
61-
return (
62-
<CDropdownItem key={idx} onClick={() => onFilterGraph(item.filter)}>
63-
{item.filterName}
64-
</CDropdownItem>
65-
)
66-
} else {
67-
return (
68-
<CDropdownItem key={idx} onClick={() => onFilterPreset(item.filter)}>
69-
{item.filterName}
70-
</CDropdownItem>
71-
)
72-
}
52+
return (
53+
<CDropdownItem key={idx} onClick={() => onFilterPreset(item.filter)}>
54+
{item.filterName}
55+
</CDropdownItem>
56+
)
7357
})}
7458
</CDropdownMenu>
7559
</CDropdown>
@@ -93,7 +77,6 @@ FilterComponent.propTypes = {
9377
onClear: PropTypes.func,
9478
filterlist: PropTypes.arrayOf(PropTypes.object),
9579
onFilterPreset: PropTypes.func,
96-
onFilterGraph: PropTypes.func,
9780
}
9881

9982
const customSort = (rows, selector, direction) => {
@@ -204,8 +187,23 @@ export default function CippTable({
204187
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
205188
}
206189

190+
const setGraphFilter = (e) => {
191+
if (graphFilterFunction) {
192+
graphFilterFunction(e)
193+
console.log(e)
194+
}
195+
}
196+
197+
const debounceSetGraphFilter = useMemo(() => {
198+
return debounce(setGraphFilter, 1000)
199+
}, [])
200+
207201
const filterData = (data, filterText) => {
208-
if (filterText.startsWith('Complex:')) {
202+
if (filterText.startsWith('Graph:')) {
203+
var query = filterText.slice(6).trim()
204+
debounceSetGraphFilter(query)
205+
return data
206+
} else if (filterText.startsWith('Complex:')) {
209207
const conditions = filterText.slice(9).split(';')
210208

211209
return conditions.reduce((filteredData, condition) => {
@@ -262,12 +260,6 @@ export default function CippTable({
262260
setFilterText(e.target.value)
263261
}
264262

265-
const setGraphFilter = (e) => {
266-
if (graphFilterFunction) {
267-
graphFilterFunction(e)
268-
}
269-
}
270-
271263
useEffect(() => {
272264
if (columns !== updatedColumns) {
273265
setUpdatedColumns(columns)
@@ -592,11 +584,6 @@ export default function CippTable({
592584
onFilter={(e) => setFilterText(e.target.value)}
593585
onFilterPreset={(e) => {
594586
setFilterText(e)
595-
setGraphFilter('')
596-
}}
597-
onFilterGraph={(e) => {
598-
setFilterText('')
599-
setGraphFilter(e)
600587
}}
601588
onClear={handleClear}
602589
filterText={filterText}
@@ -620,65 +607,61 @@ export default function CippTable({
620607
const tablePageSize = useSelector((state) => state.app.tablePageSize)
621608
return (
622609
<div className="ms-n3 me-n3 cipp-tablewrapper">
623-
{!isFetching && error && <span>Error loading data</span>}
624-
{!error && (
625-
<div>
626-
{(columns.length === updatedColumns.length || !dynamicColumns) && (
627-
<>
628-
{(massResults.length >= 1 || loopRunning) && (
629-
<CCallout color="info">
630-
{massResults.map((message, idx) => {
631-
const results = message.data?.Results
632-
const displayResults = Array.isArray(results) ? results.join(', ') : results
610+
{!isFetching && error && <CCallout color="info">Error loading data</CCallout>}
611+
<div>
612+
{(columns.length === updatedColumns.length || !dynamicColumns) && (
613+
<>
614+
{(massResults.length >= 1 || loopRunning) && (
615+
<CCallout color="info">
616+
{massResults.map((message, idx) => {
617+
const results = message.data?.Results
618+
const displayResults = Array.isArray(results) ? results.join(', ') : results
633619

634-
return <li key={`message-${idx}`}>{displayResults}</li>
635-
})}
636-
{loopRunning && (
637-
<li>
638-
<CSpinner size="sm" />
639-
</li>
640-
)}
641-
</CCallout>
642-
)}
643-
<DataTable
644-
customStyles={customStyles}
645-
className="cipp-table"
646-
theme={theme}
647-
subHeader={subheader}
648-
selectableRows={selectableRows}
649-
onSelectedRowsChange={
650-
onSelectedRowsChange ? onSelectedRowsChange : handleSelectedChange
651-
}
652-
subHeaderComponent={subHeaderComponentMemo}
653-
subHeaderAlign="left"
654-
paginationResetDefaultPage={resetPaginationToggle}
655-
//actions={actionsMemo}
656-
pagination={pagination}
657-
responsive={responsive}
658-
dense={dense}
659-
striped={striped}
660-
columns={columns}
661-
data={filteredItems}
662-
expandableRows={expandableRows}
663-
expandableRowsComponent={expandableRowsComponent}
664-
highlightOnHover={highlightOnHover}
665-
expandOnRowClicked={expandOnRowClicked}
666-
defaultSortAsc
667-
defaultSortFieldId={1}
668-
sortFunction={customSort}
669-
paginationPerPage={tablePageSize}
670-
progressPending={isFetching}
671-
progressComponent={<CSpinner color="info" component="div" />}
672-
paginationRowsPerPageOptions={[25, 50, 100, 200, 500]}
673-
{...rest}
674-
/>
675-
{selectedRows.length >= 1 && (
676-
<CCallout>Selected {selectedRows.length} items</CCallout>
677-
)}
678-
</>
679-
)}
680-
</div>
681-
)}
620+
return <li key={`message-${idx}`}>{displayResults}</li>
621+
})}
622+
{loopRunning && (
623+
<li>
624+
<CSpinner size="sm" />
625+
</li>
626+
)}
627+
</CCallout>
628+
)}
629+
<DataTable
630+
customStyles={customStyles}
631+
className="cipp-table"
632+
theme={theme}
633+
subHeader={subheader}
634+
selectableRows={selectableRows}
635+
onSelectedRowsChange={
636+
onSelectedRowsChange ? onSelectedRowsChange : handleSelectedChange
637+
}
638+
subHeaderComponent={subHeaderComponentMemo}
639+
subHeaderAlign="left"
640+
paginationResetDefaultPage={resetPaginationToggle}
641+
//actions={actionsMemo}
642+
pagination={pagination}
643+
responsive={responsive}
644+
dense={dense}
645+
striped={striped}
646+
columns={columns}
647+
data={filteredItems}
648+
expandableRows={expandableRows}
649+
expandableRowsComponent={expandableRowsComponent}
650+
highlightOnHover={highlightOnHover}
651+
expandOnRowClicked={expandOnRowClicked}
652+
defaultSortAsc
653+
defaultSortFieldId={1}
654+
sortFunction={customSort}
655+
paginationPerPage={tablePageSize}
656+
progressPending={isFetching}
657+
progressComponent={<CSpinner color="info" component="div" />}
658+
paginationRowsPerPageOptions={[25, 50, 100, 200, 500]}
659+
{...rest}
660+
/>
661+
{selectedRows.length >= 1 && <CCallout>Selected {selectedRows.length} items</CCallout>}
662+
</>
663+
)}
664+
</div>
682665
</div>
683666
)
684667
}

src/views/identity/administration/Users.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -356,13 +356,11 @@ const Users = (row) => {
356356
{ filterName: 'Users without a license', filter: '"assignedLicenses":[]' },
357357
{
358358
filterName: 'Users with a license (Graph)',
359-
filter: 'assignedLicenses/$count ne 0',
360-
graphFilter: true,
359+
filter: 'Graph: assignedLicenses/$count ne 0',
361360
},
362361
{
363362
filterName: 'Users with a license & Enabled (Graph)',
364-
filter: 'assignedLicenses/$count ne 0 and accountEnabled eq true',
365-
graphFilter: true,
363+
filter: 'Graph: assignedLicenses/$count ne 0 and accountEnabled eq true',
366364
},
367365
],
368366
columns,

src/views/tenant/administration/ListEnterpriseApps.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ const EnterpriseApplications = () => {
7575
selector: (row) => row.homepage,
7676
sortable: true,
7777
exportSelector: 'homepage',
78-
cell: cellDateFormatter({ format: 'short' }),
7978
},
8079
]
8180
return (
@@ -88,13 +87,12 @@ const EnterpriseApplications = () => {
8887
filterlist: [
8988
{
9089
filterName: 'All Enterprise Apps',
91-
filter: "tags/any(t:t eq 'WindowsAzureActiveDirectoryIntegratedApp')",
92-
graphFilter: true,
90+
filter: "Graph: tags/any(t:t eq 'WindowsAzureActiveDirectoryIntegratedApp')",
9391
},
9492
{
9593
filterName: 'Enterprise Apps (SAML)',
96-
filter: "tags/any(t:t eq 'WindowsAzureActiveDirectoryGalleryApplicationPrimaryV1')",
97-
graphFilter: true,
94+
filter:
95+
"Graph: tags/any(t:t eq 'WindowsAzureActiveDirectoryGalleryApplicationPrimaryV1')",
9896
},
9997
],
10098
tableProps: {

src/views/tenant/administration/ListGDAPRelationships.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ const Actions = (row, rowIndex, formatExtraData) => {
6868
})
6969
const tenant = useSelector((state) => state.app.currentTenant)
7070

71-
row?.accessDetails.unifiedRoles.map((role) => {
71+
row?.accessDetails?.unifiedRoles?.map((role) => {
7272
for (var x = 0; x < GDAPRoles.length; x++) {
7373
if (GDAPRoles[x].ObjectId == role.roleDefinitionId) {
7474
extendedInfo.push({

0 commit comments

Comments
 (0)