Skip to content

Commit

Permalink
Merge branch 'flagSets_xor' into flagSets
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilianoSanchez committed Nov 15, 2023
2 parents 78bece2 + a46a180 commit 9dd8b46
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 12 deletions.
2 changes: 1 addition & 1 deletion CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
1.10.0 (November XX, 2023)
1.10.0 (November 16, 2023)
- 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):
- 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.
- 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.
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@splitsoftware/splitio-react",
"version": "1.9.1-rc.0",
"version": "1.9.1-rc.1",
"description": "A React library to easily integrate and use Split JS SDK",
"main": "lib/index.js",
"module": "es/index.js",
Expand Down
5 changes: 4 additions & 1 deletion src/__tests__/SplitTreatments.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ describe('SplitTreatments', () => {

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

expect(logSpy).toBeCalledWith('[WARN] Both names and flagSets props were provided. flagSets will be ignored.');
expect(logSpy).toBeCalledWith('[WARN] Both names and flagSets properties were provided. flagSets will be ignored.');
});
});

Expand All @@ -171,6 +172,7 @@ let renderTimes = 0;
*/
describe.each([
({ names, flagSets, attributes }: { names?: string[], flagSets?: string[], attributes?: SplitIO.Attributes }) => (
// @ts-expect-error names and flagSets are mutually exclusive
<SplitTreatments names={names} attributes={attributes} flagSets={flagSets} >
{() => {
renderTimes++;
Expand All @@ -179,6 +181,7 @@ describe.each([
</SplitTreatments>
),
({ names, flagSets, attributes }: { names?: string[], flagSets?: string[], attributes?: SplitIO.Attributes }) => {
// @ts-expect-error names and flagSets are mutually exclusive
useSplitTreatments({ names, flagSets, attributes });
renderTimes++;
return null;
Expand Down
6 changes: 5 additions & 1 deletion src/__tests__/useSplitTreatments.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ describe('useSplitTreatments', () => {
{React.createElement(() => {
treatments = useSplitTreatments({ names: featureFlagNames, attributes }).treatments;
treatmentsByFlagSets = useSplitTreatments({ flagSets, attributes }).treatments;

// @ts-expect-error Options object must provide either names or flagSets
expect(useSplitTreatments({}).treatments).toEqual({});
return null;
})}
</SplitFactory>
Expand Down Expand Up @@ -246,13 +249,14 @@ describe('useSplitTreatments', () => {
test('ignores flagSets and logs a warning if both names and flagSets params are provided.', () => {
render(
React.createElement(() => {
// @ts-expect-error names and flagSets are mutually exclusive
const treatments = useSplitTreatments({ names: featureFlagNames, flagSets, attributes }).treatments;
expect(treatments).toEqual({ split1: CONTROL_WITH_CONFIG });
return null;
})
);

expect(logSpy).toHaveBeenLastCalledWith('[WARN] Both names and flagSets props were provided. flagSets will be ignored.');
expect(logSpy).toHaveBeenLastCalledWith('[WARN] Both names and flagSets properties were provided. flagSets will be ignored.');
});

});
2 changes: 1 addition & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ export const WARN_ST_NO_CLIENT: string = '[WARN] SplitTreatments does not have

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.';

export const WARN_NAMES_AND_FLAGSETS: string = '[WARN] Both names and flagSets props were provided. flagSets will be ignored.';
export const WARN_NAMES_AND_FLAGSETS: string = '[WARN] Both names and flagSets properties were provided. flagSets will be ignored.';
14 changes: 9 additions & 5 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,17 +170,21 @@ export interface ISplitClientProps extends IUseSplitClientOptions {
children: ((props: ISplitClientChildProps) => ReactNode) | ReactNode;
}

export type GetTreatmentsOptions = {
export type GetTreatmentsOptions = ({

/**
* 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.
*/
names?: string[];
names: string[];
flagSets?: undefined;
} | {

/**
* 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.
*/
flagSets?: string[];
flagSets: string[];
names?: undefined;
}) & {

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

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

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

0 comments on commit 9dd8b46

Please sign in to comment.