Skip to content

Commit 18b1f46

Browse files
committed
fix: Remove any type
1 parent f7cbdac commit 18b1f46

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

flagsmith-jira-app/src/IssueFlagPanel.tsx

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ type IssueFlagTableProps = {
8181
canEdit: boolean;
8282
};
8383

84+
type FeatureState = FlagModel & {
85+
[key: string]: string | number | EnvironmentFeatureState[];
86+
};
87+
8488
const IssueFlagTable = ({
8589
projectUrl,
8690
apiKey,
@@ -90,7 +94,7 @@ const IssueFlagTable = ({
9094
onRemove,
9195
canEdit,
9296
}: IssueFlagTableProps) => {
93-
const [environmentFlags, setEnvironmentFlags] = useState<any>([]);
97+
const [environmentFlags, setEnvironmentFlags] = useState<FeatureState[]>([]);
9498

9599
useEffect(async () => {
96100
// Filtered features by comparing their IDs with the feature IDs stored in Jira.
@@ -99,7 +103,7 @@ const IssueFlagTable = ({
99103
);
100104
try {
101105
if (environments.length > 0 && flagsmithfeaturesFiltered.length > 0) {
102-
const featureState: any = {};
106+
const featureState: { [key: string]: FeatureState } = {};
103107
// Iterate over each filtered feature.
104108
for (const feature of flagsmithfeaturesFiltered) {
105109
// Initialize an object to store the state of the feature.
@@ -119,11 +123,13 @@ const IssueFlagTable = ({
119123
ffData.name = environment.name;
120124
ffData.api_key = String(environment.api_key);
121125
// Add the feature state data to the feature state object.
122-
featureState[String(feature.name)].environments.push(ffData);
126+
featureState[String(feature.name)]?.environments.push(ffData);
123127
}
124128
}
125-
const ffArray = Object.keys(featureState).map((featureName) => featureState[featureName]);
126-
setEnvironmentFlags(ffArray);
129+
const ffArray = Object.keys(featureState).map(
130+
(featureName) => featureState[featureName],
131+
) as FeatureState[];
132+
setEnvironmentFlags(ffArray as FeatureState[]);
127133
} else {
128134
setEnvironmentFlags([]);
129135
}
@@ -139,7 +145,7 @@ const IssueFlagTable = ({
139145
let first = true;
140146
return (
141147
<Fragment>
142-
{environmentFlags.map((environmentFlag: FlagModel) => {
148+
{environmentFlags.map((environmentFlag: FeatureState) => {
143149
// add vertical space to separate the previous feature's Remove button from this feature
144150
const spacer = first ? null : <Text>&nbsp;</Text>;
145151
first = false;
@@ -173,12 +179,12 @@ const IssueFlagTable = ({
173179
if (!flag) return null;
174180
// count variations/overrides
175181
const variations = flag.multivariate_feature_state_values.length;
176-
const segments = environmentFlags.filter(
182+
const segments = environmentFlag.environments.filter(
177183
(each: EnvironmentFeatureState) =>
178184
String(each.feature) === String(environmentFlag.feature_id) &&
179185
each.feature_segment !== null,
180186
).length;
181-
const identities = environmentFlags.filter(
187+
const identities = environmentFlag.environments.filter(
182188
(each: EnvironmentFeatureState) =>
183189
String(each.feature) === String(environmentFlag.feature_id) &&
184190
each.identity !== null,

flagsmith-jira-app/src/flagsmith.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export type FeatureStateValue = {
3131

3232
export type FlagModel = {
3333
name: string;
34-
feature_id: string;
34+
feature_id: string | number;
3535
description: string | null;
3636
environments: EnvironmentFeatureState[];
3737
};
@@ -46,7 +46,11 @@ type PaginatedModels<TModel extends Model> = {
4646
export type EnvironmentFeatureState = {
4747
id: number;
4848
feature_state_value: string | null;
49-
multivariate_feature_state_values: any[];
49+
multivariate_feature_state_values: {
50+
id: number;
51+
multivariate_feature_option: number;
52+
percentage_allocation: number;
53+
}[];
5054
identity: number | null;
5155
deleted_at: string | null;
5256
uuid: string;
@@ -195,7 +199,7 @@ export const fetchFeatureState = async ({
195199
apiKey: string;
196200
featureName: string;
197201
envAPIKey: string;
198-
}): Promise<any> => {
202+
}): Promise<EnvironmentFeatureState> => {
199203
checkApiKey(apiKey);
200204
if (!envAPIKey) throw new ApiError("Flagsmith environment not configured", 400);
201205
const path = route`/environments/${envAPIKey}/featurestates/?feature_name=${featureName}`;
@@ -204,6 +208,6 @@ export const fetchFeatureState = async ({
204208
if (!results || results.length === 0) {
205209
throw new ApiError("Flagsmith project has no features", 404);
206210
} else {
207-
return results[0];
211+
return results[0] as EnvironmentFeatureState;
208212
}
209213
};

0 commit comments

Comments
 (0)