Appwrite Dart Runtime [Error] Message: An internal curl error has occurred within the executor! Error Msg: Operation timed out - appwrite

I have appwrite dart function dart-2.17 hosted locally, when function is created using appwrite init function and immediately deploy & execute with out any changes appwrite deploy function
it all works fine. But now when i do the following code it always return an execution timeout error, (does not matter if i add try/catch block)
#.env (from appwrite function settings console)
APPWRITE_FUNCTION_ENDPOINT=http://localhost/v1
APPWRITE_FUNCTION_API_KEY=%MyKey%
#functions/Create Company/lib/main.dart
import 'dart:convert';
import 'package:dart_appwrite/dart_appwrite.dart';
/*
'req' variable has:
'headers' - object with request headers
'payload' - request body data as a string
'variables' - object with function variables
'res' variable has:
'send(text, status: status)' - function to return text response. Status code defaults to 200
'json(obj, status: status)' - function to return JSON response. Status code defaults to 200
If an error is thrown, a response with code 500 will be returned.
*/
Future<void> start(final req, final res) async {
final client = Client();
final database = Databases(client);
final teams = Teams(client);
if (req.variables['APPWRITE_FUNCTION_ENDPOINT'] == null || req.variables['APPWRITE_FUNCTION_API_KEY'] == null) {
res.send('Endpoint is not yet Configred', 500);
return;
}
client
.setEndpoint(req.variables['APPWRITE_FUNCTION_ENDPOINT'])
.setProject(req.variables['APPWRITE_FUNCTION_PROJECT_ID'])
.setKey(req.variables['APPWRITE_FUNCTION_API_KEY'])
.setSelfSigned(status: true);
print(req.payload);
final data = jsonDecode(req.payload);
print(data);
print('checking data');
final applicationModalAccess = data['applicationModalAccess'];
if (applicationModalAccess is! String) {
res.send('field "applicationModalAccess" is suppose to be string 0-32', 400);
return;
}
String redirectUrl;
try {
final appModal = await database.getDocument(databaseId: 'STORE', collectionId: 'APPLICATION-MODALS', documentId: applicationModalAccess);
redirectUrl = appModal.data['redirectUrl'];
} catch (err) {
res.send('field "applicationModalAccess" as not a valid id', 404);
return;
}
final companyName = data['companyName'];
if (companyName is! String || !RegExp(r'^[a-zA-Z0-9.\-_\(\)]{5,50}$').hasMatch(companyName)) {
res.send('field "companyName" is suppose to be string of length 5-50', 400);
return;
}
final ownerEmail = data['ownerEmail'];
if (ownerEmail is! String || !RegExp(r"^[a-zA-Z0-9.a-zA-Z0-9.!#$%&'*+-/=?^_`{|}~]+#[a-zA-Z0-9]+\.[a-zA-Z]+").hasMatch(ownerEmail)) {
res.send('field "ownerEmail" is suppose to be email formated string', 400);
return;
}
final ownerName = data['ownerName'];
if (ownerName is! String || !RegExp('^[A-Za-z0-9]{5,20}\$').hasMatch(ownerName)) {
res.send('field "ownerName" is suppose to be string of length 5-20', 400);
return;
}
print('creating team');
final team = await teams.create(teamId: ID.unique(), name: companyName, roles: []);
final companyID = team.$id;
print('creating database');
await database.create(databaseId: companyID, name: '$companyName(STANDARD)');
print('setting up products collection');
final productPermission = [
Permission.read(Role.team(companyID)),
Permission.create(Role.team(companyID, 'OWNER')),
Permission.update(Role.team(companyID, 'OWNER')),
Permission.create(Role.team(companyID, 'PRODUCT-CREATE')),
Permission.update(Role.team(companyID, 'PRODUCT-UPDATE'))
];
await database.createCollection(databaseId: companyID, collectionId: 'PRODUCTS', name: 'Products', permissions: productPermission, documentSecurity: false);
await database.createStringAttribute(databaseId: companyID, collectionId: 'PRODUCTS', key: 'name', size: 25, xrequired: true);
await database.createUrlAttribute(databaseId: companyID, collectionId: 'PRODUCTS', key: 'imgUrl', xrequired: false);
await database.createStringAttribute(databaseId: companyID, collectionId: 'PRODUCTS', key: 'measurmentUnit', size: 10, xrequired: true);
await database.createStringAttribute(databaseId: companyID, collectionId: 'PRODUCTS', key: 'selectionCode', size: 5, xrequired: false);
await database.createStringAttribute(databaseId: companyID, collectionId: 'PRODUCTS', key: 'selectionType', size: 15, xrequired: false);
await database.createStringAttribute(databaseId: companyID, collectionId: 'PRODUCTS', key: 'selection1DBarCode', size: 30, xrequired: false);
await database.createIntegerAttribute(databaseId: companyID, collectionId: 'PRODUCTS', key: 'sgst', xrequired: false, xdefault: 0, min: 0, max: 10000);
await database.createIntegerAttribute(databaseId: companyID, collectionId: 'PRODUCTS', key: 'cgst', xrequired: false, xdefault: 0, min: 0, max: 10000);
await database.createStringAttribute(databaseId: companyID, collectionId: 'PRODUCTS', key: 'hsn', size: 10, xrequired: false);
await database.createIndex(databaseId: companyID, collectionId: 'PRODUCTS', key: '\$updatedAt', type: 'key', attributes: ['\$updatedAt']);
await database.createCollection(databaseId: companyID, collectionId: 'DELETED-PRODUCTS', name: 'Deleted Products', permissions: [Permission.read(Role.team(companyID))], documentSecurity: false);
await database.createStringAttribute(databaseId: companyID, collectionId: 'DELETED-PRODUCTS', key: 'deletedBy', size: 15, xrequired: true);
await database.createIndex(databaseId: companyID, collectionId: 'DELETED-PRODUCTS', key: '\$updatedAt', type: 'key', attributes: ['\$updatedAt']);
print('setting up branches collection');
final branchPermission = [
Permission.read(Role.team(companyID)),
Permission.create(Role.team(companyID, 'OWNER')),
Permission.update(Role.team(companyID, 'OWNER')),
Permission.create(Role.team(companyID, 'BRANCH-CREATE')),
Permission.update(Role.team(companyID, 'BRANCH-UPDATE'))
];
await database.createCollection(databaseId: companyID, collectionId: 'BRANCHES', name: 'Branches', permissions: branchPermission, documentSecurity: false);
await database.createStringAttribute(databaseId: companyID, collectionId: 'BRANCHES', key: 'name', size: 25, xrequired: true);
await database.createStringAttribute(databaseId: companyID, collectionId: 'BRANCHES', key: 'type', size: 10, xrequired: false);
await database.createCollection(databaseId: companyID, collectionId: 'DELETED-BRANCHES', name: 'Deleted Branches', permissions: [Permission.read(Role.team(companyID))], documentSecurity: false);
await database.createStringAttribute(databaseId: companyID, collectionId: 'DELETED-BRANCHES', key: 'deletedBy', size: 15, xrequired: true);
await database.createIndex(databaseId: companyID, collectionId: 'DELETED-BRANCHES', key: '\$updatedAt', type: 'key', attributes: ['\$updatedAt']);
print('setting up inventory');
final inventoryPermissions = [Permission.read(Role.team(companyID, 'OWNER')), Permission.read(Role.team(companyID, 'READ-ALL-INVENTORY'))];
await database.createStringAttribute(databaseId: companyID, collectionId: 'INVENTORY', key: 'productID', size: 32, xrequired: true);
await database.createStringAttribute(databaseId: companyID, collectionId: 'INVENTORY', key: 'branchID', size: 32, xrequired: true);
await database.createCollection(databaseId: companyID, collectionId: 'INVENTORY', name: 'Inventory', permissions: inventoryPermissions, documentSecurity: true);
await database.createIntegerAttribute(databaseId: companyID, collectionId: 'INVENTORY', key: 'quantity', xrequired: true);
await database.createIndex(databaseId: companyID, collectionId: 'INVENTORY', key: '\$updatedAt', type: 'key', attributes: ['\$updatedAt']);
await database.createIndex(databaseId: companyID, collectionId: 'INVENTORY', key: 'uniqueID', type: 'unique', attributes: ['productID', 'branchID']);
print('setting up other companies');
final otherCompaniesPermissions = [
Permission.read(Role.team(companyID)),
Permission.create(Role.team(companyID, 'OWNER')),
Permission.update(Role.team(companyID, 'OWNER')),
Permission.create(Role.team(companyID, 'OTHER-COMPANY-MANAGER')),
Permission.update(Role.team(companyID, 'OTHER-COMPANY-MANAGER')),
];
await database.createCollection(databaseId: companyID, collectionId: 'OTHER-COMPANIES', name: 'Other Companies', permissions: otherCompaniesPermissions, documentSecurity: false);
await database.createStringAttribute(databaseId: companyID, collectionId: 'OTHER-COMPANIES', key: 'name', size: 15, xrequired: true);
await database.createUrlAttribute(databaseId: companyID, collectionId: 'OTHER-COMPANIES', key: 'imgUrl', xrequired: false);
await database.createStringAttribute(databaseId: companyID, collectionId: 'OTHER-COMPANIES', key: 'phone', size: 15, xrequired: false);
await database.createEmailAttribute(databaseId: companyID, collectionId: 'OTHER-COMPANIES', key: 'email', xrequired: false);
await database.createStringAttribute(databaseId: companyID, collectionId: 'OTHER-COMPANIES', key: 'branchIDs', size: 15, xrequired: true, array: true);
await database.createIndex(databaseId: companyID, collectionId: 'OTHER-COMPANIES', key: '\$updatedAt', type: 'key', attributes: ['\$updatedAt']);
await database.createIndex(databaseId: companyID, collectionId: 'OTHER-COMPANIES', key: 'email', type: 'fulltext', attributes: ['email']);
await database.createIndex(databaseId: companyID, collectionId: 'OTHER-COMPANIES', key: 'phone', type: 'fulltext', attributes: ['phone']);
await database.createCollection(databaseId: companyID, collectionId: 'DELETED-COMPANIES', name: 'Deleted Branches', permissions: [Permission.read(Role.team(companyID))], documentSecurity: false);
await database.createStringAttribute(databaseId: companyID, collectionId: 'DELETED-COMPANIES', key: 'deletedBy', size: 15, xrequired: true);
await database.createIndex(databaseId: companyID, collectionId: 'DELETED-COMPANIES', key: '\$updatedAt', type: 'key', attributes: ['\$updatedAt']);
print('setting up product rates');
final productRatesPermissions = [
Permission.read(Role.team(companyID, 'OWNER')),
Permission.write(Role.team(companyID, 'OWNER')),
Permission.read(Role.team(companyID, 'OTHER-PRODUCT-MANAGER')),
Permission.create(Role.team(companyID, 'OTHER-PRODUCT-MANAGER')),
Permission.update(Role.team(companyID, 'OTHER-PRODUCT-MANAGER')),
Permission.read(Role.team(companyID, 'READ-ALL-PRODUCT-RATES'))
];
await database.createCollection(databaseId: companyID, collectionId: 'PRODUCT-RATES', name: 'Company Rates', permissions: productRatesPermissions, documentSecurity: true);
await database.createStringAttribute(databaseId: companyID, collectionId: 'PRODUCT-RATES', key: 'productID', size: 32, xrequired: true);
await database.createStringAttribute(databaseId: companyID, collectionId: 'PRODUCT-RATES', key: 'branchID', size: 32, xrequired: false, xdefault: '*');
await database.createStringAttribute(databaseId: companyID, collectionId: 'PRODUCT-RATES', key: 'companyID', size: 32, xrequired: false, xdefault: '*');
await database.createStringAttribute(databaseId: companyID, collectionId: 'PRODUCT-RATES', key: 'type', size: 10, xrequired: false, xdefault: '*');
await database.createIntegerAttribute(databaseId: companyID, collectionId: 'PRODUCT-RATES', key: 'aboveCondition', xrequired: false, min: 0, xdefault: 0);
await database.createIntegerAttribute(databaseId: companyID, collectionId: 'PRODUCT-RATES', key: 'rate', xrequired: true);
await database.createIndex(databaseId: companyID, collectionId: 'PRODUCT-RATES', key: '\$updatedAt', type: 'key', attributes: ['\$updatedAt']);
await database.createIndex(databaseId: companyID, collectionId: 'PRODUCT-RATES', key: 'aboveCondition', type: 'key', attributes: ['aboveCondition']);
await database.createIndex(databaseId: companyID, collectionId: 'PRODUCT-RATES', key: 'uniqueID', type: 'unique', attributes: ['productID', 'branchID', 'companyID', 'type']);
print('setting up due money');
final dueMoneyPermissions = [Permission.read(Role.team(companyID, 'OWNER')), Permission.read(Role.team(companyID, 'READ-ALL-DUE-MONEY'))];
await database.createCollection(databaseId: companyID, collectionId: 'DUE-MONEY', name: 'Due Money', permissions: dueMoneyPermissions, documentSecurity: true);
await database.createStringAttribute(databaseId: companyID, collectionId: 'DUE-MONEY', key: 'branchID', size: 32, xrequired: true);
await database.createStringAttribute(databaseId: companyID, collectionId: 'DUE-MONEY', key: 'companyID', size: 32, xrequired: true);
await database.createIntegerAttribute(databaseId: companyID, collectionId: 'DUE-MONEY', key: 'dueMoney', xrequired: true);
await database.createIndex(databaseId: companyID, collectionId: 'DUE-MONEY', key: '\$updatedAt', type: 'key', attributes: ['\$updatedAt']);
await database.createIndex(databaseId: companyID, collectionId: 'DUE-MONEY', key: 'uniqueID', type: 'unique', attributes: ['branchID', 'companyID']);
print('setting up customers');
await database.createCollection(databaseId: companyID, collectionId: 'CUSTOMER', name: 'Customer', permissions: [Permission.read(Role.team(companyID))], documentSecurity: false);
await database.createStringAttribute(databaseId: companyID, collectionId: 'CUSTOMER', key: 'name', size: 15, xrequired: false);
await database.createStringAttribute(databaseId: companyID, collectionId: 'CUSTOMER', key: 'phone', size: 15, xrequired: false);
await database.createEmailAttribute(databaseId: companyID, collectionId: 'CUSTOMER', key: 'email', xrequired: false);
await database.createStringAttribute(databaseId: companyID, collectionId: 'CUSTOMER', key: 'address', size: 20, xrequired: false, array: true);
await database.createStringAttribute(databaseId: companyID, collectionId: 'CUSTOMER', key: 'branchIDs', size: 15, xrequired: true, array: true);
await database.createIndex(databaseId: companyID, collectionId: 'CUSTOMER', key: 'email', type: 'fulltext', attributes: ['email']);
await database.createIndex(databaseId: companyID, collectionId: 'CUSTOMER', key: 'phone', type: 'fulltext', attributes: ['phone']);
print('setting up company prefrences');
await database.createCollection(databaseId: companyID, collectionId: 'PREFRENCES', name: 'Prefrences', documentSecurity: false);
await database.createStringAttribute(databaseId: companyID, collectionId: 'PREFRENCES', key: 'value', size: 100, xrequired: true);
print('creating company document in global database');
final now = DateTime.now().toIso8601String();
final companyStoreDoc = {"type": 'STANDARD', "name": companyName, "inventoryUpdatedAt": now, "dewMoneyUpdateAt": now, "customersUpdatedAt": now, "applicationModalAccess": applicationModalAccess};
await database.createDocument(databaseId: 'STORE', collectionId: 'COMPANIES', documentId: companyID, data: companyStoreDoc, permissions: [Permission.read(Role.team(companyID))]);
print('setting up company owner');
await teams.createMembership(teamId: companyID, email: ownerEmail, roles: ['OWNER'], url: redirectUrl);
res.send('Company was successfully created under "$companyID" ID', 201);
}
#functions/Create Company/lib/pubspec.yaml
name: appwrite_function
description: Dart starter for Appwrite function.
version: 1.0.0
publish_to: 'none'
environment:
sdk: '>=2.17.0 <3.0.0'
dependencies:
convert: ^3.1.0
dart_appwrite: ^7.1.0
dev_dependencies:
lints: ^2.0.1
#appwrite.json
{
"projectId": "63c4397e307e9341d13e",
"projectName": "Local Market",
"functions": [
{
"$id": "63de1a41cb003b045a4d",
"name": "Create Company",
"runtime": "dart-2.17",
"path": "functions/Create Company",
"entrypoint": "lib/main.dart",
"ignore": [
".packages",
".dart_tool"
],
"execute": [],
"events": [],
"schedule": "",
"timeout": 60
}
]
}
#http://localhost/console/project-63c4397e307e9341d13e/functions/function-63de1a41cb003b045a4d/executions
# execution, Response & Logs both tabs are empty
#Errors tab
An internal curl error has occurred within the executor! Error Msg: Operation timed out
#docker logs appwrite-executor
#last few lines are (including deploy & execution)
...other logs
Building container : 63c4397e307e9341d13e-63de2755b59b086677d6
Build Stage completed in 1 seconds
Executing Runtime: 63c4397e307e9341d13e-63de2755b59b086677d6
[Error] Type: Exception
[Error] Message: An internal curl error has occurred within the executor! Error Msg: Operation timed out
[Error] File: /usr/src/code/app/executor.php
[Error] Line: 544
How do i resolve this???

