Skip to content

Commit

Permalink
feat(React18): Adds support for react 18
Browse files Browse the repository at this point in the history
  • Loading branch information
Mitchell Lee authored and TheEvilDev committed Mar 8, 2023
1 parent 785d833 commit 596c6b0
Show file tree
Hide file tree
Showing 160 changed files with 22,959 additions and 46,995 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
ref: release-please--branches--main
fetch-depth: 2

- name: Setting up Node.js 16
- name: Setting up Node.js
uses: actions/setup-node@v3
with:
node-version: 16.x
Expand Down
6 changes: 3 additions & 3 deletions examples/react-app/.env.local.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
REACT_APP_AWS_ACCESS_KEY_ID=
REACT_APP_AWS_SECRET_ACCESS_KEY=
REACT_APP_AWS_SESSION_TOKEN=
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_SESSION_TOKEN=
36,312 changes: 0 additions & 36,312 deletions examples/react-app/package-lock.json

This file was deleted.

33 changes: 19 additions & 14 deletions examples/react-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@cloudscape-design/components": "^3.0.222",
"@iot-app-kit/components": "*",
"@iot-app-kit/core": "*",
"@iot-app-kit/react-components": "*",
Expand All @@ -11,19 +12,11 @@
"@iot-app-kit/source-iotsitewise": "*",
"@iot-app-kit/source-iottwinmaker": "*",
"@iot-app-kit/table": "*",
"@material-ui/core": "^4.12.4",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^12.0.0",
"@testing-library/user-event": "^12.0.0",
"@types/jest": "^27.5.2",
"@types/node": "^16.11.59",
"@types/react": "^17.0.2",
"@types/react-dom": "^17.0.2",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "5.0.1",
"typescript": "^4.8.3",
"web-vitals": "^2.1.4"
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.8.2",
"web-vitals": "^2.1.4",
"zustand": "^3.7.1"
},
"scripts": {
"start": "GENERATE_SOURCEMAP=false react-app-rewired start",
Expand Down Expand Up @@ -51,10 +44,22 @@
]
},
"devDependencies": {
"@svgr/webpack": "^6.5.1",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^14.0.0",
"@testing-library/user-event": "^12.0.0",
"@tsconfig/recommended": "^1.0.1",
"@types/jest": "^27.5.2",
"@types/node": "^16.11.59",
"@types/react": "^18.0.28",
"@types/react-dom": "^18.0.11",
"adjust-sourcemap-loader": "^5.0.0",
"node-polyfill-webpack-plugin": "^2.0.1",
"nodemon": "^2.0.19",
"postcss-initial": "^4.0.1",
"react-app-rewired": "^2.2.1",
"sass": "^1.58.3"
"react-scripts": "5.0.1",
"sass": "^1.58.3",
"typescript": "^4.8.3"
}
}
12 changes: 0 additions & 12 deletions examples/react-app/src/App.tsx

This file was deleted.

42 changes: 42 additions & 0 deletions examples/react-app/src/components/DashboardManager/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { ISceneNodeInternal } from "@iot-app-kit/scene-composer/dist/src/store";
import React, { createContext, FC, ReactNode, useContext, useState } from "react";

interface SceneNode {
node: ISceneNodeInternal,
entityId?: string,
targetName?: string
};

interface IDashboardManagerContext {
selectedNode?: SceneNode,
setSelectedNode: (node: SceneNode | undefined) => void
}

interface DashboardManagerProps {
children: ReactNode;
}

const DashboardManagerContext = createContext<IDashboardManagerContext>({
setSelectedNode: () => {},
});



export const useDashboardContext = () => {
return useContext(DashboardManagerContext);
}

const DashboardManager: FC<DashboardManagerProps> = ({ children }) => {
const [selectedNode, setSelectedNode] = useState<SceneNode | undefined>();

return (
<DashboardManagerContext.Provider value={{
selectedNode,
setSelectedNode
}}>
{children}
</DashboardManagerContext.Provider>
)
}

export default DashboardManager;
4 changes: 2 additions & 2 deletions examples/react-app/src/components/SceneViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ const queries = [
];

