mirror of
https://github.com/datahub-project/datahub.git
synced 2025-11-30 20:56:03 +00:00
refactors comments feature: initial get comments and create comment updates tsconfig to support es2017 object prototype methods: values, entries, creates user-avatar component, adds styles, converts constants files to ts updates comment editor. updates styling. adds auto focus on click adds comment deletion adds confirmation dialog for comment deletion adds string union generic constraint type. adds comment stream header. adds comment update feature. adds style modifications and additions for comment components. refactors actions for comments using strategy pattern to allow for abstraction. adds dataset-constants constants module
56 lines
1.7 KiB
TypeScript
56 lines
1.7 KiB
TypeScript
import Ember from 'ember';
|
|
import { CommentTypes } from 'wherehows-web/constants';
|
|
import { StringUnionKeyToValue } from 'wherehows-web/typings/generic';
|
|
import { DatasetStreamActionsUnion } from 'wherehows-web/constants';
|
|
|
|
const { Component, assert } = Ember;
|
|
|
|
const StreamActions: StringUnionKeyToValue<DatasetStreamActionsUnion> = {
|
|
add: 'add',
|
|
modify: 'modify',
|
|
destroy: 'destroy'
|
|
};
|
|
|
|
export default Component.extend({
|
|
classNames: ['dataset-comments'],
|
|
|
|
/**
|
|
* Mapping of available dataset stream action
|
|
* @type {StringUnionKeyToValue<DatasetStreamActionsUnion>}
|
|
*/
|
|
streamActions: StreamActions,
|
|
|
|
/**
|
|
* Comments on the parent dataset
|
|
* @type Array<IDatasetComment>
|
|
*/
|
|
comments: [],
|
|
|
|
/**
|
|
* List of available comment types
|
|
* @type ReadonlyArray<CommentTypeUnion>
|
|
*/
|
|
commentTypes: CommentTypes,
|
|
|
|
actions: {
|
|
/**
|
|
* Handles the action for adding | modifying | destroying a dataset comment
|
|
* invokes handler passed in from parent: controller
|
|
* @return {Promise<boolean>}
|
|
*/
|
|
handleStreamAction(strategy: DatasetStreamActionsUnion): Promise<boolean> {
|
|
const [, ...args] = [...Array.from(arguments)];
|
|
|
|
// assert that handler is in CommentAction needed since we are calling from component template
|
|
// TS currently has no jurisdiction there
|
|
assert(`Expected action to be one of ${Object.keys(StreamActions)}`, strategy in StreamActions);
|
|
|
|
return {
|
|
add: (): Promise<boolean> => this.attrs.addDatasetComment(...args),
|
|
destroy: (): Promise<boolean> => this.attrs.deleteDatasetComment(...args),
|
|
modify: (): Promise<boolean> => this.attrs.updateDatasetComment(...args)
|
|
}[strategy]();
|
|
}
|
|
}
|
|
});
|