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

[DropZone] Allow duplicate files to be uploaded consecutively/ removed and added again #782

Merged
merged 1 commit into from
Jan 16, 2019

Conversation

elileto
Copy link
Contributor

@elileto elileto commented Dec 18, 2018

WHY are these changes introduced?

Resolves #425

WHAT is this pull request doing?

This is addressing the issue that the DropZone will not allow duplicate files to be added consecutively. This also caused issues when a file was removed , it could not be added again.

How to 🎩

🖥 Local development instructions
🗒 General tophatting guidelines
📄 Changelog guidelines

Copy-paste this code in playground/Playground.tsx:
import * as React from 'react';
import {
  Page,
  Stack,
  Thumbnail,
  DropZone,
  Button,
  Card,
  Caption,
} from '@shopify/polaris';

interface State {}

export default class Playground extends React.Component<{}, State> {
  state = {
    files: [],
  };

  render() {
    const {files} = this.state;
    const validImageTypes = ['image/gif', 'image/jpeg', 'image/png'];

    const fileUpload = !files.length && <DropZone.FileUpload />;
    const uploadedFiles = files.length > 0 && (
      <Stack vertical>
        {files.map((file, index) => (
          <Stack alignment="center" key={index}>
            <Thumbnail
              size="small"
              alt={file.name}
              source={
                validImageTypes.indexOf(file.type) > 0
                  ? window.URL.createObjectURL(file)
                  : 'https://cdn.shopify.com/s/files/1/0757/9955/files/New_Post.png?12678548500147524304'
              }
            />
            <div>
              {file.name} <Caption>{file.size} bytes</Caption>
            </div>
          </Stack>
        ))}
      </Stack>
    );

    return (
      <Card>
        <Stack vertical>
          <Button
            plain
            onClick={() => this.setState({files: []}, () => console.log())}
          >
            Remove
          </Button>
          <DropZone
            onDrop={(files) =>
              this.setState({files: [...this.state.files, ...files]}, () =>
                console.log(files),
              )
            }
            // onClick={() => console.log('HELP IM A TINY MAN STUCK IN A BOX!')}
          >
            {uploadedFiles}
            {fileUpload}
          </DropZone>
        </Stack>
      </Card>
    );
  }
}

🎩 checklist

@BPScott BPScott temporarily deployed to polaris-react-pr-782 December 18, 2018 22:15 Inactive
@elileto elileto changed the title [WIP]{DropZone] reset inputHTMLElement in onChange to allow duplicate files uploaded consecutively [WIP][DropZone] reset inputHTMLElement in onChange to allow duplicate files uploaded consecutively Dec 18, 2018
@elileto elileto changed the title [WIP][DropZone] reset inputHTMLElement in onChange to allow duplicate files uploaded consecutively [WIP][DropZone] Allow duplicate files to be uploaded consecutively/ removed and added again Dec 18, 2018
@elileto
Copy link
Contributor Author

elileto commented Dec 18, 2018

Will add a UNRELEASED and some testing tomorrow.

@elileto elileto force-pushed the drop-zone-duplicates branch from 3399562 to e40925f Compare December 20, 2018 15:59
@BPScott BPScott temporarily deployed to polaris-react-pr-782 December 20, 2018 15:59 Inactive
@elileto
Copy link
Contributor Author

elileto commented Dec 20, 2018

@AndrewMusgrave and I are going to refactor the drop zone testing page in the new year.

@elileto elileto force-pushed the drop-zone-duplicates branch from e40925f to 64ae565 Compare January 7, 2019 14:44
@BPScott BPScott temporarily deployed to polaris-react-pr-782 January 7, 2019 14:44 Inactive
@elileto
Copy link
Contributor Author

elileto commented Jan 7, 2019

This is still a WIP . I'll re-ping once its ready to go! @solonaarmstrong @AndrewMusgrave but feel free to leave comments if you see anything that stands out.

@elileto elileto force-pushed the drop-zone-duplicates branch from 64ae565 to 624d39a Compare January 7, 2019 15:06
@BPScott BPScott temporarily deployed to polaris-react-pr-782 January 7, 2019 15:06 Inactive
@elileto elileto self-assigned this Jan 7, 2019
@elileto elileto force-pushed the drop-zone-duplicates branch from 624d39a to ae8935c Compare January 7, 2019 15:09
@BPScott BPScott temporarily deployed to polaris-react-pr-782 January 7, 2019 15:10 Inactive
@elileto elileto changed the title [WIP][DropZone] Allow duplicate files to be uploaded consecutively/ removed and added again [DropZone] Allow duplicate files to be uploaded consecutively/ removed and added again Jan 7, 2019
@elileto elileto requested a review from AndrewMusgrave January 7, 2019 17:40
@elileto elileto force-pushed the drop-zone-duplicates branch from ae8935c to fdb0362 Compare January 11, 2019 15:01
@BPScott BPScott temporarily deployed to polaris-react-pr-782 January 11, 2019 15:02 Inactive
@elileto elileto force-pushed the drop-zone-duplicates branch from fdb0362 to c1d1a24 Compare January 11, 2019 16:38
@BPScott BPScott temporarily deployed to polaris-react-pr-782 January 11, 2019 16:38 Inactive
@elileto
Copy link
Contributor Author

elileto commented Jan 11, 2019

@solonaarmstrong @AndrewMusgrave this is ready for your review :)

UNRELEASED.md Outdated Show resolved Hide resolved
Copy link
Member

@AndrewMusgrave AndrewMusgrave left a comment

Choose a reason for hiding this comment

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

Other than @solonaarmstrong comment 💯

@elileto elileto force-pushed the drop-zone-duplicates branch from c1d1a24 to 3ace71a Compare January 16, 2019 13:09
@BPScott BPScott temporarily deployed to polaris-react-pr-782 January 16, 2019 13:09 Inactive
@elileto elileto force-pushed the drop-zone-duplicates branch from 3ace71a to 3c9910b Compare January 16, 2019 13:23
@BPScott BPScott temporarily deployed to polaris-react-pr-782 January 16, 2019 13:23 Inactive
@elileto elileto force-pushed the drop-zone-duplicates branch from 3c9910b to a81f094 Compare January 16, 2019 13:26
@elileto elileto merged commit 7fc84af into master Jan 16, 2019
@danrosenthal danrosenthal temporarily deployed to production January 16, 2019 18:10 Inactive
@solonaarmstrong-zz solonaarmstrong-zz deleted the drop-zone-duplicates branch January 22, 2019 01:49
@jzsplk
Copy link

jzsplk commented Jan 24, 2019

👍

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.

6 participants