Skip to content

Commit 9dd8b46

Browse files
Merge branch 'flagSets_xor' into flagSets
2 parents 78bece2 + a46a180 commit 9dd8b46

7 files changed

Lines changed: 23 additions & 12 deletions

File tree

CHANGES.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1.10.0 (November XX, 2023)
1+
1.10.0 (November 16, 2023)
22
- Added support for Flag Sets on the SDK, which enables grouping feature flags and interacting with the group rather than individually (more details in our documentation):
33
- Added a new `flagSets` prop to the `SplitTreatments` component and `flagSets` option to the `useSplitTreatments` hook options object, to support evaluating flags in given flag set/s. Either `names` or `flagSets` must be provided to the component and hook. If both are provided, `names` will be used.
44
- Added a new optional Split Filter configuration option. This allows the SDK and Split services to only synchronize the flags in the specified flag sets, avoiding unused or unwanted flags from being synced on the SDK instance, bringing all the benefits from a reduced payload.

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@splitsoftware/splitio-react",
3-
"version": "1.9.1-rc.0",
3+
"version": "1.9.1-rc.1",
44
"description": "A React library to easily integrate and use Split JS SDK",
55
"main": "lib/index.js",
66
"module": "es/index.js",

src/__tests__/SplitTreatments.test.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ describe('SplitTreatments', () => {
152152

153153
test('ignores flagSets and logs a warning if both names and flagSets params are provided.', () => {
154154
render(
155+
// @ts-expect-error flagSets and names are mutually exclusive
155156
<SplitTreatments names={featureFlagNames} flagSets={flagSets} >
156157
{({ treatments }) => {
157158
expect(treatments).toEqual({ split1: CONTROL_WITH_CONFIG, split2: CONTROL_WITH_CONFIG });
@@ -160,7 +161,7 @@ describe('SplitTreatments', () => {
160161
</SplitTreatments>
161162
);
162163

163-
expect(logSpy).toBeCalledWith('[WARN] Both names and flagSets props were provided. flagSets will be ignored.');
164+
expect(logSpy).toBeCalledWith('[WARN] Both names and flagSets properties were provided. flagSets will be ignored.');
164165
});
165166
});
166167

@@ -171,6 +172,7 @@ let renderTimes = 0;
171172
*/
172173
describe.each([
173174
({ names, flagSets, attributes }: { names?: string[], flagSets?: string[], attributes?: SplitIO.Attributes }) => (
175+
// @ts-expect-error names and flagSets are mutually exclusive
174176
<SplitTreatments names={names} attributes={attributes} flagSets={flagSets} >
175177
{() => {
176178
renderTimes++;
@@ -179,6 +181,7 @@ describe.each([
179181
</SplitTreatments>
180182
),
181183
({ names, flagSets, attributes }: { names?: string[], flagSets?: string[], attributes?: SplitIO.Attributes }) => {
184+
// @ts-expect-error names and flagSets are mutually exclusive
182185
useSplitTreatments({ names, flagSets, attributes });
183186
renderTimes++;
184187
return null;

src/__tests__/useSplitTreatments.test.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ describe('useSplitTreatments', () => {
3737
{React.createElement(() => {
3838
treatments = useSplitTreatments({ names: featureFlagNames, attributes }).treatments;
3939
treatmentsByFlagSets = useSplitTreatments({ flagSets, attributes }).treatments;
40+
41+
// @ts-expect-error Options object must provide either names or flagSets
42+
expect(useSplitTreatments({}).treatments).toEqual({});
4043
return null;
4144
})}
4245
</SplitFactory>
@@ -246,13 +249,14 @@ describe('useSplitTreatments', () => {
246249
test('ignores flagSets and logs a warning if both names and flagSets params are provided.', () => {
247250
render(
248251
React.createElement(() => {
252+
// @ts-expect-error names and flagSets are mutually exclusive
249253
const treatments = useSplitTreatments({ names: featureFlagNames, flagSets, attributes }).treatments;
250254
expect(treatments).toEqual({ split1: CONTROL_WITH_CONFIG });
251255
return null;
252256
})
253257
);
254258

255-
expect(logSpy).toHaveBeenLastCalledWith('[WARN] Both names and flagSets props were provided. flagSets will be ignored.');
259+
expect(logSpy).toHaveBeenLastCalledWith('[WARN] Both names and flagSets properties were provided. flagSets will be ignored.');
256260
});
257261

258262
});

src/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ export const WARN_ST_NO_CLIENT: string = '[WARN] SplitTreatments does not have
4040

4141
export const EXCEPTION_NO_REACT_OR_CREATECONTEXT: string = 'React library is not available or its version is not supported. Check that it is properly installed or imported. Split SDK requires version 16.3.0+ of React.';
4242

43-
export const WARN_NAMES_AND_FLAGSETS: string = '[WARN] Both names and flagSets props were provided. flagSets will be ignored.';
43+
export const WARN_NAMES_AND_FLAGSETS: string = '[WARN] Both names and flagSets properties were provided. flagSets will be ignored.';

src/types.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,17 +170,21 @@ export interface ISplitClientProps extends IUseSplitClientOptions {
170170
children: ((props: ISplitClientChildProps) => ReactNode) | ReactNode;
171171
}
172172

173-
export type GetTreatmentsOptions = {
173+
export type GetTreatmentsOptions = ({
174174

175175
/**
176176
* List of feature flag names to evaluate. Either this or the `flagSets` property must be provided. If both are provided, the `flagSets` option is ignored.
177177
*/
178-
names?: string[];
178+
names: string[];
179+
flagSets?: undefined;
180+
} | {
179181

180182
/**
181183
* List of feature flag sets to evaluate. Either this or the `names` property must be provided. If both are provided, the `flagSets` option is ignored.
182184
*/
183-
flagSets?: string[];
185+
flagSets: string[];
186+
names?: undefined;
187+
}) & {
184188

185189
/**
186190
* An object of type Attributes used to evaluate the feature flags.
@@ -192,7 +196,7 @@ export type GetTreatmentsOptions = {
192196
* useSplitTreatments options interface. This is the options object accepted by useSplitTreatments hook,
193197
* used to call 'client.getTreatmentsWithConfig()', or 'client.getTreatmentsWithConfigByFlagSets()', and retrieve the result together with the Split context.
194198
*/
195-
export interface IUseSplitTreatmentsOptions extends GetTreatmentsOptions, IUseSplitClientOptions { }
199+
export type IUseSplitTreatmentsOptions = GetTreatmentsOptions & IUseSplitClientOptions;
196200

197201
/**
198202
* SplitTreatments Child Props interface. These are the props that the child component receives from the 'SplitTreatments' component.
@@ -214,7 +218,7 @@ export interface ISplitTreatmentsChildProps extends ISplitContextValues {
214218
* SplitTreatments Props interface. These are the props accepted by SplitTreatments component,
215219
* used to call 'client.getTreatmentsWithConfig()', or 'client.getTreatmentsWithConfigByFlagSets()', and pass the result to the child component.
216220
*/
217-
export interface ISplitTreatmentsProps extends GetTreatmentsOptions {
221+
export type ISplitTreatmentsProps = GetTreatmentsOptions & {
218222

219223
/**
220224
* Children of the SplitTreatments component. It must be a functional component (child as a function) you want to show.

0 commit comments

Comments
 (0)