Skip to content

Commit

Permalink
add owner team feature flag
Browse files Browse the repository at this point in the history
  • Loading branch information
apeni committed Jan 8, 2024
1 parent 8ac072b commit d579833
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/features.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export enum GitlabFeaturesEnum {
SEND_STAGING_EVENTS = 'isSendStagingEventsEnabled',
OWNER_TEAM = 'isOwnerTeamEnabled',
}

export type FeaturesList = { [key in GitlabFeaturesEnum]: boolean };
25 changes: 25 additions & 0 deletions src/services/feature-flags.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { listFeatures } from './feature-flags';

describe('listFeatures', () => {
beforeEach(() => {
process.env.OWNER_TEAM_FF = 'false';
process.env.FF_SEND_STAGING_EVENTS = 'false';
});

test('gets feature flags from their variables', async () => {
process.env.OWNER_TEAM_FF = 'true';
process.env.FF_SEND_STAGING_EVENTS = 'true';

const featureFlags = listFeatures();

expect(featureFlags.isOwnerTeamEnabled).toEqual(true);
expect(featureFlags.isSendStagingEventsEnabled).toEqual(true);
});

test('gets feature flags in their default state', async () => {
const featureFlags = listFeatures();

expect(featureFlags.isOwnerTeamEnabled).toEqual(false);
expect(featureFlags.isSendStagingEventsEnabled).toEqual(false);
});
});
5 changes: 5 additions & 0 deletions src/services/feature-flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ export const isSendStagingEventsEnabled = (defaultValue = false): boolean => {
return process.env.FF_SEND_STAGING_EVENTS === 'true' || defaultValue;
};

export const isOwnerTeamEnabled = (defaultValue = false): boolean => {
return process.env.OWNER_TEAM_FF === 'true' || defaultValue;
};

export const listFeatures = (): FeaturesList => {
return {
[GitlabFeaturesEnum.SEND_STAGING_EVENTS]: isSendStagingEventsEnabled(),
[GitlabFeaturesEnum.OWNER_TEAM]: isOwnerTeamEnabled(),
};
};
1 change: 1 addition & 0 deletions ui/src/hooks/useFeatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { DefaultErrorTypes, ErrorTypes } from '../resolverTypes';
export const useFeatures = (): [FeaturesList, boolean, ErrorTypes | undefined] => {
const [features, setFeatures] = useState<FeaturesList>({
[GitlabFeaturesEnum.SEND_STAGING_EVENTS]: false,
[GitlabFeaturesEnum.OWNER_TEAM]: false,
});
const [loading, setLoading] = useState<boolean>(false);
const [error, setError] = useState<ErrorTypes>();
Expand Down

0 comments on commit d579833

Please sign in to comment.