This error typically happens because an exception is thrown in your Function. I highly recommend wrapping your code in a try/catch and calling res.json({'error': error.toString()}) in the catch to return the error to the Appwrite Console.
In addition, it looks like you're using http://localhost/v1 in your Function. This won't work because your Function will try to connect to itself rather than Appwrite. You can try using your LAN IP instead.
Reference: Functions Docs

Related

Consumption of an api data into ant-design table react-typescript

interface DataType {
id: string;
first_name: string;
last_name: string;
email: string;
phone: string;
ip_address: string;
is_active: Boolean;
Avatar: string;
}
const columns: ColumnsType<DataType> = [
{
title: 'First Name',
dataIndex: 'first_name',
key: 'first_name',
render: (first_name, data) => {
return (
<div>
<img className='customers-avatar' src={data.Avatar} alt="" />
{first_name}
</div>
)
},
},
{
title: 'Last Name',
dataIndex: 'last_name',
key: 'last_name',
},
{
title: 'Email Address',
dataIndex: 'email',
key: 'email',
},
{
title: 'Phone Number',
dataIndex: 'phone',
key: 'phone',
},
{
title: 'Last Login',
render: () => {
return (
<p>April 2, 2022</p>
)
},
},
{
title: '',
key: 'action',
render: () => (
<Space size="middle">
<Link to="/shipments" className='space-action' >Shipment</Link>
<Link to="/" className='space-action-green'>Edit</Link>
</Space>
),
},
];
const Customers: React.FC = () => {
const [customersData, setCustomersData] = useState(null);
const [loading, setLoading] = useState(false);
useEffect(() => {
getCustomers();
});
const getCustomers = () => {
setLoading(true);
return makeAPICall({
path: `get_customers`,
method: "GET",
})
.then((data) => {
setCustomersData(data);
setLoading(false);
console.log(data);
})
.catch((err) => {
setLoading(false);
console.log(err);
});
}
return (
<SiderLayout>
<div className="site-layout-background" style={{ padding: "40px 40px", minHeight: 710 }}>
<button type='submit'>Add Customer {" "} +</button>
{loading ? 'loading...' : (
<div>
{!customersData ? ("No data") : (<Table columns={columns} dataSource={customersData} />)}
</div>
)}
</div>
</SiderLayout>
)
}
export default Customers;
I've consumed the get_customers api, which I think I did it correctly, but the data is not displaying on the browser.
When I went to inspect element, I thought is as a result of CORS, so I turned on CORS, but it wasn't still working, it would fetch all the data in that process of loading the state, it would display a blank screen at the end.

