Skip to content

Commit ed490b5

Browse files
committed
Removes deprecated hook and replaces it with the current hook
1 parent 4fbc770 commit ed490b5

File tree

43 files changed

+235
-232
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+235
-232
lines changed

framework/PageDialogs/BulkActionDialog.tsx

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { usePaged } from '../PageTable/useTableItems';
1919
import { pfDanger, pfInfo, pfSuccess } from '../components/pfcolors';
2020
import { useAbortController } from '../hooks/useAbortController';
2121
import { useFrameworkTranslations } from '../useFrameworkTranslations';
22-
import { usePageDialog } from './PageDialog';
22+
import { usePageDialogs } from './PageDialog';
2323

2424
export interface BulkActionDialogProps<T extends object> {
2525
/** The title of the model.
@@ -99,7 +99,7 @@ export function BulkActionDialog<T extends object>(props: BulkActionDialogProps<
9999
const [error, setError] = useState('');
100100
const [statuses, setStatuses] = useState<Record<string | number, string | null | undefined>>();
101101
const abortController = useAbortController();
102-
const [_, setDialog] = usePageDialog();
102+
const { popDialog } = usePageDialogs();
103103

104104
const onCancelClicked = useCallback(() => {
105105
setCanceled(true);
@@ -118,9 +118,9 @@ export function BulkActionDialog<T extends object>(props: BulkActionDialogProps<
118118
}, [abortController, items, keyFn, t]);
119119

120120
const onCloseClicked = useCallback(() => {
121-
setDialog(undefined);
121+
popDialog();
122122
onClose?.();
123-
}, [onClose, setDialog]);
123+
}, [onClose, popDialog]);
124124

125125
useEffect(() => {
126126
async function process() {
@@ -260,7 +260,6 @@ export function BulkActionDialog<T extends object>(props: BulkActionDialogProps<
260260
},
261261
]}
262262
keyFn={keyFn}
263-
// pagination={pagination}
264263
compact
265264
errorStateTitle=""
266265
emptyStateTitle={t('No items')}
@@ -310,24 +309,24 @@ export function BulkActionDialog<T extends object>(props: BulkActionDialogProps<
310309
export function useBulkActionDialog<T extends object>(
311310
defaultErrorAdapter: ErrorAdapter = genericErrorAdapter
312311
) {
313-
const [_, setDialog] = usePageDialog();
312+
const { pushDialog, popDialog } = usePageDialogs();
314313
const [props, setProps] = useState<BulkActionDialogProps<T>>();
315314
useEffect(() => {
316315
if (props) {
317316
const onCloseHandler = () => {
318317
setProps(undefined);
319318
props.onClose?.();
320319
};
321-
setDialog(
320+
pushDialog(
322321
<BulkActionDialog<T>
323322
{...props}
324323
errorAdapter={props.errorAdapter ?? defaultErrorAdapter}
325324
onClose={onCloseHandler}
326325
/>
327326
);
328327
} else {
329-
setDialog(undefined);
328+
popDialog();
330329
}
331-
}, [props, setDialog, defaultErrorAdapter]);
330+
}, [props, popDialog, pushDialog, defaultErrorAdapter]);
332331
return setProps;
333332
}

framework/PageDialogs/BulkConfirmationDialog.tsx

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { usePaged } from '../PageTable/useTableItems';
1919
import { useFrameworkTranslations } from '../useFrameworkTranslations';
2020
import { compareStrings } from '../utils/compare';
2121
import { BulkActionDialogProps, useBulkActionDialog } from './BulkActionDialog';
22-
import { usePageDialog } from './PageDialog';
22+
import { usePageDialogs } from './PageDialog';
2323

2424
const ModalBodyDiv = styled.div`
2525
display: flex;
@@ -95,12 +95,12 @@ function BulkConfirmationDialog<T extends object>(props: BulkConfirmationDialog<
9595
actionButtonText,
9696
isDanger,
9797
} = props;
98-
const [_, setDialog] = usePageDialog();
98+
const { popDialog } = usePageDialogs();
9999
const [translations] = useFrameworkTranslations();
100100
const onCloseClicked = useCallback(() => {
101-
setDialog(undefined);
101+
popDialog();
102102
onClose?.();
103-
}, [onClose, setDialog]);
103+
}, [onClose, popDialog]);
104104

105105
// Non-actionable rows appear first
106106
const sortedItems = useMemo<T[]>(() => {
@@ -198,7 +198,6 @@ function BulkConfirmationDialog<T extends object>(props: BulkConfirmationDialog<
198198
itemCount={items.length}
199199
tableColumns={modalColumns}
200200
keyFn={keyFn}
201-
// pagination={pagination}
202201
compact
203202
errorStateTitle="Error"
204203
emptyStateTitle="No items"
@@ -225,19 +224,19 @@ function BulkConfirmationDialog<T extends object>(props: BulkConfirmationDialog<
225224
}
226225

227226
function useBulkConfirmationDialog<T extends object>() {
228-
const [_, setDialog] = usePageDialog();
227+
const { popDialog, pushDialog } = usePageDialogs();
229228
const [props, setProps] = useState<BulkConfirmationDialog<T>>();
230229
useEffect(() => {
231230
if (props) {
232231
const onCloseHandler = () => {
233232
setProps(undefined);
234233
props.onClose?.();
235234
};
236-
setDialog(<BulkConfirmationDialog<T> {...props} onClose={onCloseHandler} />);
235+
pushDialog(<BulkConfirmationDialog<T> {...props} onClose={onCloseHandler} />);
237236
} else {
238-
setDialog(undefined);
237+
popDialog();
239238
}
240-
}, [props, setDialog]);
239+
}, [props, popDialog, pushDialog]);
241240
return setProps;
242241
}
243242

framework/PageDialogs/MultiSelectDialog.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { ISelected } from '../PageTable/useTableItems';
55
import { IToolbarFilter } from '../PageToolbar/PageToolbarFilter';
66
import { useFrameworkTranslations } from '../useFrameworkTranslations';
77
import { IView } from '../useView';
8-
import { usePageDialog } from './PageDialog';
8+
import { usePageDialogs } from './PageDialog';
99
import { PageMultiSelectList } from '../PageTable/PageMultiSelectList';
1010

1111
export type MultiSelectDialogProps<T extends object> = {
@@ -40,8 +40,8 @@ export function MultiSelectDialog<T extends object>(props: MultiSelectDialogProp
4040
maxSelections,
4141
allowZeroSelections,
4242
} = props;
43-
const [_, setDialog] = usePageDialog();
44-
let onClose = useCallback(() => setDialog(undefined), [setDialog]);
43+
const { popDialog } = usePageDialogs();
44+
let onClose = useCallback(() => popDialog(), [popDialog]);
4545
if (props.onClose) {
4646
onClose = props.onClose;
4747
}

framework/PageDialogs/PageDialog.tsx

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -34,26 +34,26 @@ export function usePageDialogs() {
3434
return useContext(PageDialogContext);
3535
}
3636

37-
/*
38-
* @deprecated Use usePageDialogs instead
39-
*/
40-
export function usePageDialog(): [
41-
dialog: ReactNode | undefined,
42-
setDialog: (dialog: ReactNode | undefined) => void,
43-
] {
44-
const { dialogs, clearDialogs, pushDialog } = usePageDialogs();
45-
const dialog = useMemo(
46-
() => (dialogs.length > 0 ? dialogs[dialogs.length - 1] : undefined),
47-
[dialogs]
48-
);
49-
const setDialog = useCallback(
50-
(dialog: ReactNode | undefined) => {
51-
clearDialogs();
52-
if (dialog !== undefined) {
53-
pushDialog(dialog);
54-
}
55-
},
56-
[clearDialogs, pushDialog]
57-
);
58-
return useMemo(() => [dialog, setDialog] as const, [dialog, setDialog]);
59-
}
37+
// /*
38+
// * @deprecated Use usePageDialogs instead
39+
// */
40+
// export function usePageDialog(): [
41+
// dialog: ReactNode | undefined,
42+
// setDialog: (dialog: ReactNode | undefined) => void,
43+
// ] {
44+
// const { dialogs, clearDialogs, pushDialog } = usePageDialogs();
45+
// const dialog = useMemo(
46+
// () => (dialogs.length > 0 ? dialogs[dialogs.length - 1] : undefined),
47+
// [dialogs]
48+
// );
49+
// const setDialog = useCallback(
50+
// (dialog: ReactNode | undefined) => {
51+
// clearDialogs();
52+
// if (dialog !== undefined) {
53+
// pushDialog(dialog);
54+
// }
55+
// },
56+
// [clearDialogs, pushDialog]
57+
// );
58+
// return useMemo(() => [dialog, setDialog] as const, [dialog, setDialog]);
59+
// }

framework/PageDialogs/SingleSelectDialog.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ import { ISelected } from '../PageTable/useTableItems';
66
import { IToolbarFilter } from '../PageToolbar/PageToolbarFilter';
77
import { useFrameworkTranslations } from '../useFrameworkTranslations';
88
import { IView } from '../useView';
9-
import { usePageDialog } from './PageDialog';
10-
9+
import { usePageDialogs } from './PageDialog';
1110
export type SingleSelectDialogProps<T extends object> = {
1211
title: string;
1312
view: IView & ISelected<T> & { itemCount?: number; pageItems: T[] | undefined };
@@ -23,8 +22,8 @@ export type SingleSelectDialogProps<T extends object> = {
2322

2423
export function SingleSelectDialog<T extends object>(props: SingleSelectDialogProps<T>) {
2524
const { title, view, tableColumns, toolbarFilters, confirmText, cancelText, onSelect } = props;
26-
const [_, setDialog] = usePageDialog();
27-
let onClose = useCallback(() => setDialog(undefined), [setDialog]);
25+
const { popDialog } = usePageDialogs();
26+
let onClose = useCallback(() => popDialog(), [popDialog]);
2827
if (props.onClose) {
2928
onClose = props.onClose;
3029
}

framework/PageDialogs/useSelectDialog.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { ISelected } from '../PageTable/useTableItems';
1717
import { IToolbarFilter } from '../PageToolbar/PageToolbarFilter';
1818
import { Collapse } from '../components/Collapse';
1919
import { IView } from '../useView';
20-
import { usePageDialog } from './PageDialog';
20+
import { usePageDialogs } from './PageDialog';
2121

2222
/**
2323
* @deprecated use SingleSelectDialog
@@ -47,10 +47,10 @@ export function useSelectDialog<
4747
setTitle(title ?? '');
4848
setOnSelect(() => onSelect);
4949
}, []);
50-
const [_, setDialog] = usePageDialog();
50+
const { pushDialog, popDialog } = usePageDialogs();
5151
useEffect(() => {
5252
if (onSelect !== undefined) {
53-
setDialog(
53+
pushDialog(
5454
<SelectDialog<T, TMultiple>
5555
title={title}
5656
open
@@ -67,15 +67,16 @@ export function useSelectDialog<
6767
/>
6868
);
6969
} else {
70-
setDialog(undefined);
70+
popDialog();
7171
view.unselectAll();
7272
}
7373
}, [
7474
cancel,
7575
confirm,
7676
onSelect,
7777
selected,
78-
setDialog,
78+
popDialog,
79+
pushDialog,
7980
tableColumns,
8081
title,
8182
toolbarFilters,

framework/components/useManagedItems.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { Button, Divider, Modal, ModalBoxBody, ModalVariant } from '@patternfly/react-core';
22
import { ReactNode, useCallback, useMemo, useState } from 'react';
33
import { useTranslation } from 'react-i18next';
4-
import { usePageDialog } from '../PageDialogs/PageDialog';
54
import { useSelected } from '../PageTable/useTableItems';
65
import { ReorderItems } from './ReorderItems';
6+
import { usePageDialogs } from '../PageDialogs/PageDialog';
77

88
interface IManageItemColumn<ItemT extends object> {
99
header: string;
@@ -61,7 +61,7 @@ export interface ManageItemsProps<ItemT extends object> {
6161
* - Display type
6262
*/
6363
export function useManageItems<ItemT extends object>(options: ManageItemsProps<ItemT>) {
64-
const [_, setDialog] = usePageDialog();
64+
const { pushDialog } = usePageDialogs();
6565
const [keyFn] = useState(() => options.keyFn);
6666
const [saveFn] = useState(() => options.saveFn);
6767
const [loadFn] = useState(() => options.loadFn);
@@ -137,7 +137,7 @@ export function useManageItems<ItemT extends object>(options: ManageItemsProps<I
137137
);
138138

139139
const openManageItems = () =>
140-
setDialog(
140+
pushDialog(
141141
<ManageItemsModal
142142
{...options}
143143
keyFn={keyFn}
@@ -159,8 +159,8 @@ export function ManageItemsModal<ItemT extends object>(
159159
const { t } = useTranslation();
160160
const { title, description, columns, onApplyChanges } = props;
161161
const [keyFn] = useState(() => props.keyFn);
162-
const [_, setDialog] = usePageDialog();
163-
const onClose = () => setDialog(undefined);
162+
const { popDialog } = usePageDialogs();
163+
const onClose = () => popDialog();
164164
const [items, setItems] = useState<ItemT[]>(() => props.items);
165165
const {
166166
selectedItems,
@@ -174,7 +174,7 @@ export function ManageItemsModal<ItemT extends object>(
174174

175175
const onApply = () => {
176176
onApplyChanges(items, selectedItems);
177-
setDialog(undefined);
177+
popDialog();
178178
};
179179

180180
return (

frontend/awx/access/common/DeleteRoleConfirmation.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Button, Modal, ModalVariant } from '@patternfly/react-core';
22
import { useCallback, useEffect, useState } from 'react';
33
import { useTranslation } from 'react-i18next';
4-
import { usePageDialog } from '../../../../framework';
4+
import { usePageDialogs } from '../../../../framework';
55
import { AccessRole, AwxUser } from '../../interfaces/User';
66

77
export interface DeleteRoleConfirmationProps {
@@ -20,13 +20,13 @@ export interface DeleteRoleConfirmationProps {
2020

2121
export function DeleteRoleConfirmation(props: DeleteRoleConfirmationProps) {
2222
const { title, role, user, onConfirm, onClose } = props;
23-
const [_, setDialog] = usePageDialog();
23+
const { popDialog } = usePageDialogs();
2424
const { t } = useTranslation();
2525
const sourceOfRole = () => (typeof role.team_id !== 'undefined' ? t(`team`) : t(`user`));
2626
const onCloseClicked = useCallback(() => {
27-
setDialog(undefined);
27+
popDialog();
2828
onClose?.();
29-
}, [onClose, setDialog]);
29+
}, [onClose, popDialog]);
3030

3131
return (
3232
<Modal
@@ -100,18 +100,18 @@ export function DeleteRoleConfirmation(props: DeleteRoleConfirmationProps) {
100100
* openDeleteRoleConfirmationDialog(...) // Pass DeleteRoleConfirmationProps
101101
*/
102102
export function useDeleteRoleConfirmationDialog() {
103-
const [_, setDialog] = usePageDialog();
103+
const { popDialog, pushDialog } = usePageDialogs();
104104
const [props, setProps] = useState<DeleteRoleConfirmationProps>();
105105
useEffect(() => {
106106
if (props) {
107107
const onCloseHandler = () => {
108108
setProps(undefined);
109109
props.onClose?.();
110110
};
111-
setDialog(<DeleteRoleConfirmation {...props} onClose={onCloseHandler} />);
111+
pushDialog(<DeleteRoleConfirmation {...props} onClose={onCloseHandler} />);
112112
} else {
113-
setDialog(undefined);
113+
popDialog();
114114
}
115-
}, [props, setDialog]);
115+
}, [props, pushDialog, popDialog]);
116116
return setProps;
117117
}

frontend/awx/access/credentials/hooks/useSelectCredential.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useCallback, useMemo } from 'react';
22
import { useTranslation } from 'react-i18next';
3-
import { IToolbarFilter, usePageDialog, useSelectDialog } from '../../../../../framework';
3+
import { IToolbarFilter, usePageDialogs, useSelectDialog } from '../../../../../framework';
44
import { SingleSelectDialog } from '../../../../../framework/PageDialogs/SingleSelectDialog';
55
import { awxAPI } from '../../../common/api/awx-utils';
66
import {
@@ -83,11 +83,11 @@ export function useSingleSelectCredential(
8383
title?: string,
8484
sourceType?: string
8585
) {
86-
const [_, setDialog] = usePageDialog();
86+
const { pushDialog } = usePageDialogs();
8787
const { t } = useTranslation();
8888
const openSelectCredential = useCallback(
8989
(onSelect: (credential: Credential) => void) => {
90-
setDialog(
90+
pushDialog(
9191
<SelectCredential
9292
title={title ? title : t('Select credential')}
9393
onSelect={onSelect}
@@ -96,7 +96,7 @@ export function useSingleSelectCredential(
9696
/>
9797
);
9898
},
99-
[credentialType, setDialog, t, title, sourceType]
99+
[credentialType, pushDialog, t, title, sourceType]
100100
);
101101
return openSelectCredential;
102102
}

0 commit comments

Comments
 (0)