1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-04-10 01:16:39 +02:00

Feat/apply changes api (#2276)

* feat: initial setup

* fix: add types for suggest changes payload

* feat: add types for change events

* fix: change param order

* fix: remove enum

* fix: remove unused method

* fix: remove method from interface
This commit is contained in:
Fredrik Strand Oseberg 2022-10-28 09:29:00 +02:00 committed by GitHub
parent 95da63c8c7
commit b2c099a1c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 76 additions and 8 deletions

View File

@ -381,10 +381,10 @@ export interface ISuggestChangeFeature {
changes: ISuggestChange[];
}
export interface ISuggestChange {
export interface ISuggestChangeBase {
id?: number;
action: SuggestChangeAction;
payload: any;
payload: SuggestChangePayload;
createdBy?: Pick<User, 'id' | 'username' | 'imageUrl'>;
createdAt?: Date;
}
@ -397,13 +397,66 @@ export enum SuggestChangesetState {
CANCELLED = 'Cancelled',
}
export enum SuggestChangeAction {
UPDATE_ENABLED = 'updateEnabled',
ADD_STRATEGY = 'strategyAdd',
UPDATE_STRATEGY = 'strategyUpdate',
DELETE_STRATEGY = 'strategyDelete',
type SuggestChangePayload =
| SuggestChangeEnabled
| SuggestChangeAddStrategy
| SuggestChangeEditStrategy
| SuggestChangeDeleteStrategy;
export interface ISuggestChangeAddStrategy extends ISuggestChangeBase {
action: 'addStrategy';
payload: SuggestChangeAddStrategy;
}
export interface ISuggestChangeDeleteStrategy extends ISuggestChangeBase {
action: 'deleteStrategy';
payload: SuggestChangeDeleteStrategy;
}
export interface ISuggestChangeUpdateStrategy extends ISuggestChangeBase {
action: 'updateStrategy';
payload: SuggestChangeEditStrategy;
}
export interface ISuggestChangeEnabled extends ISuggestChangeBase {
action: 'updateEnabled';
payload: SuggestChangeEnabled;
}
export type ISuggestChange =
| ISuggestChangeAddStrategy
| ISuggestChangeDeleteStrategy
| ISuggestChangeUpdateStrategy
| ISuggestChangeEnabled;
type SuggestChangeEnabled = { enabled: boolean };
type SuggestChangeAddStrategy = Pick<
IFeatureStrategy,
'parameters' | 'constraints'
> & { name: string };
type SuggestChangeEditStrategy = SuggestChangeAddStrategy & { id: string };
type SuggestChangeDeleteStrategy = {
deleteId: string;
};
export enum SuggestChangesetEvent {
CREATED = 'CREATED',
UPDATED = 'UPDATED',
SUBMITTED = 'SUBMITTED',
APPROVED = 'APPROVED',
REJECTED = 'REJECTED',
CLOSED = 'CLOSED',
}
export type SuggestChangeAction =
| 'updateEnabled'
| 'addStrategy'
| 'updateStrategy'
| 'deleteStrategy';
export interface ISuggestChangeEventData {
feature: string;
data: unknown;

View File

@ -124,6 +124,20 @@ export default class FakeFeatureStrategiesStore
return Promise.resolve(rows);
}
async getFeatureToggleForEnvironment(
featureName: string,
// eslint-disable-next-line
environment: string,
): Promise<FeatureToggleWithEnvironment> {
const toggle = this.featureToggles.find((f) => f.name === featureName);
if (toggle) {
return { ...toggle, environments: [] };
}
throw new NotFoundError(
`Could not find feature with name ${featureName}`,
);
}
async getFeatureToggleWithEnvs(
featureName: string,
archived: boolean = false,

View File

@ -29,7 +29,7 @@ export default class FakeSuggestChangeStore implements ISuggestChangeStore {
}
addChangeToSet(
change: PartialSome<ISuggestChange, 'id' | 'createdBy' | 'createdAt'>,
change: ISuggestChange,
feature: string,
changeSetID: number,
userId: number,
@ -44,6 +44,7 @@ export default class FakeSuggestChangeStore implements ISuggestChangeStore {
},
],
});
return Promise.resolve();
}