Skip to content

Commit 2b59d07

Browse files
add button tables
1 parent 389b13a commit 2b59d07

File tree

2 files changed

+79
-12
lines changed

2 files changed

+79
-12
lines changed

src/components/tables/CellTable.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import React from 'react'
2+
import { CButton } from '@coreui/react'
3+
import { ModalService } from '../utilities'
4+
import { CBadge } from '@coreui/react'
5+
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
6+
import { faCheckCircle } from '@fortawesome/free-solid-svg-icons'
7+
import { cellGenericFormatter } from './CellGenericFormat'
8+
9+
export default function cellTable(row, column, propertyName) {
10+
const handleTable = ({ row }) => {
11+
const QueryColumns = []
12+
const columns = Object.keys(row[propertyName][0]).map((key) => {
13+
QueryColumns.push({
14+
name: key,
15+
selector: (row) => row[key], // Accessing the property using the key
16+
sortable: true,
17+
exportSelector: key,
18+
cell: cellGenericFormatter(),
19+
})
20+
})
21+
ModalService.open({
22+
data: row[propertyName],
23+
componentType: 'table',
24+
componentProps: {
25+
columns: QueryColumns,
26+
keyField: 'SKU',
27+
},
28+
title: `Data`,
29+
size: 'lg',
30+
})
31+
}
32+
33+
if (!row[propertyName] || !Array.isArray(row[propertyName]) || row.length === 0) {
34+
return <FontAwesomeIcon icon={faCheckCircle} className="text-success" />
35+
}
36+
37+
return (
38+
<CButton className="btn-danger" key={row} size="sm" onClick={() => handleTable({ row })}>
39+
{row[propertyName].length} Items
40+
</CButton>
41+
)
42+
}
43+
44+
export const cellTableFormatter = (propertyName) => (row, index, column, id) => {
45+
return cellTable(row, column, propertyName)
46+
}

src/views/tenant/standards/BestPracticeAnalyser.js

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
faExclamationTriangle,
2323
faCheck,
2424
} from '@fortawesome/free-solid-svg-icons'
25-
import { CippTable } from 'src/components/tables'
25+
import { CippTable, cellBooleanFormatter } from 'src/components/tables'
2626
import { useSelector } from 'react-redux'
2727
import { useNavigate } from 'react-router-dom'
2828
import { CippPage } from 'src/components/layout/CippPage'
@@ -32,6 +32,7 @@ import { queryString } from 'src/helpers'
3232
import { cellGenericFormatter } from 'src/components/tables/CellGenericFormat'
3333
import { useExecBestPracticeAnalyserMutation } from 'src/store/api/reports'
3434
import { ModalService } from 'src/components/utilities'
35+
import { cellTableFormatter } from 'src/components/tables/CellTable'
3536
const RefreshAction = () => {
3637
const [execBestPracticeAnalyser, { isLoading, isSuccess, error }] =
3738
useExecBestPracticeAnalyserMutation()
@@ -58,7 +59,7 @@ const RefreshAction = () => {
5859
)
5960
}
6061
const BestPracticeAnalyser = () => {
61-
const { data: templates = [] } = useGenericGetRequestQuery({
62+
const { data: templates = [], isLoading: templatesfetch } = useGenericGetRequestQuery({
6263
path: 'api/listBPATemplates',
6364
})
6465
let navigate = useNavigate()
@@ -102,18 +103,36 @@ const BestPracticeAnalyser = () => {
102103
return acc ? acc[part] : undefined
103104
}, obj)
104105
}
105-
106-
// Set columns
107106
const flatObj = graphrequest.data.Columns
108-
flatObj.map((col) =>
107+
108+
flatObj.map((col) => {
109+
// Determine the cell selector based on the 'formatter' property
110+
let cellSelector
111+
if (col.formatter) {
112+
switch (col.formatter) {
113+
case 'bool':
114+
cellSelector = cellBooleanFormatter()
115+
break
116+
case 'table':
117+
cellSelector = cellTableFormatter(col.value)
118+
break
119+
default:
120+
cellSelector = cellGenericFormatter()
121+
break
122+
}
123+
} else {
124+
cellSelector = cellGenericFormatter()
125+
}
126+
109127
QueryColumns.data.push({
110128
name: col.name,
111129
selector: (row) => getNestedValue(row, col.value),
112130
sortable: true,
113131
exportSelector: col.value,
114-
cell: cellGenericFormatter(),
115-
}),
116-
)
132+
cell: cellSelector, // Use the determined cell selector
133+
})
134+
})
135+
117136
QueryColumns.set = true
118137
}
119138

@@ -157,13 +176,14 @@ const BestPracticeAnalyser = () => {
157176
<RFFCFormSelect
158177
name="reportTemplate"
159178
label="Select a report"
160-
placeholder={'Select a report'}
179+
placeholder={templatesfetch ? 'Loading...' : 'Select a report'}
161180
values={templates.map((template) => ({
162181
label: template.Name,
163182
value: template.Name,
164183
}))}
165184
/>
166185
</CCol>
186+
{templatesfetch && <CSpinner />}
167187
</CRow>
168188
<CRow></CRow>
169189
<CRow className="mb-3">
@@ -187,11 +207,12 @@ const BestPracticeAnalyser = () => {
187207
<CRow>
188208
<CCol>
189209
<CippPage title="Report Results" tenantSelector={false}>
190-
{!SearchNow && <span>Choose a BPA Report to get started.</span>}
191-
{graphrequest.isSuccess && QueryColumns.set && SearchNow && (
210+
{graphrequest.isUninitialized && <span>Choose a BPA Report to get started.</span>}
211+
{graphrequest.isFetching && <CSpinner />}
212+
{graphrequest.isSuccess && QueryColumns.set && (
192213
<CCard className="content-card">
193214
<CCardHeader className="d-flex justify-content-between align-items-center">
194-
<CCardTitle>Results</CCardTitle>
215+
<CCardTitle>Best Practice Report</CCardTitle>
195216
</CCardHeader>
196217
<CCardBody>
197218
<CippTable

0 commit comments

Comments
 (0)