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

Saleor 1712 dashboard unable to handle empty channel list #924

Merged
merged 13 commits into from
Jan 13, 2021

Conversation

MarekChoinski
Copy link
Contributor

I want to merge this change because... it handles empty channels on:

  • homepage
  • /dashboard/channels
  • /dashboard/orders
  • /dashboard/products

NOTE: Tested by mocking up response to [{"data": {"channels": []}}] on AppChannelContext.tsx.

PR intended to be tested with API branch:

Screenshots

image

Pull Request Checklist

  1. All visible strings are translated with proper context.
  2. All data-formatting is locale-aware (dates, numbers, and so on).
  3. Translated strings are extracted.
  4. Number of API calls is optimized.
  5. The changes are tested.
  6. Data-test are added for new elements.
  7. Type definitions are up to date.
  8. Changes are mentioned in the changelog.

Test environment config

API_URI=https://master.staging.saleor.rocks/graphql/

@github-actions github-actions bot temporarily deployed to saleor-1712-dashboard-unable-to-handle-empty-channel-list December 28, 2020 16:37 Inactive
@github-actions github-actions bot temporarily deployed to storybook saleor-1712-dashboard-unable-to-handle-empty-channel-list December 28, 2020 16:37 Inactive
@MarekChoinski MarekChoinski marked this pull request as ready for review December 28, 2020 17:43
@MarekChoinski MarekChoinski force-pushed the SALEOR-1712-dashboard-unable-to-handle-empty-channel-list branch from c2ff1f5 to 1bd4385 Compare December 28, 2020 18:04
@github-actions github-actions bot temporarily deployed to saleor-1712-dashboard-unable-to-handle-empty-channel-list December 28, 2020 18:04 Inactive
@github-actions github-actions bot temporarily deployed to storybook saleor-1712-dashboard-unable-to-handle-empty-channel-list December 28, 2020 18:04 Inactive
src/categories/views/CategoryDetails.tsx Outdated Show resolved Hide resolved
</ActionDialog>
</>
) : (
<Skeleton />
Copy link
Contributor

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";
Copy link
Contributor

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?

Copy link
Contributor Author

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?

</HomePageQuery>
<HomePage
activities={data?.activities.edges.map(edge => edge.node).reverse()}
orders={!noChannel ? data?.ordersToday.totalCount : 0}
Copy link
Contributor

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

orders={!noChannel ? data?.ordersToday.totalCount : 0}
sales={maybe(() => data?.salesToday.gross)}
topProducts={
!noChannel ? data?.productTopToday.edges.map(edge => edge.node) : null
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above

})
)
}
ordersToCapture={!noChannel ? data?.ordersToCapture.totalCount : 0}
Copy link
Contributor

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

ordersToFulfill={!noChannel ? data?.ordersToFulfill.totalCount : 0}
productsOutOfStock={!noChannel ? data?.productsOutOfStock.totalCount : 0}
userName={getUserName(user, true)}
userPermissions={user?.userPermissions || []}
Copy link
Contributor

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" &&
Copy link
Contributor

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";
Copy link
Contributor

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 ? (
Copy link
Contributor

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

const noChannel = !channel && typeof channel !== "undefined";

const { data } = !noChannel
? useHomePage({
Copy link
Contributor

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

@MarekChoinski MarekChoinski force-pushed the SALEOR-1712-dashboard-unable-to-handle-empty-channel-list branch from 1bd4385 to eed545a Compare January 7, 2021 09:30
@github-actions github-actions bot temporarily deployed to saleor-1712-dashboard-unable-to-handle-empty-channel-list January 7, 2021 09:31 Inactive
@github-actions github-actions bot temporarily deployed to storybook saleor-1712-dashboard-unable-to-handle-empty-channel-list January 7, 2021 09:31 Inactive
@github-actions github-actions bot temporarily deployed to saleor-1712-dashboard-unable-to-handle-empty-channel-list January 7, 2021 09:54 Inactive
@github-actions github-actions bot temporarily deployed to storybook saleor-1712-dashboard-unable-to-handle-empty-channel-list January 7, 2021 09:54 Inactive
src/home/views/index.tsx Outdated Show resolved Hide resolved
@github-actions github-actions bot temporarily deployed to saleor-1712-dashboard-unable-to-handle-empty-channel-list January 7, 2021 21:54 Inactive
@github-actions github-actions bot temporarily deployed to storybook saleor-1712-dashboard-unable-to-handle-empty-channel-list January 7, 2021 21:54 Inactive
@jwm0 jwm0 requested review from orzechdev and removed request for krzysztofwolski and dominik-zeglen January 8, 2021 16:03
Copy link
Contributor

@jwm0 jwm0 left a 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

@github-actions github-actions bot temporarily deployed to saleor-1712-dashboard-unable-to-handle-empty-channel-list January 12, 2021 14:27 Inactive
@github-actions github-actions bot temporarily deployed to storybook saleor-1712-dashboard-unable-to-handle-empty-channel-list January 12, 2021 14:27 Inactive
@github-actions github-actions bot temporarily deployed to saleor-1712-dashboard-unable-to-handle-empty-channel-list January 13, 2021 09:09 Inactive
@jwm0 jwm0 merged commit d0be941 into master Jan 13, 2021
@jwm0 jwm0 deleted the SALEOR-1712-dashboard-unable-to-handle-empty-channel-list branch January 13, 2021 09:33
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.

4 participants