UNPKG

@focuson/form_components

Version:

Components that can be used by @focuson/forms

51 lines (50 loc) 3.87 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AllSummaryDetails = exports.SummaryDetailsPage = exports.SummaryTable = void 0; const jsx_runtime_1 = require("react/jsx-runtime"); const state_1 = require("@focuson/state"); function SummaryTable(props) { const { state, accountId, selectedItem, id } = props; // const AuthTable = rawTable<S, any, C> ( [ ...order, 'Halt' ], defaultOnClick ( props ), defaultOneRowWithGetValue ( getValueForAuthorisedTable ) ( id, order, [], haltBox ( state, id ) ) ) const data = state.optJsonOr([]); console.log('data', data, state.optional.description); console.log('state', state); // @ts-ignore const accId = accountId.optJson(); const dataForMyAccountIdThatIsntHeldAndIsACredit = data.filter(d => d.accountNo === accId && d.hold !== true && d.type === 'CR'); const initialValue = {}; const groups = dataForMyAccountIdThatIsntHeldAndIsACredit.reduce((groups, d) => { const chargeType = d.chargeType; const status = d.status; const key = status + "_" + chargeType; const existingAmount = groups[key]; const newAmount = Number.parseFloat(d.amount) + (existingAmount ? existingAmount : 0); groups[key] = newAmount; return groups; }, initialValue); console.log(groups); const tableLines = Object.entries(groups).map(([key, accAmount]) => { const index = key.indexOf("_"); const status = key.slice(0, index); //might be +/-1 on index const chargeType = key.slice(index + 1); //ditto return { status, chargeType, accAmount, accountId: accId }; }); const totalWaste = Object.values(groups).reduce((acc, v) => acc + v, 0); const onClick = (i) => (e) => { selectedItem.setJson(tableLines[i], (0, state_1.reasonFor)('SummaryDetailsPage', 'onClick', id, `selected row ${i}`)); }; return (0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("table", Object.assign({ className: 'grid' }, { children: (0, jsx_runtime_1.jsx)("tbody", Object.assign({ className: "grid-sub" }, { children: tableLines.map(({ status, chargeType, accAmount }, i) => (0, jsx_runtime_1.jsxs)("tr", Object.assign({ onClick: onClick(i) }, { children: [(0, jsx_runtime_1.jsx)("td", { children: chargeType }), (0, jsx_runtime_1.jsx)("td", { children: status }), (0, jsx_runtime_1.jsx)("td", { children: accAmount })] }), i)) })) })), (0, jsx_runtime_1.jsx)("label", { children: "Total Waste" }), (0, jsx_runtime_1.jsx)("input", { type: 'number', value: totalWaste, readOnly: true })] }); } exports.SummaryTable = SummaryTable; function SummaryDetailsPage({ id, state, selectedItem }) { const data = state.optJsonOr([]); const item = selectedItem.optJson(); const items = data.filter(d => item && d.hold !== true && d.accountNo === item.accountId && d.status === item.status && d.chargeType === item.chargeType); console.log('items', items); return (0, jsx_runtime_1.jsx)("div", { children: (0, jsx_runtime_1.jsx)("table", Object.assign({ className: 'grid' }, { children: (0, jsx_runtime_1.jsx)("tbody", Object.assign({ className: "grid-sub" }, { children: items.map(({ status, chargeType, amount }, i) => (0, jsx_runtime_1.jsxs)("tr", { children: [(0, jsx_runtime_1.jsx)("td", { children: chargeType }), (0, jsx_runtime_1.jsx)("td", { children: status }), (0, jsx_runtime_1.jsx)("td", { children: amount })] }, i)) })) })) }); } exports.SummaryDetailsPage = SummaryDetailsPage; function AllSummaryDetails(props) { return (0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)(SummaryTable, Object.assign({}, props, { id: `${props.id}.summaryTable` })), (0, jsx_runtime_1.jsx)(SummaryDetailsPage, Object.assign({}, props, { id: `${props.id}.summaryDetailsPage` }))] }); } exports.AllSummaryDetails = AllSummaryDetails;