Skip to content

Commit

Permalink
Make type private
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Jun 26, 2024
1 parent abc4508 commit b86375d
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 34 deletions.
9 changes: 5 additions & 4 deletions packages/dataviews/src/bulk-actions-toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ import { useRegistry } from '@wordpress/data';
* Internal dependencies
*/
import { ActionWithModal } from './item-actions';
import type { Action, AnyItem, setSelection } from './types';
import type { Action, AnyItem } from './types';
import type { ActionTriggerProps } from './item-actions';
import type { SetSelection } from './private-types';

interface ActionButtonProps< Item extends AnyItem > {
action: Action< Item >;
Expand All @@ -32,14 +33,14 @@ interface ToolbarContentProps< Item extends AnyItem > {
selection: string[];
actionsToShow: Action< Item >[];
selectedItems: Item[];
onSelectionChange: setSelection;
onSelectionChange: SetSelection;
}

interface BulkActionsToolbarProps< Item extends AnyItem > {
data: Item[];
selection: string[];
actions: Action< Item >[];
onSelectionChange: setSelection;
onSelectionChange: SetSelection;
getItemId: ( item: Item ) => string;
}

Expand Down Expand Up @@ -131,7 +132,7 @@ function renderToolbarContent< Item extends AnyItem >(
selectedItems: Item[],
actionInProgress: string | null,
setActionInProgress: ( actionId: string | null ) => void,
onSelectionChange: setSelection
onSelectionChange: SetSelection
) {
return (
<>
Expand Down
5 changes: 3 additions & 2 deletions packages/dataviews/src/bulk-actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import { useRegistry } from '@wordpress/data';
* Internal dependencies
*/
import { unlock } from './lock-unlock';
import type { Action, ActionModal, AnyItem, setSelection } from './types';
import type { Action, ActionModal, AnyItem } from './types';
import type { SetSelection } from './private-types';

const {
DropdownMenuV2: DropdownMenu,
Expand Down Expand Up @@ -46,7 +47,7 @@ interface BulkActionsProps< Item extends AnyItem > {
data: Item[];
actions: Action< Item >[];
selection: string[];
onSelectionChange: setSelection;
onSelectionChange: SetSelection;
getItemId: ( item: Item ) => string;
}

Expand Down
16 changes: 4 additions & 12 deletions packages/dataviews/src/dataviews.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,8 @@ import { VIEW_LAYOUTS } from './layouts';
import BulkActions from './bulk-actions';
import { normalizeFields } from './normalize-fields';
import BulkActionsToolbar from './bulk-actions-toolbar';
import type {
setSelection,
Action,
AnyItem,
Field,
View,
ViewBaseProps,
} from './types';
import type { Action, AnyItem, Field, View, ViewBaseProps } from './types';
import type { SetSelection, SelectionOrUpdater } from './private-types';

interface DataViewsProps< Item extends AnyItem > {
view: View;
Expand All @@ -46,7 +40,7 @@ interface DataViewsProps< Item extends AnyItem > {
};
supportedLayouts: string[];
selection?: string[];
setSelection?: setSelection;
setSelection?: SetSelection;
onSelectionChange?: ( items: Item[] ) => void;
}

Expand Down Expand Up @@ -94,9 +88,7 @@ export default function DataViews< Item extends AnyItem >( {
: setSelectionProperty;
const [ openedFilter, setOpenedFilter ] = useState< string | null >( null );

function setSelectionWithChange(
value: string[] | ( ( prevValue: string[] ) => string[] )
) {
function setSelectionWithChange( value: SelectionOrUpdater ) {
const newValue =
typeof value === 'function' ? value( selection ) : value;
onSelectionChange(
Expand Down
2 changes: 2 additions & 0 deletions packages/dataviews/src/private-types.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export type SelectionOrUpdater = string[] | ( ( prev: string[] ) => string[] );
export type SetSelection = ( selection: SelectionOrUpdater ) => void;
5 changes: 3 additions & 2 deletions packages/dataviews/src/single-selection-checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import { CheckboxControl } from '@wordpress/components';
/**
* Internal dependencies
*/
import type { Field, AnyItem, setSelection } from './types';
import type { Field, AnyItem } from './types';
import type { SetSelection } from './private-types';

interface SingleSelectionCheckboxProps< Item extends AnyItem > {
selection: string[];
onSelectionChange: setSelection;
onSelectionChange: SetSelection;
item: Item;
getItemId: ( item: Item ) => string;
primaryField?: Field< Item >;
Expand Down
9 changes: 6 additions & 3 deletions packages/dataviews/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
/**
* External dependencies
*/
import type { ReactElement, ReactNode, Dispatch, SetStateAction } from 'react';
import type { ReactElement, ReactNode } from 'react';

export type setSelection = Dispatch< SetStateAction< string[] > >;
/**
* Internal dependencies
*/
import type { SetSelection } from './private-types';

export type SortDirection = 'asc' | 'desc';

Expand Down Expand Up @@ -378,7 +381,7 @@ export interface ViewBaseProps< Item extends AnyItem > {
getItemId: ( item: Item ) => string;
isLoading?: boolean;
onChangeView( view: View ): void;
onSelectionChange: setSelection;
onSelectionChange: SetSelection;
selection: string[];
setOpenedFilter: ( fieldId: string ) => void;
view: View;
Expand Down
11 changes: 3 additions & 8 deletions packages/dataviews/src/view-grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,12 @@ import { __ } from '@wordpress/i18n';
import ItemActions from './item-actions';
import SingleSelectionCheckbox from './single-selection-checkbox';
import { useHasAPossibleBulkAction } from './bulk-actions';
import type {
Action,
AnyItem,
NormalizedField,
ViewGridProps,
setSelection,
} from './types';
import type { Action, AnyItem, NormalizedField, ViewGridProps } from './types';
import type { SetSelection } from './private-types';

interface GridItemProps< Item extends AnyItem > {
selection: string[];
onSelectionChange: setSelection;
onSelectionChange: SetSelection;
getItemId: ( item: Item ) => string;
item: Item;
actions: Action< Item >[];
Expand Down
6 changes: 3 additions & 3 deletions packages/dataviews/src/view-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ import type {
SortDirection,
ViewTable as ViewTableType,
ViewTableProps,
setSelection,
} from './types';
import type { SetSelection } from './private-types';

const {
DropdownMenuV2: DropdownMenu,
Expand All @@ -73,7 +73,7 @@ interface HeaderMenuProps< Item extends AnyItem > {

interface BulkSelectionCheckboxProps< Item extends AnyItem > {
selection: string[];
onSelectionChange: setSelection;
onSelectionChange: SetSelection;
data: Item[];
actions: Action< Item >[];
getItemId: ( item: Item ) => string;
Expand All @@ -88,7 +88,7 @@ interface TableRowProps< Item extends AnyItem > {
primaryField?: NormalizedField< Item >;
selection: string[];
getItemId: ( item: Item ) => string;
onSelectionChange: setSelection;
onSelectionChange: SetSelection;
}

function WithDropDownMenuSeparators( { children }: { children: ReactNode } ) {
Expand Down

0 comments on commit b86375d

Please sign in to comment.