Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: switch to FeatureSchema #8811

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ export const useCurrentStrategy = (
environmentName: string,
) => {
const { feature: currentFeature } = useFeature(project, feature);

const currentStrategy = currentFeature?.environments
.find((environment) => environment.name === environmentName)
?.find((environment) => environment.name === environmentName)
?.strategies.find(
(strategy) =>
'id' in change.payload && strategy.id === change.payload.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@
const children = fetchedFeature.children;
const parents = fetchedFeature.dependencies;

if (children.length > 0) {
if (children?.length > 0) {
return (
<>
<Box>Children</Box>
Expand All @@ -238,7 +238,7 @@
))}
</>
);
} else if (parents[0]) {

Check failure on line 241 in frontend/src/component/common/Table/cells/FeatureOverviewCell/FeatureOverviewCell.tsx

View workflow job for this annotation

GitHub Actions / build

Unhandled error

TypeError: Cannot read properties of undefined (reading '0') ❯ DependencyPreview src/component/common/Table/cells/FeatureOverviewCell/FeatureOverviewCell.tsx:241:16 ❯ renderWithHooks node_modules/react-dom/cjs/react-dom.development.js:15486:18 ❯ mountIndeterminateComponent node_modules/react-dom/cjs/react-dom.development.js:20103:13 ❯ beginWork node_modules/react-dom/cjs/react-dom.development.js:21626:16 ❯ beginWork$1 node_modules/react-dom/cjs/react-dom.development.js:27465:14 ❯ performUnitOfWork node_modules/react-dom/cjs/react-dom.development.js:26599:12 ❯ workLoopSync node_modules/react-dom/cjs/react-dom.development.js:26505:5 ❯ renderRootSync node_modules/react-dom/cjs/react-dom.development.js:26473:7 ❯ recoverFromConcurrentError node_modules/react-dom/cjs/react-dom.development.js:25889:20 ❯ performSyncWorkOnRoot node_modules/react-dom/cjs/react-dom.development.js:26135:20 This error originated in "src/component/common/Table/cells/FeatureOverviewCell/DependentFeaturesPreview.test.tsx" test file. It doesn't mean the error was thrown inside the file itself, but while it was running. The latest test that might've caused the error is "Preview parent feature". It might mean one of the following: - The error was thrown, while Vitest was running this test. - If the error occurred after the test had been completed, this was the last documented test before it was thrown.

Check failure on line 241 in frontend/src/component/common/Table/cells/FeatureOverviewCell/FeatureOverviewCell.tsx

View workflow job for this annotation

GitHub Actions / build

Unhandled error

TypeError: Cannot read properties of undefined (reading '0') ❯ DependencyPreview src/component/common/Table/cells/FeatureOverviewCell/FeatureOverviewCell.tsx:241:16 ❯ renderWithHooks node_modules/react-dom/cjs/react-dom.development.js:15486:18 ❯ mountIndeterminateComponent node_modules/react-dom/cjs/react-dom.development.js:20103:13 ❯ beginWork node_modules/react-dom/cjs/react-dom.development.js:21626:16 ❯ beginWork$1 node_modules/react-dom/cjs/react-dom.development.js:27465:14 ❯ performUnitOfWork node_modules/react-dom/cjs/react-dom.development.js:26599:12 ❯ workLoopSync node_modules/react-dom/cjs/react-dom.development.js:26505:5 ❯ renderRootSync node_modules/react-dom/cjs/react-dom.development.js:26473:7 ❯ recoverFromConcurrentError node_modules/react-dom/cjs/react-dom.development.js:25889:20 ❯ performSyncWorkOnRoot node_modules/react-dom/cjs/react-dom.development.js:26135:20 This error originated in "src/component/common/Table/cells/FeatureOverviewCell/DependentFeaturesPreview.test.tsx" test file. It doesn't mean the error was thrown inside the file itself, but while it was running. The latest test that might've caused the error is "Preview child features". It might mean one of the following: - The error was thrown, while Vitest was running this test. - If the error occurred after the test had been completed, this was the last documented test before it was thrown.
const parentFeature = parents[0].feature;
return (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export const FeatureStrategyCreate = () => {
const navigate = useNavigate();

const { feature, refetchFeature } = useFeature(projectId, featureId);
const featureEnvironment = feature?.environments.find(
const featureEnvironment = feature?.environments?.find(
(featureEnvironment) => featureEnvironment.name === environmentId,
);
const strategyCount = featureEnvironment?.strategies.length || 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const FlagExposure: FC<{
onUncomplete={refetchFeature}
/>

{feature.children.length > 0 ? (
{feature?.children?.length > 0 ? (
<FeatureArchiveNotAllowedDialog
features={feature.children}
project={project}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,14 @@ const FeatureOverviewEnvironment = ({
const { feature } = useFeature(projectId, featureId);
const { value: globalStore } = useGlobalLocalStorage();

const featureMetrics = getFeatureMetrics(feature?.environments, metrics);
const featureMetrics = getFeatureMetrics(
feature?.environments ?? [],
metrics,
);
const environmentMetric = featureMetrics.find(
(featureMetric) => featureMetric.environment === env.name,
);
const featureEnvironment = feature?.environments.find(
const featureEnvironment = feature?.environments?.find(
(featureEnvironment) => featureEnvironment.name === env.name,
);

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/component/feature/FeatureView/FeatureView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@

const useLegacyVariants = (environments: IFeatureToggle['environments']) => {
const enableLegacyVariants = useUiFlag('enableLegacyVariants');
const existingLegacyVariantsExist = environments.some(
const existingLegacyVariantsExist = environments?.some(
(environment) => environment.variants?.length,
);
return enableLegacyVariants || existingLegacyVariantsExist;
Expand Down Expand Up @@ -274,7 +274,7 @@
/>
</StyledFlagInfoContainer>
<ConditionallyRender
condition={feature.dependencies.length > 0}

Check failure on line 277 in frontend/src/component/feature/FeatureView/FeatureView.tsx

View workflow job for this annotation

GitHub Actions / build

src/component/changeRequest/ChangeRequest.test.tsx > add flag change to pending change request

TypeError: Cannot read properties of undefined (reading 'length') ❯ FeatureView src/component/feature/FeatureView/FeatureView.tsx:277:65 ❯ renderWithHooks node_modules/react-dom/cjs/react-dom.development.js:15486:18 ❯ mountIndeterminateComponent node_modules/react-dom/cjs/react-dom.development.js:20103:13 ❯ beginWork node_modules/react-dom/cjs/react-dom.development.js:21626:16 ❯ beginWork$1 node_modules/react-dom/cjs/react-dom.development.js:27465:14 ❯ performUnitOfWork node_modules/react-dom/cjs/react-dom.development.js:26599:12 ❯ workLoopSync node_modules/react-dom/cjs/react-dom.development.js:26505:5 ❯ renderRootSync node_modules/react-dom/cjs/react-dom.development.js:26473:7 ❯ recoverFromConcurrentError node_modules/react-dom/cjs/react-dom.development.js:25889:20 ❯ performConcurrentWorkOnRoot node_modules/react-dom/cjs/react-dom.development.js:25789:22

Check failure on line 277 in frontend/src/component/feature/FeatureView/FeatureView.tsx

View workflow job for this annotation

GitHub Actions / build

src/component/changeRequest/ChangeRequestPermissions.test.tsx > open mode + non-project member can perform basic change request actions

TypeError: Cannot read properties of undefined (reading 'length') ❯ FeatureView src/component/feature/FeatureView/FeatureView.tsx:277:65 ❯ renderWithHooks node_modules/react-dom/cjs/react-dom.development.js:15486:18 ❯ mountIndeterminateComponent node_modules/react-dom/cjs/react-dom.development.js:20103:13 ❯ beginWork node_modules/react-dom/cjs/react-dom.development.js:21626:16 ❯ beginWork$1 node_modules/react-dom/cjs/react-dom.development.js:27465:14 ❯ performUnitOfWork node_modules/react-dom/cjs/react-dom.development.js:26599:12 ❯ workLoopSync node_modules/react-dom/cjs/react-dom.development.js:26505:5 ❯ renderRootSync node_modules/react-dom/cjs/react-dom.development.js:26473:7 ❯ recoverFromConcurrentError node_modules/react-dom/cjs/react-dom.development.js:25889:20 ❯ performConcurrentWorkOnRoot node_modules/react-dom/cjs/react-dom.development.js:25789:22

Check failure on line 277 in frontend/src/component/feature/FeatureView/FeatureView.tsx

View workflow job for this annotation

GitHub Actions / build

src/component/changeRequest/ChangeRequestPermissions.test.tsx > protected mode + project member can perform basic change request actions

TypeError: Cannot read properties of undefined (reading 'length') ❯ FeatureView src/component/feature/FeatureView/FeatureView.tsx:277:65 ❯ renderWithHooks node_modules/react-dom/cjs/react-dom.development.js:15486:18 ❯ mountIndeterminateComponent node_modules/react-dom/cjs/react-dom.development.js:20103:13 ❯ beginWork node_modules/react-dom/cjs/react-dom.development.js:21626:16 ❯ beginWork$1 node_modules/react-dom/cjs/react-dom.development.js:27465:14 ❯ performUnitOfWork node_modules/react-dom/cjs/react-dom.development.js:26599:12 ❯ workLoopSync node_modules/react-dom/cjs/react-dom.development.js:26505:5 ❯ renderRootSync node_modules/react-dom/cjs/react-dom.development.js:26473:7 ❯ recoverFromConcurrentError node_modules/react-dom/cjs/react-dom.development.js:25889:20 ❯ performConcurrentWorkOnRoot node_modules/react-dom/cjs/react-dom.development.js:25789:22
show={
<StyledDependency>
<b>Has parent: </b>
Expand Down
9 changes: 4 additions & 5 deletions frontend/src/hooks/api/getters/useFeature/useFeature.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import useSWR, { type SWRConfiguration } from 'swr';
import { useCallback } from 'react';
import { emptyFeature } from './emptyFeature';
import handleErrorResponses from '../httpErrorResponseHandler';
import { formatApiPath } from 'utils/formatPath';
import type { IFeatureToggle } from 'interfaces/featureToggle';
import type { FeatureSchema } from 'openapi';

export interface IUseFeatureOutput {
feature: IFeatureToggle;
feature: FeatureSchema;
refetchFeature: () => void;
loading: boolean;
status?: number;
Expand All @@ -15,7 +14,7 @@ export interface IUseFeatureOutput {

export interface IFeatureResponse {
status: number;
body?: IFeatureToggle;
body?: FeatureSchema;
}

export const useFeature = (
Expand All @@ -36,7 +35,7 @@ export const useFeature = (
}, [mutate]);

return {
feature: data?.body || emptyFeature,
feature: data?.body || { name: '' },
refetchFeature,
loading: !error && !data,
status: data?.status,
Expand Down
Loading