Skip to content

Conversation

elileto
Copy link
Contributor

@elileto elileto commented Feb 6, 2019

WHY are these changes introduced?

Resolves #888

WHAT is this pull request doing?

Adds an example to of resource list to the styleguide that includes, bulk actions, persistent item shortcut actions, sorting and filtering.

In the styleguide:
image

Copy-paste this code in playground/Playground.tsx:
import * as React from 'react';
import {Page, Avatar, TextStyle, ResourceList, Card, FilterType} from '../src';

interface State {}

export default class Playground extends React.Component<{}, State> {
  state = {
    selectedItems: [],
    sortValue: 'DATE_MODIFIED_DESC',
    searchValue: '',
    appliedFilters: [
      {
        key: 'accountStatusFilter',
        value: 'Account enabled',
      },
    ],
  };

  handleSearchChange = (searchValue) => {
    this.setState({searchValue});
  };

  handleFiltersChange = (appliedFilters) => {
    this.setState({appliedFilters});
  };

  handleSortChange = (sortValue) => {
    this.setState({sortValue});
  };

  handleSelectionChange = (selectedItems) => {
    this.setState({selectedItems});
  };

  renderItem = (item) => {
    const {id, url, name, location, latestOrderUrl} = item;
    const media = <Avatar customer size="medium" name={name} />;
    const shortcutActions = latestOrderUrl
      ? [{content: 'View latest order', url: latestOrderUrl}]
      : null;
    return (
      <ResourceList.Item
        id={id}
        url={url}
        media={media}
        accessibilityLabel={`View details for ${name}`}
        shortcutActions={shortcutActions}
        persistActions
      >
        <h3>
          <TextStyle variation="strong">{name}</TextStyle>
        </h3>
        <div>{location}</div>
      </ResourceList.Item>
    );
  };

  render() {
    const resourceName = {
      singular: 'customer',
      plural: 'customers',
    };
    const items = [
      {
        id: 341,
        url: 'customers/341',
        name: 'Mae Jemison',
        location: 'Decatur, USA',
        latestOrderUrl: 'orders/1456',
      },
      {
        id: 256,
        url: 'customers/256',
        name: 'Ellen Ochoa',
        location: 'Los Angeles, USA',
        latestOrderUrl: 'orders/1457',
      },
    ];
    const promotedBulkActions = [
      {
        content: 'Edit customers',
        onAction: () => console.log('Todo: implement bulk edit'),
      },
    ];
    const bulkActions = [
      {
        content: 'Add tags',
        onAction: () => console.log('Todo: implement bulk add tags'),
      },
      {
        content: 'Remove tags',
        onAction: () => console.log('Todo: implement bulk remove tags'),
      },
      {
        content: 'Delete customers',
        onAction: () => console.log('Todo: implement bulk delete'),
      },
    ];
    const filters = [
      {
        key: 'orderCountFilter',
        label: 'Number of orders',
        operatorText: 'is greater than',
        type: FilterType.TextField,
      },
      {
        key: 'accountStatusFilter',
        label: 'Account status',
        operatorText: 'is',
        type: FilterType.Select,
        options: ['Enabled', 'Invited', 'Not invited', 'Declined'],
      },
    ];
    const filterControl = (
      <ResourceList.FilterControl
        filters={filters}
        appliedFilters={this.state.appliedFilters}
        onFiltersChange={this.handleFiltersChange}
        searchValue={this.state.searchValue}
        onSearchChange={this.handleSearchChange}
        additionalAction={{
          content: 'Save',
          onAction: () => console.log('New filter saved'),
        }}
      />
    );
    return (
      <Card>
        <ResourceList
          resourceName={resourceName}
          items={items}
          renderItem={this.renderItem}
          selectedItems={this.state.selectedItems}
          onSelectionChange={this.handleSelectionChange}
          promotedBulkActions={promotedBulkActions}
          bulkActions={bulkActions}
          sortValue={this.state.sortValue}
          sortOptions={[
            {label: 'Newest update', value: 'DATE_MODIFIED_DESC'},
            {label: 'Oldest update', value: 'DATE_MODIFIED_ASC'},
          ]}
          onSortChange={(selected) => {
            this.setState({sortValue: selected});
            console.log(`Sort option changed to ${selected}.`);
          }}
          filterControl={filterControl}
        />
      </Card>
    );
  }
}

🎩 checklist

@elileto elileto self-assigned this Feb 6, 2019
@BPScott BPScott temporarily deployed to polaris-react-pr-978 February 6, 2019 18:34 Inactive
@elileto elileto force-pushed the resourcelist-kitchen-sink branch from aa6f8b8 to 01dac7b Compare February 6, 2019 18:58
@BPScott BPScott temporarily deployed to polaris-react-pr-978 February 6, 2019 18:59 Inactive
@elileto elileto force-pushed the resourcelist-kitchen-sink branch from 01dac7b to ec9aee8 Compare February 6, 2019 19:25
@BPScott BPScott temporarily deployed to polaris-react-pr-978 February 6, 2019 19:25 Inactive
@BPScott BPScott temporarily deployed to polaris-react-pr-978 February 6, 2019 20:02 Inactive
@elileto elileto force-pushed the resourcelist-kitchen-sink branch from 86384c8 to 97e54f1 Compare February 6, 2019 20:12
@BPScott BPScott temporarily deployed to polaris-react-pr-978 February 6, 2019 20:12 Inactive
@elileto elileto force-pushed the resourcelist-kitchen-sink branch from 97e54f1 to dfea852 Compare February 6, 2019 22:11
@BPScott BPScott temporarily deployed to polaris-react-pr-978 February 6, 2019 22:11 Inactive
@elileto elileto changed the title [WIP][ResourceList] Add full example of resource list to styleguide [ResourceList] Add full example of resource list to styleguide Feb 11, 2019
@elileto elileto changed the title [ResourceList] Add full example of resource list to styleguide [WIP][ResourceList] Add full example of resource list to styleguide Feb 11, 2019
@elileto elileto changed the title [WIP][ResourceList] Add full example of resource list to styleguide [ResourceList] Add full example of resource list to styleguide Feb 11, 2019
@elileto elileto force-pushed the resourcelist-kitchen-sink branch from dfea852 to d5af2bc Compare February 11, 2019 21:38
@BPScott BPScott temporarily deployed to polaris-react-pr-978 February 11, 2019 21:38 Inactive
@elileto elileto force-pushed the resourcelist-kitchen-sink branch from d5af2bc to 0bcb1f7 Compare February 11, 2019 21:48
@BPScott BPScott temporarily deployed to polaris-react-pr-978 February 11, 2019 21:48 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants