Skip to content

Commit

Permalink
implement landing page changes
Browse files Browse the repository at this point in the history
  • Loading branch information
abailly-akamai committed Mar 26, 2024
1 parent efc2fb4 commit 0d6fda4
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {

import { LinodeSelect } from '../Linodes/LinodeSelect/LinodeSelect';
import {
getAffinityEnforcement,
getAffinityTypeEnforcement,
getLinodesFromAllPlacementGroups,
} from './utils';

Expand Down Expand Up @@ -139,7 +139,7 @@ export const PlacementGroupsAssignLinodesDrawer = (
{generalError ? <Notice text={generalError} variant="error" /> : null}
<Typography my={4}>
<strong>Affinity Enforcement: </strong>
{getAffinityEnforcement(selectedPlacementGroup.is_strict)}
{getAffinityTypeEnforcement(selectedPlacementGroup.is_strict)}
</Typography>
<Divider sx={{ mb: 4 }} />
<form onSubmit={handleAssignLinode}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
import { getFormikErrorsFromAPIErrors } from 'src/utilities/formikErrorUtils';
import { scrollErrorIntoView } from 'src/utilities/scrollErrorIntoView';

import { getAffinityEnforcement } from './utils';
import { getAffinityTypeEnforcement } from './utils';

import type { PlacementGroupsEditDrawerProps } from './types';
import type { UpdatePlacementGroupPayload } from '@linode/api-v4';
Expand Down Expand Up @@ -137,7 +137,7 @@ export const PlacementGroupsEditDrawer = (

<Typography mb={4}>
<strong>Affinity Enforcement: </strong>
{getAffinityEnforcement(placementGroup.is_strict)}
{getAffinityTypeEnforcement(placementGroup.is_strict)}
</Typography>
<Divider />
<form onSubmit={handleSubmit}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as React from 'react';
import { useHistory } from 'react-router-dom';

import { CircleProgress } from 'src/components/CircleProgress';
import { DebouncedSearchTextField } from 'src/components/DebouncedSearchTextField';
import { ErrorState } from 'src/components/ErrorState/ErrorState';
import { Hidden } from 'src/components/Hidden';
import { IconButton } from 'src/components/IconButton';
Expand All @@ -14,8 +15,8 @@ import { TableBody } from 'src/components/TableBody';
import { TableCell } from 'src/components/TableCell';
import { TableHead } from 'src/components/TableHead';
import { TableRow } from 'src/components/TableRow';
import { TableRowEmpty } from 'src/components/TableRowEmpty/TableRowEmpty';
import { TableSortCell } from 'src/components/TableSortCell/TableSortCell';
import { TextField } from 'src/components/TextField';
import { getRestrictedResourceText } from 'src/features/Account/utils';
import { useOrder } from 'src/hooks/useOrder';
import { usePagination } from 'src/hooks/usePagination';
Expand Down Expand Up @@ -57,13 +58,16 @@ export const PlacementGroupsLanding = React.memo(() => {
filter['label'] = { '+contains': query };
}

const params = {
page: pagination.page,
page_size: pagination.pageSize,
};

const { data: placementGroups, error, isLoading } = usePlacementGroupsQuery(
params,
const {
data: placementGroups,
error,
isFetching,
isLoading,
} = usePlacementGroupsQuery(
{
page: pagination.page,
page_size: pagination.pageSize,
},
filter
);

Expand Down Expand Up @@ -101,7 +105,7 @@ export const PlacementGroupsLanding = React.memo(() => {
return <CircleProgress />;
}

if (placementGroups?.results === 0) {
if (placementGroups?.results === 0 && query === '') {
return (
<>
<PlacementGroupsLandingEmptyState
Expand Down Expand Up @@ -146,21 +150,26 @@ export const PlacementGroupsLanding = React.memo(() => {
onButtonClick={handleCreatePlacementGroup}
title="Placement Groups"
/>
<TextField
<DebouncedSearchTextField
InputProps={{
endAdornment: query && (
<InputAdornment position="end">
<IconButton
aria-label="Clear"
onClick={() => setQuery('')}
size="small"
sx={{ padding: 'unset' }}
>
<CloseIcon sx={{ color: '#aaa !important' }} />
</IconButton>
{isFetching ? (
<CircleProgress mini />
) : (
<IconButton
aria-label="Clear"
onClick={() => setQuery('')}
size="small"
sx={{ padding: 'unset' }}
>
<CloseIcon sx={{ color: '#aaa !important' }} />
</IconButton>
)}
</InputAdornment>
),
}}
debounceTime={250}
hideLabel
label="Filter"
onChange={(e) => setQuery(e.target.value)}
Expand All @@ -176,10 +185,29 @@ export const PlacementGroupsLanding = React.memo(() => {
direction={order}
handleClick={handleOrderChange}
label="label"
sx={{ width: '40%' }}
sx={{ width: '20%' }}
>
Label
</TableSortCell>
<TableSortCell
active={orderBy === 'affinity_type'}
direction={order}
handleClick={handleOrderChange}
label="affinity_type"
>
Affinity Type
</TableSortCell>
<Hidden smDown>
<TableSortCell
active={orderBy === 'is_strict'}
direction={order}
handleClick={handleOrderChange}
label="is_strict"
sx={{ width: '20%' }}
>
Affinity Type Enforcement
</TableSortCell>
</Hidden>
<TableCell>Linodes</TableCell>
<Hidden smDown>
<TableSortCell
Expand All @@ -195,6 +223,7 @@ export const PlacementGroupsLanding = React.memo(() => {
</TableRow>
</TableHead>
<TableBody>
{placementGroups?.data.length === 0 && <TableRowEmpty colSpan={4} />}
{placementGroups?.data.map((placementGroup) => (
<PlacementGroupsRow
handleDeletePlacementGroup={() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ describe('PlacementGroupsLanding', () => {
);

expect(getByTestId('link-to-placement-group-1')).toHaveTextContent(
'group 1 (Anti-affinity)'
'group 1'
);
expect(getByText('Non-compliant')).toBeInTheDocument();
expect(getByTestId('placement-group-1-assigned-linodes')).toHaveTextContent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { TextTooltip } from 'src/components/TextTooltip';
import { Typography } from 'src/components/Typography';
import { usePlacementGroupData } from 'src/hooks/usePlacementGroupsData';

import { getAffinityTypeEnforcement } from '../utils';
import { StyledWarningIcon } from './PlacementGroupsRow.styles';

import type { PlacementGroup } from '@linode/api-v4';
Expand All @@ -31,7 +32,13 @@ export const PlacementGroupsRow = React.memo(
handleEditPlacementGroup,
placementGroup,
}: PlacementGroupsRowProps) => {
const { affinity_type, id, is_compliant, label } = placementGroup;
const {
affinity_type,
id,
is_compliant,
is_strict,
label,
} = placementGroup;
const { assignedLinodes, linodesCount, region } = usePlacementGroupData({
placementGroup,
});
Expand All @@ -57,7 +64,7 @@ export const PlacementGroupsRow = React.memo(
style={{ marginRight: 8 }}
to={`/placement-groups/${id}`}
>
{label} ({AFFINITY_TYPES[affinity_type]})
{label}
</Link>
{!is_compliant && (
<Typography component="span" sx={{ whiteSpace: 'nowrap' }}>
Expand All @@ -66,18 +73,26 @@ export const PlacementGroupsRow = React.memo(
</Typography>
)}
</TableCell>
<TableCell>{AFFINITY_TYPES[affinity_type]}</TableCell>
<Hidden smDown>
<TableCell>{getAffinityTypeEnforcement(is_strict)}</TableCell>
</Hidden>
<TableCell data-testid={`placement-group-${id}-assigned-linodes`}>
<TextTooltip
tooltipText={
<List>
{assignedLinodes?.map((linode, idx) => (
<ListItem key={`pg-linode-${idx}`}>{linode.label}</ListItem>
))}
</List>
}
displayText={`${linodesCount}`}
minWidth={200}
/>
{assignedLinodes?.length === 0 ? (
'0'
) : (
<TextTooltip
tooltipText={
<List>
{assignedLinodes?.map((linode, idx) => (
<ListItem key={`pg-linode-${idx}`}>{linode.label}</ListItem>
))}
</List>
}
displayText={`${linodesCount}`}
minWidth={200}
/>
)}
&nbsp; of {region?.maximum_vms_per_pg}
</TableCell>
<Hidden smDown>
Expand Down
6 changes: 3 additions & 3 deletions packages/manager/src/features/PlacementGroups/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { placementGroupFactory, regionFactory } from 'src/factories';

import {
affinityTypeOptions,
getAffinityEnforcement,
getAffinityTypeEnforcement,
getLinodesFromAllPlacementGroups,
getPlacementGroupLinodeCount,
hasPlacementGroupReachedCapacity,
Expand Down Expand Up @@ -109,11 +109,11 @@ describe('getLinodesFromAllPlacementGroups', () => {

describe('getAffinityEnforcement', () => {
it('returns "Strict" if `is_strict` is true', () => {
expect(getAffinityEnforcement(true)).toBe('Strict');
expect(getAffinityTypeEnforcement(true)).toBe('Strict');
});

it('returns "Flexible" if `is_strict` is false', () => {
expect(getAffinityEnforcement(false)).toBe('Flexible');
expect(getAffinityTypeEnforcement(false)).toBe('Flexible');
});
});

Expand Down
2 changes: 1 addition & 1 deletion packages/manager/src/features/PlacementGroups/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type {
/**
* Helper to get the affinity enforcement readable string.
*/
export const getAffinityEnforcement = (
export const getAffinityTypeEnforcement = (
is_strict: boolean
): AffinityEnforcement => {
return is_strict ? 'Strict' : 'Flexible';
Expand Down

0 comments on commit 0d6fda4

Please sign in to comment.