Skip to content

Commit 5c1aa04

Browse files
committed
IKImage bugfix: changes and cleanup
1 parent ac3241d commit 5c1aa04

File tree

15 files changed

+58
-73
lines changed

15 files changed

+58
-73
lines changed

.github/workflows/nodejs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ jobs:
5555
- name: Run E2E tests
5656
uses: cypress-io/github-action@v2
5757
with:
58-
start: npm run start:test-app
59-
wait-on: http://localhost:3001
58+
start: npm run serve:test-app
59+
wait-on: http://localhost:4000
6060
env:
6161
CI: true
6262
REACT_APP_PUBLIC_KEY: ${{ secrets.ik_public_key }}

CONTRIBUTING.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ npm run build
1212

1313
## Running test cases
1414

15-
The designated directory for tests is `/test/jest` folder. All tests will be run against the assertion present in the `/test/jest/__snapshot__` folder. To create this file you need to just run below command just once. Any update in the tests can be updated to by pressing `u` while the test environment is running.
15+
The designated directory for tests is `/tests/jest` folder. All tests will be run against the assertion present in the `/tests/jest/__snapshot__` folder. To create this file you need to run the following command once. To rerun tests after making changes press`u` while the test environment is running.
1616

1717
Execute following command from the root folder to start testing.
1818
```sh
1919
npm run test
2020
```
2121

22-
## Running sample frontend react app
22+
## Running the test frontend React app
2323

24-
Please refer to the sample app `Readme.md` for details.
24+
Please refer to the the test app `README.md` for details.
2525

26-
## Running sample backend server
26+
## Running the test backend server
2727

28-
Please refer to the sample app `Readme.md` for details.
28+
Please refer to the the test app `README.md` for details.

