Skip to content

Enhance List pinned to accept object #7213

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

Merged
merged 12 commits into from
Apr 24, 2024

Conversation

britt6612
Copy link
Collaborator

@britt6612 britt6612 commented Apr 24, 2024

What does this PR do?

This PR enhances the pinned prop on List to accept an object of shape:

{
        items?: (string | number)[];
        background?: BackgroundType; // applies to background of list item
        color?: ColorType; // applies to number (if onOrder), primaryKey, secondaryKey, icon
        icon?: JSX.Element;
};

This enables us to enhance DataTableColumns pinned with the desired styling.

Where should the reviewer start?

List.js

What testing has been done on this PR?

locally, use this storybook code

import React, { useState } from 'react';

import { Box, List, Text } from 'grommet';
import { Lock } from 'grommet-icons';

const locations = [
  'Los Angelos',
  'Boise',
  'Fort Collins',
  'Los Gatos',
  'Palo Alto',
  'Pheonix',
  'San Francisco',
  'Trenton',
];

const pinnedLocations = [
  'Los Angelos',
  'Fort Collins',
  'Palo Alto',
  'Pheonix',
  'Trenton',
];

const pinnedObject = {
  icon: <Lock />,
  background: { color: 'purple', opacity: 'weak' },
  color: 'blue',
  items: ['Los Angelos', 'Fort Collins', 'Palo Alto', 'Pheonix', 'Trenton'],
};

const pinnedObjectCustomColor = {
  icon: <Lock color="green" />,
  background: { color: 'purple', opacity: 'weak' },
  color: 'blue',
  items: ['Los Angelos', 'Fort Collins', 'Palo Alto', 'Pheonix', 'Trenton'],
};

const objectData = [
  { location: 'Los Angelos', state: 'California' },
  { location: 'Boise', state: 'Idaho' },
  { location: 'Fort Collins', state: 'Colorado' },
  { location: 'Los Gatos', state: 'California' },
  { location: 'Palo Alto', state: 'California' },
  { location: 'Pheonix', state: 'Arizona' },
  { location: 'San Francisco', state: 'California' },
  { location: 'Trenton', state: 'New Jersey' },
];

export const Temp = () => {
  const [ordered, setOrder] = useState(locations);
  return (
    <>
      <Box pad="large" direction="row" gap="medium">
        <Box gap="small">
          data as array of strings, pinned as array of strings matching data
          <List
            aria-label="pinned list"
            data={ordered}
            onOrder={setOrder}
            pinned={pinnedLocations}
          />
        </Box>
        <Box gap="small">
          data as array of strings, pinned as object with pinned.items array
          matching data
          <List
            aria-label="pinned list"
            data={ordered}
            onOrder={setOrder}
            pinned={pinnedObject}
          />
        </Box>
        <Box gap="small">
          data as array of objects, primaryKey locations, secondaryKey state,
          pinned as array
          <List
            aria-label="pinned list"
            data={objectData}
            onOrder={setOrder}
            pinned={pinnedLocations}
            primaryKey="location"
            secondaryKey="state"
          />
        </Box>
      </Box>
      <Box direction="row" gap="medium">
        <Box gap="small">
          data as array of objects, primaryKey locations, secondaryKey state,
          pinned as object
          <List
            aria-label="pinned list"
            data={objectData}
            onOrder={setOrder}
            pinned={pinnedObject}
            primaryKey="location"
            secondaryKey="state"
          />
        </Box>
        <Box gap="small">
          data as array of objects, primaryKey locations, secondaryKey state,
          pinned as object with color defined on icon
          <List
            aria-label="pinned list"
            data={objectData}
            onOrder={setOrder}
            pinned={pinnedObjectCustomColor}
            primaryKey="location"
            secondaryKey="state"
          />
        </Box>
        <Box gap="small">
          data as array of objects, primaryKey function, secondaryKey state,
          pinned as object with color defined on icon
          <List
            aria-label="pinned list"
            data={objectData}
            onOrder={setOrder}
            pinned={pinnedObjectCustomColor}
            primaryKey={(item) => (
              <Text key={item.location} color="red">
                {item.location}
              </Text>
            )}
            secondaryKey={(item) => (
              <Text key={item.state} color="purple">
                {item.state}
              </Text>
            )}
            itemKey="location"
          />
        </Box>
      </Box>
    </>
  );
};

export default {
  title: 'Visualizations/List/Temp',
};

How should this be manually tested?

storybook

Do Jest tests follow these best practices?

  • screen is used for querying.
  • The correct query is used. (Refer to this list of queries)
  • asFragment() is used for snapshot testing.

Any background context you want to provide?

What are the relevant issues?

Related to #7193

Screenshots (if appropriate)

Do the grommet docs need to be updated?

Yes.

Should this PR be mentioned in the release notes?

Yes.

Is this change backwards compatible or is it a breaking change?

Backwards compatible.

@britt6612 britt6612 marked this pull request as draft April 24, 2024 15:41
@britt6612 britt6612 marked this pull request as ready for review April 24, 2024 19:54
@britt6612 britt6612 requested a review from taysea April 24, 2024 19:54
@taysea taysea changed the title enhance pinned to also take in an objecct Enhance List pinned to accept object Apr 24, 2024
Copy link
Collaborator

@halocline halocline left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good. Thank you.

Reminder to remove Temp story prior to final approval.

@taysea taysea self-requested a review April 24, 2024 23:10
Copy link
Collaborator

@taysea taysea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

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.

3 participants