Skip to content

Commit c59fe5e

Browse files
Fix logs for new SplitFactoryProvider component
1 parent 326aa6d commit c59fe5e

File tree

8 files changed

+236
-92
lines changed

8 files changed

+236
-92
lines changed

.github/workflows/ci-cd.yml

+163
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
name: ci
2+
3+
on:
4+
push:
5+
branches:
6+
- '**'
7+
pull_request:
8+
branches:
9+
- master
10+
- development
11+
12+
concurrency:
13+
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
14+
cancel-in-progress: true
15+
16+
permissions:
17+
contents: read
18+
id-token: write
19+
20+
jobs:
21+
build:
22+
name: Build
23+
runs-on: ubuntu-latest
24+
steps:
25+
- name: Checkout code
26+
uses: actions/checkout@v4
27+
with:
28+
fetch-depth: 0
29+
30+
- name: Set up nodejs
31+
uses: actions/setup-node@v3
32+
with:
33+
node-version: 'lts/*'
34+
cache: 'npm'
35+
36+
- name: npm ci
37+
run: npm ci
38+
39+
- name: npm check
40+
run: npm run check
41+
42+
- name: npm test
43+
run: npm run test -- --coverage
44+
45+
- name: npm build
46+
run: BUILD_BRANCH=$(echo "${GITHUB_REF#refs/heads/}") npm run build
47+
48+
- name: Set VERSION env
49+
run: echo "VERSION=$(cat package.json | jq -r .version)" >> $GITHUB_ENV
50+
51+
- name: SonarQube Scan (Push)
52+
if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/development')
53+
uses: SonarSource/[email protected]
54+
env:
55+
SONAR_TOKEN: ${{ secrets.SONARQUBE_TOKEN }}
56+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
57+
with:
58+
projectBaseDir: .
59+
args: >
60+
-Dsonar.host.url=${{ secrets.SONARQUBE_HOST }}
61+
-Dsonar.projectVersion=${{ env.VERSION }}
62+
-Dsonar.branch.name=${{ github.ref_name }}
63+
64+
- name: SonarQube Scan (Pull Request)
65+
if: github.event_name == 'pull_request'
66+
uses: SonarSource/[email protected]
67+
env:
68+
SONAR_TOKEN: ${{ secrets.SONARQUBE_TOKEN }}
69+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
70+
with:
71+
projectBaseDir: .
72+
args: >
73+
-Dsonar.host.url=${{ secrets.SONARQUBE_HOST }}
74+
-Dsonar.projectVersion=${{ env.VERSION }}
75+
-Dsonar.pullrequest.key=${{ github.event.pull_request.number }}
76+
-Dsonar.pullrequest.branch=${{ github.event.pull_request.head.ref }}
77+
-Dsonar.pullrequest.base=${{ github.event.pull_request.base.ref }}
78+
79+
- name: Store assets
80+
if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/development')
81+
uses: actions/upload-artifact@v3
82+
with:
83+
name: assets
84+
path: umd/
85+
retention-days: 1
86+
87+
upload-stage:
88+
name: Upload assets
89+
runs-on: ubuntu-latest
90+
needs: build
91+
if: github.event_name == 'push' && github.ref == 'refs/heads/development'
92+
strategy:
93+
matrix:
94+
environment:
95+
- stage
96+
include:
97+
- environment: stage
98+
account_id: "079419646996"
99+
bucket: split-public-stage
100+
101+
steps:
102+
- name: Download assets
103+
uses: actions/download-artifact@v3
104+
with:
105+
name: assets
106+
path: umd
107+
108+
- name: Display structure of assets
109+
run: ls -R
110+
working-directory: umd
111+
112+
- name: Configure AWS credentials
113+
uses: aws-actions/configure-aws-credentials@v1-node16
114+
with:
115+
role-to-assume: arn:aws:iam::${{ matrix.account_id }}:role/gha-public-assets-role
116+
aws-region: us-east-1
117+
118+
- name: Upload to S3
119+
run: aws s3 sync $SOURCE_DIR s3://$BUCKET/$DEST_DIR $ARGS
120+
env:
121+
BUCKET: ${{ matrix.bucket }}
122+
SOURCE_DIR: ./umd
123+
DEST_DIR: sdk
124+
ARGS: --acl public-read --follow-symlinks --cache-control max-age=31536000,public
125+
126+
upload-prod:
127+
name: Upload assets
128+
runs-on: ubuntu-latest
129+
needs: build
130+
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
131+
strategy:
132+
matrix:
133+
environment:
134+
- prod
135+
include:
136+
- environment: prod
137+
account_id: "825951051969"
138+
bucket: split-public
139+
140+
steps:
141+
- name: Download assets
142+
uses: actions/download-artifact@v3
143+
with:
144+
name: assets
145+
path: umd
146+
147+
- name: Display structure of assets
148+
run: ls -R
149+
working-directory: umd
150+
151+
- name: Configure AWS credentials
152+
uses: aws-actions/configure-aws-credentials@v1-node16
153+
with:
154+
role-to-assume: arn:aws:iam::${{ matrix.account_id }}:role/gha-public-assets-role
155+
aws-region: us-east-1
156+
157+
- name: Upload to S3
158+
run: aws s3 sync $SOURCE_DIR s3://$BUCKET/$DEST_DIR $ARGS
159+
env:
160+
BUCKET: ${{ matrix.bucket }}
161+
SOURCE_DIR: ./umd
162+
DEST_DIR: sdk
163+
ARGS: --acl public-read --follow-symlinks --cache-control max-age=31536000,public

.nvmrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v16.16.0
1+
lts/*

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Below is a simple example that describes the instantiation and most basic usage
2020
import React from 'react';
2121

2222
// Import SDK functions
23-
import { SplitFactory, useSplitTreatments } from '@splitsoftware/splitio-react';
23+
import { SplitFactoryProvider, useSplitTreatments } from '@splitsoftware/splitio-react';
2424

2525
// Define your config object
2626
const CONFIG = {
@@ -48,10 +48,10 @@ function MyComponent() {
4848

4949
function MyApp() {
5050
return (
51-
// Use SplitFactory to instantiate the SDK and makes it available to nested components
52-
<SplitFactory config={CONFIG} >
51+
// Use SplitFactoryProvider to instantiate the SDK and makes it available to nested components
52+
<SplitFactoryProvider config={CONFIG} >
5353
<MyComponent />
54-
</SplitFactory>
54+
</SplitFactoryProvider>
5555
);
5656
}
5757
```

src/SplitClient.tsx

+3-10
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import React from 'react';
22
import { SplitContext } from './SplitContext';
33
import { ISplitClientProps, ISplitContextValues, IUpdateProps } from './types';
4-
import { ERROR_SC_NO_FACTORY } from './constants';
54
import { getStatus, getSplitClient, initAttributes, IClientWithContext } from './utils';
65
import { DEFAULT_UPDATE_OPTIONS } from './useSplitClient';
76

87
/**
98
* Common component used to handle the status and events of a Split client passed as prop.
10-
* Reused by both SplitFactory (main client) and SplitClient (shared client) components.
9+
* Reused by both SplitFactoryProvider (main client) and SplitClient (any client) components.
1110
*/
1211
export class SplitComponent extends React.Component<IUpdateProps & { factory: SplitIO.IBrowserSDK | null, client: SplitIO.IBrowserClient | null, attributes?: SplitIO.Attributes, children: any }, ISplitContextValues> {
1312

@@ -47,11 +46,6 @@ export class SplitComponent extends React.Component<IUpdateProps & { factory: Sp
4746
super(props);
4847
const { factory, client } = props;
4948

50-
// Log error if factory is not available
51-
if (!factory) {
52-
console.error(ERROR_SC_NO_FACTORY);
53-
}
54-
5549
this.state = {
5650
factory,
5751
client,
@@ -129,9 +123,8 @@ export class SplitComponent extends React.Component<IUpdateProps & { factory: Sp
129123
* SplitClient will initialize a new SDK client and listen for its events in order to update the Split Context.
130124
* Children components will have access to the new client when accessing Split Context.
131125
*
132-
* Unlike SplitFactory, the underlying SDK client can be changed during the component lifecycle
133-
* if the component is updated with a different splitKey or trafficType prop. Since the client can change,
134-
* its release is not handled by SplitClient but by its container SplitFactory component.
126+
* The underlying SDK client can be changed during the component lifecycle
127+
* if the component is updated with a different splitKey or trafficType prop.
135128
*
136129
* @see {@link https://help.split.io/hc/en-us/articles/360020448791-JavaScript-SDK#advanced-instantiate-multiple-sdk-clients}
137130
*/

src/SplitTreatments.tsx

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React from 'react';
22
import { SplitContext } from './SplitContext';
33
import { ISplitTreatmentsProps, ISplitContextValues } from './types';
4-
import { WARN_ST_NO_CLIENT } from './constants';
54
import { memoizeGetTreatmentsWithConfig } from './utils';
65

76
/**
@@ -26,7 +25,7 @@ export class SplitTreatments extends React.Component<ISplitTreatmentsProps> {
2625
{(splitContext: ISplitContextValues) => {
2726
const { client, lastUpdate } = splitContext;
2827
const treatments = this.evaluateFeatureFlags(client, lastUpdate, names, attributes, client ? { ...client.getAttributes() } : {}, flagSets);
29-
if (!client) { this.logWarning = true; }
28+
3029
// SplitTreatments only accepts a function as a child, not a React Element (JSX)
3130
return children({
3231
...splitContext, treatments,
@@ -35,9 +34,4 @@ export class SplitTreatments extends React.Component<ISplitTreatmentsProps> {
3534
</SplitContext.Consumer>
3635
);
3736
}
38-
39-
componentDidMount() {
40-
if (this.logWarning) { console.log(WARN_ST_NO_CLIENT); }
41-
}
42-
4337
}

0 commit comments

Comments
 (0)