Skip to content

Commit

Permalink
style: Navigation improvements (Flagsmith#3864)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyle-ssg authored May 9, 2024
1 parent 9753e66 commit d92c082
Show file tree
Hide file tree
Showing 186 changed files with 4,144 additions and 4,963 deletions.
1 change: 0 additions & 1 deletion frontend/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ module.exports = {
'Radio': true,
'React': true,
'ReactDOM': true,
'RemoveIcon': true,
'RequiredElement': true,
'RequiredFunc': true,
'RequiredObject': true,
Expand Down
3 changes: 2 additions & 1 deletion frontend/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export default {
),
}),

'USER_TRAITS': (envId: string, userId?: string) => ({
'USER_TRAITS': (envId: string, userId = keywords.USER_ID) => ({
'.NET': require('./code-help/traits/traits-dotnet')(
envId,
keywords,
Expand Down Expand Up @@ -522,4 +522,5 @@ export default {
'#DE3163',
],
untaggedTag: { color: '#dedede', label: 'Untagged' },
upgradeURL: '/organisation-settings?tab=billing',
}
6 changes: 4 additions & 2 deletions frontend/common/providers/OrganisationProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,21 @@ import { useGetGroupsQuery } from 'common/services/useGroup'
type OrganisationProviderType = {
onRemoveProject?: () => void
onSave?: (data: { environmentId: number; projectId: number }) => void
id?: number
id?: number | string
children: (props: {
createProject: typeof AppActions.createProject
invalidateInviteLink: typeof AppActions.invalidateInviteLink
inviteLinks: InviteLink[] | null
invites: Invite[] | null
error: any
isLoading: boolean
isSaving: boolean
name: string
project: Project | null
groups: UserGroupSummary[] | null
projects: Project[] | null
subscriptionMeta: SubscriptionMeta | null
users: User[] | null
users: User[]
}) => ReactNode
}

Expand Down Expand Up @@ -76,6 +77,7 @@ const OrganisationProvider: FC<OrganisationProviderType> = ({
<>
{children({
createProject: AppActions.createProject,
error: AccountStore.error,
groups: groups?.results || [],
invalidateInviteLink: AppActions.invalidateInviteLink,
inviteLinks: OrganisationStore.getInviteLinks(),
Expand Down
2 changes: 1 addition & 1 deletion frontend/common/providers/Permission.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const Permission: FC<PermissionType> = ({
{children({
isLoading,
permission: hasPermission || AccountStore.isAdmin(),
}) || <div />}
}) || null}
</>
)
}
Expand Down
5 changes: 1 addition & 4 deletions frontend/common/services/useEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,9 @@ export async function getEnvironments(
typeof environmentService.endpoints.getEnvironments.initiate
>[1],
) {
store.dispatch(
return store.dispatch(
environmentService.endpoints.getEnvironments.initiate(data, options),
)
return Promise.all(
store.dispatch(environmentService.util.getRunningQueriesThunk()),
)
}
export async function getEnvironment(
store: any,
Expand Down
15 changes: 12 additions & 3 deletions frontend/common/stores/account-store.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { matchPath } from 'react-router'

const Dispatcher = require('../dispatcher/dispatcher')
const BaseStore = require('./base/_store')
const data = require('../data/base/_data')
Expand Down Expand Up @@ -52,7 +54,7 @@ const controller = {

store.saved()
if (isLoginPage) {
window.location.href = `/organisation-settings`
window.location.href = `/organisations`
}
})
.catch((e) => {
Expand Down Expand Up @@ -278,6 +280,7 @@ const controller = {
},

selectOrganisation: (id) => {
API.setCookie('organisation', `${id}`)
store.organisation = _.find(store.model.organisations, { id })
store.changed()
},
Expand All @@ -300,12 +303,18 @@ const controller = {
if (user && user.organisations) {
store.organisation = user.organisations[0]
const cookiedID = API.getCookie('organisation')
if (cookiedID) {
const pathID = matchPath(document.location.pathname, {
path: '/organisation/:organisationId',
strict: false,
})?.params?.organisationId
const orgId = pathID || cookiedID
if (orgId) {
const foundOrganisation = user.organisations.find(
(v) => `${v.id}` === cookiedID,
(v) => `${v.id}` === orgId,
)
if (foundOrganisation) {
store.organisation = foundOrganisation
AppActions.getOrganisation(orgId)
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions frontend/common/stores/organisation-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const controller = {
environmentId: res[0].api_key,
projectId: project.id,
}
AppActions.refreshOrganisation()
store.saved()
})
})
Expand Down Expand Up @@ -126,7 +127,7 @@ const controller = {
})
},
getOrganisation: (id, force) => {
if (id !== store.id || force) {
if (`${id}` !== `${store.id}` || force) {
store.id = id
store.loading()

Expand All @@ -147,7 +148,7 @@ const controller = {
: [],
),
).then((res) => {
if (id === store.id) {
if (`${id}` === `${store.id}`) {
// eslint-disable-next-line prefer-const
let [_projects, users, invites, subscriptionMeta] = res
let projects = _.sortBy(_projects, 'name')
Expand Down
1 change: 1 addition & 0 deletions frontend/common/stores/project-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ const controller = {
data.put(`${Project.api}projects/${project.id}/`, project).then((res) => {
store.model = Object.assign(store.model, res)
getStore().dispatch(projectService.util.invalidateTags(['Project']))
AppActions.refreshOrganisation()
store.saved()
})
},
Expand Down
2 changes: 2 additions & 0 deletions frontend/common/types/responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ export type githubIntegration = {
export type User = {
id: number
email: string
last_login?: string
first_name: string
last_name: string
role: 'ADMIN' | 'USER'
Expand Down Expand Up @@ -555,6 +556,7 @@ export type Invite = {
email: string
date_created: string
invited_by: User
link: string
permission_groups: number[]
}

Expand Down
15 changes: 15 additions & 0 deletions frontend/common/utils/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,13 @@ const Utils = Object.assign({}, require('./base/_utils'), {
}
return 'UPDATE_FEATURE_STATE'
},
canCreateOrganisation() {
return (
!Utils.getFlagsmithHasFeature('disable_create_org') &&
(!Project.superUserCreateOnly ||
(Project.superUserCreateOnly && AccountStore.isSuper()))
)
},
getManageFeaturePermissionDescription(isChangeRequest: boolean) {
if (isChangeRequest) {
return 'Create Change Request'
Expand All @@ -255,6 +262,13 @@ const Utils = Object.assign({}, require('./base/_utils'), {
getManageUserPermissionDescription() {
return 'Manage Identities'
},
getOrganisationHomePage(id?: string) {
const orgId = id || AccountStore.getOrganisation()?.id
if (!orgId) {
return `/organisations`
}
return `/organisation/${orgId}/projects`
},
getPermissionList(
isAdmin: boolean,
permissions: string[] | undefined | null,
Expand Down Expand Up @@ -285,6 +299,7 @@ const Utils = Object.assign({}, require('./base/_utils'), {
.map((item) => `${Format.enumeration.get(item)}`),
}
},

getPlanName: (plan: string) => {
if (plan && plan.includes('scale-up')) {
return planNames.scaleUp
Expand Down
3 changes: 3 additions & 0 deletions frontend/e2e/helpers.cafe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export const getLogger = () =>
})

export const gotoTraits = async () => {
await click('#features-link')
await click('#users-link')
await click(byId('user-item-0'))
await waitForElementVisible('#add-trait')
Expand Down Expand Up @@ -219,6 +220,7 @@ export const saveFeatureSegments = async () => {
}

export const goToUser = async (index: number) => {
await click('#features-link')
await click('#users-link')
await click(byId(`user-item-${index}`))
}
Expand Down Expand Up @@ -331,6 +333,7 @@ export const createRemoteConfig = async (

export const createOrganisationAndProject = async (organisationName:string,projectName:string) =>{
log('Create Organisation')
await click(byId('home-link'))
await click(byId('create-organisation-btn'))
await setText('[name="orgName"]', organisationName)
await click('#create-org-btn')
Expand Down
1 change: 1 addition & 0 deletions frontend/e2e/tests/initialise-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export default async function () {
await waitForElementVisible(byId('features-page'))

log('Hide disabled flags')
await click('#project-link')
await click('#project-settings-link')
await click(byId('js-sdk-settings'))
await click(byId('js-hide-disabled-flags'))
Expand Down
1 change: 1 addition & 0 deletions frontend/e2e/tests/invite-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default async function () {
log('Get Invite url')
await t.navigateTo('http://localhost:3000/organisation-settings')
await Selector(byId('organisation-name')).value
await click(byId('users-and-permissions'))
const inviteLink = await Selector(byId('invite-link')).value
log('Accept invite')
await t.navigateTo(inviteLink)
Expand Down
7 changes: 5 additions & 2 deletions frontend/e2e/tests/project-test.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
import {
assertTextContent,
byId,
click,
log,
login,
setText,
waitForElementVisible,
} from '../helpers.cafe'
} from '../helpers.cafe';
import { E2E_USER, PASSWORD } from '../config'

export default async function () {
log('Login')
await login(E2E_USER, PASSWORD)
await click('#project-select-0')
log('Edit Project')
await click('#project-link')
await click('#project-settings-link')
await setText("[name='proj-name']", 'Test Project')
await click('#save-proj-btn')
await waitForElementVisible(byId('switch-project-test-project'))
await assertTextContent(`#project-link`, 'Test Project')

}
1 change: 0 additions & 1 deletion frontend/e2e/tests/versioning-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
editRemoteConfig,
log,
login, refreshUntilElementVisible,
waitAndRefresh,
waitForElementVisible
} from "../helpers.cafe";
import { E2E_USER, PASSWORD } from '../config';
Expand Down
1 change: 0 additions & 1 deletion frontend/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ declare global {
const FormGroup: typeof Component
const Select: typeof _Select
const Column: typeof Component
const RemoveIcon: typeof Component
const Loader: typeof Component
const E2E: boolean
const DYNATRACE_URL: string | undefined
Expand Down
34 changes: 0 additions & 34 deletions frontend/web/components/AlertBar.js

This file was deleted.

Loading

0 comments on commit d92c082

Please sign in to comment.