1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-09-28 17:55:15 +02:00
unleash.unleash/frontend/src/component/strategies/StrategyView/StrategyView.tsx
Nuno Góis 4167a60588
feat: biome lint frontend (#4903)
Follows up on https://github.com/Unleash/unleash/pull/4853 to add Biome
to the frontend as well.


![image](https://github.com/Unleash/unleash/assets/14320932/1906faf1-fc29-4172-a4d4-b2716d72cd65)

Added a few `biome-ignore` to speed up the process but we may want to
check and fix them in the future.
2023-10-02 13:25:46 +01:00

75 lines
3.1 KiB
TypeScript

import { Grid } from '@mui/material';
import { useNavigate } from 'react-router-dom';
import { UPDATE_STRATEGY } from 'component/providers/AccessProvider/permissions';
import { PageContent } from 'component/common/PageContent/PageContent';
import { useStrategies } from 'hooks/api/getters/useStrategies/useStrategies';
import { useFeatures } from 'hooks/api/getters/useFeatures/useFeatures';
import useApplications from 'hooks/api/getters/useApplications/useApplications';
import { StrategyDetails } from './StrategyDetails/StrategyDetails';
import { PageHeader } from 'component/common/PageHeader/PageHeader';
import PermissionIconButton from 'component/common/PermissionIconButton/PermissionIconButton';
import { Edit } from '@mui/icons-material';
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
import { useRequiredPathParam } from 'hooks/useRequiredPathParam';
import { FeatureSchema } from 'openapi/models';
export const StrategyView = () => {
const name = useRequiredPathParam('name');
const { strategies } = useStrategies();
const { features = [] } = useFeatures();
const { applications } = useApplications();
const navigate = useNavigate();
// Has been broken since the migration to environments. We need to create an
// endpoint that returns all environments and strategies for all features to make this
// work properly OR alternatively create an endpoint that abstracts this logic into the backend
const toggles = features.filter((toggle: FeatureSchema) => {
return toggle?.environments
?.flatMap((env) => env.strategies)
.some((strategy) => strategy && strategy.name === name);
});
const strategy = strategies.find((strategy) => strategy.name === name);
const handleEdit = () => {
navigate(`/strategies/${name}/edit`);
};
if (!strategy) return null;
return (
<PageContent
header={
<PageHeader
title={strategy?.name}
subtitle={strategy?.description}
actions={
<ConditionallyRender
condition={strategy.editable}
show={
<PermissionIconButton
permission={UPDATE_STRATEGY}
data-loading
onClick={handleEdit}
tooltipProps={{ title: 'Edit strategy' }}
>
<Edit />
</PermissionIconButton>
}
/>
}
/>
}
>
<Grid container>
<Grid item xs={12} sm={12}>
<StrategyDetails
strategy={strategy}
toggles={toggles}
applications={applications}
/>
</Grid>
</Grid>
</PageContent>
);
};