Skip to content

Commit

Permalink
Test data generation (#499)
Browse files Browse the repository at this point in the history
  • Loading branch information
espenkalle authored Oct 18, 2023
1 parent 660fec8 commit 34c0617
Showing 1 changed file with 96 additions and 129 deletions.
225 changes: 96 additions & 129 deletions apps/test-app/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,107 @@ const GlobalStyle = createGlobalStyle`
font-family: Equinor;
}
`;

function getAllGroupingOptions(): GroupingOption[] {
return [
{
groupingKey: 'RFOC',
timeInterval: ['Daily', 'Weekly', 'Monthly'],
dateVariant: ['Forecast', 'Planned'],
},
{
groupingKey: 'RFCC',
timeInterval: ['Daily', 'Weekly', 'Monthly'],
dateVariant: ['Forecast', 'Planned'],
},
{
groupingKey: 'Some very long keys',
timeInterval: ['Daily', 'Weekly'],
dateVariant: ['Forecast', 'Planned', 'Done'],
},
{ groupingKey: 'System', timeInterval: null, dateVariant: null },
];
}
function getRandomInt(min: number, max: number): number {
return Math.floor(Math.random() * (max - min + 1)) + min;
}

function getGardenBlockData(num_columns: number = 2): any[] {
const gardenData: any[] = [];

for (let i = 0; i < num_columns; i++) {
const columnName = String.fromCharCode(65 + i);
const numItems = getRandomInt(2, 30);
const items = Array.from({ length: numItems }, () => {
return { id: `${columnName}-${getRandomInt(100, 999)}` };
});

gardenData.push({
columnName: columnName,
items: items,
subGroupCount: 0,
subGroups: [],
totalItemsCount: numItems,
});
}

return gardenData;
}

function getGardenHeaderData(gardenData: any[] | null = null): any[] {
if (gardenData === null) {
gardenData = getGardenBlockData(5);
}

return gardenData.map((column) => {
return { count: column.totalItemsCount, name: column.columnName };
});
}

function getGridRowData(num_rows: number = 4): any[] {
return Array.from({ length: num_rows }, () => {
return { id: `${getRandomInt(100, 9999)}` };
});
}

function getFilterMetaData(num_filters: number = 2): any[] {
const filterData: any[] = [];

for (let i = 0; i < num_filters; i++) {
const filterName = String.fromCharCode(65 + i);
const numItems = getRandomInt(1, 20);
const items = Array.from({ length: numItems }, () => {
return { count: getRandomInt(10, 40), value: `${filterName}-${getRandomInt(1, 999)}` };
});

filterData.push({
filterItems: items,
isQuickFilter: true,
name: `Filter ${filterName}`,
});
}

return filterData;
}

let GARDEN_SIZE = 30;
let GRID_SIZE = 150;
let FILTER_SIZE = 5;
const GardenBlockData = getGardenBlockData(GARDEN_SIZE);

export function App() {
return (
<Workspace<{ id: string }>
workspaceOptions={{ getIdentifier: (a) => a.id }}
gridOptions={{
columnDefinitions: [{ field: 'id' }],
getRows: async ({ success, request }, filter) => {
success({ rowData: [{ id: '123' }, { id: '125' }, { id: '9342' }, { id: '1212' }], rowCount: 4 });
success({ rowData: getGridRowData(GRID_SIZE), rowCount: GRID_SIZE });
},
excelExport: async (filterState) =>
new Promise((res, rej) =>
setTimeout(() => {
res();
console.log('løøøøøøø');
}, 2000)
),
}}
Expand All @@ -40,50 +127,17 @@ export function App() {
getGardenMeta: async (a, b, c) => {
console.log(a);
return {
allGroupingOptions: [
{
groupingKey: 'RFOC',
timeInterval: ['Daily', 'Weekly', 'Monthly'],
dateVariant: ['Forecast', 'Planned'],
},
{
groupingKey: 'RFCC',
timeInterval: ['Daily', 'Weekly', 'Monthly'],
dateVariant: ['Forecast', 'Planned'],
},
{
groupingKey: 'Some very long keys',
timeInterval: ['Daily', 'Weekly'],
dateVariant: ['Forecast', 'Planned', 'Done'],
},
{ groupingKey: 'System', timeInterval: null, dateVariant: null },
] as GroupingOption[],
columnCount: 2,
allGroupingOptions: getAllGroupingOptions(),
columnCount: GARDEN_SIZE,
columnStart: 0,
rowCount: 10000,
validGroupingOptions: ['RFOC', 'PartitionKey'],
columnWidth: 150,
};
},
getBlockAsync: async (a) => {
return [
{ columnName: 'Some name', items: [], subGroupCount: 0, subGroups: [], totalItemsCount: 0 },
{
columnName: 'some other name',
items: [{ id: '123' }],
subGroupCount: 0,
subGroups: [],
totalItemsCount: 1,
},
];
},
getDisplayName: () => '',
getHeader: async (a) => {
return [
{ count: 0, name: 'Some name' },
{ count: 1, name: 'some other name' },
];
},
getBlockAsync: async (a) => GardenBlockData,
getDisplayName: (a) => a.id,
getHeader: async (a) => getGardenHeaderData(GardenBlockData),
getSubgroupItems: () => {
throw new Error('');
},
Expand All @@ -93,94 +147,7 @@ export function App() {
}}
filterOptions={{
dataSource: {
getFilterMeta: async () => [
{
filterItems: [
{ count: 10, value: 'test' },
{
count: 9,
value: 'test2',
},
],
isQuickFilter: true,
name: 'test',
},
{
name: 'single',
filterItems: [{ count: 1, value: 'abc' }],
isQuickFilter: true,
},
{
name: 'item1',
filterItems: [{ count: 1, value: 'value1' }],
isQuickFilter: true,
},
{
name: 'item2',
filterItems: [{ count: 1, value: 'value2' }],
isQuickFilter: true,
},
{
name: 'item3',
filterItems: [{ count: 1, value: 'value3' }],
isQuickFilter: true,
},
{
name: 'item4',
filterItems: [{ count: 1, value: 'value4' }],
isQuickFilter: true,
},
{
name: 'item5',
filterItems: [{ count: 1, value: 'value5' }],
isQuickFilter: true,
},
{
name: 'item6',
filterItems: [{ count: 1, value: 'value6' }],
isQuickFilter: true,
},
{
name: 'item7',
filterItems: [{ count: 1, value: 'value7' }],
isQuickFilter: true,
},
{
name: 'item8',
filterItems: [{ count: 1, value: 'value8' }],
isQuickFilter: true,
},
{
name: 'item9',
filterItems: [{ count: 1, value: 'value9' }],
isQuickFilter: true,
},
{
name: 'item10',
filterItems: [{ count: 1, value: 'value10' }],
isQuickFilter: true,
},
{
name: 'item11',
filterItems: [{ count: 1, value: 'value11' }],
isQuickFilter: true,
},
{
name: 'item12',
filterItems: [{ count: 1, value: 'value12' }],
isQuickFilter: true,
},
{
name: 'item13',
filterItems: [{ count: 1, value: 'value13' }],
isQuickFilter: true,
},
{
name: 'item14',
filterItems: [{ count: 1, value: 'value14' }],
isQuickFilter: true,
},
],
getFilterMeta: async () => getFilterMetaData(FILTER_SIZE),
},
}}
modules={[gridModule, gardenModule]}
Expand All @@ -189,7 +156,7 @@ export function App() {
}

const container = document.getElementById('root')!;
const root = createRoot(container); // createRoot(container!) if you use TypeScript
const root = createRoot(container);

root.render(
<>
Expand Down

0 comments on commit 34c0617

Please sign in to comment.