Skip to content

Commit

Permalink
Better method name
Browse files Browse the repository at this point in the history
This method does more than show the modal.
  • Loading branch information
scottybollinger committed Dec 3, 2021
1 parent c6c06f3 commit f8e112c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ describe('ApiKeysLogic', () => {
const tokenName = 'my-token';

it('should set deleteModalVisible to true and set apiTokenNameToDelete', () => {
ApiKeysLogic.actions.showDeleteModal(tokenName);
ApiKeysLogic.actions.stageTokenNameForDeletion(tokenName);

expect(ApiKeysLogic.values).toEqual({
...values,
Expand Down Expand Up @@ -445,7 +445,7 @@ describe('ApiKeysLogic', () => {
jest.spyOn(ApiKeysLogic.actions, 'fetchApiKeys').mockImplementationOnce(() => {});
http.delete.mockReturnValue(Promise.resolve());

ApiKeysLogic.actions.showDeleteModal(tokenName);
ApiKeysLogic.actions.stageTokenNameForDeletion(tokenName);
ApiKeysLogic.actions.deleteApiKey();
expect(http.delete).toHaveBeenCalledWith(
`/internal/workplace_search/api_keys/${tokenName}`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ interface ApiKeysLogicActions {
onPaginate(newPageIndex: number): { newPageIndex: number };
deleteApiKey(): void;
onApiFormSubmit(): void;
showDeleteModal(tokenName: string): string;
stageTokenNameForDeletion(tokenName: string): string;
hideDeleteModal(): void;
}

Expand Down Expand Up @@ -76,7 +76,7 @@ export const ApiKeysLogic = kea<MakeLogicType<ApiKeysLogicValues, ApiKeysLogicAc
fetchApiKeys: true,
onPaginate: (newPageIndex) => ({ newPageIndex }),
deleteApiKey: true,
showDeleteModal: (tokenName) => tokenName,
stageTokenNameForDeletion: (tokenName) => tokenName,
hideDeleteModal: true,
onApiFormSubmit: () => null,
}),
Expand Down Expand Up @@ -134,14 +134,14 @@ export const ApiKeysLogic = kea<MakeLogicType<ApiKeysLogicValues, ApiKeysLogicAc
deleteModalVisible: [
false,
{
showDeleteModal: () => true,
stageTokenNameForDeletion: () => true,
hideDeleteModal: () => false,
},
],
apiTokenNameToDelete: [
'',
{
showDeleteModal: (_, tokenName) => tokenName,
stageTokenNameForDeletion: (_, tokenName) => tokenName,
hideDeleteModal: () => '',
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { ApiKey } from './api_key';
import { ApiKeysList } from './api_keys_list';

describe('ApiKeysList', () => {
const showDeleteModal = jest.fn();
const stageTokenNameForDeletion = jest.fn();
const hideDeleteModal = jest.fn();
const deleteApiKey = jest.fn();
const onPaginate = jest.fn();
Expand All @@ -42,7 +42,7 @@ describe('ApiKeysList', () => {

beforeEach(() => {
setMockValues(values);
setMockActions({ deleteApiKey, onPaginate, showDeleteModal, hideDeleteModal });
setMockActions({ deleteApiKey, onPaginate, stageTokenNameForDeletion, hideDeleteModal });
});

it('renders', () => {
Expand Down Expand Up @@ -182,11 +182,11 @@ describe('ApiKeysList', () => {
name: 'some-name',
};

it('calls showDeleteModal when clicked', () => {
it('calls stageTokenNameForDeletion when clicked', () => {
const action = columns[2].actions[0];
action.onClick(token);

expect(showDeleteModal).toHaveBeenCalledWith('some-name');
expect(stageTokenNameForDeletion).toHaveBeenCalledWith('some-name');
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ import {
import { ApiKey } from './api_key';

export const ApiKeysList: React.FC = () => {
const { deleteApiKey, onPaginate, showDeleteModal, hideDeleteModal } = useActions(ApiKeysLogic);
const { deleteApiKey, onPaginate, stageTokenNameForDeletion, hideDeleteModal } =
useActions(ApiKeysLogic);
const { apiTokens, meta, dataLoading, deleteModalVisible } = useValues(ApiKeysLogic);

const deleteModal = (
Expand Down Expand Up @@ -87,7 +88,7 @@ export const ApiKeysList: React.FC = () => {
type: 'icon',
icon: 'trash',
color: 'danger',
onClick: (token: ApiToken) => showDeleteModal(token.name),
onClick: (token: ApiToken) => stageTokenNameForDeletion(token.name),
},
],
},
Expand Down

0 comments on commit f8e112c

Please sign in to comment.