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

[ui] add TeamModal component #582

Merged
merged 1 commit into from
Aug 17, 2021
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
54 changes: 54 additions & 0 deletions ui/src/apollo/mutations.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,25 @@ const ADD_ORGANIZATION = gql`
}
}
`;

const ADD_TEAM = gql`
mutation addTeam(
$teamName: String!
$organization: String
$parentName: String
) {
addTeam(
teamName: $teamName
organization: $organization
parentName: $parentName
) {
team {
name
}
}
}
`;

const ADD_IDENTITY = gql`
mutation addIdentity(
$email: String
Expand Down Expand Up @@ -306,6 +325,16 @@ const DELETE_ORGANIZATION = gql`
}
`;

const DELETE_TEAM = gql`
mutation deleteTeam($teamName: String!, $organization: String!) {
deleteTeam(teamName: $teamName, organization: $organization) {
team {
name
}
}
}
`;

const UPDATE_ENROLLMENT = gql`
mutation updateEnrollment(
$fromDate: DateTime!
Expand Down Expand Up @@ -475,6 +504,18 @@ const addOrganization = (apollo, name) => {
return response;
};

const addTeam = (apollo, teamName, organization, parentName) => {
let response = apollo.mutate({
mutation: ADD_TEAM,
variables: {
teamName: teamName,
organization: organization,
parentName: parentName
}
});
return response;
};

const addDomain = (apollo, domain, organization) => {
let response = apollo.mutate({
mutation: ADD_DOMAIN,
Expand Down Expand Up @@ -515,6 +556,17 @@ const deleteOrganization = (apollo, name) => {
return response;
};

const deleteTeam = (apollo, teamName, organization) => {
let response = apollo.mutate({
mutation: DELETE_TEAM,
variables: {
teamName: teamName,
organization: organization
}
});
return response;
};

const updateEnrollment = (apollo, data) => {
let response = apollo.mutate({
mutation: UPDATE_ENROLLMENT,
Expand Down Expand Up @@ -543,6 +595,8 @@ export {
deleteOrganization,
addDomain,
deleteDomain,
addTeam,
deleteTeam,
addIdentity,
updateProfile,
withdraw,
Expand Down
23 changes: 23 additions & 0 deletions ui/src/apollo/queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,17 @@ const GET_COUNTRIES = gql`
}
`;

const GET_TEAMS = gql`
query GetTeams($filters: TeamFilterType) {
teams(pageSize: 500, filters: $filters) {
entities {
name
numchild
}
}
}
`;

const GET_JOBS = gql`
query getJobs($page: Int!, $pageSize: Int!) {
jobs(page: $page, pageSize: $pageSize) {
Expand Down Expand Up @@ -298,12 +309,24 @@ const getJobs = (apollo, page, pageSize) => {
return response;
};

const getTeams = (apollo, filters) => {
let response = apollo.query({
query: GET_TEAMS,
variables: {
filters: filters
},
fetchPolicy: "no-cache"
});
return response;
};

export {
getCountries,
getIndividuals,
getIndividualByUuid,
getProfileByUuid,
getPaginatedIndividuals,
getPaginatedOrganizations,
getTeams,
getJobs
};
149 changes: 141 additions & 8 deletions ui/src/components/ExpandedOrganization.stories.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,157 @@
import ExpandedOrganization from "./ExpandedOrganization.vue";
import ExpandedOrganization from './ExpandedOrganization.vue';

export default {
title: "ExpandedOrganization",
excludeStories: /.*Data$/
title: 'ExpandedOrganization',
excludeStories: /.*Data$/,
};

const ExpandedOrganizationTemplate = `<expanded-organization :domains="domains" />`;
const ExpandedOrganizationTemplate = `<expanded-organization :domains="domains" :organization="organization" :add-team="addTeam" :delete-team="deleteTeam" :fetch-teams="fetchTeams"/>`;

export const Default = () => ({
components: { ExpandedOrganization },
template: ExpandedOrganizationTemplate,
data: () => ({
domains: [{ domain: "hogwarts.edu" }, { domain: "hogwarts.com" }]
})
domains: [{ domain: 'hogwarts.edu' }, { domain: 'hogwarts.com' }],
organization: 'Hogwarts',
query: [
{
data: {
teams: {
entities: [
{
name: 'BU1',
numchild: 2,
},
{
name: 'BU2',
numchild: 0,
},
{
name: 'BU3',
numchild: 1,
},
{
name: 'Team1',
parent: 'BU1',
numchild: 0,
},
{
name: 'Team2',
parent: 'BU1',
numchild: 0,
},
{
name: 'Team4',
parent: 'BU3',
numchild: 0,
},
],
},
},
},
],
}),
methods: {
fetchTeams(filters) {
let data = [];
if (Object.keys(filters).includes('parent')) {
this.query[0].data.teams.entities.forEach((team) => {
if (team['parent'] === filters['parent']) {
data.push(team);
}
});
} else {
this.query[0].data.teams.entities.forEach((team) => {
if (team['parent'] === undefined) {
data.push(team);
}
});
}
const resp = {
data: {
teams: {
entities: data
},
},
};
return resp;
},
addTeam(team, organization, parent) {
const insertData = {
name: team,
};
if (parent) {
insertData['parent'] = parent;
}
this.query[0].data.teams.entities.push(insertData);
return true;
},
deleteTeam(team, organization) {
this.query[0].data.teams.entities = this.query[0].data.teams.entities.filter(
(elem) => elem.name != team,
);
return true;
},
},
});

export const Empty = () => ({
components: { ExpandedOrganization },
template: ExpandedOrganizationTemplate,
data: () => ({
domains: []
})
domains: [],
organization: 'Hogwarts',
query: [
{
data: {
teams: {
entities: [],
},
},
},
],
}),
methods: {
fetchTeams(filters) {
let data = [];
if (Object.keys(filters).includes('parent')) {
this.query[0].data.teams.entities.forEach((team) => {
if (team['parent'] === filters['parent']) {
data.push(team);
}
});
} else {
this.query[0].data.teams.entities.forEach((team) => {
if (team['parent'] === undefined) {
data.push(team);
}
});
}
const resp = {
data: {
teams: {
entities: data,
},
},
};

return resp;
},
addTeam(team, organization, parent) {
const insertData = {
name: team,
};
if (parent) {
insertData['parent'] = parent;
}
this.query[0].data.teams.entities.push(insertData);
return true;
},
deleteTeam(team, organization) {
this.query[0].data.teams.entities = this.query[0].data.teams.entities.filter(
(elem) => elem.name != team,
);
return true;
},
},
});
63 changes: 63 additions & 0 deletions ui/src/components/ExpandedOrganization.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,80 @@
</v-list-item-content>
</v-list-item>
</v-list>
<v-list dense>
<v-subheader>
Teams ({{ teams.length }}<span v-if="teams.length > 0">+</span>)
<v-btn depressed small height="34" @click.stop="openModal" text>
View all
</v-btn>
</v-subheader>
<v-list-item v-for="(item, index) in teams" :key="index">
<v-list-item-content>
<v-list-item-title>{{ item.name }}</v-list-item-title>
</v-list-item-content>
</v-list-item>
</v-list>
<team-modal
:is-open.sync="modal.open"
:organization="organization"
:add-team="addTeam"
:delete-team="deleteTeam"
:fetch-teams="fetchTeams"
@updateTeams="getTeams"
/>
</td>
</template>

<script>
import TeamModal from "./TeamModal.vue";

export default {
name: "ExpandedOrganization",
components: {
TeamModal
},
props: {
domains: {
type: Array,
required: true
},
organization: {
type: String,
required: true
},
addTeam: {
type: Function,
required: true
},
deleteTeam: {
type: Function,
required: true
},
fetchTeams: {
type: Function,
required: true
}
},
data() {
return {
teams: [],
modal: {
open: false
}
};
},
methods: {
openModal() {
Object.assign(this.modal, { open: true });
},
async getTeams() {
const filters = { organization: this.organization };
const response = await this.fetchTeams(filters);
this.teams = response.data.teams.entities;
}
},
async created() {
await this.getTeams();
}
};
</script>
Loading