From f7cdbfa28c3867076fe25feb5d89b62592a9bf81 Mon Sep 17 00:00:00 2001 From: Janicki Artur Date: Mon, 6 Aug 2018 14:22:37 +0200 Subject: [PATCH] create tag model and change code Feature #13854 Arvados-DCO-1.1-Signed-off-by: Janicki Artur --- src/models/link.ts | 10 +------- src/models/tag.ts | 20 +++++++++++++++ src/services/tag-service/tag-service.ts | 25 +++++++++++-------- .../collection-panel-action.ts | 23 ++++++++--------- .../collection-panel-reducer.ts | 4 +-- .../collection-panel/collection-panel.tsx | 8 +++--- 6 files changed, 52 insertions(+), 38 deletions(-) create mode 100644 src/models/tag.ts diff --git a/src/models/link.ts b/src/models/link.ts index 8665c9ea..da9dfd03 100644 --- a/src/models/link.ts +++ b/src/models/link.ts @@ -9,15 +9,7 @@ export interface LinkResource extends Resource { tailUuid: string; linkClass: string; name: string; - properties: { - key?: string; - value?: any; - }; -} - -export enum TailType { - COLLECTION = 'Collection', - JOB = 'Job' + properties: {}; } export enum LinkClass { diff --git a/src/models/tag.ts b/src/models/tag.ts new file mode 100644 index 00000000..9c229aff --- /dev/null +++ b/src/models/tag.ts @@ -0,0 +1,20 @@ +// Copyright (C) The Arvados Authors. All rights reserved. +// +// SPDX-License-Identifier: AGPL-3.0 + +import { LinkResource } from "./link"; + +export interface TagResource extends LinkResource { + tailUuid: TagTailType; + properties: TagProperty; +} + +export interface TagProperty { + key: string; + value: string; +} + +export enum TagTailType { + COLLECTION = 'Collection', + JOB = 'Job' +} \ No newline at end of file diff --git a/src/services/tag-service/tag-service.ts b/src/services/tag-service/tag-service.ts index 78c930d2..d8caca2c 100644 --- a/src/services/tag-service/tag-service.ts +++ b/src/services/tag-service/tag-service.ts @@ -3,34 +3,37 @@ // SPDX-License-Identifier: AGPL-3.0 import { LinkService } from "../link-service/link-service"; -import { LinkResource, LinkClass, TailType } from "../../models/link"; +import { LinkClass } from "../../models/link"; import { FilterBuilder } from "../../common/api/filter-builder"; +import { TagTailType, TagResource } from "../../models/tag"; 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 - }); + return this.linkService + .create({ + headUuid: uuid, + tailUuid: TagTailType.COLLECTION, + linkClass: LinkClass.TAG, + name: '', + properties: data + }) + .then(tag => tag as TagResource ); } list(uuid: string) { const filters = FilterBuilder - .create() + .create() .addEqual("headUuid", uuid) - .addEqual("tailUuid", TailType.COLLECTION) + .addEqual("tailUuid", TagTailType.COLLECTION) .addEqual("linkClass", LinkClass.TAG); return this.linkService .list({ filters }) .then(results => { - return results.items; + return results.items.map((tag => tag as TagResource )); }); } diff --git a/src/store/collection-panel/collection-panel-action.ts b/src/store/collection-panel/collection-panel-action.ts index 083e548c..01f430c0 100644 --- a/src/store/collection-panel/collection-panel-action.ts +++ b/src/store/collection-panel/collection-panel-action.ts @@ -8,15 +8,16 @@ 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"; +import { TagResource, TagProperty } from "../../models/tag"; +import { snackbarActions } from "../snackbar/snackbar-actions"; export const collectionPanelActions = unionize({ LOAD_COLLECTION: ofType<{ uuid: string, kind: ResourceKind }>(), LOAD_COLLECTION_SUCCESS: ofType<{ item: CollectionResource }>(), LOAD_COLLECTION_TAGS: ofType<{ uuid: string }>(), - LOAD_COLLECTION_TAGS_SUCCESS: ofType<{ tags: LinkResource[] }>(), + LOAD_COLLECTION_TAGS_SUCCESS: ofType<{ tags: TagResource[] }>(), CREATE_COLLECTION_TAG: ofType<{ data: any }>(), - CREATE_COLLECTION_TAG_SUCCESS: ofType<{ tag: LinkResource }>() + CREATE_COLLECTION_TAG_SUCCESS: ofType<{ tag: TagResource }>() }, { tag: 'type', value: 'payload' }); export type CollectionPanelAction = UnionOf; @@ -42,18 +43,16 @@ export const loadCollectionTags = (uuid: string) => }; -export const createCollectionTag = (uuid: string, data: {}) => +export const createCollectionTag = (uuid: string, data: TagProperty) => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { - const linkResource = { - key: 'testowanie', - value: 'by Arturo' - }; - - dispatch(collectionPanelActions.CREATE_COLLECTION_TAG({ data: linkResource })); + dispatch(collectionPanelActions.CREATE_COLLECTION_TAG({ data })); return services.tagService - .create(uuid, linkResource) + .create(uuid, data) .then(tag => { - console.log('tag: ', tag); dispatch(collectionPanelActions.CREATE_COLLECTION_TAG_SUCCESS({ tag })); + dispatch(snackbarActions.OPEN_SNACKBAR({ + message: "Tag has been successfully added.", + hideDuration: 2000 + })); }); }; diff --git a/src/store/collection-panel/collection-panel-reducer.ts b/src/store/collection-panel/collection-panel-reducer.ts index 61f4127f..ac07ae37 100644 --- a/src/store/collection-panel/collection-panel-reducer.ts +++ b/src/store/collection-panel/collection-panel-reducer.ts @@ -4,11 +4,11 @@ import { collectionPanelActions, CollectionPanelAction } from "./collection-panel-action"; import { CollectionResource } from "../../models/collection"; -import { LinkResource } from "../../models/link"; +import { TagResource } from "../../models/tag"; export interface CollectionPanelState { item: CollectionResource | null; - tags: LinkResource[]; + tags: TagResource[]; } const initialState = { diff --git a/src/views/collection-panel/collection-panel.tsx b/src/views/collection-panel/collection-panel.tsx index 32961905..271fb8bc 100644 --- a/src/views/collection-panel/collection-panel.tsx +++ b/src/views/collection-panel/collection-panel.tsx @@ -16,7 +16,7 @@ import { DetailsAttribute } from '../../components/details-attribute/details-att 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'; +import { TagResource } from '../../models/tag'; type CssRules = 'card' | 'iconHeader' | 'tag' | 'copyIcon'; @@ -41,7 +41,7 @@ const styles: StyleRulesCallback = (theme: ArvadosTheme) => ({ interface CollectionPanelDataProps { item: CollectionResource; - tags: LinkResource[]; + tags: TagResource[]; } interface CollectionPanelActionProps { @@ -125,7 +125,7 @@ export const CollectionPanel = withStyles(styles)( // Temporary method to add new tag addTag = () => { - this.props.dispatch(createCollectionTag(this.props.item.uuid, 'dodalem nowy')); + this.props.dispatch(createCollectionTag(this.props.item.uuid, { key: 'test', value: 'value for tag'})); } componentWillReceiveProps({ match, item, onItemRouteChange }: CollectionPanelProps) { @@ -138,7 +138,7 @@ export const CollectionPanel = withStyles(styles)( ) ); -const renderTagLabel = (tag: LinkResource) => { +const renderTagLabel = (tag: TagResource) => { const { properties } = tag; return `${properties.key}: ${properties.value}`; }; \ No newline at end of file -- 2.30.2