lodash#uniqWith JavaScript Examples
The following examples show how to use
lodash#uniqWith.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HiddenColumnsEditModal.js From hzero-front with Apache License 2.0 | 6 votes |
handleSaveHiddenColumns() {
const { onOk } = this.props;
const { hiddenColumnsDataSource = [] } = this.state;
const saveDataSource = getEditTableData(hiddenColumnsDataSource, []);
let errMessage;
const uniqDataSource = uniqWith(saveDataSource, (r1, r2) => r1.columnName === r2.columnName);
if (uniqDataSource.length !== saveDataSource.length) {
errMessage = '隐藏域字段名 必须唯一';
return false;
}
if (errMessage) {
notification.error({ message: errMessage });
return;
}
const hiddenColumns = [];
forEach(saveDataSource, hiddenColumn => {
hiddenColumns.push({
[attributeNameProp]: `${hiddenColumnPrefix}[${hiddenColumn.columnKey}]`,
[attributeValueProp]: `${hiddenColumn.columnName}${hiddenColumnSep}${hiddenColumn.columnLabel}`,
[attributeTypeProp]: DataType.String,
});
});
onOk(hiddenColumns);
}
Example #2
Source File: UploadButton.js From hzero-front with Apache License 2.0 | 5 votes |
@Bind()
onChange({ file, fileList }) {
const { single = false, tenantId, bucketName, bucketDirectory } = this.props;
let list = [...fileList];
if (file.status === 'done') {
const { response } = file;
if (response && response.failed === true) {
this.onUploadError(file, fileList);
} else {
if (single) {
if (fileList.length > 1) {
const { onRemove } = this.props;
Promise.all(
fileList.slice(0, fileList.length - 1).map(async (fileItem) => {
if (fileItem.url) {
if (onRemove) {
// onRemove 返回 undefined 或 Promise
try {
await onRemove(fileItem);
} catch (e) {
// 单文件 上传成功后 删除之前的问题,报错不用管
}
} else {
const splitDatas = (fileItem.url && fileItem.url.split('=')) || [];
const fileUrl = splitDatas[splitDatas.length - 1];
try {
await removeUploadFile({
tenantId,
bucketName,
urls: [fileUrl],
});
} catch (e) {
// 单文件 上传成功后 删除之前的问题,报错不用管
}
}
}
})
).catch(() => {
// 单文件 上传成功后 删除之前的问题,报错不用管
});
}
list = [
{
uid: file.uid,
name: file.name,
url: getAttachmentUrl(file.response, bucketName, tenantId, bucketDirectory),
thumbUrl: getAttachmentUrl(file.response, bucketName, tenantId, bucketDirectory),
},
];
} else {
list = fileList.map((f) => {
if (f.uid === file.uid) {
// f.url = file.response;
// eslint-disable-next-line
f.url = getAttachmentUrl(f.response, bucketName, tenantId, bucketDirectory);
// f.url = `${HZERO_FILE}/v1${
// !isUndefined(tenantId) ? `/${tenantId}/` : '/'
// }files/redirect-url?access_token=${accessToken}&bucketName=${bucketName}${
// !isUndefined(bucketDirectory) ? `&directory=${bucketDirectory}&` : '&'
// }url=${f.response}`;
}
return f;
});
}
this.onUploadSuccess(file, list);
}
} else if (file.status === 'error') {
this.onUploadError(file, fileList);
list = fileList.filter((f) => f.status !== 'error' && f.uid);
}
this.setState({
fileList: uniqWith(list, (r1, r2) => r1.uid === r2.uid),
});
}
Example #3
Source File: useUsersDripData.js From v3-ui with MIT License | 5 votes |
// This is deprecated but needs to be around for the old rewards system so people
// can still claim from the drips. It only needs the 3_1_0 subgraph
export function useUsersDripData() {
const { address: usersAddress } = useOnboard()
const chainId = usePoolTokenChainId()
const readProvider = useReadProvider(chainId)
const { contractAddresses } = useContractAddresses(chainId)
const { data: graphDripData, error } = usePoolDripsQuery()
if (error) {
console.error(error)
}
let pairs = []
let dripTokens = []
let comptrollerAddress
if (graphDripData?.balanceDrips) {
const balanceDripPairs = graphDripData?.balanceDrips.map((drip) => [
drip.sourceAddress,
drip.measureToken
])
const volumeDripPairs = graphDripData?.volumeDrips.map((drip) => [
drip.sourceAddress,
drip.measureToken
])
pairs = uniqWith(balanceDripPairs?.concat(volumeDripPairs), isEqual)
const balanceDripTokens = graphDripData?.balanceDrips.map((drip) => drip.dripToken)
const volumeDripTokens = graphDripData?.volumeDrips.map((drip) => drip.dripToken)
dripTokens = uniqWith(balanceDripTokens?.concat(volumeDripTokens), isEqual)
if (graphDripData.balanceDrips.length > 0) {
comptrollerAddress = graphDripData.balanceDrips[0].comptroller.id
}
}
const { data: usersDripData, error: usersDripError } = useUsersDripQuery({
provider: readProvider,
comptrollerAddress,
dripTokens,
usersAddress,
pairs,
contractAddresses
})
if (usersDripError) {
console.error(usersDripError)
}
return { graphDripData, usersDripData }
}