Skip to content

Commit

Permalink
feat: environment diff (#4007)
Browse files Browse the repository at this point in the history
  • Loading branch information
kwasniew committed Jun 19, 2023
1 parent 15dc98b commit 11e6236
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 13 deletions.
Expand Up @@ -104,4 +104,5 @@ test('should render advanced playground table', async () => {
expect(screen.getByText('ChangeReqs')).toBeInTheDocument();
expect(screen.getByText('Development')).toBeInTheDocument();
expect(screen.getByText('Production')).toBeInTheDocument();
expect(screen.getByText('Preview diff')).toBeInTheDocument();
});
Expand Up @@ -32,9 +32,14 @@ import { AdvancedPlaygroundEnvironmentCell } from './AdvancedPlaygroundEnvironme
import {
AdvancedPlaygroundRequestSchema,
AdvancedPlaygroundFeatureSchema,
AdvancedPlaygroundFeatureSchemaEnvironments,
AdvancedPlaygroundEnvironmentFeatureSchema,
} from 'openapi';
import { capitalizeFirst } from 'utils/capitalizeFirst';
import { AdvancedPlaygroundEnvironmentDiffCell } from './AdvancedPlaygroundEnvironmentCell/AdvancedPlaygroundEnvironmentDiffCell';
import {
AdvancedPlaygroundEnvironmentDiffCell,
IAdvancedPlaygroundEnvironmentCellProps,
} from './AdvancedPlaygroundEnvironmentCell/AdvancedPlaygroundEnvironmentDiffCell';

const defaultSort: SortingRule<string> = { id: 'name' };
const { value, setValue } = createLocalStorage(
Expand Down Expand Up @@ -67,6 +72,10 @@ export const AdvancedPlaygroundResultsTable = ({
);
const theme = useTheme();
const isSmallScreen = useMediaQuery(theme.breakpoints.down('md'));
const environmentsCount =
features && features.length > 0
? Object.keys(features[0].environments).length
: 0;

const COLUMNS = useMemo(() => {
return [
Expand Down Expand Up @@ -106,17 +115,29 @@ export const AdvancedPlaygroundResultsTable = ({
),
};
}) || []),
{
Header: 'Diff',
minWidth: 150,
id: 'diff',
align: 'left',
Cell: ({ row }: any) => (
<AdvancedPlaygroundEnvironmentDiffCell
value={row.original.environments}
/>
),
},
...(environmentsCount > 1
? [
{
Header: 'Diff',
minWidth: 150,
id: 'diff',
align: 'left',
Cell: ({
row,
}: {
row: {
original: {
environments: AdvancedPlaygroundFeatureSchemaEnvironments;
};
};
}) => (
<AdvancedPlaygroundEnvironmentDiffCell
value={row.original.environments}
/>
),
},
]
: []),
];
}, [input]);

Expand All @@ -131,7 +152,7 @@ export const AdvancedPlaygroundResultsTable = ({
? Array(5).fill({
name: 'Feature name',
projectId: 'Feature Project',
environments: { name: 'Feature Envrironments', variants: [] },
environments: { name: 'Feature Environments', variants: [] },
enabled: true,
})
: searchedData;
Expand Down
@@ -0,0 +1,65 @@
import { screen } from '@testing-library/react';
import { render } from 'utils/testRenderer';
import { PlaygroundEnvironmentDiffTable } from './PlaygroundEnvironmentDiffTable';
import { UIProviderContainer } from '../../../providers/UIProvider/UIProviderContainer';

const irrelevantDetails = {
strategies: {
data: [],
result: false,
},
isEnabledInCurrentEnvironment: true,
variants: [],
variant: {
name: 'variantName',
enabled: true,
payload: {
type: 'string' as const,
value: 'variantValue',
},
},
projectId: 'projectA',
};

test('should render environment table', async () => {
render(
<UIProviderContainer>
<PlaygroundEnvironmentDiffTable
features={{
development: [
{
name: 'featureA',
isEnabled: true,
environment: 'development',
context: {
channel: 'web',
client: 'clientA',
appName: 'myapp',
},
...irrelevantDetails,
},
],
production: [
{
name: 'featureA',
isEnabled: false,
environment: 'production',
context: {
channel: 'web',
client: 'clientA',
appName: 'myapp',
},
...irrelevantDetails,
},
],
}}
/>
</UIProviderContainer>
);

expect(screen.getByText('web')).toBeInTheDocument();
expect(screen.getByText('clientA')).toBeInTheDocument();
expect(screen.getByText('True')).toBeInTheDocument();
expect(screen.getByText('False')).toBeInTheDocument();
expect(screen.getByText('myapp')).toBeInTheDocument();
});

1 comment on commit 11e6236

@vercel
Copy link

@vercel vercel bot commented on 11e6236 Jun 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

unleash-docs – ./website

unleash-docs.vercel.app
unleash-docs-git-main-unleash-team.vercel.app
unleash-docs-unleash-team.vercel.app

Please sign in to comment.