Skip to content
Open
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
3 changes: 2 additions & 1 deletion frontend/common/dispatcher/app-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,10 @@ const AppActions = Object.assign({}, BaseAppActions, {
id,
})
},
getOrganisation(organisationId) {
getOrganisation(organisationId, force) {
Dispatcher.handleViewAction({
actionType: Actions.GET_ORGANISATION,
force,
id: organisationId,
})
},
Expand Down
145 changes: 80 additions & 65 deletions frontend/common/stores/organisation-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import filter from 'lodash/filter'
import findIndex from 'lodash/findIndex'
import keyBy from 'lodash/keyBy'

// Placeholder id until an organisation loads; never a real API id.
const NO_ORGANISATION = 'account'

const controller = {
createProject: (name) => {
store.saving()
Expand Down Expand Up @@ -132,73 +135,80 @@ const controller = {
]
: [],
),
).then((res) => {
if (`${id}` === `${store.id}`) {
// eslint-disable-next-line prefer-const
let [_projects, users, invites, subscriptionMeta] = res
let projects = sortBy(_projects, (project) =>
project.name.toLowerCase(),
)
)
.then((res) => {
if (`${id}` === `${store.id}`) {
// eslint-disable-next-line prefer-const
let [_projects, users, invites, subscriptionMeta] = res
let projects = sortBy(_projects, (project) =>
project.name.toLowerCase(),
)

store.model = {
...store.model,
invites: invites && invites.results,
subscriptionMeta,
users: sortBy(users, (user) => {
const isYou = user.id === AccountStore.getUser().id
if (isYou) {
return ``
}
return `${user.first_name || ''} ${
user.last_name || ''
}`.toLowerCase()
}),
}
store.model = {
...store.model,
invites: invites && invites.results,
subscriptionMeta,
users: sortBy(users, (user) => {
const isYou = user.id === AccountStore.getUser().id
if (isYou) {
return ``
}
return `${user.first_name || ''} ${
user.last_name || ''
}`.toLowerCase()
}),
}

if (Project.hideInviteLinks) {
store.loaded()
} else {
data
.get(`${Project.api}organisations/${id}/invite-links/`)
.then((links) => {
store.model.inviteLinks = links
if (!links || !links.length) {
Promise.all([
data.post(
`${Project.api}organisations/${id}/invite-links/`,
{
role: 'ADMIN',
},
),
data.post(
`${Project.api}organisations/${id}/invite-links/`,
{
role: 'USER',
},
),
]).then(() => {
data
.get(`${Project.api}organisations/${id}/invite-links/`)
.then((links) => {
store.model.inviteLinks = links
if (Project.hideInviteLinks) {
store.loaded()
} else {
data
.get(`${Project.api}organisations/${id}/invite-links/`)
.then((links) => {
store.model.inviteLinks = links
if (!links || !links.length) {
// Returned so a failure reaches the catch below.
return Promise.all([
data.post(
`${Project.api}organisations/${id}/invite-links/`,
{
role: 'ADMIN',
},
),
data.post(
`${Project.api}organisations/${id}/invite-links/`,
{
role: 'USER',
},
),
]).then(() =>
data
.get(`${Project.api}organisations/${id}/invite-links/`)
.then((links) => {
store.model.inviteLinks = links

store.loaded()
})
})
} else {
store.loaded()
}),
)
}
store.loaded()
}
})
.catch((e) => {
API.ajaxHandler(store, e)
})
}
})
.catch((e) => {
API.ajaxHandler(store, e)
})
}

store.model.projects = projects
store.model.keyedProjects = keyBy(store.model.projects, 'id')
store.loaded()
}
})
store.model.projects = projects
store.model.keyedProjects = keyBy(store.model.projects, 'id')
store.loaded()
}
})
.catch((e) => {
// A newer request may have replaced this one.
if (`${id}` === `${store.id}`) {
API.ajaxHandler(store, e)
}
})
}
},
invalidateInviteLink: (link) => {
Expand Down Expand Up @@ -263,16 +273,21 @@ const store = Object.assign({}, BaseStore, {
return store.model && store.model.subscriptionMeta
},
getUsers: () => store.model && store.model.users,
id: 'account',
id: NO_ORGANISATION,
})

store.dispatcherIndex = Dispatcher.register(store, (payload) => {
const action = payload.action // this is our action from handleViewAction

switch (action.actionType) {
case Actions.GET_ORGANISATION:
controller.getOrganisation(action.id || store.id, action.force)
case Actions.GET_ORGANISATION: {
// A refresh before any organisation has loaded has nothing to fetch.
const id = action.id || store.id
if (id && id !== NO_ORGANISATION) {
controller.getOrganisation(id, action.force)
}
break
}
case Actions.CREATE_PROJECT:
controller.createProject(action.name)
break
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,8 @@ export async function bootstrapOnboarding(
if (flag) {
await ensureOnboardingTag(store, project, flag)
}
AppActions.refreshOrganisation()
// The store has no organisation loaded on this page, so name it.
AppActions.getOrganisation(organisation.id, true)
return {
environment,
featureName: flag?.name ?? FLAG_NAME,
Expand Down
Loading