Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,4 @@ check-documentation-videos-format: ## Check the documentation format
./scripts/check-documentation-videos-format.sh

release: ## Start the release process and publish the packages to npm using lerna
./scripts/release.sh
./scripts/release.sh
9 changes: 8 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,14 @@ export default defineConfig([
{
name: 'lodash',
message:
"Named import from lodash should be avoided for performance reasons. Use a default import instead. E.g. `import merge from 'lodash/merge';` instead of `import { merge } from 'lodash';`.",
"Named import from lodash should be avoided for performance reasons. Use a default import instead. E.g. `import merge from 'lodash/merge.js';` (note the file extension) instead of `import { merge } from 'lodash';`.",
},
],
patterns: [
{
regex: 'lodash/(?![a-zA-Z]*\\.js$)',
message:
'Always specify the file extension when importing from lodash or it will cause runtime issues for ESM environments.',
},
],
},
Expand Down
3 changes: 1 addition & 2 deletions examples/crm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
"private": true,
"type": "module",
"dependencies": {
"@faker-js/faker": "^10.0.0",
"@hello-pangea/dnd": "^16.3.0",
"@mui/icons-material": "^5.16.12",
"@mui/material": "^5.16.12",
"@nivo/bar": "^0.80.0",
"@nivo/core": "^0.80.0",
"clsx": "^2.1.1",
"date-fns": "^3.6.0",
"faker": "~5.4.0",
"fakerest": "4.1.3",
"lodash": "~4.17.5",
"papaparse": "^5.4.1",
Expand All @@ -28,7 +28,6 @@
"@testing-library/jest-dom": "^6.4.5",
"@testing-library/react": "^15.0.7",
"@testing-library/user-event": "^14.5.2",
"@types/faker": "^5.1.7",
"@types/jest": "^29.5.2",
"@types/jsonexport": "^3.0.5",
"@types/lodash": "~4.14.168",
Expand Down
2 changes: 1 addition & 1 deletion examples/crm/src/deals/DealListContent.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DragDropContext, OnDragEndResponder } from '@hello-pangea/dnd';
import { Box } from '@mui/material';
import isEqual from 'lodash/isEqual';
import isEqual from 'lodash/isEqual.js';
import { useEffect, useState } from 'react';
import { DataProvider, useDataProvider, useListContext } from 'react-admin';

Expand Down
46 changes: 23 additions & 23 deletions examples/crm/src/providers/fakerest/dataGenerator/companies.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
import {
address,
company,
internet,
lorem,
phone,
random,
} from 'faker/locale/en_US';
import { faker } from '@faker-js/faker';
import { randomDate } from './utils';

import { defaultCompanySectors } from '../../../root/defaultConfiguration';
Expand All @@ -18,35 +11,42 @@ const regex = /\W+/;

