+
+interface CollectionVersionBrowserProps {
+ currentCollection: CollectionResource | undefined;
+ versions: CollectionResource[];
+}
+
+interface CollectionVersionBrowserDispatchProps {
+ showVersion: (c: CollectionResource) => void;
+ handleContextMenu: (event: React.MouseEvent<HTMLElement>, collection: CollectionResource) => void;
+}
+
+const mapStateToProps = (state: RootState): CollectionVersionBrowserProps => {
+ const currentCollection = getResource<CollectionResource>(state.detailsPanel.resourceUuid)(state.resources);
+ const versions = (currentCollection
+ && filterResources(rsc =>
+ (rsc as CollectionResource).currentVersionUuid === currentCollection.currentVersionUuid)(state.resources)
+ .sort((a: CollectionResource, b: CollectionResource) => b.version - a.version) as CollectionResource[])
+ || [];
+ return { currentCollection, versions };
+};
+
+const mapDispatchToProps = () =>
+ (dispatch: Dispatch): CollectionVersionBrowserDispatchProps => ({
+ showVersion: (collection) => dispatch<any>(navigateTo(collection.uuid)),
+ handleContextMenu: (event: React.MouseEvent<HTMLElement>, collection: CollectionResource) => {
+ const menuKind = dispatch<any>(resourceUuidToContextMenuKind(collection.uuid));
+ if (collection && menuKind) {
+ dispatch<any>(openContextMenu(event, {
+ name: collection.name,
+ uuid: collection.uuid,
+ description: collection.description,
+ storageClassesDesired: collection.storageClassesDesired,
+ ownerUuid: collection.ownerUuid,
+ isTrashed: collection.isTrashed,
+ kind: collection.kind,
+ menuKind
+ }));
+ }
+ },
+ });
+
+const CollectionVersionBrowser = withStyles(styles)(
+ connect(mapStateToProps, mapDispatchToProps)(
+ ({ currentCollection, versions, showVersion, handleContextMenu, classes }: CollectionVersionBrowserProps & CollectionVersionBrowserDispatchProps & WithStyles<CssRules>) => {
+ return <div data-cy="collection-version-browser">
+ <Grid container>
+ <Grid item xs={2}>
+ <Typography variant="caption" className={classes.versionBrowserHeader}>
+ Nr
+ </Typography>
+ </Grid>
+ <Grid item xs={4}>
+ <Typography variant="caption" className={classes.versionBrowserHeader}>
+ Size
+ </Typography>
+ </Grid>
+ <Grid item xs={6}>
+ <Typography variant="caption" className={classes.versionBrowserHeader}>
+ Date
+ </Typography>
+ </Grid>
+ { versions.map(item => {
+ const isSelectedVersion = !!(currentCollection && currentCollection.uuid === item.uuid);
+ return (
+ <ListItem button style={{padding: '4px'}}
+ data-cy={`collection-version-browser-select-${item.version}`}
+ key={item.version}
+ onClick={e => showVersion(item)}
+ onContextMenu={event => handleContextMenu(event, item)}
+ selected={isSelectedVersion}
+ className={classes.versionBrowserItem}>
+ <Grid item xs={2}>
+ <Typography variant="caption" className={classes.versionBrowserField}>
+ {item.version}
+ </Typography>
+ </Grid>
+ <Grid item xs={4}>
+ <Typography variant="caption" className={classes.versionBrowserField}>
+ {formatFileSize(item.fileSizeTotal)}
+ </Typography>
+ </Grid>
+ <Grid item xs={6}>
+ <Typography variant="caption" className={classes.versionBrowserField}>
+ {formatDate(item.modifiedAt)}
+ </Typography>
+ </Grid>
+ <Grid item xs={12}>
+ <Typography variant="caption" className={classes.versionBrowserField}>
+ Modified by: <UserNameFromID uuid={item.modifiedByUserUuid} />
+ </Typography>
+ </Grid>
+ </ListItem>
+ );
+ })}
+ </Grid>
+ </div>;
+ }));