Skip to content

Commit

Permalink
feat: add tags
Browse files Browse the repository at this point in the history
  • Loading branch information
Allen Zhang (张涛) committed May 8, 2024
1 parent a6c218c commit 9cc93a9
Show file tree
Hide file tree
Showing 16 changed files with 209 additions and 187 deletions.
1 change: 1 addition & 0 deletions packages/canyon-backend/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ model Project {
description String
bu String
tag String
tags Json
coverage String
defaultBranch String @map("default_branch")
createdAt DateTime @default(now()) @map("created_at") @db.Timestamp(3)
Expand Down
18 changes: 10 additions & 8 deletions packages/canyon-backend/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ A date-time string at UTC, such as 2019-12-03T09:54:33Z, compliant with the date
"""
scalar DateTime

type Rule {
type Tag {
id: String!
name: String!
config: String!
updatedAt: DateTime!
link: String!
color: String!
}

type Project {
Expand All @@ -33,7 +34,7 @@ type Project {
description: String!
tag: String!
coverage: String!
rules: [Rule!]!
tags: [Tag!]!
bu: String!
branchOptions: [String!]!
maxCoverage: Float!
Expand Down Expand Up @@ -254,12 +255,13 @@ type Mutation {
tag: String!
coverage: String!
defaultBranch: String!
rules: [RuleInput!]!
tags: [TagInput!]
): Project2!
}

input RuleInput {
input TagInput {
id: String!
name: String!
config: String!
updatedAt: DateTime!
link: String!
color: String!
}
16 changes: 9 additions & 7 deletions packages/canyon-backend/src/project/input-type.args.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { ArgsType, Field, ID, InputType } from '@nestjs/graphql';

@InputType() // 定义规则输入类型
class RuleInput {
class TagInput {
@Field()
id: string;
@Field()
name: string;

@Field()
config: string;

link: string;
@Field()
updatedAt: Date;
color: string;
}

@ArgsType()
Expand All @@ -31,6 +31,8 @@ export class UpdateProjectArgs {
@Field()
defaultBranch: string;

@Field(() => [RuleInput])
rules: RuleInput[];
@Field(() => [TagInput], {
nullable: true,
})
tags?: TagInput[];
}
15 changes: 9 additions & 6 deletions packages/canyon-backend/src/project/project.model.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { Field, ID, ObjectType } from '@nestjs/graphql';

@ObjectType()
export class Rule {
export class Tag {
@Field(() => String)
id: string;

@Field(() => String)
name: string;

@Field(() => String)
config: string;
link: string;

@Field(() => Date)
updatedAt: Date;
@Field(() => String)
color: string;
}

@ObjectType()
Expand All @@ -32,8 +35,8 @@ export class Project {
@Field(() => String)
coverage: string;

@Field(() => [Rule])
rules: Rule[];
@Field(() => [Tag])
tags: Tag[];

@Field(() => String)
bu: string;
Expand Down
3 changes: 2 additions & 1 deletion packages/canyon-backend/src/project/project.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { GqlAuthGuard } from '../guards/gql-auth.guard';
import { UseGuards } from '@nestjs/common';
import { GqlUser } from '../decorators/gql-user.decorator';
import { AuthUser } from '../types/AuthUser';
import { BuOption, Project, Rule } from './project.model';
import { BuOption, Project, Tag } from './project.model';
import { ProjectPagesModel } from './models/project-pages.model';
import { ProjectService } from './services/project.service';
import { GetProjectChartDataService } from './services/get-project-chart-data.service';
Expand Down Expand Up @@ -183,6 +183,7 @@ export class ProjectResolver {
args.tag,
args.coverage,
args.defaultBranch,
args.tags,
// args.rules,
);
}
Expand Down
9 changes: 5 additions & 4 deletions packages/canyon-backend/src/project/project.zod.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { z } from 'zod';

export const projectRules = z.array(
export const projectTags = z.array(
z.object({
name: z.string().default('nihao'),
updatedAt: z.coerce.date().default(new Date()),
config: z.string().default('ddd'),
id: z.string().default(''),
name: z.string().default(''),
link: z.string().default(''),
color: z.string().default(''),
}),
);
// console.log(User.parse([{ usernam: "Ludwig" }]));
12 changes: 11 additions & 1 deletion packages/canyon-backend/src/project/services/project.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Injectable } from '@nestjs/common';
import { PrismaService } from '../../prisma/prisma.service';
import { Project } from '../project.model';
import { getProjectByID } from 'src/adapter/gitlab.adapter';
import { projectTags } from '../project.zod';

// import { getProjectByID } from '../adapter/gitlab.adapter';
function parseGitLabUrl(gitLabUrl) {
Expand Down Expand Up @@ -65,6 +66,7 @@ export class ProjectService {
coverage: '',
tag: '',
defaultBranch: '-',
tags: [],
},
});
}
Expand All @@ -84,6 +86,7 @@ export class ProjectService {
tag,
coverage,
defaultBranch,
tags,
) {
function removeEmptyValues(obj) {
for (const key in obj) {
Expand All @@ -106,6 +109,7 @@ export class ProjectService {
tag: tag,
coverage: coverage,
defaultBranch: defaultBranch,
tags: tags,
}),
});
}
Expand Down Expand Up @@ -136,6 +140,7 @@ export class ProjectService {
coverage,
tag,
defaultBranch,
tags,
}) => {
return {
id,
Expand All @@ -152,7 +157,12 @@ export class ProjectService {
defaultBranch,
branchOptions,
favored: false,
rules: [],
tags: projectTags.parse(tags).map(({ id, name, link, color }) => ({
id,
name,
link,
color,
})),
};
},
);
Expand Down
2 changes: 2 additions & 0 deletions packages/canyon-platform/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
"codegen": "graphql-codegen --config codegen.ts"
},
"dependencies": {
"@ant-design/colors": "^7.0.2",
"@ant-design/icons": "^5.3.0",
"@apollo/client": "^3.9.5",
"@canyon/data": "workspace:^",
"@graphql-typed-document-node/core": "^3.2.0",
"@monaco-editor/react": "^4.6.0",
"@paralleldrive/cuid2": "^2.2.2",
"ahooks": "^3.7.10",
"antd": "^5.14.1",
"axios": "^1.6.7",
Expand Down
1 change: 1 addition & 0 deletions packages/canyon-platform/src/auto-imports.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export {}
declare global {
const Button: typeof import('antd')['Button']
const Card: typeof import('antd')['Card']
const ColorPicker: typeof import('antd')['ColorPicker']
const Divider: typeof import('antd')['Divider']
const Drawer: typeof import('antd')['Drawer']
const Flex: typeof import('antd')['Flex']
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mutation UpdateProject($projectID: ID!,$description: String!,$tag: String!,$coverage: String!,$defaultBranch: String!,$rules: [RuleInput!]!) {
updateProject(projectID: $projectID,description: $description,tag: $tag,coverage: $coverage,defaultBranch: $defaultBranch,rules:$rules) {
mutation UpdateProject($projectID: ID!,$description: String!,$tag: String!,$coverage: String!,$defaultBranch: String!,$tags: [TagInput!]) {
updateProject(projectID: $projectID,description: $description,tag: $tag,coverage: $coverage,defaultBranch: $defaultBranch,tags:$tags) {
id
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ query GetProjectByID($projectID: ID!) {
tag
branchOptions
defaultBranch
rules {
tags {
id
name
config
updatedAt
link
color
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,9 @@ const BasicForms: FC<{ data: any }> = ({ data }) => {
variables: {
projectID: prm.id,
coverage: '__null__',
tag: values.tag,
tag: '__null__',
description: values.description,
defaultBranch: '__null__',
rules:[]
},
}).then(() => {
message.success('成功');
Expand Down Expand Up @@ -108,9 +107,9 @@ const BasicForms: FC<{ data: any }> = ({ data }) => {
<TextArea autoSize={{ minRows: 3, maxRows: 3 }} />
</Form.Item>

<Form.Item<any> label='标签' name='tag'>
<TagComponent />
</Form.Item>
{/*<Form.Item<any> label='标签' name='tag'>*/}
{/* <TagComponent />*/}
{/*</Form.Item>*/}

<Form.Item>
<Button type='primary' htmlType='submit'>
Expand Down
Loading

0 comments on commit 9cc93a9

Please sign in to comment.