Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DatViews/DataForm: reorganize folders #64378

Closed
wants to merge 9 commits into from
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import { closeSmall } from '@wordpress/icons';
/**
* Internal dependencies
*/
import { normalizeFields } from '../../normalize-fields';
import type { DataFormProps, NormalizedField, Field } from '../../types';
import { normalizeFields } from '../../../utils/normalize-fields';
import type { DataFormProps, NormalizedField, Field } from '../../../types';

interface FormFieldProps< Item > {
data: Item;
Expand All @@ -34,7 +34,7 @@ function DropdownHeader( {
} ) {
return (
<VStack
className="dataforms-layouts-panel__dropdown-header"
className="dataform-layouts-panel__dropdown-header"
spacing={ 4 }
>
<HStack alignment="center">
Expand All @@ -44,7 +44,7 @@ function DropdownHeader( {
<Spacer />
{ onClose && (
<Button
className="dataforms-layouts-panel__dropdown-header-action"
className="dataform-layouts-panel__dropdown-header-action"
label={ __( 'Close' ) }
icon={ closeSmall }
onClick={ onClose }
Expand Down Expand Up @@ -81,14 +81,14 @@ function FormField< Item >( {
return (
<HStack
ref={ setPopoverAnchor }
className="dataforms-layouts-panel__field"
className="dataform-layouts-panel__field"
>
<div className="dataforms-layouts-panel__field-label">
<div className="dataform-layouts-panel__field-label">
{ field.label }
</div>
<div>
<Dropdown
contentClassName="dataforms-layouts-panel__field-dropdown"
contentClassName="dataform-layouts-panel__field-dropdown"
popoverProps={ popoverProps }
focusOnMount
toggleProps={ {
Expand All @@ -98,7 +98,7 @@ function FormField< Item >( {
} }
renderToggle={ ( { isOpen, onToggle } ) => (
<Button
className="dataforms-layouts-panel__field-control"
className="dataform-layouts-panel__field-control"
size="compact"
variant="tertiary"
aria-expanded={ isOpen }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
.dataforms-layouts-panel__field {
.dataform-layouts-panel__field {
width: 100%;
min-height: $grid-unit-40;
justify-content: flex-start !important;
align-items: flex-start !important;
}

.dataforms-layouts-panel__field-label {
.dataform-layouts-panel__field-label {
width: 38%;
flex-shrink: 0;
min-height: $grid-unit-40;
Expand All @@ -16,7 +16,7 @@
hyphens: auto;
}

.dataforms-layouts-panel__field-control {
.dataform-layouts-panel__field-control {
flex-grow: 1;
min-height: $grid-unit-40;
display: flex;
Expand All @@ -36,16 +36,16 @@
}
}

.dataforms-layouts-panel__field-dropdown .components-popover__content {
.dataform-layouts-panel__field-dropdown .components-popover__content {
min-width: 320px;
padding: $grid-unit-20;
}

.dataforms-layouts-panel__dropdown-header {
.dataform-layouts-panel__dropdown-header {
margin-bottom: $grid-unit-20;
}

[class].dataforms-layouts-panel__dropdown-header-action {
[class].dataform-layouts-panel__dropdown-header-action {
height: $icon-size;

&.has-icon {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { useMemo } from '@wordpress/element';
/**
* Internal dependencies
*/
import { normalizeFields } from '../../normalize-fields';
import type { DataFormProps, Field } from '../../types';
import { normalizeFields } from '../../../utils/normalize-fields';
import type { DataFormProps, Field } from '../../../types';

export default function FormRegular< Item >( {
data,
Expand Down
2 changes: 1 addition & 1 deletion packages/dataviews/src/components/dataform/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Internal dependencies
*/
import type { DataFormProps } from '../../types';
import { getFormLayout } from '../../dataforms-layouts';
import { getFormLayout } from '../dataform-layouts';

export default function DataForm< Item >( {
form,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { useRegistry } from '@wordpress/data';
import { useSomeItemHasAPossibleBulkAction } from '../dataviews-bulk-actions';
import DataViewsContext from '../dataviews-context';
import { ActionWithModal } from '../dataviews-item-actions';
import { LAYOUT_GRID, LAYOUT_TABLE } from '../../constants';
import { LAYOUT_GRID, LAYOUT_TABLE } from '../../utils/constants';
import type { Action } from '../../types';
import type { ActionTriggerProps } from '../dataviews-item-actions';
import type { SetSelection } from '../../private-types';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { useRegistry } from '@wordpress/data';
* Internal dependencies
*/
import DataViewsContext from '../dataviews-context';
import { LAYOUT_TABLE, LAYOUT_GRID } from '../../constants';
import { LAYOUT_TABLE, LAYOUT_GRID } from '../../utils/constants';
import { unlock } from '../../lock-unlock';
import type { Action, ActionModal } from '../../types';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { createContext } from '@wordpress/element';
*/
import type { View, Action, NormalizedField } from '../../types';
import type { SetSelection } from '../../private-types';
import { LAYOUT_TABLE } from '../../constants';
import { LAYOUT_TABLE } from '../../utils/constants';

type DataViewsContextType< Item > = {
view: View;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {
OPERATOR_IS_NONE,
OPERATOR_IS_ALL,
OPERATOR_IS_NOT_ALL,
} from '../../constants';
} from '../../utils/constants';
import type {
Filter,
NormalizedFilter,
Expand Down
8 changes: 6 additions & 2 deletions packages/dataviews/src/components/dataviews-filters/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ import FilterSummary from './filter-summary';
import { default as AddFilter, AddFilterDropdownMenu } from './add-filter';
import ResetFilters from './reset-filters';
import DataViewsContext from '../dataviews-context';
import { sanitizeOperators } from '../../utils';
import { ALL_OPERATORS, OPERATOR_IS, OPERATOR_IS_NOT } from '../../constants';
import { sanitizeOperators } from '../../utils/sanitize-operators';
import {
ALL_OPERATORS,
OPERATOR_IS,
OPERATOR_IS_NOT,
} from '../../utils/constants';
import type { NormalizedFilter, NormalizedField, View } from '../../types';

export function useFilters( fields: NormalizedField< any >[], view: View ) {
Expand Down
51 changes: 0 additions & 51 deletions packages/dataviews/src/components/dataviews-layout/index.tsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ import { __ } from '@wordpress/i18n';
/**
* Internal dependencies
*/
import ItemActions from '../../components/dataviews-item-actions';
import SingleSelectionCheckbox from '../../components/dataviews-selection-checkbox';
import { useHasAPossibleBulkAction } from '../../components/dataviews-bulk-actions';
import type { Action, NormalizedField, ViewGridProps } from '../../types';
import type { SetSelection } from '../../private-types';
import ItemActions from '../../dataviews-item-actions';
import SingleSelectionCheckbox from '../../dataviews-selection-checkbox';
import { useHasAPossibleBulkAction } from '../../dataviews-bulk-actions';
import type { Action, NormalizedField, ViewGridProps } from '../../../types';
import type { SetSelection } from '../../../private-types';

interface GridItemProps< Item > {
selection: string[];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* External dependencies
*/
import type { ComponentType } from 'react';

/**
* WordPress dependencies
*/
Expand All @@ -8,15 +13,17 @@ import {
formatListBullets,
formatListBulletsRTL,
} from '@wordpress/icons';
import { useContext } from '@wordpress/element';

/**
* Internal dependencies
*/
import ViewTable from './table';
import ViewGrid from './grid';
import ViewList from './list';
import { LAYOUT_GRID, LAYOUT_LIST, LAYOUT_TABLE } from '../constants';
import type { View } from '../types';
import { LAYOUT_GRID, LAYOUT_LIST, LAYOUT_TABLE } from '../../utils/constants';
import type { View, ViewBaseProps } from '../../types';
import DataViewsContext from '../dataviews-context';

export const VIEW_LAYOUTS = [
{
Expand Down Expand Up @@ -64,3 +71,38 @@ export function getMandatoryFields( view: View ): string[] {

return [];
}

export default function DataViewsLayout() {
const {
actions = [],
data,
fields,
getItemId,
isLoading,
view,
onChangeView,
selection,
onChangeSelection,
setOpenedFilter,
density,
} = useContext( DataViewsContext );

const ViewComponent = VIEW_LAYOUTS.find( ( v ) => v.type === view.type )
?.component as ComponentType< ViewBaseProps< any > >;

return (
<ViewComponent
actions={ actions }
data={ data }
fields={ fields }
getItemId={ getItemId }
isLoading={ isLoading }
onChangeView={ onChangeView }
onChangeSelection={ onChangeSelection }
selection={ selection }
setOpenedFilter={ setOpenedFilter }
view={ view }
density={ density }
/>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ import { useRegistry } from '@wordpress/data';
/**
* Internal dependencies
*/
import { unlock } from '../../lock-unlock';
import { unlock } from '../../../lock-unlock';
import {
ActionsDropdownMenuGroup,
ActionModal,
} from '../../components/dataviews-item-actions';
import type { Action, NormalizedField, ViewListProps } from '../../types';
} from '../../dataviews-item-actions';
import type { Action, NormalizedField, ViewListProps } from '../../../types';

interface ListViewItemProps< Item > {
actions: Action< Item >[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@ import { forwardRef, Children, Fragment } from '@wordpress/element';
/**
* Internal dependencies
*/
import { unlock } from '../../lock-unlock';
import { sanitizeOperators } from '../../utils';
import { SORTING_DIRECTIONS, sortArrows, sortLabels } from '../../constants';
import { unlock } from '../../../lock-unlock';
import { sanitizeOperators } from '../../../utils/sanitize-operators';
import {
SORTING_DIRECTIONS,
sortArrows,
sortLabels,
} from '../../../utils/constants';
import type {
NormalizedField,
SortDirection,
ViewTable as ViewTableType,
} from '../../types';
} from '../../../types';

const {
DropdownMenuV2: DropdownMenu,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@ import {
/**
* Internal dependencies
*/
import SingleSelectionCheckbox from '../../components/dataviews-selection-checkbox';
import ItemActions from '../../components/dataviews-item-actions';
import { sortValues } from '../../constants';
import SingleSelectionCheckbox from '../../dataviews-selection-checkbox';
import ItemActions from '../../dataviews-item-actions';
import { sortValues } from '../../../utils/constants';
import {
useSomeItemHasAPossibleBulkAction,
useHasAPossibleBulkAction,
} from '../../components/dataviews-bulk-actions';
} from '../../dataviews-bulk-actions';
import type {
Action,
NormalizedField,
ViewTable as ViewTableType,
ViewTableProps,
CombinedField,
} from '../../types';
import type { SetSelection } from '../../private-types';
} from '../../../types';
import type { SetSelection } from '../../../private-types';
import ColumnHeaderMenu from './column-header-menu';

interface BulkSelectionCheckboxProps< Item > {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ import warning from '@wordpress/warning';
/**
* Internal dependencies
*/
import { SORTING_DIRECTIONS, sortIcons, sortLabels } from '../../constants';
import { VIEW_LAYOUTS, getMandatoryFields } from '../../dataviews-layouts';
import {
SORTING_DIRECTIONS,
sortIcons,
sortLabels,
} from '../../utils/constants';
import { VIEW_LAYOUTS, getMandatoryFields } from '../dataviews-layouts';
import type { SupportedLayouts } from '../../types';
import DataViewsContext from '../dataviews-context';
import { unlock } from '../../lock-unlock';
Expand Down
Loading
Loading