cypress.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
"videosFolder": "tests/cypress/videos",
77
"supportFile": "tests/cypress/support/index.js",
88
"env": {
9-
"APP_HOST": "http://localhost:3001/"
9+
"APP_HOST": "http://localhost:4000/"
1010
}
1111
}

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
{
22
"name": "imagekitio-react",
3-
"version": "1.0.9",
3+
"version": "1.0.10",
44
"description": "React SDK for ImageKit.io which implements client-side upload and URL generation for use inside a react application.",
55
"scripts": {
66
"build": "rm -rf dist*;rollup -c",
77
"test": "jest",
88
"test:ci": "jest --coverage && codecov",
99
"test:cov": "jest --coverage",
10-
"test:e2e": "cypress open --project ./tests",
10+
"test:e2e": "cypress open",
1111
"test:watch": "jest --watch",
12-
"start:sample": "export SKIP_PREFLIGHT_CHECK=true;npx serve -s samples/sample-app/build -p 3000",
13-
"start:test-app": "export SKIP_PREFLIGHT_CHECK=true;npx serve -s tests/test-app/build -p 3001"
12+
"serve:test-app": "export SKIP_PREFLIGHT_CHECK=true;npx serve -s tests/test-app/build -p 4000"
1413
},
1514
"repository": {
1615
"type": "git",

samples/sample-app/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
22

3-
We will assume you are in the directory `samples\sample-app` while following the further instructions
3+
We will assume you are in the directory `samples/sample-app` while executing the following instructions.
44

55
## Installation
66

samples/sample-app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
"version": "0.1.0",
44
"private": true,
55
"dependencies": {
6-
"imagekitio-react": "^1.0.7",
76
"@testing-library/jest-dom": "^4.2.4",
87
"@testing-library/react": "^9.3.2",
98
"@testing-library/user-event": "^7.1.2",
9+
"imagekitio-react": "^1.0.10",
1010
"react": "^16.12.0",
1111
"react-dom": "^16.12.0",
1212
"react-scripts": "3.4.0"

samples/sample-app/server/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"scripts": {
77
"server": "nodemon server"
88
},
9-
"author": "Utkarsh Maharana",
9+
"author": "ImageKit",
1010
"license": "ISC",
1111
"devDependencies": {
1212
"cors": "^2.8.5",

samples/sample-app/src/App.js

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,10 @@ function App() {
1818
const onSuccess = res => {
1919
console.log("Success");
2020
console.log(res);
21-
setUploadedImageSource(res.url);
21+
setUploadedImageSource(res.url);
2222
};
2323

2424
const [uploadedImageSource, setUploadedImageSource] = useState();
25-
const [imageTr, setImageTr] = useState([{
26-
"height": "200",
27-
"width": "200"
28-
}]);
2925

3026
return (
3127
<div className="App">
@@ -40,19 +36,11 @@ function App() {
4036
<IKImage src={src} />
4137

4238
<p>Transformation - height and width manipulation</p>
43-
<IKImage className={'img-transformation'} path={path} transformation={imageTr} />
44-
<div>
45-
<p>Click here to apply max radius on above image </p>
46-
<button
47-
className={'btn-to-change-tr'}
48-
onClick={() => setImageTr([{
49-
"height": "200",
50-
"width": "200",
51-
"radius" : "max"
52-
}])}
53-
>Click to apply radius</button>
54-
</div>
55-
<br />
39+
<IKImage className={'img-transformation'} path={path} transformation={[{
40+
"height": "200",
41+
"width": "200"
42+
}]} />
43+
<br />
5644
<p>Chained transformation</p>
5745
<IKImage path={path} transformation={[{
5846
"height": "200",
@@ -75,7 +63,7 @@ function App() {
7563

7664
<p>Progressive image loading wihtout lazy loading</p>
7765
<IKImage
78-
className={'lqip'}
66+
className={'lqip'}
7967
path={path}
8068
transformation={[{
8169
"height": "200",
@@ -88,7 +76,7 @@ function App() {
8876

8977
<p>Progressive image loading with lazy loading</p>
9078
<IKImage
91-
className={'lazyload-lqip'}
79+
className={'lazyload-lqip'}
9280
path={path}
9381
transformation={[{
9482
"height": "200",
@@ -99,12 +87,6 @@ function App() {
9987
/>
10088

10189

102-
<p>File upload - To use this funtionality please remember to setup the server</p>
103-
<IKUpload
104-
onError={onError}
105-
onSuccess={onSuccess}
106-
/>
107-
10890
<p>File upload along with upload API options - To use this funtionality please remember to setup the server</p>
10991
<IKUpload
11092
fileName="test.jpg"
@@ -114,11 +96,12 @@ function App() {
11496
useUniqueFileName={true}
11597
responseFields={["tags"]}
11698
folder={"/sample-folder"}
117-
onError={onError} onSuccess={onSuccess}
99+
onError={onError}
100+
onSuccess={onSuccess}
118101
/>
119102

120-
<p>Your above uploaded file will appear here </p>
121-
<IKImage urlEndpoint={urlEndpoint} src={uploadedImageSource} />
103+
<p>Your uploaded file will appear here </p>
104+
<IKImage urlEndpoint={urlEndpoint} src={uploadedImageSource} />
122105
</IKContext>
123106
</div>
124107
);

src/components/IKImage/index.js

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class IKImage extends ImageKitComponent {
2020
lqipSrc: lqipSrc,
2121
originalSrcLoaded: false,
2222
intersected: false,
23-
contextOptions : {}
23+
contextOptions : {}
2424
};
2525
}
2626

@@ -128,7 +128,7 @@ class IKImage extends ImageKitComponent {
128128

129129
componentDidMount() {
130130
this.updateImageUrl();
131-
this.setState({ contextOptions : this.getContext() });
131+
this.setState({ contextOptions : this.getContext() });
132132

133133
const image = this.imageRef.current;
134134
const { lqip, loading } = this.props;
@@ -169,26 +169,28 @@ class IKImage extends ImageKitComponent {
169169
}
170170

171171
areObjectsDifferent(prevProps, newProps) {
172-
for(var index=0; index<propsAffectingURL.length; index++){
173-
if(prevProps[propsAffectingURL[index]] != newProps[propsAffectingURL[index]]) return true;
174-
}
175-
return false;
172+
for (let index = 0; index < propsAffectingURL.length; index++) {
173+
if (prevProps[propsAffectingURL[index]] != newProps[propsAffectingURL[index]]) {
174+
return true;
175+
};
176+
}
177+
return false;
176178
}
177179

178-
componentDidUpdate(prevProps, prevState) {
179-
var contextOptions = this.getContext();
180-
181-
if (
182-
this.areObjectsDifferent(prevProps, this.props) ||
183-
this.areObjectsDifferent(prevState.contextOptions, contextOptions)
184-
) {
185-
const { originalSrc, lqipSrc } = this.getSrc();
186-
this.setState({originalSrc, lqipSrc }, () => {
187-
this.updateImageUrl();
188-
this.setState({ contextOptions : this.getContext() });
189-
});
190-
}
191-
}
180+
componentDidUpdate(prevProps, prevState) {
181+
let contextOptions = this.getContext();
182+
183+
if (
184+
this.areObjectsDifferent(prevProps, this.props) ||
185+
this.areObjectsDifferent(prevState.contextOptions, contextOptions)
186+
) {
187+
const { originalSrc, lqipSrc } = this.getSrc();
188+
this.setState({ originalSrc, lqipSrc }, () => {
189+
this.updateImageUrl();
190+
this.setState({ contextOptions: this.getContext() });
191+
});
192+
}
193+
}
192194

193195
render() {
194196
let { currentUrl } = this.state;

tests/cypress.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

0 commit comments

Comments
 (0)