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

feat: show status indicator for collection and items #1580

Merged
merged 12 commits into from
Sep 29, 2021

Conversation

cazala
Copy link
Member

@cazala cazala commented Sep 24, 2021

Closes #1545

@vercel
Copy link

vercel bot commented Sep 24, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/decentraland/builder/DgVhi6otiCpW2oD7mfy9jh23ntLh
✅ Preview: https://builder-git-feat-show-status-indicator-decentraland1.vercel.app

@cazala cazala marked this pull request as draft September 24, 2021 15:33
@coveralls
Copy link

coveralls commented Sep 24, 2021

Pull Request Test Coverage Report for Build 1288429294

  • 111 of 163 (68.1%) changed or added relevant lines in 18 files are covered.
  • 2 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.9%) to 9.187%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/modules/common/reducer.ts 0 1 0.0%
src/modules/item/utils.ts 12 13 92.31%
src/components/CollectionStatus/index.ts 0 2 0.0%
src/components/ItemStatus/index.ts 0 2 0.0%
src/modules/common/sagas.ts 0 2 0.0%
src/modules/item/selectors.ts 38 40 95.0%
src/modules/common/store.ts 0 4 0.0%
src/modules/item/export.ts 1 6 16.67%
src/modules/item/sagas.ts 9 15 60.0%
src/components/CollectionStatus/CollectionStatus.container.ts 0 8 0.0%
Files with Coverage Reduction New Missed Lines %
src/modules/common/store.ts 1 0%
src/modules/item/export.ts 1 46.48%
Totals Coverage Status
Change from base Build 1283274429: 0.9%
Covered Lines: 975
Relevant Lines: 9096

💛 - Coveralls

import { Props } from './ItemStatus.types'
import './ItemStatus.css'

export default class ItemStatus extends React.PureComponent<Props> {
Copy link
Contributor

Choose a reason for hiding this comment

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

ItemStatus and CollectionStatus share the same css and code. They could be abstracted to a general Status component on which a type: 'item' | 'collection' prop is provided.
The container has a minimal difference in both, but it can be handled by using this prop from ownProps

)}
</>
)}
<>
Copy link
Contributor

Choose a reason for hiding this comment

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

We should check why the formatter is doing this.

@cazala cazala changed the base branch from master to feat/improved-approval-flow September 28, 2021 20:42
@@ -126,7 +127,7 @@ export default class CollectionDetailPage extends React.PureComponent<Props, Sta
<Column className="header-column">
<Row className="header-row" onClick={this.handleEditName}>
<Header size="huge" className="name">
{collection.name}
{collection.isPublished ? <CollectionStatus collection={collection} /> : null}{collection.name}
Copy link
Contributor

Choose a reason for hiding this comment

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

Not a required change, but remember that lines like this can be written like

collection.isPublished && <CollectionStatus collection={collection} />

To avoid the unnecessary null at the end

Copy link
Contributor

@fzavalia fzavalia Sep 29, 2021

Choose a reason for hiding this comment

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

This is just a personal preference

