1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-05-08 01:15:49 +02:00

fix: fix broken ImportOptions.tsx (#3657)

<!-- Thanks for creating a PR! To make it easier for reviewers and
everyone else to understand what your changes relate to, please add some
relevant content to the headings below. Feel free to ignore or delete
sections that you don't think are relevant. Thank you! ❤️ -->
Fixes ImportOptions.tsx

## About the changes
<!-- Describe the changes introduced. What are they and why are they
being introduced? Feel free to also add screenshots or steps to view the
changes if they're visual. -->

<!-- Does it close an issue? Multiple? -->
Closes #

<!-- (For internal contributors): Does it relate to an issue on public
roadmap? -->
<!--
Relates to [roadmap](https://github.com/orgs/Unleash/projects/10) item:
#
-->

### Important files
<!-- PRs can contain a lot of changes, but not all changes are equally
important. Where should a reviewer start looking to get an overview of
the changes? Are any files particularly important? -->


## Discussion points
<!-- Anything about the PR you'd like to discuss before it gets merged?
Got any questions or doubts? -->

---------

Signed-off-by: andreas-unleash <andreas@getunleash.ai>
Co-authored-by: Prabodh Meshram <prabodh.meshram7@gmail.com>
This commit is contained in:
andreas-unleash 2023-05-02 10:17:05 +03:00 committed by GitHub
parent e901303808
commit e61c4524b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 28 additions and 32 deletions

View File

@ -50,7 +50,7 @@ const FeatureSettingsProjectConfirm = ({
const hasSameEnvironments: boolean = useMemo(() => {
return arraysHaveSameItems(
feature.environments.map(env => env.name),
project.environments
project.environments.map(projectEnv => projectEnv.environment)
);
}, [feature, project]);

View File

@ -32,11 +32,13 @@ export const ImportOptions: FC<IImportOptionsProps> = ({
onChange,
}) => {
const { project: projectInfo } = useProject(project);
const environmentOptions = projectInfo.environments.map(environment => ({
key: environment,
label: environment,
title: environment,
}));
const environmentOptions = projectInfo.environments.map(
({ environment }) => ({
key: environment,
label: environment,
title: environment,
})
);
useEffect(() => {
if (environment === '' && environmentOptions[0]) {

View File

@ -148,7 +148,9 @@ export const ProjectFeatureToggles = ({
const [searchParams, setSearchParams] = useSearchParams();
const { isChangeRequestConfigured } = useChangeRequestsEnabled(projectId);
const environments = useEnvironmentsRef(
loading ? ['a', 'b', 'c'] : newEnvironments
loading
? [{ environment: 'a' }, { environment: 'b' }, { environment: 'c' }]
: newEnvironments
);
const { refetch } = useProject(projectId);
const { setToastData, setToastApiError } = useToast();

View File

@ -7,23 +7,14 @@ import { CreateFeatureStrategySchema } from 'openapi';
export type ProjectEnvironmentType = {
environment: string;
defaultStrategy: CreateFeatureStrategySchema | null;
defaultStrategy?: CreateFeatureStrategySchema;
};
export const useEnvironmentsRef = (
environments: Array<string | ProjectEnvironmentType> = []
environments: Array<ProjectEnvironmentType> = []
): string[] => {
let names: string[];
if (
environments &&
environments.length > 0 &&
typeof environments[0] !== 'string'
) {
names = environments.map(
env => (env as ProjectEnvironmentType).environment
);
} else {
names = environments as string[];
}
let names = environments.map(
env => (env as ProjectEnvironmentType).environment
);
const ref = useRef<Array<string>>(names);
if (names.join('') !== ref.current?.join('')) {
ref.current = names;

View File

@ -73,9 +73,9 @@ const ProjectEnvironmentList = () => {
() =>
environments.map(environment => ({
...environment,
projectVisible: project?.environments.includes(
environment.name
),
projectVisible: project?.environments
.map(projectEnvironment => projectEnvironment.environment)
.includes(environment.name),
})),
[environments, project?.environments]
);

View File

@ -1,5 +1,6 @@
import { ProjectStatsSchema } from 'openapi';
import { IFeatureToggleListItem } from './featureToggle';
import { ProjectEnvironmentType } from '../component/project/Project/ProjectFeatureToggles/hooks/useEnvironmentsRef';
export interface IProjectCard {
name: string;
@ -18,7 +19,7 @@ export interface IProject {
version: string;
name: string;
description?: string;
environments: string[];
environments: Array<ProjectEnvironmentType>;
health: number;
stats: ProjectStatsSchema;
favorite: boolean;

View File

@ -428,11 +428,11 @@ test(`should not show environment on feature toggle, when environment is disable
.get('/api/admin/projects/default/features/my-feature')
.expect(200);
// sort to have predictable test results
const result = body.environments.sort((e1, e2) => e1.name < e2.name);
expect(result).toHaveLength(2);
expect(result[0].name).toBe('development');
expect(result[0].enabled).toBeTruthy();
expect(result[1].name).toBe('production');
expect(result[1].enabled).toBeFalsy();
const result = body.environments;
const sorted = result.sort((e1, e2) => e1.name[0] < e2.name[0]);
expect(sorted).toHaveLength(2);
expect(sorted[0].name).toBe('development');
expect(sorted[0].enabled).toBeTruthy();
expect(sorted[1].name).toBe('production');
expect(sorted[1].enabled).toBeFalsy();
});