Skip to content

Commit

Permalink
fix: backport lifecycle and playground fixes (#7396)
Browse files Browse the repository at this point in the history
  • Loading branch information
kwasniew authored Jun 14, 2024
1 parent 29e0167 commit 406f906
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ export const comparisonModerator = (
): DeepOmit<IFeatureToggle, keyof IFeatureToggle> => {
const tempData = { ...data };

return deepOmit(tempData, 'lastSeenAt', 'yes', 'no');
return deepOmit(tempData, 'lastSeenAt', 'yes', 'no', 'lifecycle');
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
DELETE_FEATURE,
UPDATE_FEATURE,
} from 'component/providers/AccessProvider/permissions';
import { Route, Routes } from 'react-router-dom';

const currentTime = '2024-04-25T08:05:00.000Z';
const twoMinutesAgo = '2024-04-25T08:03:00.000Z';
Expand All @@ -22,16 +23,24 @@ const renderOpenTooltip = (
loading = false,
) => {
render(
<FeatureLifecycleTooltip
stage={stage}
onArchive={onArchive}
onComplete={onComplete}
onUncomplete={onUncomplete}
loading={loading}
>
<span>child</span>
</FeatureLifecycleTooltip>,
<Routes>
<Route
path={'/projects/:projectId'}
element={
<FeatureLifecycleTooltip
stage={stage}
onArchive={onArchive}
onComplete={onComplete}
onUncomplete={onUncomplete}
loading={loading}
>
<span>child</span>
</FeatureLifecycleTooltip>
}
/>
</Routes>,
{
route: '/projects/default',
permissions: [
{ permission: DELETE_FEATURE },
{ permission: UPDATE_FEATURE },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { isSafeToArchive } from './isSafeToArchive';
import { useLocationSettings } from 'hooks/useLocationSettings';
import { formatDateYMDHMS } from 'utils/formatDate';
import { formatDistanceToNow, parseISO } from 'date-fns';
import { useRequiredPathParam } from 'hooks/useRequiredPathParam';

const TimeLabel = styled('span')(({ theme }) => ({
color: theme.palette.text.secondary,
Expand Down Expand Up @@ -264,6 +265,8 @@ const LiveStageDescription: FC<{
onComplete: () => void;
loading: boolean;
}> = ({ children, onComplete, loading }) => {
const projectId = useRequiredPathParam('projectId');

return (
<>
<BoldTitle>Is this feature complete?</BoldTitle>
Expand All @@ -282,6 +285,7 @@ const LiveStageDescription: FC<{
size='small'
onClick={onComplete}
disabled={loading}
projectId={projectId}
>
Mark completed
</PermissionButton>
Expand All @@ -300,6 +304,8 @@ const SafeToArchive: FC<{
onUncomplete: () => void;
loading: boolean;
}> = ({ onArchive, onUncomplete, loading }) => {
const projectId = useRequiredPathParam('projectId');

return (
<>
<BoldTitle>Safe to archive</BoldTitle>
Expand All @@ -316,6 +322,7 @@ const SafeToArchive: FC<{
sx={{
display: 'flex',
flexDirection: 'row',
flexWrap: 'wrap',
gap: 2,
}}
>
Expand All @@ -326,6 +333,7 @@ const SafeToArchive: FC<{
size='small'
onClick={onUncomplete}
disabled={loading}
projectId={projectId}
>
Revert to live
</PermissionButton>
Expand All @@ -336,6 +344,7 @@ const SafeToArchive: FC<{
size='small'
sx={{ mb: 2 }}
onClick={onArchive}
projectId={projectId}
>
Archive feature
</PermissionButton>
Expand Down
24 changes: 5 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@
"testTimeout": 10000,
"globalSetup": "./scripts/jest-setup.js",
"transform": {
"^.+\\.tsx?$": [
"@swc/jest"
]
"^.+\\.tsx?$": ["@swc/jest"]
},
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
"testPathIgnorePatterns": [
Expand All @@ -93,13 +91,7 @@
"/frontend/",
"/website/"
],
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json"
],
"moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json"],
"coveragePathIgnorePatterns": [
"/node_modules/",
"/dist/",
Expand Down Expand Up @@ -240,14 +232,8 @@
"tough-cookie": "4.1.4"
},
"lint-staged": {
"*.{js,ts}": [
"biome check --write --no-errors-on-unmatched"
],
"*.{jsx,tsx}": [
"biome check --write --no-errors-on-unmatched"
],
"*.json": [
"biome format --write --no-errors-on-unmatched"
]
"*.{js,ts}": ["biome check --write --no-errors-on-unmatched"],
"*.{jsx,tsx}": ["biome check --write --no-errors-on-unmatched"],
"*.json": ["biome format --write --no-errors-on-unmatched"]
}
}
31 changes: 30 additions & 1 deletion src/lib/features/playground/advanced-playground.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ test('advanced playground evaluation with no toggles', async () => {
});
});

test('advanced playground evaluation with parent dependency', async () => {
test('advanced playground evaluation with unsatisfied parent dependency', async () => {
await createFeatureToggle('test-parent');
await createFeatureToggle('test-child');
await enableToggle('test-child');
Expand Down Expand Up @@ -126,6 +126,35 @@ test('advanced playground evaluation with parent dependency', async () => {
expect(parent.isEnabled).toBe(false);
});

test('advanced playground evaluation with satisfied disabled parent dependency', async () => {
await createFeatureToggle('test-parent');
await createFeatureToggle('test-child');
await enableToggle('test-child');
await app.addDependency('test-child', {
feature: 'test-parent',
enabled: false,
variants: [],
});

const { body: result } = await app.request
.post('/api/admin/playground/advanced')
.send({
environments: ['default'],
projects: ['default'],
context: { appName: 'test' },
})
.set('Content-Type', 'application/json')
.expect(200);

const child = result.features[0].environments.default[0];
const parent = result.features[1].environments.default[0];

expect(child.hasUnsatisfiedDependency).toBe(false);
expect(child.isEnabled).toBe(true);
expect(parent.hasUnsatisfiedDependency).toBe(false);
expect(parent.isEnabled).toBe(false);
});

test('advanced playground evaluation happy path', async () => {
await createFeatureToggleWithStrategy('test-playground-feature');
await enableToggle('test-playground-feature');
Expand Down
12 changes: 3 additions & 9 deletions src/lib/features/playground/feature-evaluator/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,6 @@ export default class UnleashClient {
}

if (parent.enabled !== false) {
if (!parentToggle.enabled) {
return false;
}
if (parent.variants?.length) {
return parent.variants.includes(
this.getVariant(parent.feature, context).name,
Expand All @@ -91,12 +88,9 @@ export default class UnleashClient {
);
}

return (
!parentToggle.enabled &&
!(
this.isEnabled(parent.feature, context, () => false)
.result === true
)
return !(
this.isEnabled(parent.feature, context, () => false).result ===
true
);
});
}
Expand Down
10 changes: 7 additions & 3 deletions src/test/e2e/helpers/test-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import type { Db } from '../../../lib/db/db';
import type { IContextFieldDto } from '../../../lib/types/stores/context-field-store';
import { DEFAULT_ENV } from '../../../lib/util';
import type {
CreateDependentFeatureSchema,
CreateFeatureSchema,
CreateFeatureStrategySchema,
ImportTogglesSchema,
Expand Down Expand Up @@ -102,7 +103,10 @@ export interface IUnleashHttpAPI {
expectedResponseCode?: number,
): supertest.Test;

addDependency(child: string, parent: string): supertest.Test;
addDependency(
child: string,
parent: string | CreateDependentFeatureSchema,
): supertest.Test;

addTag(
feature: string,
Expand Down Expand Up @@ -224,15 +228,15 @@ function httpApis(

addDependency(
child: string,
parent: string,
parent: string | CreateDependentFeatureSchema,
project = DEFAULT_PROJECT,
expectedResponseCode: number = 200,
): supertest.Test {
return request
.post(
`/api/admin/projects/${project}/features/${child}/dependencies`,
)
.send({ feature: parent })
.send(typeof parent === 'string' ? { feature: parent } : parent)
.set('Content-Type', 'application/json')
.expect(expectedResponseCode);
},
Expand Down

0 comments on commit 406f906

Please sign in to comment.