-
Notifications
You must be signed in to change notification settings - Fork 82
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
feat: show status indicator for collection and items #1580
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/decentraland/builder/DgVhi6otiCpW2oD7mfy9jh23ntLh |
… feat/show-status-indicator
Pull Request Test Coverage Report for Build 1288429294
💛 - Coveralls |
import { Props } from './ItemStatus.types' | ||
import './ItemStatus.css' | ||
|
||
export default class ItemStatus extends React.PureComponent<Props> { |
There was a problem hiding this comment.
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
)} | ||
</> | ||
)} | ||
<> |
There was a problem hiding this comment.
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.
…ntraland/builder into feat/show-status-indicator
@@ -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} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the undescore?
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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 => ({}) |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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
src/modules/collection/selectors.ts
Outdated
const { collectionId } = item | ||
if (collectionId) { | ||
if (collectionId in statusByCollectionId) { | ||
statusByCollectionId[collectionId] = getMostRelevantStauts(statusByCollectionId[collectionId], itemStatusByItemId[item.id]) |
There was a problem hiding this comment.
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) => { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.mockReturnValueOnce
There was a problem hiding this comment.
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).
Looks good! |
* 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>
Closes #1545