import { msToggleTrashAction } from "views-components/multiselect-toolbar/ms-project-action-set";
import { copyToClipboardAction } from "store/open-in-new-tab/open-in-new-tab.actions";
import { ContainerRequestResource } from "models/container-request";
+import { FavoritesState } from "store/favorites/favorites-reducer";
type CssRules = "root" | "button";
width: 0,
padding: 0,
margin: "1rem auto auto 0.5rem",
- overflow: "hidden",
+ overflowY: 'scroll',
transition: "width 150ms",
},
button: {
export type MultiselectToolbarProps = {
checkedList: TCheckedList;
selectedUuid: string | null
- resources: ResourcesState;
+ iconProps: IconProps
executeMulti: (action: ContextMenuAction, checkedList: TCheckedList, resources: ResourcesState) => void;
- favorites: any
};
+type IconProps = {
+ resources: ResourcesState;
+ favorites: FavoritesState
+}
+
export const MultiselectToolbar = connect(
mapStateToProps,
mapDispatchToProps
)(
withStyles(styles)((props: MultiselectToolbarProps & WithStyles<CssRules>) => {
- const { classes, checkedList, resources, selectedUuid, favorites } = props;
+ const { classes, checkedList, selectedUuid: singleSelectedUuid, iconProps } = props;
const currentResourceKinds = Array.from(selectedToKindSet(checkedList));
const currentPathIsTrash = window.location.pathname === "/trash";
- const buttons =
- currentPathIsTrash && selectedToKindSet(checkedList).size
- ? [msToggleTrashAction]
- : selectActionsByKind(currentResourceKinds, multiselectActionsFilters);
+ const actions =
+ currentPathIsTrash && selectedToKindSet(checkedList).size
+ ? [msToggleTrashAction]
+ : selectActionsByKind(currentResourceKinds, multiselectActionsFilters)
+ .filter((action) => (singleSelectedUuid === null ? action.isForMulti : true));
return (
<React.Fragment>
<Toolbar
className={classes.root}
- style={{ width: `${buttons.length * 2.5}rem` }}
+ style={{ width: `${actions.length * 2.5}rem` }}
>
- {buttons.length ? (
- buttons.map((btn, i) =>
- btn.isDefault ? (
+ {actions.length ? (
+ actions.map((action, i) =>
+ action.hasAlts ? (
<Tooltip
className={classes.button}
- title={btn.isDefault(selectedUuid, resources, favorites) ? btn.defaultText : btn.altText}
+ title={currentPathIsTrash || action.useAlts(singleSelectedUuid, iconProps) ? action.altName : action.name}
key={i}
disableFocusListener
>
- <IconButton onClick={() => props.executeMulti(btn, checkedList, resources)}>
- {btn.isDefault(selectedUuid, resources, favorites) ? btn.icon && btn.icon({}) : btn.altIcon && btn.altIcon({})}
+ <IconButton onClick={() => props.executeMulti(action, checkedList, iconProps.resources)}>
+ {currentPathIsTrash || action.useAlts(singleSelectedUuid, iconProps) ? action.altIcon && action.altIcon({}) : action.icon({})}
</IconButton>
</Tooltip>
) : (
<Tooltip
className={classes.button}
- title={btn.name}
+ title={action.name}
key={i}
disableFocusListener
>
- <IconButton onClick={() => props.executeMulti(btn, checkedList, resources)}>{btn.icon ? btn.icon({}) : <></>}</IconButton>
+ <IconButton onClick={() => props.executeMulti(action, checkedList, iconProps.resources)}>{action.icon({})}</IconButton>
</Tooltip>
)
)
});
const filteredNameSet = allFiltersArray.map(filterArray => {
- const resultSet = new Set();
- filterArray.forEach(action => resultSet.add(action.name || ""));
+ const resultSet = new Set<string>();
+ filterArray.forEach(action => resultSet.add(action.name as string || ""));
return resultSet;
});
const filteredResult = Array.from(rawResult).filter(action => {
for (let i = 0; i < filteredNameSet.length; i++) {
- if (!filteredNameSet[i].has(action.name)) return false;
+ if (!filteredNameSet[i].has(action.name as string)) return false;
}
return true;
});
});
}
-const isExactlyOneSelected = (checkedList: TCheckedList) => {
+export const isExactlyOneSelected = (checkedList: TCheckedList) => {
let tally = 0;
let current = '';
for (const uuid in checkedList) {
//--------------------------------------------------//
-function mapStateToProps(state: RootState) {
+function mapStateToProps({multiselect, resources, favorites}: RootState) {
return {
- checkedList: state.multiselect.checkedList as TCheckedList,
- selectedUuid: isExactlyOneSelected(state.multiselect.checkedList),
- resources: state.resources,
- favorites: state.favorites
- };
+ checkedList: multiselect.checkedList as TCheckedList,
+ selectedUuid: isExactlyOneSelected(multiselect.checkedList),
+ iconProps: {
+ resources,
+ favorites
+ }
+ }
}
function mapDispatchToProps(dispatch: Dispatch) {