Skip to content

Commit

Permalink
chore: update Frontend schema (#8037)
Browse files Browse the repository at this point in the history
update types, fix frontend types issues in insights and archive
  • Loading branch information
Tymek authored Sep 2, 2024
1 parent e4fcb25 commit 76ffdb2
Show file tree
Hide file tree
Showing 17 changed files with 247 additions and 90 deletions.
4 changes: 2 additions & 2 deletions frontend/src/component/archive/ArchiveTable/ArchiveTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { LinkCell } from 'component/common/Table/cells/LinkCell/LinkCell';
import { ArchivedFeatureActionCell } from 'component/archive/ArchiveTable/ArchivedFeatureActionCell/ArchivedFeatureActionCell';
import { featuresPlaceholder } from 'component/feature/FeatureToggleList/FeatureToggleListTable';
import theme from 'themes/theme';
import type { FeatureSchema } from 'openapi';
import type { ArchivedFeatureSchema } from 'openapi';
import { useSearch } from 'hooks/useSearch';
import { FeatureArchivedCell } from './FeatureArchivedCell/FeatureArchivedCell';
import { useSearchParams } from 'react-router-dom';
Expand All @@ -36,7 +36,7 @@ import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig';
import { ArchivedFeatureReviveConfirm } from './ArchivedFeatureActionCell/ArchivedFeatureReviveConfirm/ArchivedFeatureReviveConfirm';

export interface IFeaturesArchiveTableProps {
archivedFeatures: FeatureSchema[];
archivedFeatures: ArchivedFeatureSchema[];
title: string;
refetch: () => void;
loading: boolean;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,16 @@
import useSWR from 'swr';
import type { FeatureSchema, FeaturesSchema } from 'openapi';
import type { ArchivedFeaturesSchema } from 'openapi';
import handleErrorResponses from '../httpErrorResponseHandler';
import { formatApiPath } from 'utils/formatPath';

export interface IUseFeaturesArchiveOutput {
archivedFeatures?: FeatureSchema[];
refetchArchived: () => void;
loading: boolean;
error?: Error;
}

const fetcher = (path: string) => {
return fetch(path)
.then(handleErrorResponses('Feature flag archive'))
.then((res) => res.json());
};

export const useFeaturesArchive = (
projectId?: string,
): IUseFeaturesArchiveOutput => {
const { data, error, mutate, isLoading } = useSWR<FeaturesSchema>(
export const useFeaturesArchive = (projectId?: string) => {
const { data, error, mutate, isLoading } = useSWR<ArchivedFeaturesSchema>(
formatApiPath(
projectId
? `/api/admin/archive/features/${projectId}`
Expand Down
34 changes: 16 additions & 18 deletions frontend/src/hooks/api/getters/useInsights/useInsights.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,16 @@ import useSWR, { mutate, type SWRConfiguration } from 'swr';
import { useCallback } from 'react';
import { formatApiPath } from 'utils/formatPath';
import handleErrorResponses from '../httpErrorResponseHandler';
import type { InstanceInsightsSchema } from 'openapi';

interface IUseInsightsDataOutput {
insights: InstanceInsightsSchema;
refetchInsights: () => void;
loading: boolean;
error?: Error;
}
import type {
InstanceInsightsSchema,
GetInstanceInsightsParams,
} from 'openapi';

export const useInsights = (
from = '',
to = '',
from: GetInstanceInsightsParams['from'] = '',
to: GetInstanceInsightsParams['to'] = '',
options?: SWRConfiguration,
): IUseInsightsDataOutput => {
) => {
const path = formatApiPath(`api/admin/insights?from=${from}&to=${to}`);

const { data, error } = useSWR<InstanceInsightsSchema>(
Expand All @@ -29,13 +25,15 @@ export const useInsights = (
}, [path]);

return {
insights: data || {
userTrends: [],
flagTrends: [],
projectFlagTrends: [],
metricsSummaryTrends: [],
environmentTypeTrends: [],
},
insights:
data ||
({
userTrends: [],
flagTrends: [],
projectFlagTrends: [],
metricsSummaryTrends: [],
environmentTypeTrends: [],
} as InstanceInsightsSchema),
refetchInsights,
loading: !error && !data,
error,
Expand Down
42 changes: 42 additions & 0 deletions frontend/src/openapi/models/archivedFeatureSchema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* Generated by Orval
* Do not edit manually.
* See `gen:api` script in package.json
*/
import type { ArchivedFeatureSchemaEnvironmentsItem } from './archivedFeatureSchemaEnvironmentsItem';

/**
* An archived project feature flag definition
*/
export interface ArchivedFeatureSchema {
/** The date the feature was archived */
archivedAt?: string;
/** The date the feature was created */
createdAt?: string;
/**
* Detailed description of the feature
* @nullable
*/
description?: string | null;
/**
* The list of environments where the feature can be used
* @deprecated
*/
environments?: ArchivedFeatureSchemaEnvironmentsItem[];
/** `true` if the impression data collection is enabled for the feature, otherwise `false`. */
impressionData?: boolean;
/**
* The date when metrics where last collected for the feature. This field was deprecated in v5, use the one in featureEnvironmentSchema
* @deprecated
* @nullable
*/
lastSeenAt?: string | null;
/** Unique feature name */
name: string;
/** Name of the project the feature belongs to */
project: string;
/** `true` if the feature is stale based on the age and feature type, otherwise `false`. */
stale?: boolean;
/** Type of the flag e.g. experiment, kill-switch, release, operational, permission */
type?: string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* Generated by Orval
* Do not edit manually.
* See `gen:api` script in package.json
*/

export type ArchivedFeatureSchemaEnvironmentsItem = {
/** `true` if the feature is enabled for the environment, otherwise `false`. */
enabled?: boolean;
/**
* The date when metrics where last collected for the feature environment
* @nullable
*/
lastSeenAt?: string | null;
/** The name of the environment */
name?: string;
};
16 changes: 16 additions & 0 deletions frontend/src/openapi/models/archivedFeaturesSchema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Generated by Orval
* Do not edit manually.
* See `gen:api` script in package.json
*/
import type { ArchivedFeatureSchema } from './archivedFeatureSchema';

/**
* A list of archived features
*/
export interface ArchivedFeaturesSchema {
/** A list of features */
features: ArchivedFeatureSchema[];
/** The version of the feature's schema */
version: number;
}
10 changes: 7 additions & 3 deletions frontend/src/openapi/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ export * from './archiveFeatures415';
export * from './archiveProject400';
export * from './archiveProject401';
export * from './archiveProject403';
export * from './archivedFeatureSchema';
export * from './archivedFeatureSchemaEnvironmentsItem';
export * from './archivedFeaturesSchema';
export * from './bannerSchema';
export * from './bannersSchema';
export * from './batchFeaturesSchema';
Expand Down Expand Up @@ -576,7 +579,6 @@ export * from './featureTypesSchema';
export * from './featureTypesSchemaVersion';
export * from './featureUsageSchema';
export * from './featureVariantsSchema';
export * from './featuresSchema';
export * from './feedbackCreateSchema';
export * from './feedbackListSchema';
export * from './feedbackResponseSchema';
Expand Down Expand Up @@ -801,18 +803,17 @@ export * from './inactiveUserSchema';
export * from './inactiveUsersSchema';
export * from './instanceAdminStatsSchema';
export * from './instanceAdminStatsSchemaActiveUsers';
export * from './instanceAdminStatsSchemaApiTokens';
export * from './instanceAdminStatsSchemaClientAppsItem';
export * from './instanceAdminStatsSchemaClientAppsItemRange';
export * from './instanceAdminStatsSchemaPreviousDayMetricsBucketsCount';
export * from './instanceAdminStatsSchemaProductionChanges';
export * from './instanceInsightsSchema';
export * from './instanceInsightsSchemaEnvironmentTypeTrendsItem';
export * from './instanceInsightsSchemaFlagTrendsItem';
export * from './instanceInsightsSchemaFlags';
export * from './instanceInsightsSchemaMetricsSummaryTrendsItem';
export * from './instanceInsightsSchemaProjectFlagTrendsItem';
export * from './instanceInsightsSchemaUserTrendsItem';
export * from './instanceInsightsSchemaUsers';
export * from './integrationEventSchema';
export * from './integrationEventSchemaDetails';
export * from './integrationEventSchemaState';
Expand Down Expand Up @@ -931,6 +932,9 @@ export * from './projectCreatedSchemaChangeRequestEnvironmentsItem';
export * from './projectCreatedSchemaMode';
export * from './projectDoraMetricsSchema';
export * from './projectEnvironmentSchema';
export * from './projectFeatureEnvironmentSchema';
export * from './projectFeatureSchema';
export * from './projectFeaturesSchema';
export * from './projectFlagCreatorsSchema';
export * from './projectFlagCreatorsSchemaItem';
export * from './projectInsightsSchema';
Expand Down
34 changes: 18 additions & 16 deletions frontend/src/openapi/models/instanceAdminStatsSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* See `gen:api` script in package.json
*/
import type { InstanceAdminStatsSchemaActiveUsers } from './instanceAdminStatsSchemaActiveUsers';
import type { InstanceAdminStatsSchemaApiTokens } from './instanceAdminStatsSchemaApiTokens';
import type { InstanceAdminStatsSchemaClientAppsItem } from './instanceAdminStatsSchemaClientAppsItem';
import type { InstanceAdminStatsSchemaPreviousDayMetricsBucketsCount } from './instanceAdminStatsSchemaPreviousDayMetricsBucketsCount';
import type { InstanceAdminStatsSchemaProductionChanges } from './instanceAdminStatsSchemaProductionChanges';
Expand All @@ -14,6 +15,8 @@ import type { InstanceAdminStatsSchemaProductionChanges } from './instanceAdminS
export interface InstanceAdminStatsSchema {
/** The number of active users in the last 7, 30 and 90 days */
activeUsers?: InstanceAdminStatsSchemaActiveUsers;
/** The number of API tokens in Unleash, split by type */
apiTokens?: InstanceAdminStatsSchemaApiTokens;
/** A count of connected applications in the last week, last month and all time since last restart */
clientApps?: InstanceAdminStatsSchemaClientAppsItem[];
/**
Expand Down Expand Up @@ -48,6 +51,21 @@ export interface InstanceAdminStatsSchema {
groups?: number;
/** A unique identifier for this instance. Generated by the database migration scripts at first run. Typically a UUID. */
instanceId: string;
/**
* The highest number of constraints used on a single strategy.
* @minimum 0
*/
maxConstraints?: number;
/**
* The highest number of constraint values used on a single constraint.
* @minimum 0
*/
maxConstraintValues?: number;
/**
* The highest number of strategies used on a single feature flag in a single environment.
* @minimum 0
*/
maxEnvironmentStrategies?: number;
/** Whether or not OIDC authentication is enabled for this instance */
OIDCenabled?: boolean;
/** The number client metrics buckets records recorded in the previous day. # features * # apps * # envs * # hours with metrics */
Expand Down Expand Up @@ -92,20 +110,4 @@ export interface InstanceAdminStatsSchema {
versionEnterprise?: string;
/** The version of Unleash OSS that is bundled in this instance */
versionOSS?: string;

/** A breakdown of API tokens that exist in this instance */
apiTokens: {
client: number;
admin: number;
frontend: number;
};

// The highest number of strategies used on a single feature flag in a single environment.
maxEnvironmentStrategies: number;

// The highest number of constraints used on a single strategy.
maxConstraints: number;

// The highest number of constraint values used on a single constraint.
maxConstraintValues: number;
}
26 changes: 26 additions & 0 deletions frontend/src/openapi/models/instanceAdminStatsSchemaApiTokens.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Generated by Orval
* Do not edit manually.
* See `gen:api` script in package.json
*/

/**
* The number of API tokens in Unleash, split by type
*/
export type InstanceAdminStatsSchemaApiTokens = {
/**
* The number of admin tokens.
* @minimum 0
*/
admin?: number;
/**
* The number of client tokens.
* @minimum 0
*/
client?: number;
/**
* The number of frontend tokens.
* @minimum 0
*/
frontend?: number;
};
13 changes: 0 additions & 13 deletions frontend/src/openapi/models/instanceInsightsSchemaFlags.ts

This file was deleted.

17 changes: 0 additions & 17 deletions frontend/src/openapi/models/instanceInsightsSchemaUsers.ts

This file was deleted.

30 changes: 30 additions & 0 deletions frontend/src/openapi/models/projectFeatureEnvironmentSchema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Generated by Orval
* Do not edit manually.
* See `gen:api` script in package.json
*/

/**
* A detailed description of the feature environment
*/
export interface ProjectFeatureEnvironmentSchema {
/** `true` if the feature is enabled for the environment, otherwise `false`. */
enabled: boolean;
/** Whether the feature has any enabled strategies defined. */
hasEnabledStrategies?: boolean;
/** Whether the feature has any strategies defined. */
hasStrategies?: boolean;
/**
* The date when metrics where last collected for the feature environment
* @nullable
*/
lastSeenAt: string | null;
/** The name of the environment */
name: string;
/** The sort order of the feature environment in the feature environments list */
sortOrder: number;
/** The type of the environment */
type: string;
/** The number of defined variants */
variantCount: number;
}
Loading

0 comments on commit 76ffdb2

Please sign in to comment.