-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Saleor 1712 dashboard unable to handle empty channel list #924
Saleor 1712 dashboard unable to handle empty channel list #924
Conversation
c2ff1f5
to
1bd4385
Compare
</ActionDialog> | ||
</> | ||
) : ( | ||
<Skeleton /> |
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.
Maybe for easier readability, instead of making a huge positive condition outcome and then simple skeleton, put the short and simple outcome before everything else?
if(!channel) {
return <><TitleSomething><Skeleton /></>
}
return everything as normal
|
||
const HomeSection = () => { | ||
const navigate = useNavigator(); | ||
const { user } = useUser(); | ||
const { channel } = useAppChannel(); | ||
|
||
const noChannel = !channel && typeof channel !== "undefined"; |
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.
I'd rather see this as a positive const, such as channelExists
or hasChannel
, especially since most places we use it, it's negated. Besides that it seems easier to overall think of positives +- negation, rather than negatives +- negation (that more easily created negated negative), don't you think?
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.
I left noChannel
after the refactor in which I added default props in HomePage
. In this component it's mostly positive value. What do you think?
src/home/views/index.tsx
Outdated
</HomePageQuery> | ||
<HomePage | ||
activities={data?.activities.edges.map(edge => edge.node).reverse()} | ||
orders={!noChannel ? data?.ordersToday.totalCount : 0} |
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.
I think in this case HomePage component should have a default when orders is undefined. Then it also doesn't require to check if !noChannel
src/home/views/index.tsx
Outdated
orders={!noChannel ? data?.ordersToday.totalCount : 0} | ||
sales={maybe(() => data?.salesToday.gross)} | ||
topProducts={ | ||
!noChannel ? data?.productTopToday.edges.map(edge => edge.node) : null |
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.
Same as above
src/home/views/index.tsx
Outdated
}) | ||
) | ||
} | ||
ordersToCapture={!noChannel ? data?.ordersToCapture.totalCount : 0} |
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.
63-65 same as above
src/home/views/index.tsx
Outdated
ordersToFulfill={!noChannel ? data?.ordersToFulfill.totalCount : 0} | ||
productsOutOfStock={!noChannel ? data?.productsOutOfStock.totalCount : 0} | ||
userName={getUserName(user, true)} | ||
userPermissions={user?.userPermissions || []} |
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.
Also should be default in home page
src/index.tsx
Outdated
@@ -145,7 +145,7 @@ const Routes: React.FC = () => { | |||
return ( | |||
<> | |||
<WindowTitle title={intl.formatMessage(commonMessages.dashboard)} /> | |||
{channel && | |||
{typeof channel !== "undefined" && |
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.
Would happily see those 4 &&'s moved to a const with a nice name
@@ -71,6 +71,8 @@ export const OrderList: React.FC<OrderListProps> = ({ params }) => { | |||
|
|||
const { channel, availableChannels } = useAppChannel(); | |||
|
|||
const noChannel = !channel && typeof channel !== "undefined"; |
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.
Same as before
@@ -99,7 +103,9 @@ const HomePage: React.FC<HomePageProps> = props => { | |||
/> | |||
} | |||
> | |||
{sales ? ( | |||
{noChannel ? ( |
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.
Maybe if there are three outcomes here, it'd be worth to just move it to a function? Chaining conditions makes it less readable. Also, would rather see this in positive, like channelExists + negation
src/home/views/index.tsx
Outdated
const noChannel = !channel && typeof channel !== "undefined"; | ||
|
||
const { data } = !noChannel | ||
? useHomePage({ |
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.
I'm afraid conditionally using hook might cause React errors in the future - https://reactjs.org/docs/hooks-rules.html#only-call-hooks-at-the-top-level
1bd4385
to
eed545a
Compare
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.
I clicked through the dashboard and there's a lot of pages that do not work because they "cannot read property id of undefined". Please check where we use channel.id
and replace it with channel?.id
. Products/categories/orders/discounts should be accessible
I want to merge this change because... it handles empty channels on:
/dashboard/channels
/dashboard/orders
/dashboard/products
NOTE: Tested by mocking up response to
[{"data": {"channels": []}}]
onAppChannelContext.tsx
.PR intended to be tested with API branch:
Screenshots
Pull Request Checklist
Test environment config
API_URI=https://master.staging.saleor.rocks/graphql/