Files
plane/web/ee/store/feature-flags/feature-flags.store.ts
Nikhil 4e8bfe0024 dev: feature flagging implementation (#443)
* dev: initialize feature flagging

* dev: feature flagging workspace active cycles

* dev: update feature flag implementation

* dev: add `FEATURE_FLAG_SERVER_AUTH_TOKEN` env

* dev: add feature flagging for backend apis

* dev: setup feature flags store and hooks. (#558)

* dev: setup feature flags store and hooks.

* minor improvements for swr key and flags enum.

* dev: workspace active cycles feature flag. (#562)

* dev: add task for cancelling the workspace subscription when the workspace is deleted

* dev: rename feaure flagging component

* dev: update feature flagging function for spaces

* dev: add feature flags for bulk ops, issue embeds and page publish. (#589)

* dev: add logging for member sync task

* dev: restrict workspace from deleting if the subscription is active

* dev: workspace delete check endpoint

* dev: subscription endpoint check

* dev: update subscriptions

* chore: plane pro billing and plans page updates.

* dev: update pro pill display logic.

* dev: fix feature flagging

* chore: minor improvement in cloud-badge to avoid API calls to `products` endpoint if user has PRO subscription.

---------

Co-authored-by: Prateek Shourya <prateekshourya29@gmail.com>
Co-authored-by: sriram veeraghanta <veeraghanta.sriram@gmail.com>
2024-07-11 15:14:18 +05:30

51 lines
1.4 KiB
TypeScript

import { set } from "lodash";
import { action, makeObservable, observable, runInAction } from "mobx";
// services
import { FeatureFlagService, TFeatureFlagsResponse } from "@/plane-web/services/feature-flag.service";
// plane web store
const featureFlagService = new FeatureFlagService();
type TFeatureFlagsMaps = {
[featureFlag: string]: boolean;
};
export interface IFeatureFlagsStore {
loader: boolean;
flags: TFeatureFlagsMaps;
fetchFeatureFlags: (workspaceSlug: string, userId: string) => Promise<TFeatureFlagsResponse>;
}
export class FeatureFlagsStore implements IFeatureFlagsStore {
loader = false;
flags: TFeatureFlagsMaps = {};
constructor() {
makeObservable(this, {
loader: observable.ref,
flags: observable,
fetchFeatureFlags: action,
});
}
fetchFeatureFlags = async (workspaceSlug: string, userId: string) => {
try {
set(this, "loader", true);
const response = await featureFlagService.getFeatureFlags({ workspace_slug: workspaceSlug, user_id: userId });
runInAction(() => {
if (response.values) {
Object.keys(response.values).forEach((key) => {
set(this.flags, key, response.values[key]);
});
}
set(this, "loader", false);
});
return response;
} catch (error) {
set(this, "loader", false);
console.error("Error fetching feature flags", error);
throw error;
}
};
}