Skip to content
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

chore(reveal-react-components): add formatting and linting #3422

Merged
merged 34 commits into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
865edf7
chore: restructure folder layout
christjt Jun 21, 2023
c559f9c
asd
christjt Jun 22, 2023
a2aec9f
asd
christjt Jun 22, 2023
ca83d9b
feat: add RevealContainer
christjt Jun 22, 2023
a4b3e5d
fix: update transformation when updating prop
christjt Jun 23, 2023
1e69fe0
fix: conflicts
christjt Jun 23, 2023
8c2cba7
fix: conflicts
christjt Jun 23, 2023
a20c401
fix: update storybook setup
christjt Jun 23, 2023
2100d01
fix: update reveal version
christjt Jun 26, 2023
81de060
Merge branch 'master' of https://github.com/cognitedata/reveal into c…
christjt Jun 26, 2023
881475b
chore: setup eslint linting and prettier formatting
christjt Jun 26, 2023
7011b0b
chore: run formatter
christjt Jun 26, 2023
af0a482
chore: add prettier plugin to eslintconfig
christjt Jun 26, 2023
68e3e0a
chore: replace deprecated prettier config param
christjt Jun 26, 2023
9cf65b0
fix: add proper import
christjt Jun 26, 2023
0ac0730
Merge master into christjt/react-components-linting
cognite-bulldozer[bot] Jun 26, 2023
d565a79
fix: remove unused scripts and update tsconfig
christjt Jun 26, 2023
e6db65b
Merge branch 'christjt/react-components-linting' of https://github.co…
christjt Jun 26, 2023
3d23d46
fix: set proper base URL for build
christjt Jun 26, 2023
c6a7ebd
fix: merge master
christjt Jun 26, 2023
eeb8eba
fix: config and linting
christjt Jun 26, 2023
c43d962
Merge refs/heads/master into christjt/react-components-linting
cognite-bulldozer[bot] Jun 26, 2023
8d2226a
chore: use ReactElement
christjt Jun 26, 2023
4054dde
chore: add copywrite header rule
christjt Jun 26, 2023
c2940c5
Merge branch 'christjt/react-components-linting' of https://github.co…
christjt Jun 26, 2023
3e0a076
chore: fix yarn.lock confict
christjt Jun 26, 2023
bd086b5
chore: remove unused patter
christjt Jun 26, 2023
e846d0a
fix: refactor out some functions
christjt Jun 26, 2023
2302d6a
chore: add eslint cache
christjt Jun 26, 2023
ad30e99
Merge refs/heads/master into christjt/react-components-linting
cognite-bulldozer[bot] Jun 26, 2023
4732e19
Merge refs/heads/master into christjt/react-components-linting
cognite-bulldozer[bot] Jun 27, 2023
e6a06c4
fix: add consistent type and eqeqeq lint rules
christjt Jun 27, 2023
1aa43b9
Merge branch 'christjt/react-components-linting' of https://github.co…
christjt Jun 27, 2023
f39b162
Merge refs/heads/master into christjt/react-components-linting
cognite-bulldozer[bot] Jun 27, 2023
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 react-components/.babelrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
"@babel/preset-react"
],
"plugins": []
}
}
5 changes: 5 additions & 0 deletions react-components/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
dist/*
node_modules/*
.yarn/*
.storybook/*
yarn.lock
43 changes: 43 additions & 0 deletions react-components/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
module.exports = {
env: {
browser: true,
es2021: true
},
extends: [
'standard-with-typescript',
'eslint:recommended',
'plugin:react/recommended',
'plugin:prettier/recommended'
],
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
project: ['./tsconfig.json']
},
plugins: ['react', 'prettier', 'header'],
rules: {
'react/react-in-jsx-scope': 'off'
},
settings: {
react: {
version: 'detect'
}
},
overrides: [
{
files: ['src/**/*.ts', 'src/**/*.tsx', 'stories/**/*.ts', 'stories/**/*.tsx'],
rules: {
'header/header': [
'error',
'block',
[
{
pattern: `(Copyright 20\\d{2}|istanbul ignore)`,
template: `!\n * Copyright ${new Date().getFullYear()} Cognite AS\n `
}
]
]
}
}
]
};
8 changes: 8 additions & 0 deletions react-components/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"semi": true,
"tabWidth": 2,
"printWidth": 100,
"singleQuote": true,
"trailingComma": "none",
"bracketSameLine": true
}
18 changes: 9 additions & 9 deletions react-components/.storybook/main.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import type { StorybookConfig } from "@storybook/react-webpack5";
import type { StorybookConfig } from '@storybook/react-webpack5';
const config: StorybookConfig = {
stories: ["../src/**/*.mdx", "../src/**/*.stories.@(js|jsx|ts|tsx)"],
stories: ['../stories/**/*.stories.@(js|jsx|ts|tsx)'],
addons: [
"@storybook/addon-links",
"@storybook/addon-essentials",
"@storybook/addon-interactions",
'@storybook/addon-links',
'@storybook/addon-essentials',
'@storybook/addon-interactions'
],
framework: {
name: "@storybook/react-webpack5",
options: {},
name: '@storybook/react-webpack5',
options: {}
},
docs: {
autodocs: "tag",
},
autodocs: 'tag'
}
};
export default config;
12 changes: 6 additions & 6 deletions react-components/.storybook/preview.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import type { Preview } from "@storybook/react";
import type { Preview } from '@storybook/react';

