From 76ffdb2cd3ebc24b93c0c818e4669afb45601efc Mon Sep 17 00:00:00 2001 From: Tymoteusz Czech <2625371+Tymek@users.noreply.github.com> Date: Mon, 2 Sep 2024 14:41:17 +0200 Subject: [PATCH] chore: update Frontend schema (#8037) update types, fix frontend types issues in insights and archive --- .../archive/ArchiveTable/ArchiveTable.tsx | 4 +- .../useFeaturesArchive/useFeaturesArchive.ts | 15 ++----- .../api/getters/useInsights/useInsights.ts | 34 +++++++-------- .../openapi/models/archivedFeatureSchema.ts | 42 ++++++++++++++++++ .../archivedFeatureSchemaEnvironmentsItem.ts | 17 ++++++++ .../openapi/models/archivedFeaturesSchema.ts | 16 +++++++ frontend/src/openapi/models/index.ts | 10 +++-- .../models/instanceAdminStatsSchema.ts | 34 ++++++++------- .../instanceAdminStatsSchemaApiTokens.ts | 26 +++++++++++ .../models/instanceInsightsSchemaFlags.ts | 13 ------ .../models/instanceInsightsSchemaUsers.ts | 17 -------- .../models/projectFeatureEnvironmentSchema.ts | 30 +++++++++++++ .../openapi/models/projectFeatureSchema.ts | 43 +++++++++++++++++++ ...uresSchema.ts => projectFeaturesSchema.ts} | 8 ++-- .../openapi/models/projectOverviewSchema.ts | 5 +++ frontend/src/openapi/models/projectSchema.ts | 22 ++++++++-- .../openapi/spec/archived-features-schema.ts | 1 - 17 files changed, 247 insertions(+), 90 deletions(-) create mode 100644 frontend/src/openapi/models/archivedFeatureSchema.ts create mode 100644 frontend/src/openapi/models/archivedFeatureSchemaEnvironmentsItem.ts create mode 100644 frontend/src/openapi/models/archivedFeaturesSchema.ts create mode 100644 frontend/src/openapi/models/instanceAdminStatsSchemaApiTokens.ts delete mode 100644 frontend/src/openapi/models/instanceInsightsSchemaFlags.ts delete mode 100644 frontend/src/openapi/models/instanceInsightsSchemaUsers.ts create mode 100644 frontend/src/openapi/models/projectFeatureEnvironmentSchema.ts create mode 100644 frontend/src/openapi/models/projectFeatureSchema.ts rename frontend/src/openapi/models/{featuresSchema.ts => projectFeaturesSchema.ts} (54%) diff --git a/frontend/src/component/archive/ArchiveTable/ArchiveTable.tsx b/frontend/src/component/archive/ArchiveTable/ArchiveTable.tsx index 3c9993191d8b..a61dcecec00a 100644 --- a/frontend/src/component/archive/ArchiveTable/ArchiveTable.tsx +++ b/frontend/src/component/archive/ArchiveTable/ArchiveTable.tsx @@ -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'; @@ -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; diff --git a/frontend/src/hooks/api/getters/useFeaturesArchive/useFeaturesArchive.ts b/frontend/src/hooks/api/getters/useFeaturesArchive/useFeaturesArchive.ts index 2a6f038dc2e6..ee5dd8d239dd 100644 --- a/frontend/src/hooks/api/getters/useFeaturesArchive/useFeaturesArchive.ts +++ b/frontend/src/hooks/api/getters/useFeaturesArchive/useFeaturesArchive.ts @@ -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( +export const useFeaturesArchive = (projectId?: string) => { + const { data, error, mutate, isLoading } = useSWR( formatApiPath( projectId ? `/api/admin/archive/features/${projectId}` diff --git a/frontend/src/hooks/api/getters/useInsights/useInsights.ts b/frontend/src/hooks/api/getters/useInsights/useInsights.ts index 796bb254abde..5723437b3774 100644 --- a/frontend/src/hooks/api/getters/useInsights/useInsights.ts +++ b/frontend/src/hooks/api/getters/useInsights/useInsights.ts @@ -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( @@ -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, diff --git a/frontend/src/openapi/models/archivedFeatureSchema.ts b/frontend/src/openapi/models/archivedFeatureSchema.ts new file mode 100644 index 000000000000..c255a0bb933d --- /dev/null +++ b/frontend/src/openapi/models/archivedFeatureSchema.ts @@ -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; +} diff --git a/frontend/src/openapi/models/archivedFeatureSchemaEnvironmentsItem.ts b/frontend/src/openapi/models/archivedFeatureSchemaEnvironmentsItem.ts new file mode 100644 index 000000000000..1bc9447f8bc8 --- /dev/null +++ b/frontend/src/openapi/models/archivedFeatureSchemaEnvironmentsItem.ts @@ -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; +}; diff --git a/frontend/src/openapi/models/archivedFeaturesSchema.ts b/frontend/src/openapi/models/archivedFeaturesSchema.ts new file mode 100644 index 000000000000..75545207ed51 --- /dev/null +++ b/frontend/src/openapi/models/archivedFeaturesSchema.ts @@ -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; +} diff --git a/frontend/src/openapi/models/index.ts b/frontend/src/openapi/models/index.ts index 410d298b9bd9..16ad454e4622 100644 --- a/frontend/src/openapi/models/index.ts +++ b/frontend/src/openapi/models/index.ts @@ -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'; @@ -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'; @@ -801,6 +803,7 @@ export * from './inactiveUserSchema'; export * from './inactiveUsersSchema'; export * from './instanceAdminStatsSchema'; export * from './instanceAdminStatsSchemaActiveUsers'; +export * from './instanceAdminStatsSchemaApiTokens'; export * from './instanceAdminStatsSchemaClientAppsItem'; export * from './instanceAdminStatsSchemaClientAppsItemRange'; export * from './instanceAdminStatsSchemaPreviousDayMetricsBucketsCount'; @@ -808,11 +811,9 @@ 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'; @@ -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'; diff --git a/frontend/src/openapi/models/instanceAdminStatsSchema.ts b/frontend/src/openapi/models/instanceAdminStatsSchema.ts index afe40ddd6dbf..496f3ec37288 100644 --- a/frontend/src/openapi/models/instanceAdminStatsSchema.ts +++ b/frontend/src/openapi/models/instanceAdminStatsSchema.ts @@ -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'; @@ -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[]; /** @@ -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 */ @@ -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; } diff --git a/frontend/src/openapi/models/instanceAdminStatsSchemaApiTokens.ts b/frontend/src/openapi/models/instanceAdminStatsSchemaApiTokens.ts new file mode 100644 index 000000000000..b80a9652ae11 --- /dev/null +++ b/frontend/src/openapi/models/instanceAdminStatsSchemaApiTokens.ts @@ -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; +}; diff --git a/frontend/src/openapi/models/instanceInsightsSchemaFlags.ts b/frontend/src/openapi/models/instanceInsightsSchemaFlags.ts deleted file mode 100644 index 2b5216c6552d..000000000000 --- a/frontend/src/openapi/models/instanceInsightsSchemaFlags.ts +++ /dev/null @@ -1,13 +0,0 @@ -/** - * Generated by Orval - * Do not edit manually. - * See `gen:api` script in package.json - */ - -/** - * High level flag count statistics - */ -export type InstanceInsightsSchemaFlags = { - /** The number of non-archived flags */ - total: number; -}; diff --git a/frontend/src/openapi/models/instanceInsightsSchemaUsers.ts b/frontend/src/openapi/models/instanceInsightsSchemaUsers.ts deleted file mode 100644 index a12705199195..000000000000 --- a/frontend/src/openapi/models/instanceInsightsSchemaUsers.ts +++ /dev/null @@ -1,17 +0,0 @@ -/** - * Generated by Orval - * Do not edit manually. - * See `gen:api` script in package.json - */ - -/** - * High level user count statistics - */ -export type InstanceInsightsSchemaUsers = { - /** The number of active Unleash users who have user Unleash in the past 60 days */ - active: number; - /** The number of inactive Unleash users who have not used Unleash in the past 60 days. */ - inactive: number; - /** The number of actual Unleash users */ - total: number; -}; diff --git a/frontend/src/openapi/models/projectFeatureEnvironmentSchema.ts b/frontend/src/openapi/models/projectFeatureEnvironmentSchema.ts new file mode 100644 index 000000000000..5dbd02de58c9 --- /dev/null +++ b/frontend/src/openapi/models/projectFeatureEnvironmentSchema.ts @@ -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; +} diff --git a/frontend/src/openapi/models/projectFeatureSchema.ts b/frontend/src/openapi/models/projectFeatureSchema.ts new file mode 100644 index 000000000000..b7f22ce8031f --- /dev/null +++ b/frontend/src/openapi/models/projectFeatureSchema.ts @@ -0,0 +1,43 @@ +/** + * Generated by Orval + * Do not edit manually. + * See `gen:api` script in package.json + */ +import type { ProjectFeatureEnvironmentSchema } from './projectFeatureEnvironmentSchema'; +import type { TagSchema } from './tagSchema'; + +/** + * A project feature flag definition + */ +export interface ProjectFeatureSchema { + /** 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 */ + environments: ProjectFeatureEnvironmentSchema[]; + /** `true` if the feature was favorited, otherwise `false`. */ + favorite: boolean; + /** `true` if the impression data collection is enabled for the feature, otherwise `false`. */ + impressionData: boolean; + /** + * The date and time when metrics where last collected for this flag in any environment. This field was deprecated in v5. You should instead use the `lastSeenAt` property on the individual environments listed under the `environments` property. + * @deprecated + * @nullable + */ + lastSeenAt: string | null; + /** Unique feature name */ + name: string; + /** `true` if the feature is stale based on the age and feature type, otherwise `false`. */ + stale: boolean; + /** + * The list of feature tags + * @nullable + */ + tags?: TagSchema[] | null; + /** Type of the flag e.g. experiment, kill-switch, release, operational, permission */ + type: string; +} diff --git a/frontend/src/openapi/models/featuresSchema.ts b/frontend/src/openapi/models/projectFeaturesSchema.ts similarity index 54% rename from frontend/src/openapi/models/featuresSchema.ts rename to frontend/src/openapi/models/projectFeaturesSchema.ts index fe3e278d9188..cb8c2592e388 100644 --- a/frontend/src/openapi/models/featuresSchema.ts +++ b/frontend/src/openapi/models/projectFeaturesSchema.ts @@ -3,15 +3,15 @@ * Do not edit manually. * See `gen:api` script in package.json */ -import type { FeatureSchema } from './featureSchema'; +import type { ProjectFeatureSchema } from './projectFeatureSchema'; /** - * A list of features + * A list of features in a project * @deprecated */ -export interface FeaturesSchema { +export interface ProjectFeaturesSchema { /** A list of features */ - features: FeatureSchema[]; + features: ProjectFeatureSchema[]; /** The version of the feature's schema */ version: number; } diff --git a/frontend/src/openapi/models/projectOverviewSchema.ts b/frontend/src/openapi/models/projectOverviewSchema.ts index 7f37c3a13915..411479299811 100644 --- a/frontend/src/openapi/models/projectOverviewSchema.ts +++ b/frontend/src/openapi/models/projectOverviewSchema.ts @@ -13,6 +13,11 @@ import type { ProjectStatsSchema } from './projectStatsSchema'; * A high-level overview of a project. It contains information such as project statistics, the name of the project, what members and what features it contains, etc. */ export interface ProjectOverviewSchema { + /** + * When the project was archived. + * @nullable + */ + archivedAt?: string | null; /** * When the project was created. * @nullable diff --git a/frontend/src/openapi/models/projectSchema.ts b/frontend/src/openapi/models/projectSchema.ts index 462f4fb0c62a..f1c0883cb524 100644 --- a/frontend/src/openapi/models/projectSchema.ts +++ b/frontend/src/openapi/models/projectSchema.ts @@ -15,14 +15,21 @@ export interface ProjectSchema { * @nullable */ archivedAt?: string | null; - /** The average time from when a feature was created to when it was enabled in the "production" environment during the current window */ + /** + * The average time from when a feature was created to when it was enabled in the "production" environment during the current window + * @deprecated + */ avgTimeToProduction?: number; /** When this project was created. */ createdAt?: string; - /** A default stickiness for the project affecting the default stickiness value for variants and Gradual Rollout strategy */ + /** + * A default stickiness for the project affecting the default stickiness value for variants and Gradual Rollout strategy + * @deprecated + */ defaultStickiness?: string; /** * Additional information about the project + * @deprecated * @nullable */ description?: string | null; @@ -42,12 +49,19 @@ export interface ProjectSchema { name: string; /** The users and/or groups that have the "owner" role in this project. If no such users or groups exist, the list will contain the "system" owner instead. */ owners?: ProjectSchemaOwners; - /** The number of potentially stale features this project has */ + /** + * The number of potentially stale features this project has + * @deprecated + */ potentiallyStaleFeatureCount?: number; - /** The number of stale features this project has */ + /** + * The number of stale features this project has + * @deprecated + */ staleFeatureCount?: number; /** * When this project was last updated. + * @deprecated * @nullable */ updatedAt?: string | null; diff --git a/src/lib/openapi/spec/archived-features-schema.ts b/src/lib/openapi/spec/archived-features-schema.ts index fbfffab30c7b..b435b4246d40 100644 --- a/src/lib/openapi/spec/archived-features-schema.ts +++ b/src/lib/openapi/spec/archived-features-schema.ts @@ -7,7 +7,6 @@ export const archivedFeaturesSchema = { additionalProperties: false, required: ['version', 'features'], description: 'A list of archived features', - deprecated: true, properties: { version: { type: 'integer',