mirror of
https://github.com/Unleash/unleash.git
synced 2025-06-09 01:17:06 +02:00
fix: refresh project after import (#7082)
This commit is contained in:
parent
a204f2c615
commit
659b3391c3
@ -12,8 +12,8 @@ import { PulsingAvatar } from '../PulsingAvatar';
|
|||||||
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
|
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
|
||||||
import { Box } from '@mui/system';
|
import { Box } from '@mui/system';
|
||||||
import { useChangeRequestsEnabled } from 'hooks/useChangeRequestsEnabled';
|
import { useChangeRequestsEnabled } from 'hooks/useChangeRequestsEnabled';
|
||||||
import useProject from 'hooks/api/getters/useProject/useProject';
|
|
||||||
import { usePendingChangeRequests } from 'hooks/api/getters/usePendingChangeRequests/usePendingChangeRequests';
|
import { usePendingChangeRequests } from 'hooks/api/getters/usePendingChangeRequests/usePendingChangeRequests';
|
||||||
|
import { useProjectFeatureSearch } from '../../PaginatedProjectFeatureToggles/useProjectFeatureSearch';
|
||||||
|
|
||||||
export const ImportStatusArea = styled(Box)(({ theme }) => ({
|
export const ImportStatusArea = styled(Box)(({ theme }) => ({
|
||||||
padding: theme.spacing(4, 2, 2, 2),
|
padding: theme.spacing(4, 2, 2, 2),
|
||||||
@ -65,7 +65,7 @@ export const ImportStage: FC<{
|
|||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
}> = ({ environment, project, payload, onClose }) => {
|
}> = ({ environment, project, payload, onClose }) => {
|
||||||
const { createImport, loading, errors } = useImportApi();
|
const { createImport, loading, errors } = useImportApi();
|
||||||
const { refetch: refreshProject } = useProject(project);
|
const { refetch: refreshProject } = useProjectFeatureSearch(project);
|
||||||
const { refetch: refreshChangeRequests } =
|
const { refetch: refreshChangeRequests } =
|
||||||
usePendingChangeRequests(project);
|
usePendingChangeRequests(project);
|
||||||
const { setToastData } = useToast();
|
const { setToastData } = useToast();
|
||||||
|
@ -20,23 +20,6 @@ import {
|
|||||||
import { useChangeRequestsEnabled } from 'hooks/useChangeRequestsEnabled';
|
import { useChangeRequestsEnabled } from 'hooks/useChangeRequestsEnabled';
|
||||||
import { useFeatureToggleSwitch } from '../ProjectFeatureToggles/FeatureToggleSwitch/useFeatureToggleSwitch';
|
import { useFeatureToggleSwitch } from '../ProjectFeatureToggles/FeatureToggleSwitch/useFeatureToggleSwitch';
|
||||||
import useLoading from 'hooks/useLoading';
|
import useLoading from 'hooks/useLoading';
|
||||||
import {
|
|
||||||
DEFAULT_PAGE_LIMIT,
|
|
||||||
useFeatureSearch,
|
|
||||||
} from 'hooks/api/getters/useFeatureSearch/useFeatureSearch';
|
|
||||||
import mapValues from 'lodash.mapvalues';
|
|
||||||
import { usePersistentTableState } from 'hooks/usePersistentTableState';
|
|
||||||
import {
|
|
||||||
BooleansStringParam,
|
|
||||||
FilterItemParam,
|
|
||||||
} from 'utils/serializeQueryParams';
|
|
||||||
import {
|
|
||||||
ArrayParam,
|
|
||||||
encodeQueryParams,
|
|
||||||
NumberParam,
|
|
||||||
StringParam,
|
|
||||||
withDefault,
|
|
||||||
} from 'use-query-params';
|
|
||||||
import { ProjectFeatureTogglesHeader } from './ProjectFeatureTogglesHeader/ProjectFeatureTogglesHeader';
|
import { ProjectFeatureTogglesHeader } from './ProjectFeatureTogglesHeader/ProjectFeatureTogglesHeader';
|
||||||
import { createColumnHelper, useReactTable } from '@tanstack/react-table';
|
import { createColumnHelper, useReactTable } from '@tanstack/react-table';
|
||||||
import { withTableState } from 'utils/withTableState';
|
import { withTableState } from 'utils/withTableState';
|
||||||
@ -52,11 +35,10 @@ import { useRowActions } from './hooks/useRowActions';
|
|||||||
import { useSelectedData } from './hooks/useSelectedData';
|
import { useSelectedData } from './hooks/useSelectedData';
|
||||||
import { FeatureOverviewCell } from '../../../common/Table/cells/FeatureOverviewCell/FeatureOverviewCell';
|
import { FeatureOverviewCell } from '../../../common/Table/cells/FeatureOverviewCell/FeatureOverviewCell';
|
||||||
import { useUiFlag } from 'hooks/useUiFlag';
|
import { useUiFlag } from 'hooks/useUiFlag';
|
||||||
|
import { useProjectFeatureSearch } from './useProjectFeatureSearch';
|
||||||
|
|
||||||
interface IPaginatedProjectFeatureTogglesProps {
|
interface IPaginatedProjectFeatureTogglesProps {
|
||||||
environments: string[];
|
environments: string[];
|
||||||
refreshInterval?: number;
|
|
||||||
storageKey?: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const formatEnvironmentColumnId = (environment: string) =>
|
const formatEnvironmentColumnId = (environment: string) =>
|
||||||
@ -67,46 +49,24 @@ const getRowId = (row: { name: string }) => row.name;
|
|||||||
|
|
||||||
export const ProjectFeatureToggles = ({
|
export const ProjectFeatureToggles = ({
|
||||||
environments,
|
environments,
|
||||||
refreshInterval = 15 * 1000,
|
|
||||||
storageKey = 'project-feature-toggles-v2',
|
|
||||||
}: IPaginatedProjectFeatureTogglesProps) => {
|
}: IPaginatedProjectFeatureTogglesProps) => {
|
||||||
const projectId = useRequiredPathParam('projectId');
|
const projectId = useRequiredPathParam('projectId');
|
||||||
|
|
||||||
const stateConfig = {
|
const {
|
||||||
offset: withDefault(NumberParam, 0),
|
features,
|
||||||
limit: withDefault(NumberParam, DEFAULT_PAGE_LIMIT),
|
total,
|
||||||
query: StringParam,
|
refetch,
|
||||||
favoritesFirst: withDefault(BooleansStringParam, true),
|
loading,
|
||||||
sortBy: withDefault(StringParam, 'createdAt'),
|
initialLoad,
|
||||||
sortOrder: withDefault(StringParam, 'desc'),
|
tableState,
|
||||||
columns: ArrayParam,
|
setTableState,
|
||||||
tag: FilterItemParam,
|
} = useProjectFeatureSearch(projectId);
|
||||||
createdAt: FilterItemParam,
|
|
||||||
};
|
|
||||||
const [tableState, setTableState] = usePersistentTableState(
|
|
||||||
`${storageKey}-${projectId}`,
|
|
||||||
stateConfig,
|
|
||||||
);
|
|
||||||
|
|
||||||
const filterState = {
|
const filterState = {
|
||||||
tag: tableState.tag,
|
tag: tableState.tag,
|
||||||
createdAt: tableState.createdAt,
|
createdAt: tableState.createdAt,
|
||||||
};
|
};
|
||||||
|
|
||||||
const { columns: _, ...apiTableState } = tableState;
|
|
||||||
const { features, total, refetch, loading, initialLoad } = useFeatureSearch(
|
|
||||||
mapValues(
|
|
||||||
{
|
|
||||||
...encodeQueryParams(stateConfig, apiTableState),
|
|
||||||
project: `IS:${projectId}`,
|
|
||||||
},
|
|
||||||
(value) => (value ? `${value}` : undefined),
|
|
||||||
),
|
|
||||||
{
|
|
||||||
refreshInterval,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
const { favorite, unfavorite } = useFavoriteFeaturesApi();
|
const { favorite, unfavorite } = useFavoriteFeaturesApi();
|
||||||
const onFavorite = useCallback(
|
const onFavorite = useCallback(
|
||||||
async (feature: FeatureSearchResponseSchema) => {
|
async (feature: FeatureSearchResponseSchema) => {
|
||||||
|
@ -0,0 +1,63 @@
|
|||||||
|
import {
|
||||||
|
ArrayParam,
|
||||||
|
encodeQueryParams,
|
||||||
|
NumberParam,
|
||||||
|
StringParam,
|
||||||
|
withDefault,
|
||||||
|
} from 'use-query-params';
|
||||||
|
import {
|
||||||
|
DEFAULT_PAGE_LIMIT,
|
||||||
|
useFeatureSearch,
|
||||||
|
} from 'hooks/api/getters/useFeatureSearch/useFeatureSearch';
|
||||||
|
import {
|
||||||
|
BooleansStringParam,
|
||||||
|
FilterItemParam,
|
||||||
|
} from 'utils/serializeQueryParams';
|
||||||
|
import { usePersistentTableState } from 'hooks/usePersistentTableState';
|
||||||
|
import mapValues from 'lodash.mapvalues';
|
||||||
|
|
||||||
|
export const useProjectFeatureSearch = (
|
||||||
|
projectId: string,
|
||||||
|
storageKey = 'project-overview-v2',
|
||||||
|
refreshInterval = 15 * 1000,
|
||||||
|
) => {
|
||||||
|
const stateConfig = {
|
||||||
|
offset: withDefault(NumberParam, 0),
|
||||||
|
limit: withDefault(NumberParam, DEFAULT_PAGE_LIMIT),
|
||||||
|
query: StringParam,
|
||||||
|
favoritesFirst: withDefault(BooleansStringParam, true),
|
||||||
|
sortBy: withDefault(StringParam, 'createdAt'),
|
||||||
|
sortOrder: withDefault(StringParam, 'desc'),
|
||||||
|
columns: ArrayParam,
|
||||||
|
tag: FilterItemParam,
|
||||||
|
createdAt: FilterItemParam,
|
||||||
|
};
|
||||||
|
const [tableState, setTableState] = usePersistentTableState(
|
||||||
|
`${storageKey}-${projectId}`,
|
||||||
|
stateConfig,
|
||||||
|
);
|
||||||
|
|
||||||
|
const { columns: _, ...apiTableState } = tableState;
|
||||||
|
const { features, total, refetch, loading, initialLoad } = useFeatureSearch(
|
||||||
|
mapValues(
|
||||||
|
{
|
||||||
|
...encodeQueryParams(stateConfig, apiTableState),
|
||||||
|
project: `IS:${projectId}`,
|
||||||
|
},
|
||||||
|
(value) => (value ? `${value}` : undefined),
|
||||||
|
),
|
||||||
|
{
|
||||||
|
refreshInterval,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
features,
|
||||||
|
total,
|
||||||
|
refetch,
|
||||||
|
loading,
|
||||||
|
initialLoad,
|
||||||
|
tableState,
|
||||||
|
setTableState,
|
||||||
|
};
|
||||||
|
};
|
@ -32,9 +32,7 @@ const StyledContentContainer = styled(Box)(({ theme }) => ({
|
|||||||
minWidth: 0,
|
minWidth: 0,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const ProjectOverview: FC<{
|
const ProjectOverview: FC = () => {
|
||||||
storageKey?: string;
|
|
||||||
}> = ({ storageKey = 'project-overview-v2' }) => {
|
|
||||||
const projectId = useRequiredPathParam('projectId');
|
const projectId = useRequiredPathParam('projectId');
|
||||||
const projectName = useProjectOverviewNameOrId(projectId);
|
const projectName = useProjectOverviewNameOrId(projectId);
|
||||||
|
|
||||||
@ -58,8 +56,6 @@ const ProjectOverview: FC<{
|
|||||||
environments={project.environments.map(
|
environments={project.environments.map(
|
||||||
(environment) => environment.environment,
|
(environment) => environment.environment,
|
||||||
)}
|
)}
|
||||||
refreshInterval={refreshInterval}
|
|
||||||
storageKey={storageKey}
|
|
||||||
/>
|
/>
|
||||||
</StyledProjectToggles>
|
</StyledProjectToggles>
|
||||||
</StyledContentContainer>
|
</StyledContentContainer>
|
||||||
|
Loading…
Reference in New Issue
Block a user