Skip to content

Commit

Permalink
Add project visibility feature
Browse files Browse the repository at this point in the history
This commit introduces visibility setting for projects. It modifies the resolver to make visibility an optional input on project creation with a default set to 'INTERNAL'. It also adjusts the GraphQL schema to recognize the new visibility options and associates it with project entities.
  • Loading branch information
claygorman committed Dec 23, 2023
1 parent 10035fb commit 9a72543
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 48 deletions.
16 changes: 16 additions & 0 deletions backend/src/db/migrations/20231223000001-add-project-visibility.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';

const TABLE_NAME = 'projects';
const COLUMN_NAME = 'visibility';

/** @type {import('sequelize-cli').Migration} */
export default {
async up(queryInterface, Sequelize) {
await queryInterface.addColumn(TABLE_NAME, COLUMN_NAME, {
type: Sequelize.STRING,
});
},
async down(queryInterface, Sequelize) {
await queryInterface.removeColumn(TABLE_NAME, COLUMN_NAME);
},
};
7 changes: 7 additions & 0 deletions backend/src/db/models/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ export default (sequelize, DataTypes) => {
status: {
type: DataTypes.STRING,
},
visibility: {
type: DataTypes.STRING,
defaultValue: 'internal',
validate: {
isIn: [['PRIVATE', 'INTERNAL', 'PUBLIC']],
},
},
createdAt: {
type: DataTypes.DATE,
field: 'created_at',
Expand Down
30 changes: 10 additions & 20 deletions backend/src/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,35 +312,25 @@ const resolvers = {
return { message: 'issue deleted', status: 'success' };
},
createProject: async (parent, { input }, { db }) => {
// TODO: we should do a sequelize transaction here
const project = await db.sequelize.models.Project.create({
name: input.name,
key: input.key,
visibility: input.visibility ?? 'INTERNAL',
});

// TODO: maybe promise all here?
const projectId = Number(project.id);

// TODO: We should create mappings for these statuses
const issueStatuses = await db.sequelize.models.IssueStatuses.bulkCreate([
{
projectId: Number(project.id),
name: 'Backlog',
},
{
projectId: Number(project.id),
name: 'To Do',
},
{
projectId: Number(project.id),
name: 'In Progress',
},
{
projectId: Number(project.id),
name: 'Done',
},
]);
const issueStatuses = await db.sequelize.models.IssueStatuses.bulkCreate(
['Backlog', 'To Do', 'In Progress', 'Done'].map((name) => ({
projectId,
name,
}))
);

const board = await db.sequelize.models.Board.create({
projectId: Number(project.id),
projectId,
name: input?.boardName ?? 'default',
style: input.boardStyle,
viewState: issueStatuses.map((is) => ({
Expand Down
8 changes: 8 additions & 0 deletions backend/src/type-defs.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ const typeDefs = gql`
# in the resolver map below.
scalar Upload
enum ProjectVisibility {
PUBLIC
INTERNAL
PRIVATE
}
enum Order {
ASC
DESC
Expand Down Expand Up @@ -61,6 +67,7 @@ const typeDefs = gql`
description: String
imageId: Int
status: String
visibility: ProjectVisibility
createdAt: String
updatedAt: String
boards: [Board]
Expand Down Expand Up @@ -159,6 +166,7 @@ const typeDefs = gql`
name: String!
key: String!
description: String
visibility: ProjectVisibility
boardName: String!
boardStyle: BoardStyle!
}
Expand Down
13 changes: 12 additions & 1 deletion frontend/components/ProjectList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,15 @@ import { useQuery } from '@apollo/client';
import { GET_PROJECTS } from '@/gql/gql-queries-mutations';
import { GetProjectsQuery, Project } from '@/gql/__generated__/graphql';

const cols = ['ID', 'Name', 'Key', 'Board Style', 'Description', ''];
const cols = [
'ID',
'Name',
'Key',
'Board Style',
'Visibility',
'Description',
'',
];

// TODO: Make this its own component?
const ProjectOptionsDropdown = () => {
Expand Down Expand Up @@ -205,6 +213,9 @@ const ProjectList = () => {
? project?.boards?.[0].style
: 'Kanban'}
</td>
<td className='whitespace-nowrap px-3 py-1'>
{project?.visibility}
</td>
<td className='whitespace-nowrap px-3 py-1'>
{project?.description}
</td>
Expand Down
16 changes: 8 additions & 8 deletions frontend/gql/__generated__/gql.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9a72543

Please sign in to comment.