[ARVADOS-WORKBENCH2] created: 1.1.4-482-g2e60bb9
Git user
git at public.curoverse.com
Mon Aug 6 07:52:21 EDT 2018
at 2e60bb998178752c3a126f077cbb891b597ed91e (commit)
commit 2e60bb998178752c3a126f077cbb891b597ed91e
Author: Janicki Artur <artur.janicki at contractors.roche.com>
Date: Mon Aug 6 13:52:07 2018 +0200
init load tags for collection
Feature #13854
Arvados-DCO-1.1-Signed-off-by: Janicki Artur <artur.janicki at contractors.roche.com>
diff --git a/src/common/custom-theme.ts b/src/common/custom-theme.ts
index ecad391..b95913f 100644
--- a/src/common/custom-theme.ts
+++ b/src/common/custom-theme.ts
@@ -34,6 +34,7 @@ const grey500 = grey["500"];
const grey600 = grey["600"];
const grey700 = grey["700"];
const grey900 = grey["900"];
+const rocheBlue = '#06C';
const themeOptions: ArvadosThemeOptions = {
customs: {
@@ -113,6 +114,12 @@ const themeOptions: ArvadosThemeOptions = {
color: purple800
}
}
+ },
+ MuiChip: {
+ root: {
+ color: 'white',
+ backgroundColor: rocheBlue
+ }
}
},
mixins: {
@@ -122,7 +129,7 @@ const themeOptions: ArvadosThemeOptions = {
},
palette: {
primary: {
- main: '#06C',
+ main: rocheBlue,
dark: blue.A100
}
}
diff --git a/src/models/link.ts b/src/models/link.ts
index 8686528..8665c9e 100644
--- a/src/models/link.ts
+++ b/src/models/link.ts
@@ -9,9 +9,18 @@ export interface LinkResource extends Resource {
tailUuid: string;
linkClass: string;
name: string;
- properties: {};
+ properties: {
+ key?: string;
+ value?: any;
+ };
+}
+
+export enum TailType {
+ COLLECTION = 'Collection',
+ JOB = 'Job'
}
export enum LinkClass {
- STAR = 'star'
+ STAR = 'star',
+ TAG = 'tag'
}
\ No newline at end of file
diff --git a/src/services/services.ts b/src/services/services.ts
index 1f0e23a..f56a30f 100644
--- a/src/services/services.ts
+++ b/src/services/services.ts
@@ -9,9 +9,9 @@ import { LinkService } from "./link-service/link-service";
import { FavoriteService } from "./favorite-service/favorite-service";
import { AxiosInstance } from "axios";
import { CommonResourceService } from "../common/api/common-resource-service";
-import { CollectionResource } from "../models/collection";
import { Resource } from "../models/resource";
import { CollectionService } from "./collection-service/collection-service";
+import { TagService } from "./tag-service/tag-service";
import Axios from "axios";
export interface ServiceRepository {
@@ -23,6 +23,7 @@ export interface ServiceRepository {
linkService: LinkService;
favoriteService: FavoriteService;
collectionService: CommonResourceService<Resource>;
+ tagService: TagService;
}
export const createServices = (baseUrl: string): ServiceRepository => {
@@ -35,7 +36,8 @@ export const createServices = (baseUrl: string): ServiceRepository => {
const linkService = new LinkService(apiClient);
const favoriteService = new FavoriteService(linkService, groupsService);
const collectionService = new CollectionService(apiClient);
-
+ const tagService = new TagService(linkService);
+
return {
apiClient,
authService,
@@ -43,6 +45,7 @@ export const createServices = (baseUrl: string): ServiceRepository => {
projectService,
linkService,
favoriteService,
- collectionService
+ collectionService,
+ tagService
};
};
diff --git a/src/services/tag-service/tag-service.ts b/src/services/tag-service/tag-service.ts
new file mode 100644
index 0000000..78c930d
--- /dev/null
+++ b/src/services/tag-service/tag-service.ts
@@ -0,0 +1,37 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import { LinkService } from "../link-service/link-service";
+import { LinkResource, LinkClass, TailType } from "../../models/link";
+import { FilterBuilder } from "../../common/api/filter-builder";
+
+export class TagService {
+
+ constructor(private linkService: LinkService) { }
+
+ create(uuid: string, data: { key: string; value: string } ) {
+ return this.linkService.create({
+ headUuid: uuid,
+ tailUuid: TailType.COLLECTION,
+ linkClass: LinkClass.TAG,
+ name: '',
+ properties: data
+ });
+ }
+
+ list(uuid: string) {
+ const filters = FilterBuilder
+ .create<LinkResource>()
+ .addEqual("headUuid", uuid)
+ .addEqual("tailUuid", TailType.COLLECTION)
+ .addEqual("linkClass", LinkClass.TAG);
+
+ return this.linkService
+ .list({ filters })
+ .then(results => {
+ return results.items;
+ });
+ }
+
+}
\ No newline at end of file
diff --git a/src/store/collection-panel/collection-panel-action.ts b/src/store/collection-panel/collection-panel-action.ts
index 673f9f0..083e548 100644
--- a/src/store/collection-panel/collection-panel-action.ts
+++ b/src/store/collection-panel/collection-panel-action.ts
@@ -8,10 +8,15 @@ import { ResourceKind } from "../../models/resource";
import { CollectionResource } from "../../models/collection";
import { RootState } from "../store";
import { ServiceRepository } from "../../services/services";
+import { LinkClass, LinkResource } from "../../models/link";
export const collectionPanelActions = unionize({
LOAD_COLLECTION: ofType<{ uuid: string, kind: ResourceKind }>(),
- LOAD_COLLECTION_SUCCESS: ofType<{ item: CollectionResource }>()
+ LOAD_COLLECTION_SUCCESS: ofType<{ item: CollectionResource }>(),
+ LOAD_COLLECTION_TAGS: ofType<{ uuid: string }>(),
+ LOAD_COLLECTION_TAGS_SUCCESS: ofType<{ tags: LinkResource[] }>(),
+ CREATE_COLLECTION_TAG: ofType<{ data: any }>(),
+ CREATE_COLLECTION_TAG_SUCCESS: ofType<{ tag: LinkResource }>()
}, { tag: 'type', value: 'payload' });
export type CollectionPanelAction = UnionOf<typeof collectionPanelActions>;
@@ -26,5 +31,29 @@ export const loadCollection = (uuid: string, kind: ResourceKind) =>
});
};
+export const loadCollectionTags = (uuid: string) =>
+ (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
+ dispatch(collectionPanelActions.LOAD_COLLECTION_TAGS({ uuid }));
+ return services.tagService
+ .list(uuid)
+ .then(tags => {
+ dispatch(collectionPanelActions.LOAD_COLLECTION_TAGS_SUCCESS({ tags }));
+ });
+ };
+export const createCollectionTag = (uuid: string, data: {}) =>
+ (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
+ const linkResource = {
+ key: 'testowanie',
+ value: 'by Arturo'
+ };
+
+ dispatch(collectionPanelActions.CREATE_COLLECTION_TAG({ data: linkResource }));
+ return services.tagService
+ .create(uuid, linkResource)
+ .then(tag => {
+ console.log('tag: ', tag);
+ dispatch(collectionPanelActions.CREATE_COLLECTION_TAG_SUCCESS({ tag }));
+ });
+ };
diff --git a/src/store/collection-panel/collection-panel-reducer.ts b/src/store/collection-panel/collection-panel-reducer.ts
index 0dd233e..61f4127 100644
--- a/src/store/collection-panel/collection-panel-reducer.ts
+++ b/src/store/collection-panel/collection-panel-reducer.ts
@@ -4,18 +4,22 @@
import { collectionPanelActions, CollectionPanelAction } from "./collection-panel-action";
import { CollectionResource } from "../../models/collection";
+import { LinkResource } from "../../models/link";
export interface CollectionPanelState {
item: CollectionResource | null;
+ tags: LinkResource[];
}
const initialState = {
- item: null
+ item: null,
+ tags: []
};
export const collectionPanelReducer = (state: CollectionPanelState = initialState, action: CollectionPanelAction) =>
collectionPanelActions.match(action, {
default: () => state,
- LOAD_COLLECTION: () => state,
LOAD_COLLECTION_SUCCESS: ({ item }) => ({ ...state, item }),
+ LOAD_COLLECTION_TAGS_SUCCESS: ({ tags }) => ({...state, tags}),
+ CREATE_COLLECTION_TAG_SUCCESS: ({ tag }) => ({...state, tags: [...state.tags, tag] })
});
diff --git a/src/views/collection-panel/collection-panel.tsx b/src/views/collection-panel/collection-panel.tsx
index 21d28b9..3296190 100644
--- a/src/views/collection-panel/collection-panel.tsx
+++ b/src/views/collection-panel/collection-panel.tsx
@@ -5,9 +5,9 @@
import * as React from 'react';
import {
StyleRulesCallback, WithStyles, withStyles, Card,
- CardHeader, IconButton, CardContent, Grid, Chip
+ CardHeader, IconButton, CardContent, Grid, Chip, TextField, Button
} from '@material-ui/core';
-import { connect } from 'react-redux';
+import { connect, DispatchProp } from "react-redux";
import { RouteComponentProps } from 'react-router';
import { ArvadosTheme } from '../../common/custom-theme';
import { RootState } from '../../store/store';
@@ -15,6 +15,8 @@ import { MoreOptionsIcon, CollectionIcon, CopyIcon } from '../../components/icon
import { DetailsAttribute } from '../../components/details-attribute/details-attribute';
import { CollectionResource } from '../../models/collection';
import * as CopyToClipboard from 'react-copy-to-clipboard';
+import { createCollectionTag } from '../../store/collection-panel/collection-panel-action';
+import { LinkResource } from '../../models/link';
type CssRules = 'card' | 'iconHeader' | 'tag' | 'copyIcon';
@@ -32,12 +34,14 @@ const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
copyIcon: {
marginLeft: theme.spacing.unit,
fontSize: '1.125rem',
+ color: theme.palette.grey["500"],
cursor: 'pointer'
}
});
interface CollectionPanelDataProps {
item: CollectionResource;
+ tags: LinkResource[];
}
interface CollectionPanelActionProps {
@@ -45,16 +49,19 @@ interface CollectionPanelActionProps {
onContextMenu: (event: React.MouseEvent<HTMLElement>, item: CollectionResource) => void;
}
-type CollectionPanelProps = CollectionPanelDataProps & CollectionPanelActionProps
+type CollectionPanelProps = CollectionPanelDataProps & CollectionPanelActionProps & DispatchProp
& WithStyles<CssRules> & RouteComponentProps<{ id: string }>;
export const CollectionPanel = withStyles(styles)(
- connect((state: RootState) => ({ item: state.collectionPanel.item }))(
+ connect((state: RootState) => ({
+ item: state.collectionPanel.item,
+ tags: state.collectionPanel.tags
+ }))(
class extends React.Component<CollectionPanelProps> {
render() {
- const { classes, item, onContextMenu } = this.props;
+ const { classes, item, tags, onContextMenu } = this.props;
return <div>
<Card className={classes.card}>
<CardHeader
@@ -87,10 +94,17 @@ export const CollectionPanel = withStyles(styles)(
<CardHeader title="Tags" />
<CardContent>
<Grid container direction="column">
- <Grid item xs={4}>
- <Chip label="Tag 1" className={classes.tag}/>
- <Chip label="Tag 2" className={classes.tag}/>
- <Chip label="Tag 3" className={classes.tag}/>
+ <Grid item xs={12}>
+ {/* Temporarty button to add new tag */}
+ <Button onClick={this.addTag}>Add Tag</Button>
+ </Grid>
+ <Grid item xs={12}>
+ {
+ tags.map(tag => {
+ return <Chip key={tag.etag} className={classes.tag}
+ label={renderTagLabel(tag)} />;
+ })
+ }
</Grid>
</Grid>
</CardContent>
@@ -109,6 +123,11 @@ export const CollectionPanel = withStyles(styles)(
</div>;
}
+ // Temporary method to add new tag
+ addTag = () => {
+ this.props.dispatch<any>(createCollectionTag(this.props.item.uuid, 'dodalem nowy'));
+ }
+
componentWillReceiveProps({ match, item, onItemRouteChange }: CollectionPanelProps) {
if (!item || match.params.id !== item.uuid) {
onItemRouteChange(match.params.id);
@@ -117,4 +136,9 @@ export const CollectionPanel = withStyles(styles)(
}
)
-);
\ No newline at end of file
+);
+
+const renderTagLabel = (tag: LinkResource) => {
+ const { properties } = tag;
+ return `${properties.key}: ${properties.value}`;
+};
\ No newline at end of file
diff --git a/src/views/workbench/workbench.tsx b/src/views/workbench/workbench.tsx
index dcce725..8491d17 100644
--- a/src/views/workbench/workbench.tsx
+++ b/src/views/workbench/workbench.tsx
@@ -39,7 +39,7 @@ import { Snackbar } from '../../views-components/snackbar/snackbar';
import { favoritePanelActions } from '../../store/favorite-panel/favorite-panel-action';
import { CreateCollectionDialog } from '../../views-components/create-collection-dialog/create-collection-dialog';
import { CollectionPanel } from '../collection-panel/collection-panel';
-import { loadCollection } from '../../store/collection-panel/collection-panel-action';
+import { loadCollection, loadCollectionTags } from '../../store/collection-panel/collection-panel-action';
import { getCollectionUrl } from '../../models/collection';
import { UpdateCollectionDialog } from '../../views-components/update-collection-dialog/update-collection-dialog.';
import { AuthService } from "../../services/auth-service/auth-service";
@@ -242,7 +242,10 @@ export const Workbench = withStyles(styles)(
}
renderCollectionPanel = (props: RouteComponentProps<{ id: string }>) => <CollectionPanel
- onItemRouteChange={(collectionId) => this.props.dispatch<any>(loadCollection(collectionId, ResourceKind.COLLECTION))}
+ onItemRouteChange={(collectionId) => {
+ this.props.dispatch<any>(loadCollection(collectionId, ResourceKind.COLLECTION));
+ this.props.dispatch<any>(loadCollectionTags(collectionId));
+ }}
onContextMenu={(event, item) => {
this.openContextMenu(event, {
uuid: item.uuid,
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list