mirror of
https://github.com/datahub-project/datahub.git
synced 2025-08-14 04:06:45 +00:00

* Releases updated version of datahub-web client UI code * Fix typo in yarn lock * Change yarn lock to match yarn registry directories * Previous commit missed some paths * Even more changes to yarnlock missing in previous commit * Include codegen file for typings * Add files to get parity for datahub-web and current OS datahub-midtier * Add in typo fix from previous commit - change to proper license * Implement proper OS fix for person entity picture url * Workarounds for open source DH issues * Fixes institutional memory api and removes unopensourced tabs for datasets * Fixes search dataset deprecation and user search issue as a result of changes * Remove internal only options in the avatar menu
119 lines
3.7 KiB
TypeScript
119 lines
3.7 KiB
TypeScript
import Component from '@ember/component';
|
|
import { set } from '@ember/object';
|
|
import {
|
|
readDatasetSchemaComments,
|
|
createDatasetSchemaComment,
|
|
updateDatasetSchemaComment,
|
|
deleteDatasetSchemaComment
|
|
} from 'datahub-web/utils/api/datasets/schema-comments';
|
|
import { augmentObjectsWithHtmlComments } from 'datahub-web/utils/api/datasets/columns';
|
|
import { IDatasetComment } from 'datahub-web/typings/api/datasets/comments';
|
|
import { IDatasetColumn } from 'datahub-web/typings/api/datasets/columns';
|
|
import Notifications from '@datahub/utils/services/notifications';
|
|
import { NotificationEvent } from '@datahub/utils/constants/notifications';
|
|
import { action } from '@ember/object';
|
|
import { inject as service } from '@ember/service';
|
|
import { TaskInstance, task } from 'ember-concurrency';
|
|
import { ETask } from '@datahub/utils/types/concurrency';
|
|
|
|
enum SchemaCommentActions {
|
|
modify = 'modify',
|
|
destroy = 'destroy',
|
|
add = 'add'
|
|
}
|
|
|
|
interface IGetCommentsTaskArgs {
|
|
datasetId: number;
|
|
columnId: number;
|
|
comments: Array<IDatasetComment>;
|
|
}
|
|
|
|
export class SchemaComment extends Component {
|
|
comments: Array<IDatasetComment> = [];
|
|
count = 0;
|
|
datasetId = 0;
|
|
columnId = 0;
|
|
isShowingFieldComment = false;
|
|
|
|
/**
|
|
* Local reference to the notifications service
|
|
* @memberof SchemaComment
|
|
*/
|
|
@service
|
|
notifications: Notifications;
|
|
|
|
/**
|
|
* Enum of applicable values for schema comment actions
|
|
* @type {SchemaCommentActions}
|
|
*/
|
|
SchemaCommentActions = SchemaCommentActions;
|
|
|
|
/**
|
|
* Task to get related schema comments
|
|
* TODO: refactor move to container component
|
|
*/
|
|
@task(function*({
|
|
datasetId,
|
|
columnId,
|
|
comments
|
|
}: IGetCommentsTaskArgs): IterableIterator<Promise<Array<IDatasetComment>>> {
|
|
const schemaComments = ((yield readDatasetSchemaComments(datasetId, columnId)) as unknown) as Array<
|
|
IDatasetComment
|
|
>;
|
|
|
|
if (Array.isArray(schemaComments)) {
|
|
const withHtmlComments = augmentObjectsWithHtmlComments(
|
|
schemaComments.map(
|
|
({ text }): Partial<IDatasetColumn> => ({
|
|
comment: text
|
|
})
|
|
) as Array<IDatasetColumn>
|
|
);
|
|
comments.setObjects.call(comments, withHtmlComments);
|
|
}
|
|
})
|
|
getCommentsTask!: ETask<Promise<Array<IDatasetComment>>, IGetCommentsTaskArgs>;
|
|
|
|
@action
|
|
showComments(): TaskInstance<Promise<Array<IDatasetComment>>> {
|
|
const { datasetId, columnId, comments } = this;
|
|
set(this, 'isShowingFieldComment', true);
|
|
|
|
return this.getCommentsTask.perform({ datasetId, columnId, comments });
|
|
}
|
|
|
|
@action
|
|
hideComments(): boolean {
|
|
return set(this, 'isShowingFieldComment', false);
|
|
}
|
|
|
|
/**
|
|
* Given a schema comment action, invokes the related action to process the schema comment
|
|
* @param {SchemaCommentActions} strategy
|
|
* @return {Promise<boolean>}
|
|
*/
|
|
@action
|
|
async handleSchemaComment(strategy: SchemaCommentActions, options: { text?: string } = {}): Promise<boolean> {
|
|
const { text = '' } = options;
|
|
const { datasetId, columnId, notifications, comments, getCommentsTask } = this;
|
|
const { notify } = notifications;
|
|
|
|
const action = {
|
|
add: (): Promise<void> => createDatasetSchemaComment(datasetId, columnId, text),
|
|
modify: (): Promise<void> => updateDatasetSchemaComment(datasetId, columnId, text),
|
|
destroy: (): Promise<void> => deleteDatasetSchemaComment(datasetId, columnId)
|
|
}[strategy];
|
|
|
|
try {
|
|
await action();
|
|
notify({ type: NotificationEvent.success, content: 'Success!' });
|
|
// @ts-ignore ts limitation with the ember object model, fixed in ember 3.1 with es5 getters
|
|
getCommentsTask.perform({ datasetId, columnId, comments });
|
|
} catch (e) {
|
|
notify({ type: NotificationEvent.error, content: e.message });
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|