Skip to content

Allow actions to be passed to ItemTableAppBar #49

Closed
campb303 opened this issue Sep 17, 2020 · 8 comments
Closed

Allow actions to be passed to ItemTableAppBar #49

campb303 opened this issue Sep 17, 2020 · 8 comments
Assignees
Labels
enhancement Request for a change to existing functionality high-priority Needs immediate extra focus quickfix Immediately actionable and should be fast

Comments

@campb303
Copy link
Collaborator

campb303 commented Sep 17, 2020

Currently, the ItemTableAppBar accepts four props: title, setDarkMode, darkMode and theme. The title and theme props work as expected. The setDarkMode and darkMode props are passed for toggling dark mode. While this works for a single action, it is not a scalable solution for more actions to be added later.

Within ItemTableAppBar, it would be relatively simple to add more actions. This is what the current dark mode toggle looks like:

<Tooltip title={"Turn " + (props.darkMode ? "off" : "on") + " dark mode"} 
	arrow 
	onClick={toggleDarkMode} 
	TransitionComponent={Zoom}
>
	<IconButton color="inherit">
		{props.darkMode ? <DarkModeIcon /> : <LightModeIcon />}
	</IconButton>
</Tooltip>

This could could be made into a component with the following props:

  • tooltipTitle: a string to show in the tooltip on hover
  • onClick: a function to execute when the button is clicked
  • icon: the image/vector to display when clicked

The component could be used with those components like this:

<ItemTableAppBarAction
    tooltipTitle={"Hello World"}
    onClick={onClickHandler}
    icon={clicked ? <InactiveIcon/> : <ActiveIcon/>}
/>

The ItemTableAppBar could then be used without the darkMode and setDarkMode props but with the actions prop like this:

itemViewAppBarActions = [
    <ItemTableAppBarAction
        tooltipTitle={"Turn " + (props.darkMode ? "off" : "on") + " dark mode"} 
        onClick={setDarkMode}
        icon={darkMode ? <DarkModeIcon /> : <LightModeIcon />}
    />
];

<ItemTableAppBar
    title="webqueue2"
    theme={theme}
    actions={itemViewAppBarActions}
/>
@campb303 campb303 added enhancement Request for a change to existing functionality frontend labels Sep 17, 2020
@campb303 campb303 added this to the v1 milestone Sep 17, 2020
@campb303
Copy link
Collaborator Author

This should also apply to ItemViewAppbar.

@campb303 campb303 self-assigned this Oct 12, 2020
@campb303
Copy link
Collaborator Author

The ItemTableAppBar and ItemViewAppBar could likely be consolidated into a single component for simplicity as the two seems to serve very similar purposes and it would be cleaner to consolidate logic into one place.

Also, this needs to be done before the ItemTable can be made responsive.

@campb303 campb303 added the quickfix Immediately actionable and should be fast label Jan 5, 2021
@campb303 campb303 added the high-priority Needs immediate extra focus label Feb 5, 2021
@campb303 campb303 added this to To do in v1.0 Mar 8, 2021
@campb303 campb303 assigned campb303 and wrigh393 and unassigned campb303 Mar 17, 2021
@campb303 campb303 removed the frontend label Mar 17, 2021
@campb303 campb303 removed this from To do in v1.0 Apr 9, 2021
@wrigh393
Copy link
Collaborator

Working on this.

@campb303
Copy link
Collaborator Author

Disregard the need to consolidate the *AppBar components.

@wrigh393
Copy link
Collaborator

wrigh393 commented May 7, 2021

The actions for toolbars have been consolidated into a separate component to make the process of implementing more actions easier in the future. Here is how that component looks:

    <Toolbar variant="dense">
            <Tooltip title={tooltipTitle}
                          arrow
                          onClick={onClick}
                          TransitionComponent={Zoom}
             >
                  <IconButton color="inherit">
                        {icon}
                  </IconButton>
            </Tooltip> 
    </Toolbar>

Here is a list of the props for the component:

  • tooltipTitle string - this is the tip that is displayed when a user hovers over the icon/action
  • onClick function- The function that runs when the icon button is clicked
  • icon component - The icon that is displayed in the toolbar

@campb303 campb303 removed their assignment May 17, 2021
@campb303 campb303 added the high-priority Needs immediate extra focus label May 17, 2021
@campb303 campb303 assigned campb303 and unassigned wrigh393 May 24, 2021
@wrigh393 wrigh393 linked a pull request Jun 25, 2021 that will close this issue
@wrigh393
Copy link
Collaborator

This issue is waiting for #215 to be reviewed. Can be closed once this PR is merged.

@campb303 campb303 removed the overdue label Jul 6, 2021
@campb303 campb303 removed this from the proof-of-concept milestone Jul 6, 2021
@campb303
Copy link
Collaborator Author

Working on this. Tried to complete this with Tyler yesterday but react-storybook has broken. Currently attempting to fix an esoteric build issue. The issue seems to stem from eslint-loader being depricated and replacted by eslint-webpack-loader.

@campb303
Copy link
Collaborator Author

This has been resolved.

Passing actions to ItemTableAppBar
A new ItemTableAppBarAction component has been created. It wraps a provided MUI Icon in a React Tooltip and MUI IconButton and applies a given onClick function to toggle a given setting.

Example:

<ItemTableAppBarAction
  title="Logout"
  icon={<LogoutIcon />}
  onClick={logout()}
/>

An actions prop has been added to the ItemTableAppBar to allow for arbitrary actions to be passed. This prop expects a list of ItemTableAppBarAction components and renders the actions from left to right in the order they're declared.

Example:

<ItemTableAppBar
  title="webqueue2"
  actions={[
    <ItemTableAppBarAction
      title="Action 1"
      icon={<Action1Icon />}
      onClick={action1callback()}
    />,
    <ItemTableAppBarAction
      title="Action 2"
      icon={<Action2Icon />}
      onClick={action2callback()}
    />
  ]}
/>

Fixing Storybook build isues
In the latest version of Storybook there seems to be an issue with the webpack loader for eslint. Previously eslint-loader was used but has been deprecated by esline-webpack-loader but the dependencies of Storybook have not been updated to use the new eslint-webpack-loader and the older eslint-loader is broken.

To address this issue, the following packages were version locked to before this breaking change occured (v6.1.20):

  • @storybook/addon-actions
  • @storybook/addon-docs
  • @storybook/addon-essentials
  • @storybook/addon-links
  • @storybook/node-logger
  • @storybook/react

Sign in to join this conversation on GitHub.
Labels
enhancement Request for a change to existing functionality high-priority Needs immediate extra focus quickfix Immediately actionable and should be fast
Projects
None yet
2 participants