const SceneViewer = () => {
const onSelectionChanged = useCallback((e) => {
const onSelectionChanged = useCallback((e: any) => {
console.log('onSelectionChanged event fired with data: ', e);
}, []);

const onWidgetClick = useCallback((e) => {
const onWidgetClick = useCallback((e: any) => {
console.log('onWidgetClick event fired with data: ', e);
}, []);

Expand Down
179 changes: 179 additions & 0 deletions examples/react-app/src/components/ViewPort/Controls.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
import { useCallback, useMemo } from "react";
import { DateRangePicker, DateRangePickerProps } from "@cloudscape-design/components";
import React from "react";
import { useViewport } from "@iot-app-kit/react-components";

const mapUnit = (unit: DateRangePickerProps.TimeUnit) => {
switch (unit) {
case 'day':
return 'd';
case 'minute':
return 'm';
case 'hour':
return 'h';
case 'week':
return 'w';
}
}

const reverseMapUnit = (symbol: string): DateRangePickerProps.TimeUnit => {
switch(symbol) {
case 'd':
return 'day';
case 'h':
return 'hour';
case 'w':
return 'week';
default:
return 'minute'
}
}

const parseDuration = (duration: string) => {
const amount = parseInt(duration);
const unitRef = duration.split(`${amount}`)[1];

return {
amount,
unit: reverseMapUnit(unitRef),
}
}

const ViewportControls = () => {
const { setViewport, viewport } = useViewport();

const value: DateRangePickerProps.Value = useMemo(() => {
const vp = viewport as any;
if (vp?.duration) {
const { amount, unit } = parseDuration(vp.duration);

return {
amount,
type: "relative",
unit
} as DateRangePickerProps.Value
} else {
return {
startDate: vp?.start,
endDate: vp?.end,
type: 'absolute',
}
}
}, [viewport]);

const apply = useCallback((newValue: DateRangePickerProps.Value | null) => {
if (newValue) {
if (newValue.type === 'absolute') {
const { startDate, endDate } = newValue as DateRangePickerProps.AbsoluteValue;

setViewport({
start: new Date(startDate),
end: new Date(endDate)
})
}
else {
const { amount, unit } = newValue as DateRangePickerProps.RelativeValue;
setViewport({
duration: `${amount}${mapUnit(unit)}`, // TODO: This probably needs to account for the unit as well, need to see how that works in AppKit
})
}
}
}, [setViewport]);

return (
<DateRangePicker
onChange={({ detail }) => apply(detail.value)}
value={value}
relativeOptions={[
{
key: "previous-5-minutes",
amount: 5,
unit: "minute",
type: "relative"
},
{
key: "previous-30-minutes",
amount: 30,
unit: "minute",
type: "relative"
},
{
key: "previous-1-hour",
amount: 1,
unit: "hour",
type: "relative"
},
{
key: "previous-6-hours",
amount: 6,
unit: "hour",
type: "relative"
}
]}
isValidRange={range => {
if (range?.type === "absolute") {
const [
startDateWithoutTime
] = range.startDate.split("T");
const [
endDateWithoutTime
] = range.endDate.split("T");
if (
!startDateWithoutTime ||
!endDateWithoutTime
) {
return {
valid: false,
errorMessage:
"The selected date range is incomplete. Select a start and end date for the date range."
};
}
if (
Number(new Date(range.startDate)) - Number(new Date(range.endDate)) >
0
) {
return {
valid: false,
errorMessage:
"The selected date range is invalid. The start date must be before the end date."
};
}
}
return { valid: true };
}}
i18nStrings={{
todayAriaLabel: "Today",
nextMonthAriaLabel: "Next month",
previousMonthAriaLabel: "Previous month",
customRelativeRangeDurationLabel: "Duration",
customRelativeRangeDurationPlaceholder:
"Enter duration",
customRelativeRangeOptionLabel: "Custom range",
customRelativeRangeOptionDescription:
"Set a custom range in the past",
customRelativeRangeUnitLabel: "Unit of time",
formatRelativeRange: e => {
const n =
1 === e.amount ? e.unit : `${e.unit}s`;
return `Last ${e.amount} ${n}`;
},
formatUnit: (e, n) => (1 === n ? e : `${e}s`),
dateTimeConstraintText:
"Range is 6 to 30 days. For date, use YYYY/MM/DD. For time, use 24 hr format.",
relativeModeTitle: "Relative range",
absoluteModeTitle: "Absolute range",
relativeRangeSelectionHeading: "Choose a range",
startDateLabel: "Start date",
endDateLabel: "End date",
startTimeLabel: "Start time",
endTimeLabel: "End time",
clearButtonLabel: "Clear and dismiss",
cancelButtonLabel: "Cancel",
applyButtonLabel: "Apply"
}}
placeholder="Filter by a date and time range"
/>
)
}

export default ViewportControls;
37 changes: 0 additions & 37 deletions examples/react-app/src/components/componentsTab.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion examples/react-app/src/configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const dataBindingTemplate: IDataBindingTemplate = {
*/
export const videoEntityId = undefined;
export const videoComponentName = undefined;

/**
* Specify time range for the video player
*/
Expand Down

0 comments on commit 596c6b0

Please sign in to comment.