From b9aa81a1712b340cdbe11e9328d4bf90f44517d5 Mon Sep 17 00:00:00 2001 From: Tuan Pham Date: Thu, 9 May 2024 15:53:49 -0700 Subject: [PATCH] fix(ui): fix demo folder --- packages/sdk-ui/src/__demo__/example-data.ts | 43 ++++++ .../sample-ecommerce-autogenerated.ts | 141 ++++++++++++++++++ .../sdk-ui/src/__demo__/sample-ecommerce.ts | 14 ++ 3 files changed, 198 insertions(+) create mode 100644 packages/sdk-ui/src/__demo__/example-data.ts create mode 100644 packages/sdk-ui/src/__demo__/sample-ecommerce-autogenerated.ts create mode 100644 packages/sdk-ui/src/__demo__/sample-ecommerce.ts diff --git a/packages/sdk-ui/src/__demo__/example-data.ts b/packages/sdk-ui/src/__demo__/example-data.ts new file mode 100644 index 00000000..164bdfa9 --- /dev/null +++ b/packages/sdk-ui/src/__demo__/example-data.ts @@ -0,0 +1,43 @@ +export const exampleData = { + data: { + columns: [ + { name: 'Years', type: 'date' }, + { name: 'Group', type: 'string' }, + { name: 'Quantity', type: 'number' }, + { name: 'Units', type: 'number' }, + { name: 'Returns', type: 'number' }, + ], + rows: [ + ['2009', 'A', 6781, 1000, 558], + ['2009', 'B', 5500, 1500, 440], + ['2010', 'A', 4471, 7000, 557], + ['2011', 'B', 1812, 5000, 151], + ['2012', 'B', 5001, 6000, 440], + ['2013', 'A', 2045, 4000, 304], + ['2014', 'B', 3010, 9000, 341], + ['2015', 'A', 5447, 8000, 444], + ['2016', 'B', 4242, 7000, 384], + ['2017', 'B', 936, 2000, 73], + ], + }, + years: { + name: 'Years', + type: 'date', + }, + group: { + name: 'Group', + type: 'string', + }, + quantity: { + name: 'Quantity', + aggregation: 'sum', + }, + units: { + name: 'Units', + aggregation: 'sum', + }, + returns: { + name: 'Returns', + aggregation: 'sum', + }, +}; diff --git a/packages/sdk-ui/src/__demo__/sample-ecommerce-autogenerated.ts b/packages/sdk-ui/src/__demo__/sample-ecommerce-autogenerated.ts new file mode 100644 index 00000000..d734a4a6 --- /dev/null +++ b/packages/sdk-ui/src/__demo__/sample-ecommerce-autogenerated.ts @@ -0,0 +1,141 @@ +import { + Dimension, + DateDimension, + Attribute, + createAttribute, + createDateDimension, + createDimension, +} from '@sisense/sdk-data'; + +export const DataSource = 'Sample ECommerce'; + +interface BrandDimension extends Dimension { + Brand: Attribute; + BrandID: Attribute; +} +export const Brand = createDimension({ + name: 'Brand', + Brand: createAttribute({ + name: 'Brand', + type: 'text-attribute', + expression: '[Brand.Brand]', + }), + BrandID: createAttribute({ + name: 'BrandID', + type: 'numeric-attribute', + expression: '[Brand.Brand ID]', + }), +}) as BrandDimension; + +interface CategoryDimension extends Dimension { + Category: Attribute; + CategoryID: Attribute; +} +export const Category = createDimension({ + name: 'Category', + Category: createAttribute({ + name: 'Category', + type: 'text-attribute', + expression: '[Category.Category]', + }), + CategoryID: createAttribute({ + name: 'CategoryID', + type: 'numeric-attribute', + expression: '[Category.Category ID]', + }), +}) as CategoryDimension; + +interface CommerceDimension extends Dimension { + AgeRange: Attribute; + BrandID: Attribute; + CategoryID: Attribute; + Condition: Attribute; + Cost: Attribute; + CountryID: Attribute; + DateMonth: Attribute; + Gender: Attribute; + Quantity: Attribute; + Revenue: Attribute; + VisitID: Attribute; + Date: DateDimension; +} +export const Commerce = createDimension({ + name: 'Commerce', + AgeRange: createAttribute({ + name: 'AgeRange', + type: 'text-attribute', + expression: '[Commerce.Age Range]', + }), + BrandID: createAttribute({ + name: 'BrandID', + type: 'numeric-attribute', + expression: '[Commerce.Brand ID]', + }), + CategoryID: createAttribute({ + name: 'CategoryID', + type: 'numeric-attribute', + expression: '[Commerce.Category ID]', + }), + Condition: createAttribute({ + name: 'Condition', + type: 'text-attribute', + expression: '[Commerce.Condition]', + }), + Cost: createAttribute({ + name: 'Cost', + type: 'numeric-attribute', + expression: '[Commerce.Cost]', + }), + CountryID: createAttribute({ + name: 'CountryID', + type: 'numeric-attribute', + expression: '[Commerce.Country ID]', + }), + DateMonth: createAttribute({ + name: 'DateMonth', + type: 'numeric-attribute', + expression: '[Commerce.Date (Month)]', + }), + Gender: createAttribute({ + name: 'Gender', + type: 'text-attribute', + expression: '[Commerce.Gender]', + }), + Quantity: createAttribute({ + name: 'Quantity', + type: 'numeric-attribute', + expression: '[Commerce.Quantity]', + }), + Revenue: createAttribute({ + name: 'Revenue', + type: 'numeric-attribute', + expression: '[Commerce.Revenue]', + }), + VisitID: createAttribute({ + name: 'VisitID', + type: 'numeric-attribute', + expression: '[Commerce.Visit ID]', + }), + Date: createDateDimension({ + name: 'Date', + expression: '[Commerce.Date (Calendar)]', + }), +}) as CommerceDimension; + +interface CountryDimension extends Dimension { + Country: Attribute; + CountryID: Attribute; +} +export const Country = createDimension({ + name: 'Country', + Country: createAttribute({ + name: 'Country', + type: 'text-attribute', + expression: '[Country.Country]', + }), + CountryID: createAttribute({ + name: 'CountryID', + type: 'numeric-attribute', + expression: '[Country.Country ID]', + }), +}) as CountryDimension; diff --git a/packages/sdk-ui/src/__demo__/sample-ecommerce.ts b/packages/sdk-ui/src/__demo__/sample-ecommerce.ts new file mode 100644 index 00000000..8a88d20f --- /dev/null +++ b/packages/sdk-ui/src/__demo__/sample-ecommerce.ts @@ -0,0 +1,14 @@ +import { measureFactory } from '@sisense/sdk-data'; + +import { Commerce, Brand, Country, Category, DataSource } from './sample-ecommerce-autogenerated'; + +export { Commerce, Brand, Category, Country, DataSource }; + +/** adding predefined set of measures */ +export const Measures = { + SumCost: measureFactory.sum(Commerce.Cost).format('0,0$'), + AvgCost: measureFactory.average(Commerce.Cost).format('0,0$'), + SumRevenue: measureFactory.sum(Commerce.Revenue, 'Total Revenue').format('0,0$'), + Quantity: measureFactory.sum(Commerce.Quantity, 'Total Quantity').format('0,0'), + CountBrands: measureFactory.countDistinct(Commerce.BrandID).format('0,0'), +};