export const generateCompanies = (db: Db): Required<Company>[] => {
return Array.from(Array(55).keys()).map(id => {
const name = company.companyName();
const name = faker.company.name();
return {
id,
name: name,
logo: {
title: lorem.text(1),
title: faker.lorem.text(),
src: `./logos/${id}.png`,
} as RAFile,
sector: random.arrayElement(defaultCompanySectors),
size: random.arrayElement(sizes) as 1 | 10 | 50 | 250 | 500,
sector: faker.helpers.arrayElement(defaultCompanySectors),
size: faker.helpers.arrayElement(sizes) as 1 | 10 | 50 | 250 | 500,
linkedin_url: `https://www.linkedin.com/company/${name
.toLowerCase()
.replace(regex, '_')}`,
website: internet.url(),
phone_number: phone.phoneNumber(),
address: address.streetAddress(),
zipcode: address.zipCode(),
city: address.city(),
stateAbbr: address.stateAbbr(),
website: faker.internet.url(),
phone_number: faker.phone.number(),
address: faker.location.streetAddress(),
zipcode: faker.location.zipCode(),
city: faker.location.city(),
stateAbbr: faker.location.state({ abbreviated: true }),
nb_contacts: 0,
nb_deals: 0,
// at least 1/3rd of companies for Jane Doe
sales_id:
random.number(2) === 0 ? 0 : random.arrayElement(db.sales).id,
faker.number.int(2) === 0
? 0
: faker.helpers.arrayElement(db.sales).id,
created_at: randomDate().toISOString(),
description: lorem.paragraph(),
revenue: random.arrayElement(['$1M', '$10M', '$100M', '$1B']),
tax_identifier: random.alphaNumeric(10),
country: random.arrayElement(['USA', 'France', 'UK']),
description: faker.lorem.paragraph(),
revenue: faker.helpers.arrayElement([
'$1M',
'$10M',
'$100M',
'$1B',
]),
tax_identifier: faker.string.alphanumeric({ length: 10 }),
country: faker.helpers.arrayElement(['USA', 'France', 'UK']),
context_links: [],
};
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { lorem, random } from 'faker/locale/en_US';
import { faker } from '@faker-js/faker';

import { defaultNoteStatuses } from '../../../root/defaultConfiguration';
import { ContactNote } from '../../../types';
Expand All @@ -7,7 +7,7 @@ import { randomDate } from './utils';

export const generateContactNotes = (db: Db): ContactNote[] => {
return Array.from(Array(1200).keys()).map(id => {
const contact = random.arrayElement(db.contacts);
const contact = faker.helpers.arrayElement(db.contacts);
const date = randomDate(new Date(contact.first_seen));
contact.last_seen =
date > new Date(contact.last_seen)
Expand All @@ -16,10 +16,10 @@ export const generateContactNotes = (db: Db): ContactNote[] => {
return {
id,
contact_id: contact.id,
text: lorem.paragraphs(random.number({ min: 1, max: 4 })),
text: faker.lorem.paragraphs(faker.number.int({ min: 1, max: 4 })),
date: date.toISOString(),
sales_id: contact.sales_id,
status: random.arrayElement(defaultNoteStatuses).value,
status: faker.helpers.arrayElement(defaultNoteStatuses).value,
};
});
};
45 changes: 22 additions & 23 deletions examples/crm/src/providers/fakerest/dataGenerator/contacts.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
import {
company as fakerCompany,
internet,
lorem,
name,
phone,
random,
} from 'faker/locale/en_US';
import { faker } from '@faker-js/faker';

import {
defaultContactGender,
Expand All @@ -30,18 +23,21 @@ export const generateContacts = (db: Db): Required<Contact>[] => {
return Array.from(Array(500).keys()).map(id => {
const has_avatar =
weightedBoolean(25) && numberOfContacts < nbAvailblePictures;
const gender = random.arrayElement(defaultContactGender).value;
const first_name = name.firstName(gender as any);
const last_name = name.lastName();
const email = internet.email(first_name, last_name);
const gender = faker.helpers.arrayElement(defaultContactGender).value;
const first_name = faker.person.firstName(gender as any);
const last_name = faker.person.lastName();
const email = faker.internet.email({
firstName: first_name,
lastName: last_name,
});
const avatar = {
src: has_avatar
? 'https://marmelab.com/posters/avatar-' +
(223 - numberOfContacts) +
'.jpeg'
: undefined,
};
const title = fakerCompany.bsAdjective();
const title = faker.company.buzzAdjective();

if (has_avatar) {
numberOfContacts++;
Expand All @@ -50,7 +46,7 @@ export const generateContacts = (db: Db): Required<Contact>[] => {
// choose company with people left to know
let company: Required<Company>;
do {
company = random.arrayElement(db.companies);
company = faker.helpers.arrayElement(db.companies);
} while (company.nb_contacts >= maxContacts[company.size]);
company.nb_contacts++;

Expand All @@ -68,19 +64,22 @@ export const generateContacts = (db: Db): Required<Contact>[] => {
company_id: company.id,
company_name: company.name,
email,
phone_1_number: phone.phoneNumber(),
phone_1_type: random.arrayElement(['Work', 'Home', 'Other']),
phone_2_number: phone.phoneNumber(),
phone_2_type: random.arrayElement(['Work', 'Home', 'Other']),
background: lorem.sentence(),
acquisition: random.arrayElement(['inbound', 'outbound']),
phone_1_number: faker.phone.number(),
phone_1_type: faker.helpers.arrayElement(['Work', 'Home', 'Other']),
phone_2_number: faker.phone.number(),
phone_2_type: faker.helpers.arrayElement(['Work', 'Home', 'Other']),
background: faker.lorem.sentence(),
acquisition: faker.helpers.arrayElement(['inbound', 'outbound']),
avatar,
first_seen: first_seen,
last_seen: last_seen,
has_newsletter: weightedBoolean(30),
status: random.arrayElement(defaultNoteStatuses).value,
tags: random
.arrayElements(db.tags, random.arrayElement([0, 0, 0, 1, 1, 2]))
status: faker.helpers.arrayElement(defaultNoteStatuses).value,
tags: faker.helpers
.arrayElements(
db.tags,
faker.helpers.arrayElement([0, 0, 0, 1, 1, 2])
)
.map(tag => tag.id), // finalize
sales_id: company.sales_id,
nb_tasks: 0,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { random, lorem } from 'faker/locale/en_US';
import { faker } from '@faker-js/faker';

import { Db } from './types';
import { randomDate } from './utils';

export const generateDealNotes = (db: Db) => {
return Array.from(Array(300).keys()).map(id => {
const deal = random.arrayElement(db.deals);
const deal = faker.helpers.arrayElement(db.deals);
return {
id,
deal_id: deal.id,
text: lorem.paragraphs(random.number({ min: 1, max: 4 })),
text: faker.lorem.paragraphs(faker.number.int({ min: 1, max: 4 })),
date: randomDate(
new Date(db.deals[deal.id as number].created_at)
).toISOString(),
Expand Down
20 changes: 11 additions & 9 deletions examples/crm/src/providers/fakerest/dataGenerator/deals.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { add } from 'date-fns';
import { lorem, random } from 'faker/locale/en_US';
import { faker } from '@faker-js/faker';

import {
defaultDealCategories,
Expand All @@ -11,13 +11,13 @@ import { randomDate } from './utils';

export const generateDeals = (db: Db): Deal[] => {
const deals = Array.from(Array(50).keys()).map(id => {
const company = random.arrayElement(db.companies);
const company = faker.helpers.arrayElement(db.companies);
company.nb_deals++;
const contacts = random.arrayElements(
const contacts = faker.helpers.arrayElements(
db.contacts.filter(contact => contact.company_id === company.id),
random.number({ min: 1, max: 3 })
faker.number.int({ min: 1, max: 3 })
);
const lowercaseName = lorem.words();
const lowercaseName = faker.lorem.words();
const created_at = randomDate(
new Date(company.created_at)
).toISOString();
Expand All @@ -32,10 +32,12 @@ export const generateDeals = (db: Db): Deal[] => {
name: lowercaseName[0].toUpperCase() + lowercaseName.slice(1),
company_id: company.id,
contact_ids: contacts.map(contact => contact.id),
category: random.arrayElement(defaultDealCategories),
stage: random.arrayElement(defaultDealStages).value,
description: lorem.paragraphs(random.number({ min: 1, max: 4 })),
amount: random.number(1000) * 100,
category: faker.helpers.arrayElement(defaultDealCategories),
stage: faker.helpers.arrayElement(defaultDealStages).value,
description: faker.lorem.paragraphs(
faker.number.int({ min: 1, max: 4 })
),
amount: faker.number.int(1000) * 100,
created_at,
updated_at: randomDate(new Date(created_at)).toISOString(),
expected_closing_date,
Expand Down
11 changes: 7 additions & 4 deletions examples/crm/src/providers/fakerest/dataGenerator/sales.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { internet, name } from 'faker/locale/en_US';
import { faker } from '@faker-js/faker';

import { RAFile, Sale } from '../../../types';
import { Db } from './types';

export const generateSales = (_: Db): Sale[] => {
const randomSales = Array.from(Array(5).keys()).map(id => {
const first_name = name.firstName();
const last_name = name.lastName();
const email = internet.email(first_name, last_name);
const first_name = faker.person.firstName();
const last_name = faker.person.lastName();
const email = faker.internet.email({
firstName: first_name,
lastName: last_name,
});

return {
id: id + 1,
Expand Down
12 changes: 7 additions & 5 deletions examples/crm/src/providers/fakerest/dataGenerator/tasks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { lorem, random } from 'faker/locale/en_US';
import { faker } from '@faker-js/faker';

import { defaultTaskTypes } from '../../../root/defaultConfiguration';
import { Task } from '../../../types';
Expand Down Expand Up @@ -37,15 +37,17 @@ export const type: TaskType[] = [

export const generateTasks = (db: Db) => {
return Array.from(Array(400).keys()).map<Task>(id => {
const contact = random.arrayElement(db.contacts);
const contact = faker.helpers.arrayElement(db.contacts);
contact.nb_tasks++;
return {
id,
contact_id: contact.id,
type: random.arrayElement(defaultTaskTypes),
text: lorem.sentence(),
type: faker.helpers.arrayElement(defaultTaskTypes),
text: faker.lorem.sentence(),
due_date: randomDate(
random.boolean() ? new Date() : new Date(contact.first_seen),
faker.datatype.boolean()
? new Date()
: new Date(contact.first_seen),
new Date(Date.now() + 100 * 24 * 60 * 60 * 1000)
).toISOString(),
done_date: undefined,
Expand Down
10 changes: 5 additions & 5 deletions examples/crm/src/providers/fakerest/dataGenerator/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import faker from 'faker/locale/en';
import { faker } from '@faker-js/faker';

export const weightedArrayElement = (values: any[], weights: any) =>
faker.random.arrayElement(
faker.helpers.arrayElement(
values.reduce(
(acc, value, index) =>
acc.concat(new Array(weights[index]).fill(value)),
Expand All @@ -10,7 +10,7 @@ export const weightedArrayElement = (values: any[], weights: any) =>
);

export const weightedBoolean = (likelyhood: number) =>
faker.random.number(99) < likelyhood;
faker.number.int(99) < likelyhood;

export const randomDate = (minDate?: Date, maxDate?: Date) => {
const minTs =
Expand All @@ -19,11 +19,11 @@ export const randomDate = (minDate?: Date, maxDate?: Date) => {
: Date.now() - 5 * 365 * 24 * 60 * 60 * 1000; // 5 years
const maxTs = maxDate instanceof Date ? maxDate.getTime() : Date.now();
const range = maxTs - minTs;
const randomRange = faker.random.number({ max: range });
const randomRange = faker.number.int({ max: range });
// move it more towards today to account for traffic increase
const ts = Math.sqrt(randomRange / range) * range;
return new Date(minTs + ts);
};

export const randomFloat = (min: number, max: number) =>
parseFloat(faker.random.number({ min, max, precision: 0.01 }).toFixed(2));
parseFloat(faker.number.float({ min, max, fractionDigits: 2 }).toFixed(2));
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import isObject from 'lodash/isObject';
import isObject from 'lodash/isObject.js';

// @or filter is an equivaluent of fakerest `q=`
export function transformOrFilter(values: any) {
Expand Down
Loading
Loading