Skip to content

Commit

Permalink
Change "rename" nomenclature
Browse files Browse the repository at this point in the history
  • Loading branch information
abailly-akamai committed Feb 16, 2024
1 parent 42137a0 commit 492ebb4
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 62 deletions.
14 changes: 7 additions & 7 deletions packages/api-v4/src/placement-groups/placement-groups.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
createPlacementGroupSchema,
renamePlacementGroupSchema,
updatePlacementGroupSchema,
} from '@linode/validation';
import { API_ROOT } from '../constants';

Expand All @@ -17,7 +17,7 @@ import type {
CreatePlacementGroupPayload,
PlacementGroup,
UnassignLinodesFromPlacementGroupPayload,
RenamePlacementGroupPayload,
UpdatePlacementGroupPayload,
} from './types';

/**
Expand Down Expand Up @@ -63,23 +63,23 @@ export const createPlacementGroup = (data: CreatePlacementGroupPayload) =>
);

/**
* renamePlacementGroup
* updatePlacementGroup
*
* Renames a Placement Group (updates label).
* Updates a Placement Group (updates label).
*
* @param placementGroupId { number } The id of the Placement Group to be updated.
* @param data { PlacementGroup } The data for the Placement Group.
*/
export const renamePlacementGroup = (
export const updatePlacementGroup = (
placementGroupId: number,
data: RenamePlacementGroupPayload
data: UpdatePlacementGroupPayload
) =>
Request<PlacementGroup>(
setURL(
`${API_ROOT}/placement/groups/${encodeURIComponent(placementGroupId)}`
),
setMethod('PUT'),
setData(data, renamePlacementGroupSchema)
setData(data, updatePlacementGroupSchema)
);

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/api-v4/src/placement-groups/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export type CreatePlacementGroupPayload = Pick<
'label' | 'affinity_type' | 'region'
> & { strict: boolean };

export type RenamePlacementGroupPayload = Pick<PlacementGroup, 'label'>;
export type UpdatePlacementGroupPayload = Pick<PlacementGroup, 'label'>;

/**
* Since the API expects an array of ONE linode id, we'll use a tuple here.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const PlacementGroupsCreateDrawer = (
const {
numberOfPlacementGroupsCreated,
onClose,
onPlacementGroupCreated,
onPlacementGroupCreate,
open,
selectedRegionId,
} = props;
Expand Down Expand Up @@ -82,8 +82,8 @@ export const PlacementGroupsCreateDrawer = (
}
);

if (onPlacementGroupCreated) {
onPlacementGroupCreated(response);
if (onPlacementGroupCreate) {
onPlacementGroupCreate(response);
}
onClose();
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import type { FormikProps } from 'formik';
interface Props {
formik: FormikProps<PlacementGroupDrawerFormikProps>;
maxNumberOfPlacementGroups?: number;
mode: 'create' | 'rename';
mode: 'create' | 'update';
numberOfPlacementGroupsCreated?: number;
onClose: () => void;
open: boolean;
Expand Down Expand Up @@ -65,7 +65,7 @@ export const PlacementGroupsDrawerContent = (props: Props) => {
}, [isSubmitting]);

const generalError = status?.generalError;
const isRenameDrawer = mode === 'rename';
const isEditDrawer = mode === 'update';

return (
<Grid>
Expand All @@ -90,7 +90,7 @@ export const PlacementGroupsDrawerContent = (props: Props) => {
setFieldValue('region', selection);
}}
currentCapability="Linodes" // TODO VM_Placement: change to Placement Groups when available
disabled={isRenameDrawer || Boolean(selectedRegionId)}
disabled={isEditDrawer || Boolean(selectedRegionId)}
errorText={errors.region}
regions={regions ?? []}
selectedId={selectedRegionId ?? values.region}
Expand All @@ -104,7 +104,7 @@ export const PlacementGroupsDrawerContent = (props: Props) => {
(option) => option.value === values.affinity_type
) ?? null
}
disabled={isRenameDrawer}
disabled={isEditDrawer}
errorText={errors.affinity_type}
label="Affinity Type"
options={affinityTypeOptions}
Expand All @@ -116,12 +116,12 @@ export const PlacementGroupsDrawerContent = (props: Props) => {
disabled:
// TODO VM_Placement: we may want to move this logic to the create button in the landing page
// We just need to wait to wait to see how we're going to get the max number of PGs (account/region)
!isRenameDrawer &&
!isEditDrawer &&
numberOfPlacementGroupsCreated &&
maxNumberOfPlacementGroups
? numberOfPlacementGroupsCreated >= maxNumberOfPlacementGroups
: false,
label: `${isRenameDrawer ? 'Rename' : 'Create'} Placement Group`,
label: `${isEditDrawer ? 'Edit' : 'Create'} Placement Group`,
loading: isSubmitting,
tooltipText: MAX_NUMBER_OF_LINODES_IN_PLACEMENT_GROUP_MESSAGE,
type: 'submit',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ import * as React from 'react';
import { placementGroupFactory } from 'src/factories/placementGroups';
import { renderWithTheme } from 'src/utilities/testHelpers';

import { PlacementGroupsRenameDrawer } from './PlacementGroupsRenameDrawer';
import { PlacementGroupsEditDrawer } from './PlacementGroupsEditDrawer';

describe('PlacementGroupsCreateDrawer', () => {
it('should render, have the proper fields populated with PG values, and have uneditable fields disabled', () => {
const { getByLabelText } = renderWithTheme(
<PlacementGroupsRenameDrawer
<PlacementGroupsEditDrawer
selectedPlacementGroup={placementGroupFactory.build({
affinity_type: 'anti_affinity',
label: 'PG-1',
region: 'us-east',
})}
numberOfPlacementGroupsCreated={0}
onClose={vi.fn()}
onPlacementGroupRenamed={vi.fn()}
onPlacementGroupEdit={vi.fn()}
open={true}
/>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { renamePlacementGroupSchema } from '@linode/validation';
import { updatePlacementGroupSchema } from '@linode/validation';
import { useFormik } from 'formik';
import { useSnackbar } from 'notistack';
import * as React from 'react';
Expand All @@ -19,18 +19,13 @@ import { PlacementGroupsDrawerContent } from './PlacementGroupsDrawerContent';

import type {
PlacementGroupDrawerFormikProps,
PlacementGroupsRenameDrawerProps,
PlacementGroupsEditDrawerProps,
} from './types';

export const PlacementGroupsRenameDrawer = (
props: PlacementGroupsRenameDrawerProps
export const PlacementGroupsEditDrawer = (
props: PlacementGroupsEditDrawerProps
) => {
const {
onClose,
onPlacementGroupRenamed,
open,
selectedPlacementGroup,
} = props;
const { onClose, onPlacementGroupEdit, open, selectedPlacementGroup } = props;
const queryClient = useQueryClient();
const { data: regions } = useRegionsQuery();
const { mutateAsync } = useMutatePlacementGroup(
Expand Down Expand Up @@ -76,14 +71,14 @@ export const PlacementGroupsRenameDrawer = (
queryClient.invalidateQueries([placementGroupQueryKey]);

enqueueSnackbar(
`Placement Group ${payload.label} successfully renamed`,
`Placement Group ${payload.label} successfully updated`,
{
variant: 'success',
}
);

if (onPlacementGroupRenamed) {
onPlacementGroupRenamed(response);
if (onPlacementGroupEdit) {
onPlacementGroupEdit(response);
}
onClose();
})
Expand All @@ -102,14 +97,14 @@ export const PlacementGroupsRenameDrawer = (
},
validateOnBlur: false,
validateOnChange: hasFormBeenSubmitted,
validationSchema: renamePlacementGroupSchema,
validationSchema: updatePlacementGroupSchema,
});

return (
<Drawer
onClose={onClose}
open={open}
title={`Rename Placement Group ${selectedPlacementGroup?.label ?? ''}`}
title={`Edit Placement Group ${selectedPlacementGroup?.label ?? ''}`}
>
<PlacementGroupsDrawerContent
formik={{
Expand All @@ -124,7 +119,7 @@ export const PlacementGroupsRenameDrawer = (
values,
...rest,
}}
mode="rename"
mode="update"
onClose={onClose}
open={open}
regions={regions ?? []}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { getAPIErrorOrDefault } from 'src/utilities/errorUtils';

import { PlacementGroupsCreateDrawer } from '../PlacementGroupsCreateDrawer';
import { PlacementGroupsDeleteModal } from '../PlacementGroupsDeleteModal';
import { PlacementGroupsRenameDrawer } from '../PlacementGroupsRenameDrawer';
import { PlacementGroupsEditDrawer } from '../PlacementGroupsEditDrawer';
import { PlacementGroupsLandingEmptyState } from './PlacementGroupsLandingEmptyState';
import { PlacementGroupsRow } from './PlacementGroupsRow';

Expand Down Expand Up @@ -69,9 +69,9 @@ export const PlacementGroupsLanding = React.memo(() => {
history.replace('/placement-groups/create');
};

const handleRenamePlacementGroup = (placementGroup: PlacementGroup) => {
const handleEditPlacementGroup = (placementGroup: PlacementGroup) => {
setSelectedPlacementGroup(placementGroup);
history.replace(`/placement-groups/rename/${placementGroup.id}`);
history.replace(`/placement-groups/edit/${placementGroup.id}`);
};

const handleDeletePlacementGroup = (placementGroup: PlacementGroup) => {
Expand All @@ -84,8 +84,8 @@ export const PlacementGroupsLanding = React.memo(() => {
};

const isPlacementGroupCreateDrawerOpen = location.pathname.endsWith('create');
const isPlacementGroupRenameDrawerOpen = location.pathname.includes('rename');
const isPlacementGroupDeleteModalOpen = location.pathname.includes('delete');
const isPlacementGroupEditDrawerOpen = location.pathname.includes('edit');

if (isLoading) {
return <CircleProgress />;
Expand Down Expand Up @@ -180,8 +180,8 @@ export const PlacementGroupsLanding = React.memo(() => {
handleDeletePlacementGroup={() =>
handleDeletePlacementGroup(placementGroup)
}
handleRenamePlacementGroup={() =>
handleRenamePlacementGroup(placementGroup)
handleEditPlacementGroup={() =>
handleEditPlacementGroup(placementGroup)
}
key={`pg-${placementGroup.id}`}
placementGroup={placementGroup}
Expand All @@ -202,10 +202,10 @@ export const PlacementGroupsLanding = React.memo(() => {
onClose={onClosePlacementGroupDrawer}
open={isPlacementGroupCreateDrawerOpen}
/>
<PlacementGroupsRenameDrawer
<PlacementGroupsEditDrawer
numberOfPlacementGroupsCreated={placementGroups?.results ?? 0}
onClose={onClosePlacementGroupDrawer}
open={isPlacementGroupRenameDrawerOpen}
open={isPlacementGroupEditDrawerOpen}
selectedPlacementGroup={selectedPlacementGroup}
/>
<PlacementGroupsDeleteModal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ vi.mock('src/queries/regions', async () => {
});

const handleDeletePlacementGroupMock = vi.fn();
const handleRenamePlacementGroupMock = vi.fn();
const handleEditPlacementGroupMock = vi.fn();

describe('PlacementGroupsLanding', () => {
it('renders the columns with proper data', () => {
Expand Down Expand Up @@ -76,7 +76,7 @@ describe('PlacementGroupsLanding', () => {
region: 'us-east',
})}
handleDeletePlacementGroup={handleDeletePlacementGroupMock}
handleRenamePlacementGroup={handleRenamePlacementGroupMock}
handleEditPlacementGroup={handleEditPlacementGroupMock}
/>
)
);
Expand All @@ -89,7 +89,7 @@ describe('PlacementGroupsLanding', () => {
'1'
);
expect(getByText('Newark, NJ')).toBeInTheDocument();
expect(getByRole('button', { name: 'Rename' })).toBeInTheDocument();
expect(getByRole('button', { name: 'Edit' })).toBeInTheDocument();
expect(getByRole('button', { name: 'Delete' })).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ import type { Action } from 'src/components/ActionMenu/ActionMenu';

interface PlacementGroupsRowProps {
handleDeletePlacementGroup: () => void;
handleRenamePlacementGroup: () => void;
handleEditPlacementGroup: () => void;
placementGroup: PlacementGroup;
}

export const PlacementGroupsRow = React.memo(
({
handleDeletePlacementGroup,
handleRenamePlacementGroup,
handleEditPlacementGroup,
placementGroup,
}: PlacementGroupsRowProps) => {
const { affinity_type, id, is_compliant, label } = placementGroup;
Expand All @@ -35,8 +35,8 @@ export const PlacementGroupsRow = React.memo(
});
const actions: Action[] = [
{
onClick: handleRenamePlacementGroup,
title: 'Rename',
onClick: handleEditPlacementGroup,
title: 'Edit',
},
{
onClick: handleDeletePlacementGroup,
Expand Down
2 changes: 1 addition & 1 deletion packages/manager/src/features/PlacementGroups/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const PlacementGroups = () => {
<Route
component={PlacementGroupsLanding}
exact
path={`${path}/rename/:id`}
path={`${path}/edit/:id`}
/>
<Route
component={PlacementGroupsLanding}
Expand Down
10 changes: 5 additions & 5 deletions packages/manager/src/features/PlacementGroups/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
CreatePlacementGroupPayload,
PlacementGroup,
RenamePlacementGroupPayload,
UpdatePlacementGroupPayload,
} from '@linode/api-v4';

export type PlacementGroupsDrawerPropsBase = {
Expand All @@ -11,16 +11,16 @@ export type PlacementGroupsDrawerPropsBase = {
};

export type PlacementGroupsCreateDrawerProps = PlacementGroupsDrawerPropsBase & {
onPlacementGroupCreated?: (placementGroup: PlacementGroup) => void;
onPlacementGroupCreate?: (placementGroup: PlacementGroup) => void;
selectedRegionId?: string;
};

export type PlacementGroupsRenameDrawerProps = PlacementGroupsDrawerPropsBase & {
onPlacementGroupRenamed?: (placementGroup: PlacementGroup) => void;
export type PlacementGroupsEditDrawerProps = PlacementGroupsDrawerPropsBase & {
onPlacementGroupEdit?: (placementGroup: PlacementGroup) => void;
selectedPlacementGroup: PlacementGroup | undefined;
};

export type PlacementGroupDrawerFormikProps = RenamePlacementGroupPayload &
export type PlacementGroupDrawerFormikProps = UpdatePlacementGroupPayload &
CreatePlacementGroupPayload;

export type PlacementGroupsAssignLinodesDrawerProps = PlacementGroupsDrawerPropsBase & {
Expand Down
Loading

0 comments on commit 492ebb4

Please sign in to comment.