Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(frontend): Catchup frontend for internal development changes #1933

Merged
merged 2 commits into from
Oct 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { encodeUrn } from '@datahub/utils/validators/urn';
* @param {ApiVersion} version the version of the api applicable to retrieve the Dataset
* @returns {string}
*/
export const datasetUrlRoot = (version: ApiVersion): string => `${getApiRoot(version)}/datasets`;
const datasetUrlRoot = (version: ApiVersion): string => `${getApiRoot(version)}/datasets`;

/**
* Constructs the url for a dataset identified by the provided string urn
Expand All @@ -16,6 +16,13 @@ export const datasetUrlRoot = (version: ApiVersion): string => `${getApiRoot(ver
*/
export const datasetUrlByUrn = (urn: string): string => `${datasetUrlRoot(ApiVersion.v2)}/${encodeUrn(urn)}`;

/**
* Constructs the url for a dataset identified by the provided string urn
* @param {string} urn the urn to use in querying for dataset entity
* @returns {string}
*/
export const datasetV1UrlByUrn = (urn: string): string => `${datasetUrlRoot(ApiVersion.v1)}/${encodeUrn(urn)}`;

/**
* Reads a dataset entity from api
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { datasetUrlByUrn } from '@datahub/data-models/api/dataset/dataset';
import { IDatasetSchema } from '@datahub/metadata-types/types/entity/dataset/scehma';
import { IDatasetSchema } from '@datahub/metadata-types/types/entity/dataset/schema';
import { getJSON } from '@datahub/utils/api/fetcher';

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ListEntity } from '@datahub/data-models/entity/list/list-entity';
import { BaseEntity } from '@datahub/data-models/entity/base-entity';
import { IBaseEntity } from '@datahub/metadata-types/types/entity/index';
import { DataConstructChangeManagementEntity } from '@datahub/data-models/entity/data-construct-change-management/data-construct-change-management-entity';
import { GroupEntity } from '@datahub/data-models/entity/group/group-entity';

/**
* Defines the interface for the DataModelEntity enum below.
Expand All @@ -13,6 +14,7 @@ export interface IDataModelEntity {
[DatasetEntity.displayName]: typeof DatasetEntity;
[PersonEntity.displayName]: typeof PersonEntity;
[ListEntity.displayName]: typeof ListEntity;
[GroupEntity.displayName]: typeof GroupEntity;
[DataConstructChangeManagementEntity.displayName]: typeof DataConstructChangeManagementEntity;
}

Expand All @@ -23,6 +25,7 @@ export interface IDataModelEntity {
export const DataModelEntity: IDataModelEntity = {
[DatasetEntity.displayName]: DatasetEntity,
[PersonEntity.displayName]: PersonEntity,
[GroupEntity.displayName]: GroupEntity,
[ListEntity.displayName]: ListEntity,
[DataConstructChangeManagementEntity.displayName]: DataConstructChangeManagementEntity
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ export class DataConstructChangeManagementEntity extends BaseEntity<
search: {
placeholder: '',
attributes: [],
isEnabled: false
isEnabled: false,
defaultAspects: []
}
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import DatasetComplianceAnnotation from '@datahub/data-models/entity/dataset/modules/compliance-annotation';
import DatasetSchema from '@datahub/data-models/entity/dataset/modules/schema';
import { IDatasetSchemaColumn } from '@datahub/metadata-types/types/entity/dataset/scehma';
import { IDatasetSchemaColumn } from '@datahub/metadata-types/types/entity/dataset/schema';

/**
* Given a list of compliance annotations and a schema to match against, removes annotations for
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IDatasetSchema, IDatasetSchemaColumn } from '@datahub/metadata-types/types/entity/dataset/scehma';
import { IDatasetSchema, IDatasetSchemaColumn } from '@datahub/metadata-types/types/entity/dataset/schema';
import { oneWay } from '@ember/object/computed';

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ import { DatasetTab } from '@datahub/data-models/constants/entity/dataset/tabs';
import { IEntityRenderProps } from '@datahub/data-models/types/entity/rendering/entity-render-props';
import { fields } from '@datahub/data-models/entity/dataset/fields';

/**
* Aspects for search datasets
*/
const defaultAspects: Array<keyof Com.Linkedin.Metadata.Aspect.DatasetAspect> = [
'com.linkedin.common.Health',
'com.linkedin.common.Likes',
'com.linkedin.common.EntityTopUsage',
'com.linkedin.common.Status'
];

