-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: set up table package and add createTableItems method #124
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
14320e2
feat: set up table package and add createTableItems method
square-li 1e43ae6
fix: update tsconfig path in eslintrc for Table package.
square-li 8304de5
fix: add tests for dataFilters.ts
square-li b484a81
fix: remove unnecessary describe block
square-li 7f1e632
fix: use object to replace CellItem class
square-li 36cbe94
fix: remove unused import
square-li File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
const tsConfig = fs.existsSync('tsconfig.json') | ||
? path.resolve('tsconfig.json') | ||
: path.resolve('./packages/table/tsconfig.json'); | ||
|
||
module.exports = { | ||
ignorePatterns: ['.storybook', 'stories', 'config', 'jest.config.ts', '**/*.js'], | ||
plugins: [ | ||
'eslint-plugin-import', | ||
'eslint-plugin-jsx-a11y', | ||
'eslint-plugin-prettier', | ||
'eslint-plugin-react', | ||
'eslint-plugin-react-hooks', | ||
], | ||
parserOptions: { | ||
project: tsConfig, | ||
}, | ||
rules: { | ||
'import/prefer-default-export': 'off', | ||
'react/jsx-props-no-spreading': 'off', | ||
'@typescript-eslint/comma-dangle': 'off', | ||
'no-param-reassign': 'warn', | ||
'react/no-array-index-key': 'warn', | ||
'no-plusplus': 'warn', | ||
}, | ||
extends: ['airbnb-typescript', 'airbnb/hooks', 'plugin:prettier/recommended'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
*.log | ||
.DS_Store | ||
node_modules | ||
.cache | ||
dist | ||
build | ||
storybook-static | ||
coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import 'jest-extended'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
setupFilesAfterEnv: ['jest-extended/all'], | ||
collectCoverageFrom: ['src/**/*.{ts,tsx}'], | ||
testPathIgnorePatterns: ['/dist'], | ||
coverageReporters: ['text-summary', 'cobertura', 'html', 'json', 'json-summary'], | ||
moduleNameMapper: { | ||
'\\.(css|scss|svg)$': 'identity-obj-proxy', | ||
'd3-array': '<rootDir>/node_modules/d3-array/dist/d3-array.min.js', | ||
}, | ||
|
||
coverageThreshold: { | ||
global: { | ||
statements: 80, | ||
branches: 80, | ||
functions: 80, | ||
lines: 80, | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
{ | ||
"name": "@iot-app-kit/table", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"version": "1.3.0", | ||
"description": "IoT Application Kit - Table component", | ||
"license": "Apache-2.0", | ||
"main": "./dist/index.cj.js", | ||
"module": "./dist/index.js", | ||
"types": "./dist/types/index.d.ts", | ||
"directories": { | ||
"dist": "dist" | ||
}, | ||
"files": [ | ||
"dist/", | ||
"CHANGELOG.md", | ||
"*NOTICE" | ||
], | ||
"author": { | ||
"name": "Amazon Web Services", | ||
"url": "https://aws.amazon.com/" | ||
}, | ||
"scripts": { | ||
"clean": "rm -rf dist && rm -rf screenshot", | ||
"build": "yarn run clean && yarn run build:types && rollup --config rollup.config.js", | ||
"build:types": "tsc --outDir dist/types --declaration true --emitDeclarationOnly true", | ||
"test": "npm-run-all -p test:jest test:typescript", | ||
"test:jest": "TZ=UTC jest --coverage", | ||
"test.watch": "TZ=UTC jest --watchAll", | ||
"jest": "TZ=UTC jest", | ||
"test:typescript": "tsc --noEmit", | ||
"copy:license": "cp ../../LICENSE LICENSE", | ||
"copy:notice": "cp ../../NOTICE NOTICE", | ||
"prepack": "yarn run copy:license && yarn run copy:notice", | ||
"pack": "yarn pack" | ||
}, | ||
"devDependencies": { | ||
"@aws-sdk/client-iotsitewise": "^3.39.0", | ||
"@awsui/design-tokens": "^3.0.0", | ||
"@rollup/plugin-typescript": "^8.3.2", | ||
"@types/jest": "^28.1.0", | ||
"eslint-config-airbnb": "^18.2.1", | ||
"eslint-config-airbnb-typescript": "^12.3.1", | ||
"jest": "^28.1.0", | ||
"jest-cli": "^28.1.0", | ||
"jest-extended": "^2.0.0", | ||
"rollup-plugin-import-css": "^3.0.3", | ||
"sass": "^1.30.0", | ||
"ts-jest": "^28.0.4" | ||
}, | ||
"dependencies": { | ||
"@awsui/collection-hooks": "^1.0.0", | ||
"@awsui/components-react": "^3.0.0", | ||
"@iot-app-kit/core": "^1.3.0", | ||
"@synchro-charts/core": "^4.0.0", | ||
"@synchro-charts/react": "^4.0.0", | ||
"d3-array": "^3.1.6", | ||
"react": ">=17.0.2", | ||
"react-dom": ">=17.0.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import typescript from '@rollup/plugin-typescript'; | ||
import pkg from './package.json'; | ||
import css from 'rollup-plugin-import-css'; | ||
|
||
export default [ | ||
{ | ||
input: 'src/index.ts', | ||
output: [ | ||
{ | ||
file: pkg.main, | ||
format: 'cjs', | ||
}, | ||
{ | ||
file: pkg.module, | ||
format: 'esm', | ||
}, | ||
], | ||
plugins: [typescript({ tsconfig: './tsconfig.json' }), css()], | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// export * from './table'; WIP | ||
export * from './utils'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,217 @@ | ||
import { DataStream, Viewport } from '@iot-app-kit/core'; | ||
import { Annotations, COMPARISON_OPERATOR, getThresholds } from '@synchro-charts/core'; | ||
import { createTableItems } from './createTableItems'; | ||
|
||
const dataStreams: DataStream[] = [ | ||
{ | ||
id: 'data-1', | ||
data: [ | ||
{ y: 0, x: new Date(2021, 1, 1, 0, 0, 1).getTime() }, | ||
{ y: 1, x: new Date(2022, 1, 1, 0, 0, 2).getTime() }, | ||
{ y: 2, x: new Date(2022, 1, 1, 0, 0, 3).getTime() }, | ||
{ y: 3, x: new Date(2022, 1, 1, 0, 0, 4).getTime() }, | ||
{ y: 4, x: new Date(2022, 1, 1, 0, 0, 5).getTime() }, | ||
], | ||
resolution: 0, | ||
}, | ||
{ | ||
id: 'data-2', | ||
data: [{ y: 11, x: new Date(2022, 1, 1, 0, 0, 1).getTime() }], | ||
resolution: 0, | ||
}, | ||
{ | ||
id: 'agg_data', | ||
aggregates: { | ||
60: [{ y: 60, x: new Date(2022, 1, 1, 0, 0, 1).getTime() }], | ||
}, | ||
data: [{ y: 0, x: new Date(2022, 1, 1, 0, 0, 1).getTime() }], | ||
resolution: 60, | ||
}, | ||
]; | ||
|
||
const viewport = { | ||
duration: '1000', | ||
}; | ||
|
||
const itemWithRef = [ | ||
{ | ||
value1: { | ||
$cellRef: { | ||
id: 'data-1', | ||
resolution: 0, | ||
}, | ||
noRef: 'No Ref', | ||
}, | ||
value2: { | ||
$cellRef: { | ||
id: 'data-2', | ||
resolution: 0, | ||
}, | ||
}, | ||
noRef: { | ||
data: [1, 2, 3, 4], | ||
}, | ||
rawValue: 10, | ||
}, | ||
{ | ||
data: { | ||
$cellRef: { | ||
id: 'data-1', | ||
resolution: 0, | ||
}, | ||
}, | ||
invalid: { | ||
$cellRef: { | ||
id: 'invalid-data-stream', | ||
resolution: 0, | ||
}, | ||
}, | ||
aggregates: { | ||
$cellRef: { | ||
id: 'agg_data', | ||
resolution: 60, | ||
}, | ||
}, | ||
invalidAggregation: { | ||
$cellRef: { | ||
id: 'agg_data', | ||
resolution: 55, | ||
}, | ||
}, | ||
}, | ||
]; | ||
|
||
describe('createTableItems', () => { | ||
it('creates table items', () => { | ||
const items = createTableItems({ dataStreams, viewport, items: itemWithRef }); | ||
expect(items).toMatchObject([ | ||
{ | ||
value1: { value: 4 }, | ||
value2: { value: 11 }, | ||
noRef: { | ||
value: { | ||
data: [1, 2, 3, 4], | ||
}, | ||
}, | ||
rawValue: { value: 10 }, | ||
}, | ||
{ | ||
data: { value: 4 }, | ||
invalid: { value: undefined }, | ||
aggregates: { value: 60 }, | ||
invalidAggregation: { value: undefined }, | ||
}, | ||
]); | ||
}); | ||
|
||
it('returns value as it is a primitive value', () => { | ||
const items = createTableItems({ dataStreams, viewport, items: itemWithRef }); | ||
const data = items[0].value1; | ||
expect((data as number) + 1).toBe(5); | ||
}); | ||
|
||
it('gets different data points on different viewports on the same data stream', () => { | ||
const viewport1: Viewport = { | ||
start: new Date(2022, 1, 1, 0, 0, 1), | ||
end: new Date(2022, 1, 1, 0, 0, 2), | ||
}; | ||
|
||
const viewport2 = { | ||
start: new Date(2022, 1, 1, 0, 0, 1), | ||
end: new Date(2022, 1, 1, 0, 0, 3), | ||
}; | ||
|
||
const itemDef = [ | ||
{ | ||
value1: { | ||
$cellRef: { | ||
id: 'data-1', | ||
resolution: 0, | ||
}, | ||
}, | ||
}, | ||
]; | ||
const items1 = createTableItems({ dataStreams, viewport: viewport1, items: itemDef }); | ||
const items2 = createTableItems({ dataStreams, viewport: viewport2, items: itemDef }); | ||
|
||
expect(items1).not.toEqual(items2); | ||
}); | ||
|
||
it('returns undefined value when no data points in data stream', () => { | ||
// no data point would match this viewport | ||
const viewport1: Viewport = { | ||
start: new Date(2020, 1, 1, 0), | ||
end: new Date(2021, 1, 1, 0), | ||
}; | ||
const itemDef = [ | ||
{ | ||
noDataPoints: { | ||
$cellRef: { | ||
id: 'data-1', | ||
resolution: 0, | ||
}, | ||
}, | ||
}, | ||
]; | ||
const items1 = createTableItems({ dataStreams, viewport: viewport1, items: itemDef }); | ||
expect(items1).toMatchObject([{ noDataPoints: { value: undefined } }]); | ||
}); | ||
|
||
it('contains breached threshold', () => { | ||
const thresholdOne = { | ||
value: 1, | ||
color: 'red', | ||
comparisonOperator: COMPARISON_OPERATOR.GREATER_THAN, | ||
dataStreamIds: ['data-1'], | ||
}; | ||
const thresholdTwo = { | ||
value: 0, | ||
color: 'black', | ||
comparisonOperator: COMPARISON_OPERATOR.GREATER_THAN, | ||
}; | ||
|
||
const annotations: Annotations = { | ||
y: [ | ||
// only apply to data stream 'data-1' | ||
thresholdOne, | ||
|
||
// apply to both data stream | ||
thresholdTwo, | ||
], | ||
}; | ||
|
||
const items = [ | ||
{ | ||
itemOne: { | ||
$cellRef: { | ||
id: 'data-1', | ||
resolution: 0, | ||
}, | ||
}, | ||
itemTwo: { | ||
$cellRef: { | ||
id: 'data-2', | ||
resolution: 0, | ||
}, | ||
}, | ||
|
||
noRef: 10, | ||
}, | ||
]; | ||
|
||
const tableItems = createTableItems({ | ||
dataStreams, | ||
viewport, | ||
items, | ||
thresholds: getThresholds(annotations), | ||
}); | ||
|
||
const { itemOne, itemTwo, noRef } = tableItems[0]; | ||
|
||
expect(itemOne.threshold).toMatchObject(thresholdOne); | ||
expect(itemTwo.threshold).toMatchObject(thresholdTwo); | ||
|
||
// Item with no $cellRef does not support threshold | ||
expect(noRef).toMatchObject({ threshold: undefined }); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still have unnecessary describe blocks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see what do you mean now. Removing all describe blocks.