diff --git a/.storybook/mocks/mocks.ts b/.storybook/mocks/mocks.ts index 127e13e2..c91b2810 100644 --- a/.storybook/mocks/mocks.ts +++ b/.storybook/mocks/mocks.ts @@ -445,6 +445,7 @@ export const organizationGroups = (groupQuota?: number) => { name: `${faker.word.words(1)}-group`, type: faker.helpers.arrayElement(['null', 'project-default-group']), members: organizationMembers(), + memberCount: faker.number.int({ min: 1, max: 10 }), __typename: 'Group', }; }); @@ -541,6 +542,7 @@ export const organizationProjects = (projectQuota: number) => { name: `project-${faker.word.noun()}`, __typename: 'OrgProject', groups: organizationGroups(), + groupCount: organizationGroups().length, notifications: [ { ...slack[0], type: 'SLACK' }, { ...rocketChat[0], type: 'ROCKETCHAT' }, diff --git a/src/components/Organizations/GroupMembers/index.js b/src/components/Organizations/GroupMembers/index.js index c7e49800..2427d86a 100644 --- a/src/components/Organizations/GroupMembers/index.js +++ b/src/components/Organizations/GroupMembers/index.js @@ -51,7 +51,7 @@ const ADD_GROUP_PROJECT_MUTATION = gql` /** * The primary list of members. */ -const GroupMembers = ({ members = [], groupName, organizationName, organizationId, projects, refetch }) => { +const GroupMembers = ({ members = [], groupName, organizationName, organizationId, orgProjects, projects, refetch }) => { const duRegex = new RegExp('^default-user@' + groupName.replace('project-', '') + '$', 'g'); const [projectModalOpen, setProjectModalOpen] = useState(false); @@ -274,9 +274,7 @@ const GroupMembers = ({ members = [], groupName, organizationName, organizationI { - return project.groups.find(group => group.name === groupName); - })} + data={projects} columns={ProjectsColumns} labelText="Projects" emptyText="No Projects" @@ -306,10 +304,8 @@ const GroupMembers = ({ members = [], groupName, organizationName, organizationI refetch().then(closeAddProjectModal); } - const filtered = projects.filter(project => { - if (project.groups.length === 0) return project; - - return project.groups.every(group => group.name !== groupName); + const filtered = orgProjects.filter(project => { + return projects.every(p => p.name !== project.name); }); const opts = filtered.map(p => { diff --git a/src/components/Organizations/Groups/index.js b/src/components/Organizations/Groups/index.js index b8722179..1f53cb6b 100644 --- a/src/components/Organizations/Groups/index.js +++ b/src/components/Organizations/Groups/index.js @@ -86,7 +86,7 @@ const Groups = ({ groups = [], organizationId, organizationName, ableToAddGroup, width: '15%', key: 'members', render: i => { - return i.members && Members: {i.members.length} ; + return typeof i.memberCount !== 'undefined' && Members: {i.memberCount} ; }, }, { diff --git a/src/components/Organizations/ProjectGroupMembers/index.js b/src/components/Organizations/ProjectGroupMembers/index.js index 4b988e25..5833c69f 100644 --- a/src/components/Organizations/ProjectGroupMembers/index.js +++ b/src/components/Organizations/ProjectGroupMembers/index.js @@ -56,7 +56,7 @@ const ProjectGroupMembers = ({ groups = [], organizationId, organizationName, pr {group.name} -
Members: {group.members.length}
+
Members: {group.memberCount}
{group.type.includes('project-default-group') && ( diff --git a/src/components/Organizations/Projects/index.js b/src/components/Organizations/Projects/index.js index ea354546..1a51a937 100644 --- a/src/components/Organizations/Projects/index.js +++ b/src/components/Organizations/Projects/index.js @@ -51,7 +51,7 @@ const OrgProjects = ({ projects = [], organizationId, organizationName, refresh, render: project => { return (
- Groups: {project.groups.length} + Groups: {project.groupCount}
); }, diff --git a/src/lib/query/organizations/GroupByNameAndOrganization.js b/src/lib/query/organizations/GroupByNameAndOrganization.js index 2e048423..3918c8ec 100644 --- a/src/lib/query/organizations/GroupByNameAndOrganization.js +++ b/src/lib/query/organizations/GroupByNameAndOrganization.js @@ -6,6 +6,10 @@ export default gql` id name type + projects { + id + name + } members{ role user{ @@ -31,9 +35,6 @@ export default gql` projects { id name - groups{ - name - } } } } diff --git a/src/lib/query/organizations/OrganizationByID.js b/src/lib/query/organizations/OrganizationByID.js index 9acebaec..4e286844 100644 --- a/src/lib/query/organizations/OrganizationByID.js +++ b/src/lib/query/organizations/OrganizationByID.js @@ -32,24 +32,13 @@ export default gql` projects { id name - groups { - type - id - name - } + groupCount } groups { id name type - members { - role - user { - email - comment - } - role - } + memberCount } slacks: notifications(type: SLACK) { __typename diff --git a/src/lib/query/organizations/ProjectAndOrganizationByID.js b/src/lib/query/organizations/ProjectAndOrganizationByID.js index fff7741c..44440415 100644 --- a/src/lib/query/organizations/ProjectAndOrganizationByID.js +++ b/src/lib/query/organizations/ProjectAndOrganizationByID.js @@ -6,28 +6,27 @@ import TeamsFragment from 'lib/fragment/Teams'; import WebhookFragment from 'lib/fragment/Webhook'; export default gql` - query getOrganization($id: Int!){ - organization: organizationById (organization: $id){ + query getOrganization($project: String!, $id: Int!) { + project: orgProjectByName(name: $project){ id name - quotaGroup - quotaNotification - projects { + groups { + type id name - groups { - type - id - name - members{ - role - } - } - notifications{ - name - type - } + memberCount + } + notifications{ + name + type } + } + + organization: organizationById (organization: $id){ + id + name + quotaGroup + quotaNotification groups{ type name diff --git a/src/pages/organizations/group.js b/src/pages/organizations/group.js index ccbf4356..f77d34f6 100644 --- a/src/pages/organizations/group.js +++ b/src/pages/organizations/group.js @@ -98,7 +98,8 @@ export const PageGroup = ({ router }) => { { return ; } - const { organization } = data; + const { organization, project } = data; if (!organization) { return ; @@ -100,36 +100,29 @@ export const PageGroupProject = ({ router }) => { - {organization.projects.map( - (project, idx) => - project.name == router.query.projectName && ( - - - - - -

{project.name}

- - -
-
-
- ) - )} + + + + +

{project.name}

+ + +
+
diff --git a/src/stories/organizations/organizationProject.stories.tsx b/src/stories/organizations/organizationProject.stories.tsx index 6b89e465..305eeae2 100644 --- a/src/stories/organizations/organizationProject.stories.tsx +++ b/src/stories/organizations/organizationProject.stories.tsx @@ -3,7 +3,7 @@ import { Meta, StoryObj } from '@storybook/react'; import { graphql } from 'msw'; import { getOrganization } from '../../../.storybook/mocks/api'; -import { organizationGroups } from '../../../.storybook/mocks/mocks'; +import { organizationGroups, organizationProjects } from '../../../.storybook/mocks/mocks'; import PageProject from '../../pages/organizations/project'; faker.seed(123); @@ -33,7 +33,7 @@ export const Default: Story = { msw: { handlers: [ graphql.query('getOrganization', (_, res, ctx) => { - return res(ctx.delay(), ctx.data({ organization: mockOrganization })); + return res(ctx.delay(), ctx.data({ organization: mockOrganization, project: organizationProjects(2)[0] })); }), graphql.mutation('addProjectToGroup', (req, res, ctx) => {