Skip to content

Commit

Permalink
Merge pull request #7 from Flagsmith/fix/remove-any-type
Browse files Browse the repository at this point in the history
fix: Remove any type
  • Loading branch information
novakzaballa authored Apr 25, 2024
2 parents f7cbdac + 18b1f46 commit 413db03
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
22 changes: 14 additions & 8 deletions flagsmith-jira-app/src/IssueFlagPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ type IssueFlagTableProps = {
canEdit: boolean;
};

type FeatureState = FlagModel & {
[key: string]: string | number | EnvironmentFeatureState[];
};

const IssueFlagTable = ({
projectUrl,
apiKey,
Expand All @@ -90,7 +94,7 @@ const IssueFlagTable = ({
onRemove,
canEdit,
}: IssueFlagTableProps) => {
const [environmentFlags, setEnvironmentFlags] = useState<any>([]);
const [environmentFlags, setEnvironmentFlags] = useState<FeatureState[]>([]);

useEffect(async () => {
// Filtered features by comparing their IDs with the feature IDs stored in Jira.
Expand All @@ -99,7 +103,7 @@ const IssueFlagTable = ({
);
try {
if (environments.length > 0 && flagsmithfeaturesFiltered.length > 0) {
const featureState: any = {};
const featureState: { [key: string]: FeatureState } = {};
// Iterate over each filtered feature.
for (const feature of flagsmithfeaturesFiltered) {
// Initialize an object to store the state of the feature.
Expand All @@ -119,11 +123,13 @@ const IssueFlagTable = ({
ffData.name = environment.name;
ffData.api_key = String(environment.api_key);
// Add the feature state data to the feature state object.
featureState[String(feature.name)].environments.push(ffData);
featureState[String(feature.name)]?.environments.push(ffData);
}
}
const ffArray = Object.keys(featureState).map((featureName) => featureState[featureName]);
setEnvironmentFlags(ffArray);
const ffArray = Object.keys(featureState).map(
(featureName) => featureState[featureName],
) as FeatureState[];
setEnvironmentFlags(ffArray as FeatureState[]);
} else {
setEnvironmentFlags([]);
}
Expand All @@ -139,7 +145,7 @@ const IssueFlagTable = ({
let first = true;
return (
<Fragment>
{environmentFlags.map((environmentFlag: FlagModel) => {
{environmentFlags.map((environmentFlag: FeatureState) => {
// add vertical space to separate the previous feature's Remove button from this feature
const spacer = first ? null : <Text>&nbsp;</Text>;
first = false;
Expand Down Expand Up @@ -173,12 +179,12 @@ const IssueFlagTable = ({
if (!flag) return null;
// count variations/overrides
const variations = flag.multivariate_feature_state_values.length;
const segments = environmentFlags.filter(
const segments = environmentFlag.environments.filter(
(each: EnvironmentFeatureState) =>
String(each.feature) === String(environmentFlag.feature_id) &&
each.feature_segment !== null,
).length;
const identities = environmentFlags.filter(
const identities = environmentFlag.environments.filter(
(each: EnvironmentFeatureState) =>
String(each.feature) === String(environmentFlag.feature_id) &&
each.identity !== null,
Expand Down
12 changes: 8 additions & 4 deletions flagsmith-jira-app/src/flagsmith.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export type FeatureStateValue = {

export type FlagModel = {
name: string;
feature_id: string;
feature_id: string | number;
description: string | null;
environments: EnvironmentFeatureState[];
};
Expand All @@ -46,7 +46,11 @@ type PaginatedModels<TModel extends Model> = {
export type EnvironmentFeatureState = {
id: number;
feature_state_value: string | null;
multivariate_feature_state_values: any[];
multivariate_feature_state_values: {
id: number;
multivariate_feature_option: number;
percentage_allocation: number;
}[];
identity: number | null;
deleted_at: string | null;
uuid: string;
Expand Down Expand Up @@ -195,7 +199,7 @@ export const fetchFeatureState = async ({
apiKey: string;
featureName: string;
envAPIKey: string;
}): Promise<any> => {
}): Promise<EnvironmentFeatureState> => {
checkApiKey(apiKey);
if (!envAPIKey) throw new ApiError("Flagsmith environment not configured", 400);
const path = route`/environments/${envAPIKey}/featurestates/?feature_name=${featureName}`;
Expand All @@ -204,6 +208,6 @@ export const fetchFeatureState = async ({
if (!results || results.length === 0) {
throw new ApiError("Flagsmith project has no features", 404);
} else {
return results[0];
return results[0] as EnvironmentFeatureState;
}
};

0 comments on commit 413db03

Please sign in to comment.