unexpected error when trying stripe with apple pay using ionic capacitor

i am using https://github.com/capacitor-community/stripe to integrate in my ionic-angular app with apple pay.
the payload and code looks like below
const Stripe = Plugins.Stripe as StripePlugin;
Stripe.setPublishableKey({ key: 'xxxx' }); //test key
const clientSecret: string = 'xxxx'; //test secret
pay(){
await Stripe.confirmPaymentIntent({
clientSecret,
applePayOptions: {
// options here
merchantId: 'merchant.xxx.xxx',
country: 'US',
currency: 'USD',
items: [
{
label: 'my desc',
amount: 1, // amount in dollars
}
]
},
})
}
this shows the apple pay sheeet nicely but when i double click to confirm the payment it thorws error that i can see in the xcode console as below
ERROR MESSAGE: {"message":"payment failed: There was an unexpected error -- try again in a few seconds","errorMessage":"There was an unexpected error -- try again in a few seconds"}
i have tried it on device and with live keys as well but no luck
The code below worked for me.
Note that it is 1 for $1 but stripe uses 100 for $1.
try {
const paymentIntent = await this.stripeService.createPaymentIntentOnServer(100);
const result = await StripePlg.confirmPaymentIntent(
{ clientSecret: paymentIntent.client_secret,
applePayOptions: {
merchantId: 'merchant.app.myapp',
items: [{ label: 'Bread sticks', amount: 1, },],
currency: 'NZD',
country: 'NZ',
},
});
// then call finalizeApplePayTransaction with the result to dismiss the UI modal
StripePlg.finalizeApplePayTransaction({ success: true });
} catch (err) {
console.log(err);
StripePlg.finalizeApplePayTransaction({ success: false })
}
// Server
// createPaymentIntentOnServer - this returns the client_secret
const paymentIntent = await stripe.paymentIntents.create({
amount: paymentAmount, // 100
currency: 'nzd',
payment_method_types: ['card'],
customer: customer.id, // I use a Stripe Customer here which I create first
expand: ['invoice']
});
Stripe allows only integer as amount (1 = 1cent) so 0.5$ would be 50, and 1$ is 100.
const Stripe = Plugins.Stripe as StripePlugin;
Stripe.setPublishableKey({ key: 'xxxx' }); //test key
const clientSecret: string = 'xxxx'; //test secret
pay(){
await Stripe.confirmPaymentIntent({
clientSecret,
applePayOptions: {
// options here
merchantId: 'merchant.xxx.xxx',
country: 'US',
currency: 'USD',
items: [
{
label: 'my desc',
amount: 50, // amount in cents
}
]
},
})
}

