Skip to content

Commit 4c030c1

Browse files
committed
Merge branch 'pe/conversation-starters' of https://github.com/continuedev/continue into pe/conversation-starters
2 parents 61ea04b + 4718c12 commit 4c030c1

File tree

9 files changed

+106
-72
lines changed

9 files changed

+106
-72
lines changed

gui/src/context/Auth.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({
4545
);
4646

4747
// Orgs
48-
const orgs = useAppSelector((store) => store.profiles.organizations);
48+
const orgs = useAppSelector((store) => store.organizations.organizations);
4949
const selectedOrgId = useAppSelector(
50-
(store) => store.profiles.selectedOrganizationId,
50+
(store) => store.organizations.selectedOrganizationId,
5151
);
5252
const selectedOrganization = useMemo(() => {
5353
if (!selectedOrgId) {

gui/src/pages/config/ScopeSelect.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { useAppDispatch, useAppSelector } from "../../redux/hooks";
1212
export function ScopeSelect() {
1313
const { organizations, selectedOrganization } = useAuth();
1414
const selectedOrgId = useAppSelector(
15-
(state) => state.profiles.selectedOrganizationId,
15+
(state) => state.organizations.selectedOrganizationId,
1616
);
1717
const dispatch = useAppDispatch();
1818

gui/src/redux/slices/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
export * from "./organizations";
12
export * from "./profiles";
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from "./slice";
2+
export * from "./thunks";
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
2+
import { OrganizationDescription } from "core/config/ProfileLifecycleManager";
3+
4+
export interface OrganizationsState {
5+
organizations: OrganizationDescription[];
6+
selectedOrganizationId: string | null;
7+
}
8+
9+
const initialState: OrganizationsState = {
10+
organizations: [],
11+
selectedOrganizationId: null,
12+
};
13+
14+
export const organizationsSlice = createSlice({
15+
name: "organizations",
16+
initialState,
17+
reducers: {
18+
setOrganizations: (
19+
state,
20+
{ payload }: PayloadAction<OrganizationDescription[]>,
21+
) => {
22+
state.organizations = payload;
23+
},
24+
setSelectedOrganizationId: (
25+
state,
26+
{ payload }: PayloadAction<string | null>,
27+
) => {
28+
state.selectedOrganizationId = payload;
29+
},
30+
},
31+
selectors: {
32+
selectOrganizations: (state) => state.organizations,
33+
selectSelectedOrganizationId: (state) => state.selectedOrganizationId,
34+
selectSelectedOrganization: (state) =>
35+
state.organizations.find(
36+
(org) => org.id === state.selectedOrganizationId,
37+
) ?? null,
38+
},
39+
});
40+
41+
export const { setOrganizations, setSelectedOrganizationId } =
42+
organizationsSlice.actions;
43+
44+
export const {
45+
selectOrganizations,
46+
selectSelectedOrganizationId,
47+
selectSelectedOrganization,
48+
} = organizationsSlice.selectors;
49+
50+
export const { reducer: organizationsReducer } = organizationsSlice;
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { createAsyncThunk } from "@reduxjs/toolkit";
2+
import { OrganizationDescription } from "core/config/ProfileLifecycleManager";
3+
import { ThunkApiType } from "../../store";
4+
import { setAvailableProfiles } from "../profiles/slice";
5+
import { setOrganizations, setSelectedOrganizationId } from "./slice";
6+
7+
export const selectOrgThunk = createAsyncThunk<
8+
void,
9+
string | null,
10+
ThunkApiType
11+
>("organizations/select", async (id, { dispatch, extra, getState }) => {
12+
const state = getState();
13+
const initialId = state.organizations.selectedOrganizationId;
14+
let newId = id;
15+
16+
// If no orgs, force clear
17+
if (state.organizations.organizations.length === 0) {
18+
newId = null;
19+
} else if (newId) {
20+
// If new id doesn't match an existing org, clear it
21+
if (!state.organizations.organizations.find((o) => o.id === newId)) {
22+
newId = null;
23+
}
24+
}
25+
// Unlike profiles, don't fallback to the first org,
26+
// Fallback to Personal (org = null)
27+
28+
if (initialId !== newId) {
29+
dispatch(setAvailableProfiles(null));
30+
dispatch(setSelectedOrganizationId(newId));
31+
extra.ideMessenger.post("didChangeSelectedOrg", {
32+
id: newId,
33+
});
34+
}
35+
});
36+
37+
export const updateOrgsThunk = createAsyncThunk<
38+
void,
39+
OrganizationDescription[],
40+
ThunkApiType
41+
>("organizations/update", async (orgs, { dispatch, getState }) => {
42+
const state = getState();
43+
dispatch(setOrganizations(orgs));
44+
45+
// This will trigger reselection if needed
46+
dispatch(selectOrgThunk(state.organizations.selectedOrganizationId));
47+
});

gui/src/redux/slices/profiles/slice.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
22
import { ProfileDescription } from "core/config/ConfigHandler";
3-
import { OrganizationDescription } from "core/config/ProfileLifecycleManager";
43
import { ensureProfilePreferences } from "./utils";
54

65
export interface PreferencesState {
@@ -10,16 +9,12 @@ export interface PreferencesState {
109
export interface ProfilesState {
1110
availableProfiles: ProfileDescription[] | null;
1211
selectedProfileId: string | null;
13-
organizations: OrganizationDescription[];
14-
selectedOrganizationId: string | null;
1512
preferencesByProfileId: Record<string, PreferencesState>;
1613
}
1714

1815
const initialState: ProfilesState = {
1916
availableProfiles: null,
2017
selectedProfileId: null,
21-
organizations: [],
22-
selectedOrganizationId: null,
2318
preferencesByProfileId: {},
2419
};
2520

@@ -46,18 +41,6 @@ export const profilesSlice = createSlice({
4641
}
4742
}
4843
},
49-
setOrganizations: (
50-
state,
51-
{ payload }: PayloadAction<OrganizationDescription[]>,
52-
) => {
53-
state.organizations = payload;
54-
},
55-
setSelectedOrganizationId: (
56-
state,
57-
{ payload }: PayloadAction<string | null>,
58-
) => {
59-
state.selectedOrganizationId = payload;
60-
},
6144
bookmarkSlashCommand: (
6245
state,
6346
action: PayloadAction<{ commandName: string }>,
@@ -112,8 +95,6 @@ export const profilesSlice = createSlice({
11295
export const {
11396
setAvailableProfiles,
11497
setSelectedProfile,
115-
setOrganizations,
116-
setSelectedOrganizationId,
11798
bookmarkSlashCommand,
11899
unbookmarkSlashCommand,
119100
} = profilesSlice.actions;

gui/src/redux/slices/profiles/thunks.ts

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
import { createAsyncThunk } from "@reduxjs/toolkit";
22
import { ProfileDescription } from "core/config/ConfigHandler";
3-
import { OrganizationDescription } from "core/config/ProfileLifecycleManager";
43
import { ThunkApiType } from "../../store";
5-
import {
6-
setAvailableProfiles,
7-
setOrganizations,
8-
setSelectedOrganizationId,
9-
setSelectedProfile,
10-
} from "./slice";
4+
import { setAvailableProfiles, setSelectedProfile } from "./slice";
115

126
export const selectProfileThunk = createAsyncThunk<
137
void,
@@ -89,45 +83,3 @@ export const updateProfilesThunk = createAsyncThunk<
8983
// This will trigger reselection if needed
9084
dispatch(selectProfileThunk(selectedProfileId));
9185
});
92-
93-
export const selectOrgThunk = createAsyncThunk<
94-
void,
95-
string | null,
96-
ThunkApiType
97-
>("session/selectOrg", async (id, { dispatch, extra, getState }) => {
98-
const state = getState();
99-
const initialId = state.profiles.selectedOrganizationId;
100-
let newId = id;
101-
102-
// If no orgs, force clear
103-
if (state.profiles.organizations.length === 0) {
104-
newId = null;
105-
} else if (newId) {
106-
// If new id doesn't match an existing org, clear it
107-
if (!state.profiles.organizations.find((o) => o.id === newId)) {
108-
newId = null;
109-
}
110-
}
111-
// Unlike profiles, don't fallback to the first org,
112-
// Fallback to Personal (org = null)
113-
114-
if (initialId !== newId) {
115-
dispatch(setAvailableProfiles(null));
116-
dispatch(setSelectedOrganizationId(newId));
117-
extra.ideMessenger.post("didChangeSelectedOrg", {
118-
id: newId,
119-
});
120-
}
121-
});
122-
123-
export const updateOrgsThunk = createAsyncThunk<
124-
void,
125-
OrganizationDescription[],
126-
ThunkApiType
127-
>("session/updateOrgs", async (orgs, { dispatch, getState }) => {
128-
const state = getState();
129-
dispatch(setOrganizations(orgs));
130-
131-
// This will trigger reselection if needed
132-
dispatch(selectOrgThunk(state.profiles.selectedOrganizationId));
133-
});

gui/src/redux/store.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { createFilter } from "redux-persist-transform-filter";
1010
import autoMergeLevel2 from "redux-persist/lib/stateReconciler/autoMergeLevel2";
1111
import storage from "redux-persist/lib/storage";
1212
import { IdeMessenger, IIdeMessenger } from "../context/IdeMessenger";
13-
import { profilesReducer } from "./slices";
13+
import { organizationsReducer, profilesReducer } from "./slices";
1414
import configReducer from "./slices/configSlice";
1515
import editModeStateReducer from "./slices/editModeState";
1616
import indexingReducer from "./slices/indexingSlice";
@@ -33,6 +33,7 @@ const rootReducer = combineReducers({
3333
indexing: indexingReducer,
3434
tabs: tabsReducer,
3535
profiles: profilesReducer,
36+
organizations: organizationsReducer,
3637
});
3738

3839
const saveSubsetFilters = [

0 commit comments

Comments
 (0)