/**
* Class properties common across instances
* Dictates how visual ui components should be rendered
Expand All @@ -27,10 +37,12 @@ export const getRenderProps = (): IEntityRenderProps => {
},
{ name: 'social/containers/social-metadata' }
],
isEnabled: true
isEnabled: true,
defaultAspects
},
userEntityOwnership: {
attributes: fields
attributes: fields,
defaultAspects
},
browse: {
showHierarchySearch: false
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { BaseEntity, statics, IBaseEntityStatics } from '@datahub/data-models/entity/base-entity';
import { IEntityRenderProps } from '@datahub/data-models/types/entity/rendering/entity-render-props';
import { ICorpGroupResponse } from '@datahub/metadata-types/types/entity/group/group-entity';

/**
* The GroupEntity represents a group of people entities, most often associated with headless
* accounts or group aliases.
*/
@statics<IBaseEntityStatics<ICorpGroupResponse>>()
export class GroupEntity extends BaseEntity<ICorpGroupResponse> {
/**
* Identifier for the entity
*/
static displayName: 'corp-groups' = 'corp-groups';

/**
* Class properties common across instances
* Dictates how visual ui components should be rendered
* Implemented as a getter to ensure that reads are idempotent
* @readonly
* @static
*/
static get renderProps(): IEntityRenderProps {
return {
apiEntityName: 'corpgroup',
search: {
placeholder: '',
attributes: [],
isEnabled: false,
defaultAspects: []
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ export class ListEntity extends BaseEntity<{}> {
search: {
placeholder: '',
attributes: [],
isEnabled: false
isEnabled: false,
defaultAspects: []
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ export class MockEntity<E = IBaseEntity> extends BaseEntity<E> {
desc: 'A mock field',
example: 'Evolutionary'
}
]
],
defaultAspects: []
},
entityPage: {
route: 'entity-type.urn',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ export interface IPersonEntitySpecificConfigs {
*
* Making sure entityPage is not marked optional in the types as we know it is defined
*/
export const getRenderProps = (): IEntityRenderProps & { entityPage: IEntityRenderPropsEntityPage } => {
export const getRenderProps = (): IEntityRenderProps & {
entityPage: IEntityRenderPropsEntityPage;
} => {
const tabIds = [PersonTab.UserOwnership];
const aspects: Array<keyof Com.Linkedin.Metadata.Aspect.CorpUserAspect> = ['com.linkedin.identity.CorpUserInfo'];

return {
apiEntityName: 'corpuser',
Expand Down Expand Up @@ -96,7 +99,8 @@ export const getRenderProps = (): IEntityRenderProps & { entityPage: IEntityRend
showFacets: false,
placeholder: 'Search for People...',
autocompleteNameField: 'fullName',
isEnabled: true
isEnabled: true,
defaultAspects: aspects
}
};
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Factory, faker } from 'ember-cli-mirage';
import { IDatasetSchemaColumn } from '@datahub/metadata-types/types/entity/dataset/schema';

export default Factory.extend<IDatasetSchemaColumn>({
comment: faker.lorem.sentence,
//faker 3 does not have database
dataType: (faker.database && faker.database.type) || ((i: number): string => `data_type_${i}`),
distributed: faker.random.boolean,
//faker 3 does not have database
fieldName: (faker.database && faker.database.column) || ((i: number): string => `field_name_${i}`),
fullFieldPath: faker.system.filePath,
indexed: faker.random.boolean,
nullable: faker.random.boolean,
partitioned: faker.random.boolean,
treeGridClass: null,
commentCount(): number {
return faker.random.number(1000);
},
id(): number | null {
return faker.random.arrayElement([faker.random.number(), null]);
},
parentSortID() {
return faker.random.number(100);
},
sortID(): number {
return faker.random.number(100);
}
});

declare module 'ember-cli-mirage/types/registries/schema' {
interface IMirageSchemaRegistry {
datasetSchemaColumns: IDatasetSchemaColumn;
datasetSchemaColumn?: IDatasetSchemaColumn;
}
}

declare module 'ember-cli-mirage/types/registries/model' {
interface IMirageModelRegistry {
datasetSchemaColumns: IDatasetSchemaColumn;
datasetSchemaColumn?: IDatasetSchemaColumn;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { getApiRoot, ApiVersion } from '@datahub/utils/api/shared';
import { ownershipEndpoint } from '@datahub/data-models/api/dataset/ownership';
import { getDatasetOwnership } from '@datahub/data-models/mirage-addon/test-helpers/datasets/ownership';
import { getEntity } from '@datahub/data-models/mirage-addon/test-helpers/get-entity';
import { getDatasetSchema } from '@datahub/data-models/mirage-addon/test-helpers/datasets/schema';
/**
* Shareable mirage/config for dependent modules
* @param {Server} server the passed in Mirage server instance in the calling test
Expand All @@ -12,4 +13,5 @@ export const setup = (server: Server): void => {

server.get('/:entityType/:identifier', getEntity);
server.get(`datasets/:urn/${ownershipEndpoint}`, getDatasetOwnership);
server.get('/datasets/:urn/schema', getDatasetSchema);
};
Original file line number Diff line number Diff line change
@@ -1,28 +1,19 @@
import DatasetSchema from '@datahub/data-models/entity/dataset/modules/schema';
import { IDatasetSchemaColumn } from '@datahub/metadata-types/types/entity/dataset/scehma';
import { IDatasetSchemaColumn } from '@datahub/metadata-types/types/entity/dataset/schema';
import { IDatasetSchema } from '@datahub/metadata-types/types/entity/dataset/schema';
import { HandlerFunction, Server } from 'ember-cli-mirage';

/**
* Allows us to abstract away most of the logic to generate a mock list of schema fields and allows
* us to create these fields easily in a customizable way through the tests and mock application
* @param {Array<string>} fieldNames - field names to generate for the mocked schema fields
*/
export const generateDatasetSchemaFields = (fieldNames: Array<string> = []): Array<IDatasetSchemaColumn> => {
export const generateDatasetSchemaFields = (
fieldNames: Array<string> = [],
server: Server
): Array<IDatasetSchemaColumn> => {
return fieldNames.map(
(name): IDatasetSchemaColumn => ({
comment: '',
commentCount: 0,
dataType: 'pretendType',
distributed: false,
fieldName: name,
fullFieldPath: name,
id: null,
indexed: false,
nullable: false,
parentSortID: 0,
partitioned: false,
sortID: 0,
treeGridClass: null
})
(name): IDatasetSchemaColumn => server.create('datasetSchemaColumn', { fieldName: name, fullFieldPath: name })
);
};

Expand All @@ -40,3 +31,22 @@ export const generateDatasetSchema = (columns: Array<IDatasetSchemaColumn> = [])
keySchema: 'testSchema'
});
};

// TODO: [META-8403] Needs to be expanded into properly getting schemas for certain dataset test scenarios,
// but this will be sufficient for the current situation of testing basic compliance table flow

/**
* This handler is used in the mirage route config to handle get requests for a dataset schema.
*/
export const getDatasetSchema: HandlerFunction = function(schema): { schema: IDatasetSchema } {
const columns = this.serialize(schema.db.datasetSchemaColumns);
const dsSchema: IDatasetSchema = {
keySchema: null,
lastModified: 1548806346860,
rawSchema: '',
schemaless: false,
columns: [...columns]
};

return { schema: dsSchema };
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,24 @@ import DatasetSchema from '@datahub/data-models/entity/dataset/modules/schema';
import DatasetComplianceAnnotation from '@datahub/data-models/entity/dataset/modules/compliance-annotation';
import { filterAnnotationsToDatasetSchema } from '@datahub/data-models/entity/dataset/helpers/validators/compliance/schema';
import {
generateDatasetSchemaFields,
generateDatasetSchema
generateDatasetSchema,
generateDatasetSchemaFields
} from '@datahub/data-models/mirage-addon/test-helpers/datasets/schema';
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
import { MirageTestContext } from '@datahub/utils/types/vendor/ember-cli-mirage/mirage-tests';

module('Unit | Utility | entity/dataset/helpers/validators/schema', function(hooks): void {
setupTest(hooks);
setupMirage(hooks);

test('filterAnnotationsToDatasetSchema', function(assert): void {
test('filterAnnotationsToDatasetSchema', function(this: MirageTestContext, assert): void {
const annotations: Array<DatasetComplianceAnnotation> = [];
let schema = new DatasetSchema();

const resultA = filterAnnotationsToDatasetSchema(annotations, schema);
assert.ok(resultA, 'Blank case works without issues');

schema = generateDatasetSchema(generateDatasetSchemaFields(['pokemon["name"]', 'type["string"]']));
schema = generateDatasetSchema(generateDatasetSchemaFields(['pokemon["name"]', 'type["string"]'], this.server));

annotations.push(
...[
Expand All @@ -41,7 +44,7 @@ module('Unit | Utility | entity/dataset/helpers/validators/schema', function(hoo
const resultC = filterAnnotationsToDatasetSchema(annotations, schema);
assert.equal(resultC.length, 4, 'Filters out the annotation that doesnt match schema');

schema = generateDatasetSchema(generateDatasetSchemaFields(['pokemon["string"]', 'type["string"]']));
schema = generateDatasetSchema(generateDatasetSchemaFields(['pokemon["string"]', 'type["string"]'], this.server));

const resultD = filterAnnotationsToDatasetSchema(annotations, schema);
assert.equal(resultD.length, 3, 'Filters out annotations that do not match schema, after schema change');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface IEntityRenderCommonPropsSearch {
// Note: Though this parameter is optional, items that rely on listing entities that are searchable
// will default this to false
isEnabled?: boolean;
defaultAspects: Array<string>;
}
/**
* This interface should live in search addon, but search addon depends on data-models and
Expand Down
Loading