-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[261] Ensure that the workspace view is located in the project router
Bug: #261 Signed-off-by: Stéphane Bégaudeau <[email protected]>
- Loading branch information
1 parent
8493060
commit 92b9925
Showing
14 changed files
with
189 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
frontend/svalyn-studio-app/src/projects/ProjectProvider.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* Copyright (c) 2023 Stéphane Bégaudeau. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and | ||
* associated documentation files (the "Software"), to deal in the Software without restriction, | ||
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, | ||
* subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all copies or substantial | ||
* portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT | ||
* LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
import { gql, useQuery } from '@apollo/client'; | ||
import CorporateFareIcon from '@mui/icons-material/CorporateFare'; | ||
import { useSnackbar } from 'notistack'; | ||
import { useEffect } from 'react'; | ||
import { useParams } from 'react-router-dom'; | ||
import { NotFoundView } from '../notfound/NotFoundView'; | ||
import { goToDomains, goToHelp, goToHome, goToNotifications, goToSettings } from '../palette/DefaultPaletteActions'; | ||
import { PaletteNavigationAction } from '../palette/Palette.types'; | ||
import { usePalette } from '../palette/usePalette'; | ||
import { GetProjectData, GetProjectVariables, ProjectProviderProps } from './ProjectProvider.types'; | ||
import { ProjectContext } from './useProject'; | ||
|
||
const getProjectQuery = gql` | ||
query getProject($identifier: ID!) { | ||
viewer { | ||
project(identifier: $identifier) { | ||
identifier | ||
name | ||
description | ||
organization { | ||
identifier | ||
name | ||
role | ||
} | ||
} | ||
} | ||
} | ||
`; | ||
|
||
export const ProjectProvider = ({ children }: ProjectProviderProps) => { | ||
const { projectIdentifier } = useParams(); | ||
|
||
const { enqueueSnackbar } = useSnackbar(); | ||
const { setActions } = usePalette(); | ||
|
||
const variables: GetProjectVariables = { identifier: projectIdentifier ?? '' }; | ||
const { data, error } = useQuery<GetProjectData, GetProjectVariables>(getProjectQuery, { variables }); | ||
|
||
useEffect(() => { | ||
if (data) { | ||
const { | ||
viewer: { project }, | ||
} = data; | ||
if (project) { | ||
const backToOrganization: PaletteNavigationAction = { | ||
type: 'navigation-action', | ||
id: 'go-to-organization', | ||
icon: <CorporateFareIcon fontSize="small" />, | ||
label: project.organization.name, | ||
to: `/orgs/${project.organization.identifier}`, | ||
}; | ||
setActions([goToHome, backToOrganization, goToDomains, goToNotifications, goToSettings, goToHelp]); | ||
} | ||
} | ||
if (error) { | ||
enqueueSnackbar(error.message, { variant: 'error' }); | ||
} | ||
}, [data, error]); | ||
|
||
if (!data) { | ||
return null; | ||
} | ||
if (!data.viewer.project) { | ||
return <NotFoundView />; | ||
} | ||
|
||
return <ProjectContext.Provider value={{ project: data.viewer.project }}>{children}</ProjectContext.Provider>; | ||
}; |
49 changes: 49 additions & 0 deletions
49
frontend/svalyn-studio-app/src/projects/ProjectProvider.types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright (c) 2023 Stéphane Bégaudeau. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and | ||
* associated documentation files (the "Software"), to deal in the Software without restriction, | ||
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, | ||
* subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all copies or substantial | ||
* portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT | ||
* LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
export interface ProjectProviderProps { | ||
children?: React.ReactNode; | ||
} | ||
|
||
export interface GetProjectData { | ||
viewer: Viewer; | ||
} | ||
|
||
export interface Viewer { | ||
project: Project | null; | ||
} | ||
|
||
export interface Project { | ||
identifier: string; | ||
name: string; | ||
description: string; | ||
organization: Organization; | ||
} | ||
|
||
export interface Organization { | ||
identifier: string; | ||
name: string; | ||
role: MembershipRole; | ||
} | ||
|
||
export type MembershipRole = 'ADMIN' | 'MEMBER' | 'NONE'; | ||
|
||
export interface GetProjectVariables { | ||
identifier: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.