mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Project switching (#206)
* Register notice component globally * Render button as flex in full width * Add buttons to / route * Rename block->full-width * Add hyrate overlay / project chooser placeholder * Make routes named * Dehydrate / hydrate when switching projects * Add choose project buttons to / route * Add main app component and hydration loader effect * Improve routing flow * Remove unused import statement * Fix test
This commit is contained in:
@@ -67,7 +67,7 @@ describe('Stores / Projects', () => {
|
||||
.mockImplementation(() => Promise.resolve({ data: { data: {} } }));
|
||||
await projectsStore.setCurrentProject('my-project');
|
||||
expect(spy).toHaveBeenCalledWith('/my-project/');
|
||||
expect(projectsStore.state.projects[0]).toEqual({ key: 'my-project' });
|
||||
expect(projectsStore.state.projects?.[0]).toEqual({ key: 'my-project' });
|
||||
});
|
||||
|
||||
it('Returns true if the project exists', async () => {
|
||||
|
||||
@@ -12,12 +12,12 @@ export const useProjectsStore = createStore({
|
||||
state: () => ({
|
||||
needsInstall: false,
|
||||
error: null as LoadingError,
|
||||
projects: [] as Projects,
|
||||
projects: null as Projects | null,
|
||||
currentProjectKey: null as string | null
|
||||
}),
|
||||
getters: {
|
||||
currentProject: (state): ProjectWithKey | ProjectError | null => {
|
||||
return state.projects.find(({ key }) => key === state.currentProjectKey) || null;
|
||||
return state.projects?.find(({ key }) => key === state.currentProjectKey) || null;
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
@@ -29,7 +29,8 @@ export const useProjectsStore = createStore({
|
||||
* Returns a boolean if the operation succeeded or not.
|
||||
*/
|
||||
async setCurrentProject(key: string): Promise<boolean> {
|
||||
const projectKeys = this.state.projects.map(project => project.key);
|
||||
const projects = this.state.projects || ([] as Projects);
|
||||
const projectKeys = projects.map(project => project.key);
|
||||
|
||||
if (projectKeys.includes(key) === false) {
|
||||
try {
|
||||
@@ -38,7 +39,7 @@ export const useProjectsStore = createStore({
|
||||
key: key,
|
||||
...projectInfoResponse.data.data
|
||||
};
|
||||
this.state.projects = [...this.state.projects, project];
|
||||
this.state.projects = [...projects, project];
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user