Can't attach a message for transaction in Waves bitcoin by package #waves/waves-transactions

I try to create transaction on Testnet Waves blockchain with short message, I use attachment as a string according to documentation, but I receive a error, that attachment is Object. I see in result of "transfer" function that attachment is not a string it is object: { type: 'string', value: '2XTb5rrCf5d1zJkj2jZGjQaA4NPV' }, but I can't do anything with that, and in the end i have the same error.
P.s.: without attachment this part of code is work fine.
const { transfer, broadcast } = require("#waves/waves-transactions");
const nodeUrl = "https://nodes-testnet.wavesnodes.com";
const privateKey = "...realPrivateKey...";
const signedTranserTx = transfer(
{
amount: 1,
recipient: "3MqfoN68Gj3Eqc9C7pHLqbYvd5k2hovSkgi",
attachment: "2XTb5rrCf5d1zJkj2jZGjQaA4NPV"
}
, {privateKey: privateKey}
);
broadcast( signedTranserTx, nodeUrl)
.then(resp => console.log(resp))
.catch(err => console.error(err));
Output of signedTranserTx =
{
type: 4,
version: 3,
senderPublicKey: 'He58mC5hQHjQtx6sKcq7MVaeTc6Je9wJthp2P8m7fUXU',
assetId: null,
recipient: '3MqfoN68Gj3Eqc9C7pHLqbYvd5k2hovSkgi',
amount: 1,
**attachment: { type: 'string', value: '2XTb5rrCf5d1zJkj2jZGjQaA4NPV' },**
fee: 100000,
feeAssetId: null,
timestamp: 1602355529316,
proofs: [
'fLmLYr2D1YMLogLtne4NW4YUiB6GufqsfmEjWGqeGS7R56DrB9mXGYDsfQngMGV3EPDwgsh5zNgiv971KezF5AG'
],
chainId: 84,
id: 'Hw55x7FTuYsPUtuczrdRaJ2kqDCVUgxPuoxndajmeC3C'
}
Error request:
{
error: 1,
message: 'failed to parse json message',
cause: null,
validationErrors: { 'obj.attachment': [ [Object] ] }
}
i add type and version attribute to transaction, but change version of transaction from 3 to 2 and now its work. But i didn`t find any information about in documentation.
const signedTranserTx = transfer(
{
type: 4,
version: 2,
amount: 10000,
recipient: "3MqfoN68Gj3Eqc9C7pHLqbYvd5k2hovSkgi",
attachment: codedAttachment
}
, {privateKey: privateKey}
);

Ant deisgn 4 table summary issue in the Table.Summary.Cell

Im usiing My react typescript project for Ant design 4 table . so when i adding ant design Summary table, got a following error
TS2741: Property 'index' is missing in type '{ children: Element; colSpan: number; }' but required in type 'SummaryCellProps'.
any one know how to fix that issue.
Thanks
import ReactDOM from 'react-dom';
import 'antd/dist/antd.css';
import './index.css';
import { Table, Typography } from 'antd';
const { Text } = Typography;
const columns = [
{
title: 'Name',
dataIndex: 'name',
},
{
title: 'Borrow',
dataIndex: 'borrow',
},
{
title: 'Repayment',
dataIndex: 'repayment',
},
];
const data = [
{
key: '1',
name: 'John Brown',
borrow: 10,
repayment: 33,
},
{
key: '2',
name: 'Jim Green',
borrow: 100,
repayment: 0,
},
{
key: '3',
name: 'Joe Black',
borrow: 10,
repayment: 10,
},
{
key: '4',
name: 'Jim Red',
borrow: 75,
repayment: 45,
},
];
const fixedColumns = [
{
title: 'Name',
dataIndex: 'name',
fixed: true,
width: 100,
},
{
title: 'Description',
dataIndex: 'description',
},
];
const fixedData = [];
for (let i = 0; i < 6; i += 1) {
fixedData.push({
key: i,
name: i % 2 ? 'Light' : 'Bamboo',
description: 'Everything that has a beginning, has an end.',
});
}
ReactDOM.render(
<>
<Table
columns={columns}
dataSource={data}
pagination={false}
bordered
summary={pageData => {
let totalBorrow = 0;
let totalRepayment = 0;
pageData.forEach(({ borrow, repayment }) => {
totalBorrow += borrow;
totalRepayment += repayment;
});
return (
<>
<Table.Summary.Row>
<Table.Summary.Cell>Total</Table.Summary.Cell>
<Table.Summary.Cell>
<Text type="danger">{totalBorrow}</Text>
</Table.Summary.Cell>
<Table.Summary.Cell>
<Text>{totalRepayment}</Text>
</Table.Summary.Cell>
</Table.Summary.Row>
<Table.Summary.Row>
<Table.Summary.Cell>Balance</Table.Summary.Cell>
<Table.Summary.Cell colSpan={2}>
<Text type="danger">{totalBorrow - totalRepayment}</Text>
</Table.Summary.Cell>
</Table.Summary.Row>
</>
);
}}
/>
</>,
document.getElementById('container'),
);
Had this issue yesterday as well, looking at the SummeryCellProps the rc-table team made index required. So I just added <Table.Summary.Row index={1}> you need to iterate through your pagedata to add the index of the that column

Updating value of the object in angular 2

I have to update the value name attribute of my object at particular index. I am having index no and also array.
This is my code,
this.menus.forEach(x => {
let temp = this.menus.findIndex(function (item) {
return item.name == 'Cost Center';
});
// this.menus.values[temp].name=this.newCC;
this.menus[temp].name=this.newCC;
console.log("menu temp",temp);
This is my array structure,
Array(11)
0:{_id: "5acc9e6320a7d71ab8372120", name: "DashBoard", link: "dashboard", icon: "fa fa-list", key: "dashboard", …}
1: {_id: "5acc9e6320a7d71ab837211f", name: "My Products", link: "print-products", icon: "fa fa-barcode", key: "print-products", …}
2:{sequence: null, key: "my-saved-jobs", icon: "fa fa-file-text-o", link: "my-saved-jobs", name: "My Saved Jobs", …}
3:{sequence: null, key: "my-placed-orders", icon: "fa fa-list-alt", link: "my-placed-orders", name: "My Orders", …}
4:{_id: "5acc9e6320a7d71ab837211b", name: "Site Design Setup", link: "storefront-setup", icon: "fa fa-university", key: "storefront-setup", …}
5:{_id: "5acc9e6320a7d71ab8372118", name: "Reports", link: "reports", icon: "icon-report", key: "reports", …}
6:{_id: "5accb9425241ed3270585b93", name: "Print Service Category", link: "print-service-category", icon: "fa fa-tasks", key: "print-service-category", …}
7:{sequence: null, key: "my-saved-files", icon: "fa fa-floppy-o", link: "my-saved-files", name: "My Saved Files", …}
8:{sequence: null, key: "product-list", icon: "fa fa-list", link: "product-list", name: "Product List", …}
9:{_id: "5acc9e6320a7d71ab8372119", name: "Deal Code", link: "deal- code", icon: "fa fa-university", key: "deal-code", …}
10:{sequence: null, key: "cost-center", icon: "icon-costCenter", link: "cost-center", name: undefined, …}
length:11
can anyone help to solve my issue?
Please reply.
Actually I was doing an mistake while writing code, this code should be written where we are getting response from backend i.e within the scope of success response.
this is my new code,
this.httpService.save(UrlDetails.$getPaymentSetting, client)
.subscribe(response => {
if (response.responseCode == 200) {
let paymentSetting = response.responseData;
console.log("client PAYMENT RESPONSE ",paymentSetting);
if( paymentSetting.paymentOption.customPayment.length != 0){
<------Some Code----->
.
.
this.menus.forEach(x => {
let temp1 = this.menus.findIndex(function (item) {
return item.name == 'Cost Center';
});
let temp2 = this.menus.findIndex(function (item) {
return item.name == 'Deal Code';
});
this.menus[temp1].name= this.newCC;
this.menus[temp2].name= this.newDC;
});
}
})

Resources