@@ -255,7 +254,7 @@ export default class RightPanel extends React.PureComponent<Props, State> {
<div className="RightPanel">
{isConnected ? (
<ItemProvider id={selectedItemId}>
{(item, collection, isItemLoading) => {
{(item, _collection, isItemLoading) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the undescore?

Copy link
Contributor

@fzavalia fzavalia Sep 29, 2021

Choose a reason for hiding this comment

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

If you mean to say that collection is an unused variable I recommend you just write an underscore without the name. just underscore means unused, underscore and name means private (in vanilla js)

Copy link
Member Author

Choose a reason for hiding this comment

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

in typescript the leading underscore does tell the linter to ignore that param for the unused param rule, without it the linter would complain. Just _ does work too, but is more vague, and you can't use it if you need to apply it on a few params but not all.


describe('when getting status by item id', () => {
it('should return the status for each published item', () => {
mockGetChainIdByNetwork.mockReturnValue(ChainId.MATIC_MAINNET)
Copy link
Contributor

Choose a reason for hiding this comment

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

Lets use .mockReturnValueOnce just in case.

Copy link
Contributor

Choose a reason for hiding this comment

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

In this particular test is unnecessary, but if you were to add a new one with another mockReturnValue, the second would not work.

Copy link
Member Author

Choose a reason for hiding this comment

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

The test fails without it because it calls that mock 3 times


const mapDispatch = (_dispatch: MapDispatch): MapDispatchProps => ({})

export default connect(mapState, mapDispatch)(ItemStatus)
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of passing an empty mapDispatch you can always pass null or nothing at all.

export default connect(mapState)(ItemStatus)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yea to be honest I just leave them like that to make it easier to connect later on which is usually what happens with most components over time :P (that's why i create the types too even tho they are empty)

}
}

const mapDispatch = (_dispatch: MapDispatch): MapDispatchProps => ({})
Copy link
Contributor

Choose a reason for hiding this comment

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

The convention for unused variables is just an undescore _, no need to declare the name (undescore and name is the convention for private)

Copy link
Member Author

Choose a reason for hiding this comment

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

mm afaik typescript allows _ if you don't use any variable but also _param if you need to select them individually, ie:

function (_paramA: any, _paramB: any, paramC: any) {
  // use only paramC
}

I think the _param is clearer and i think it's been used like that throughout the codebase

const { collectionId } = item
if (collectionId) {
if (collectionId in statusByCollectionId) {
statusByCollectionId[collectionId] = getMostRelevantStauts(statusByCollectionId[collectionId], itemStatusByItemId[item.id])
Copy link
Contributor

@fzavalia fzavalia Sep 29, 2021

Choose a reason for hiding this comment

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

Typo in getMostRelevantStauts

error: null,
data: {
...state.data,
...action.payload.entities.reduce((obj, entity) => {
Copy link
Contributor

@fzavalia fzavalia Sep 29, 2021

Choose a reason for hiding this comment

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

You can always one line this with

(obj, entity) => ({...obj, [entity.entityId]: entity })

Just personal preference

Copy link
Contributor

Choose a reason for hiding this comment

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

And even go the extra mile by doing

data: action.payload.entities.reduce((obj, entity) => ({...obj, [entity.entityId]: entity }), state.data)

Copy link
Member Author

@cazala cazala Sep 29, 2021

Choose a reason for hiding this comment

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

mm it's not the same tho, the complexity of the code I wrote is linear while the complexity of the one using the spread is exponential, every iteration you are going over all the keys of the object again. You can compare the two ways here, you will notice the expression without the spread finishes in 1 ms while the other one takes 24 seconds (24,000 times slower) oops spread the wrong object, it takes 71 ms.

const stuff = []
for (let i = 0; i < 10000; i++) stuff.push(i)
let time = Date.now()
stuff.reduce((obj, i) => {
  obj[i] = i
  return obj
}, {})
console.log('not using spread', Date.now() - time, 'ms')
time = Date.now()
stuff.reduce((obj, i) => ({...obj, [i]: i }), {})
console.log('using spread', Date.now() - time, 'ms')

// not using spread 1 ms
// using spread 71 ms

For small data sets it might not be noticeable but for anything above 100 it starts halting the UI

Copy link
Member Author

Choose a reason for hiding this comment

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

Regarding the usage of state.data as the initial value of the reduce, that only works when using the spread, but if I'd do that without using the spread within the reduce, it would be mutating

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh wait haha it's not 23 seconds (i spread the wrong object 😅 ) it's 71 ms, but still way slower

Copy link
Member Author

@cazala cazala Sep 29, 2021

Choose a reason for hiding this comment

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

10k entries might sound like a lot, but we have reducers with 10x that (like the tiles on the map), I learned this the hard way once we added a spread in on reducer or selector that handled that amount of entries and it did froze the UI for a couple seconds every time it got computed lol


describe('when getting status by item id', () => {
it('should return the status for each published item', () => {
mockGetChainIdByNetwork.mockReturnValue(ChainId.MATIC_MAINNET)
Copy link
Contributor

Choose a reason for hiding this comment

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

.mockReturnValueOnce

Copy link
Member Author

Choose a reason for hiding this comment

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

This one i had to change it back to the mockReturnValue because it's called more than once (three times in this test, once of each item).

@fzavalia
Copy link
Contributor

Looks good!
Comments are mostly suggestions.
@cazala I'll be waiting on your opinion of them.

@cazala cazala merged commit f578a79 into feat/improved-approval-flow Sep 29, 2021
@cazala cazala deleted the feat/show-status-indicator branch September 29, 2021 21:38
fzavalia added a commit that referenced this pull request Oct 8, 2021
* feat: save published items (#1569)

* feat: use label for supply in rarity dropdown

* refactor: make modalSaga a generator

* refactor: decouple modal logic from item save saga

* feat: save published items

* fix: wrong this on lambda

* chore: configure tests

* chore: fix circular dep

* chore: added tests for saveItemRequest

* chore: added tests for savePublishedItemRequest

* chore: use call instead of matchers

* ci: commented out coveralls report

* ci: uncommented coveralls report

* chore: fix eslint typescript errors

* chore: import order

* feat: show status indicator for collections and items

* refactor: CollectionAction component to simplify CollectionDetailPage

* refactor: Remove useMemo

* refactor: mergeProps so collectionId does not have to be provided

* feat: Add push changes button when collection is dirty

* feat: Add push collection changes modal (wip)

* feat: Add curation reducer, actions and types

* feat: Add curation saga and fetch curations request

* feat: Can't push a curation if there is one pending

* feat: Push curation

* refactor: More readable if structure

* chore: Add text

* feat: Fetch single curation request

* fix: canChangedBePushed and areChangesUnderReview

* chore: Update text

* chore: Update popup style for under review pushes

* feat: Fetch curations when committee member request succeeds

* feat: Display collection in curation list that were requested for review

* refactor: Update curation type

* feat: Show approve button on collections that have curation

* feat: Add reject and approve curation actions sagas and reducers

* feat: show status indicator for collection and items (#1580)

* chore: fix eslint typescript errors

* chore: import order

* feat: show status indicator for collections and items

* chore: rename file

* chore: added tests

* chore: remove thing

* chore: added another test

* fix: type

* refactor: use && instead of ternary

Co-authored-by: Fernando Zavalia <24811313+fzavalia@users.noreply.github.com>

* feat: Display buttons in item editor according to the review type

* feat: Add disable button to item editor when you want to set available to false

* fix: ReviewModal

* feat: Don't show approve button on rejected curation

* refactor: CollectionAction types + selectors

* chore: Add new translations to item_editor in chinese and spanish

* chore: Add push_collection_changes_modal translations for es and zh

* chore: Add collection_detail_page translations for es and zh

* chore: Add collection_row translations for es and zh

* chore: Remove unused authorizations from CollectionDetailPage

* chore: Rename ExtCollection

* feat: Status takes into consideration under review because of curation

* fix: selector tests

* fix: Fix CollectionItem state

* feat: approval flow

* fix: stuff

* Merge improve approval flow branch into approve collection  (#1592)

* fix: stats (#1584)

* wipardo

* refactor: cache promise and remove unused data from type

* Update src/lib/api/builder.ts

Co-authored-by: Lautaro Petaccio <1120791+LautaroPetaccio@users.noreply.github.com>

* Update src/lib/api/builder.ts

Co-authored-by: Lautaro Petaccio <1120791+LautaroPetaccio@users.noreply.github.com>

* refactor: move analytics to its own client

* chore: remove unnecessary param

Co-authored-by: Lautaro Petaccio <1120791+LautaroPetaccio@users.noreply.github.com>

* feat: Request review for updated collection items (#1581)

* chore: fix eslint typescript errors

* chore: import order

* feat: show status indicator for collections and items

* refactor: CollectionAction component to simplify CollectionDetailPage

* refactor: Remove useMemo

* refactor: mergeProps so collectionId does not have to be provided

* feat: Add push changes button when collection is dirty

* feat: Add push collection changes modal (wip)

* feat: Add curation reducer, actions and types

* feat: Add curation saga and fetch curations request

* feat: Can't push a curation if there is one pending

* feat: Push curation

* refactor: More readable if structure

* chore: Add text

* feat: Fetch single curation request

* fix: canChangedBePushed and areChangesUnderReview

* chore: Update text

* chore: Update popup style for under review pushes

* feat: Fetch curations when committee member request succeeds

* feat: Display collection in curation list that were requested for review

* refactor: Update curation type

* feat: Show approve button on collections that have curation

* feat: Add reject and approve curation actions sagas and reducers

* feat: Display buttons in item editor according to the review type

* feat: Add disable button to item editor when you want to set available to false

* fix: ReviewModal

* feat: Don't show approve button on rejected curation

* refactor: CollectionAction types + selectors

* chore: Add new translations to item_editor in chinese and spanish

* chore: Add push_collection_changes_modal translations for es and zh

* chore: Add collection_detail_page translations for es and zh

* chore: Add collection_row translations for es and zh

* chore: Remove unused authorizations from CollectionDetailPage

* chore: Rename ExtCollection

* feat: Status takes into consideration under review because of curation

* fix: selector tests

* fix: Fix CollectionItem state

* chore: Add curation selectors tests

* chore: Add curation reducer tests

* chore: Add some curation sagas tests

* chore: Add push curation saga tests

* refactor: Abstract mock builder

* chore: Remove disabled button and update some texts

* feat: Show orb on mint items modal

* feat: Show dirty item as under review when a curation is ongoing

* feat: Show warning when one of the items you are minting has changes to be approved

* feat: Show warning when trying to sell a collection with items with pending reviews

* fix: Item selectors test

* refactor: Move UnderReview component to separate files

Co-authored-by: Juan Cazala <juancazala@gmail.com>

* chore: Remove extra type (#1589)

* chore: fix tests

Co-authored-by: Juan Cazala <juan@decentraland.org>
Co-authored-by: Lautaro Petaccio <1120791+LautaroPetaccio@users.noreply.github.com>
Co-authored-by: Juan Cazala <juancazala@gmail.com>

* fix: deploy items to catalyst

* feat: wait for subgraph to index

* fix: update curation

* fix: update curation

* feat: use restful endpoints

* chore: fix tests

* feat: added collection name to tx payload in rescue action

* fix: status of items for curators

* fix: fetch curations on wallet connect

* fix: update state optimistically

* fix: curation sort

* feat: fixed styles

* chore: remove console.log

* refactor: Use enum instead of string

* chore: Remove ReviewModal for approvals, call initiateApprovalFlow from TopPanel directly

* chore: translations

Co-authored-by: Fernando Zavalia <24811313+fzavalia@users.noreply.github.com>
Co-authored-by: Lautaro Petaccio <1120791+LautaroPetaccio@users.noreply.github.com>
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.

Show status on Collection/Items
3 participants