const preview: Preview = {
parameters: {
actions: { argTypesRegex: "^on[A-Z].*" },
actions: { argTypesRegex: '^on[A-Z].*' },
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/,
},
},
},
date: /Date$/
}
}
}
};

export default preview;
Binary file not shown.
14 changes: 13 additions & 1 deletion react-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"build:watch": "yarn run build --watch",
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build",
"tsc": "tsc"
"tsc": "tsc",
"lint": "eslint . --cache"
},
"peerDependencies": {
"@cognite/cogs.js": ">=9",
Expand All @@ -39,7 +40,18 @@
"@types/react": "18.2.7",
"@types/styled-components": "5.1.26",
"@types/three": "0.152.0",
"@typescript-eslint/eslint-plugin": "^5.50.0",
"eslint": "^8.0.1",
"eslint-config-prettier": "^8.8.0",
"eslint-config-standard-with-typescript": "latest",
"eslint-plugin-header": "^3.1.1",
"eslint-plugin-import": "^2.25.2",
"eslint-plugin-n": "^15.0.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-promise": "^6.0.0",
"eslint-plugin-react": "latest",
"moq.ts": "^10.0.6",
"prettier": "^2.8.8",
"prop-types": "15.8.1",
"react": "18.2.0",
"react-dom": "18.2.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,27 @@
import { useEffect, useRef } from "react";
import { AddModelOptions, CogniteCadModel } from "@cognite/reveal";
import { useReveal } from "../RevealContainer/RevealContext";
import { Matrix4 } from "three";
/*!
* Copyright 2023 Cognite AS
*/
import { type ReactElement, useEffect, useRef } from 'react';
import { type AddModelOptions, type CogniteCadModel } from '@cognite/reveal';
import { useReveal } from '../RevealContainer/RevealContext';
import { type Matrix4 } from 'three';

type Cognite3dModelProps = {
interface Cognite3dModelProps {
addModelOptions: AddModelOptions;
transform?: THREE.Matrix4;
};
transform?: Matrix4;
}

export default function CogniteCadModelContainer({
addModelOptions,
transform,
}: Cognite3dModelProps) {
transform
}: Cognite3dModelProps): ReactElement {
const modelRef = useRef<CogniteCadModel>();
const viewer = useReveal();
const { modelId, revisionId } = addModelOptions;

useEffect(() => {
addModel(modelId, revisionId, transform).catch(console.error);
return () => {
if (
modelRef.current === undefined ||
!viewer.models.includes(modelRef.current)
) {
return;
}
viewer.removeModel(modelRef.current);
modelRef.current = undefined;
};
return removeModel;
}, [addModelOptions]);

useEffect(() => {
Expand All @@ -37,15 +31,17 @@ export default function CogniteCadModelContainer({

return <></>;

async function addModel(
modelId: number,
revisionId: number,
transform?: Matrix4
) {
async function addModel(modelId: number, revisionId: number, transform?: Matrix4): Promise<void> {
const cadModel = await viewer.addCadModel({ modelId, revisionId });
if (transform !== undefined) {
cadModel.setModelTransformation(transform);
}
modelRef.current = cadModel;
}

function removeModel(): void {
if (modelRef.current === undefined || !viewer.models.includes(modelRef.current)) return;
viewer.removeModel(modelRef.current);
modelRef.current = undefined;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* Copyright 2023 Cognite AS
*/

import { Cognite3DViewer, Image360 } from '@cognite/reveal';
import React, { useEffect, useRef, useState } from 'react';
import { type Cognite3DViewer, type Image360 } from '@cognite/reveal';
import { type ReactElement, useEffect, useRef, useState } from 'react';
import { Image360HistoricalPanel } from './Panel/Image360HistoricalPanel';
import { Image360HistoricalSummary } from './Toolbar/Image360HistoricalSummary';
import { formatDate } from './utils/FormatDate';
Expand All @@ -20,35 +20,37 @@ export const Image360HistoricalDetails = ({
viewer,
image360Entity,
onExpand
}: Image360HistoricalDetailsProps) => {
}: Image360HistoricalDetailsProps): ReactElement => {
const [revisionDetailsExpanded, setRevisionDetailsExpanded] = useState<boolean>(false);
const [activeRevision, setActiveRevision] = useState<number>(0);
const [revisionCollection, setRevisionCollection] = useState<
{
Array<{
date?: string;
imageUrl?: string;
index: number;
image360Entity: Image360 | undefined;
}[]
}>
>([]);
const [imageUrls, setImageUrls] = useState<(string | undefined)[]>([]);
const [imageUrls, setImageUrls] = useState<Array<string | undefined>>([]);
const [minWidth, setMinWidth] = useState('100px');
const newScrollPosition = useRef(0);

useEffect(() => {
const fetchRevisionCollection = async () => {
if (image360Entity) {
const fetchRevisionCollection = async (): Promise<void> => {
if (image360Entity != null) {
const revisions = image360Entity.getRevisions();
const revisionDates = revisions.map((revision) => revision.date);
const imageDatas = await Promise.all(revisions.map(async (revision) => await revision.getPreviewThumbnailUrl()));
const imageDatas = await Promise.all(
revisions.map(async (revision) => await revision.getPreviewThumbnailUrl())
);
setImageUrls(imageDatas);

const collection = revisionDates.map((date, index) => {
return {
date: formatDate(date!),
imageUrl: imageDatas[index]!,
index: index,
image360Entity: image360Entity
date: formatDate(date),
imageUrl: imageDatas[index],
index,
image360Entity
};
});

Expand All @@ -58,12 +60,12 @@ export const Image360HistoricalDetails = ({
}
};

fetchRevisionCollection();
void fetchRevisionCollection();

return () => {
// Remove image URLs
imageUrls.forEach((url) => {
if (url) {
if (url !== undefined) {
URL.revokeObjectURL(url);
}
});
Expand All @@ -74,14 +76,14 @@ export const Image360HistoricalDetails = ({
useEffect(() => {
const newMinWidth = revisionDetailsExpanded ? '100%' : '100px';
setMinWidth(newMinWidth);
if (onExpand) {
if (onExpand != null) {
onExpand(revisionDetailsExpanded);
}
}, [revisionDetailsExpanded]);

return (
<DetailsContainer style={{ minWidth }}>
{viewer && (
{
<>
<Image360HistoricalPanel
key={uniqueId()}
Expand All @@ -102,7 +104,7 @@ export const Image360HistoricalDetails = ({
/>
)}
</>
)}
}
</DetailsContainer>
);
};
Expand Down
Loading
Loading