Skip to content

Commit 8d9e535

Browse files
Merge pull request #78 from DiamondLightSource/export-file-context-actions
Modify and export addPage widget actions
2 parents 91f0f8d + 9baf0d7 commit 8d9e535

File tree

4 files changed

+21
-9
lines changed

4 files changed

+21
-9
lines changed

src/misc/fileContext.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ export interface TabState {
5353
export function addPage(
5454
pageState: PageState,
5555
location: string,
56-
desc: FileDescription
56+
desc: FileDescription,
57+
pathname?: string
5758
): PageState {
5859
const pagesCopy = { ...pageState };
5960
pagesCopy[location] = desc;
@@ -171,7 +172,11 @@ export function selectTab(
171172
export type FileContextType = {
172173
pageState: PageState;
173174
tabState: TabState;
174-
addPage: (location: string, fileDesc: FileDescription) => void;
175+
addPage: (
176+
location: string,
177+
fileDesc: FileDescription,
178+
pathname?: string
179+
) => void;
175180
removePage: (location: string, fileDesc?: FileDescription) => void;
176181
addTab: (
177182
location: string,
@@ -238,9 +243,13 @@ export const FileProvider: React.FC<FileProviderProps> = (
238243
const fileContext = {
239244
pageState,
240245
tabState,
241-
addPage: (location: string, fileDesc: FileDescription): void => {
246+
addPage: (
247+
location: string,
248+
fileDesc: FileDescription,
249+
pathname?: string
250+
): void => {
242251
const newPageState = addPage(pageState, location, fileDesc);
243-
history.push(history.location.pathname, {
252+
history.push(pathname ? pathname : history.location.pathname, {
244253
pageState: newPageState,
245254
tabState: history.location.state?.tabState ?? tabState
246255
});

src/misc/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export { onRenderCallback } from "./profilerCallback";
2-
export { FileProvider } from "./fileContext";
2+
export { FileProvider, FileContext } from "./fileContext";
33
export { OutlineContext, OutlineProvider } from "./outlineContext";

src/ui/widgets/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export { TabContainer } from "./Tabs/tabContainer";
3636
export { DynamicTabs } from "./Tabs/dynamicTabs";
3737
export { XYPlot } from "./XYPlot/xyPlot";
3838
export { Webcam } from "./Webcam/webcam";
39+
export { executeAction } from "./widgetActions";
3940

4041
// By importing and calling this function you ensure all the
4142
// above widgets are imported and thus registered.

src/ui/widgets/widgetActions.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,15 @@ export const getActionDescription = (action: WidgetAction): string => {
120120
export const openPage = (
121121
action: DynamicAction,
122122
fileContext?: FileContextType,
123-
parentMacros?: MacroMap
123+
parentMacros?: MacroMap,
124+
pathname?: string
124125
): void => {
125126
const { location, file } = action.dynamicInfo;
126127
file.macros = {
127128
...(parentMacros ?? {}),
128129
...file.macros
129130
};
130-
fileContext?.addPage(location, file);
131+
fileContext?.addPage(location, file, pathname);
131132
};
132133

133134
export const closePage = (
@@ -163,12 +164,13 @@ export const executeAction = (
163164
action: WidgetAction,
164165
files?: FileContextType,
165166
exitContext?: ExitContextType,
166-
parentMacros?: MacroMap
167+
parentMacros?: MacroMap,
168+
pathname?: string
167169
): void => {
168170
switch (action.type) {
169171
case OPEN_PAGE:
170172
if (files) {
171-
openPage(action, files, parentMacros);
173+
openPage(action, files, parentMacros, pathname);
172174
} else {
173175
log.error("Tried to open a page but no file context passed");
174176
}

0 commit comments

Comments
 (0)