Skip to content

Commit

Permalink
DSEGOG-57 make working hours configurable
Browse files Browse the repository at this point in the history
Opted not to make working days configurable, as likely to just be weekdays
  • Loading branch information
louise-davies committed Feb 5, 2025
1 parent 16e31b9 commit 1fa5106
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 3 deletions.
1 change: 1 addition & 0 deletions public/operationsgateway-settings.example.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"apiUrl": "",
"recordLimitWarning": -1,
"workingHours": { "start": 9, "end": 18 },
"routes": [
{
"section": "OperationsGateway",
Expand Down
10 changes: 9 additions & 1 deletion src/plotting/plot.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import type {
PlotData as PlotlyPlotData,
} from 'plotly.js';
import { useTheme } from '@mui/material';
import type { WorkingHours } from '../settings';

export interface PlotProps {
datasets: PlotDataset[];
Expand All @@ -36,6 +37,7 @@ export interface PlotProps {
leftYAxisLabel?: string;
rightYAxisLabel?: string;
viewReset: boolean;
workingHours: WorkingHours;
skipNonBusinessHours: boolean;
}

Expand All @@ -62,6 +64,7 @@ const Plot = (props: PlotProps) => {
leftYAxisLabel,
rightYAxisLabel,
viewReset,
workingHours,
skipNonBusinessHours,
} = props;

Expand Down Expand Up @@ -154,7 +157,10 @@ const Plot = (props: PlotProps) => {
? {
rangebreaks: [
{ pattern: 'day of week', bounds: ['sat', 'mon'] }, // skips from saturday to monday
{ pattern: 'hour', bounds: [18, 9] }, // skips from 6pm to 9am
{
pattern: 'hour',
bounds: [workingHours.end, workingHours.start],
}, // skips from end to start as defined in the config
],
}
: {}),
Expand Down Expand Up @@ -231,6 +237,8 @@ const Plot = (props: PlotProps) => {
viewReset,
themeMode,
skipNonBusinessHours,
workingHours.end,
workingHours.start,
]);

React.useEffect(() => {
Expand Down
4 changes: 4 additions & 0 deletions src/plotting/plotWindow.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import WindowPortal from '../windows/windowPortal.component';
import { selectSelectedChannels } from '../state/slices/tableSlice';
import { useAppSelector, useAppDispatch } from '../state/hooks';
import { PlotConfig, savePlot } from '../state/slices/plotSlice';
import { selectWorkingHours } from '../state/slices/configSlice';

interface PlotWindowProps {
onClose: () => void;
Expand Down Expand Up @@ -140,6 +141,8 @@ const PlotWindow = (props: PlotWindowProps) => {
(channel) => channel.systemName === XAxis
)?.name;

const workingHours = useAppSelector(selectWorkingHours);

const handleSavePlot = React.useCallback(() => {
const configToSave: PlotConfig = {
...plotConfig,
Expand Down Expand Up @@ -371,6 +374,7 @@ const PlotWindow = (props: PlotWindowProps) => {
leftYAxisLabel={leftYAxisLabel}
rightYAxisLabel={rightYAxisLabel}
viewReset={viewFlag}
workingHours={workingHours}
skipNonBusinessHours={skipNonBusinessHours}
/>
</Grid>
Expand Down
8 changes: 7 additions & 1 deletion src/settings.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import { PluginRoute } from './state/scigateway.actions';
import type { PluginRoute } from './state/scigateway.actions';

export interface WorkingHours {
start: number;
end: number;
}

export interface OperationsGatewaySettings {
apiUrl: string;
recordLimitWarning: number;
routes: PluginRoute[];
helpSteps?: { target: string; content: string }[];
pluginHost?: string;
workingHours?: WorkingHours;
}

export let settings: Promise<OperationsGatewaySettings | void>;
Expand Down
14 changes: 13 additions & 1 deletion src/state/slices/configSlice.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createSlice } from '@reduxjs/toolkit';
import type { PayloadAction } from '@reduxjs/toolkit';
import { AppDispatch } from '../store';
import { settings } from '../../settings';
import { settings, type WorkingHours } from '../../settings';
import { RootState } from '../store';

interface URLs {
Expand All @@ -14,6 +14,7 @@ interface ConfigState {
recordLimitWarning: number;
pluginHost: string;
settingsLoaded: boolean;
workingHours: WorkingHours;
}

// Define the initial state using that type
Expand All @@ -24,6 +25,7 @@ export const initialState: ConfigState = {
recordLimitWarning: -1,
pluginHost: '',
settingsLoaded: false,
workingHours: { start: 9, end: 18 },
};

export const configSlice = createSlice({
Expand All @@ -44,6 +46,9 @@ export const configSlice = createSlice({
loadRecordLimitWarningSetting: (state, action: PayloadAction<number>) => {
state.recordLimitWarning = action.payload;
},
loadWorkingHoursSetting: (state, action: PayloadAction<WorkingHours>) => {
state.workingHours = action.payload;
},
},
});

Expand All @@ -52,11 +57,14 @@ export const {
loadPluginHostSetting,
loadUrls,
loadRecordLimitWarningSetting,
loadWorkingHoursSetting,
} = configSlice.actions;

export const selectUrls = (state: RootState) => state.config.urls;
export const selectRecordLimitWarning = (state: RootState) =>
state.config.recordLimitWarning;
export const selectWorkingHours = (state: RootState) =>
state.config.workingHours;

// Defining a thunk
export const configureApp = () => async (dispatch: AppDispatch) => {
Expand All @@ -78,6 +86,10 @@ export const configureApp = () => async (dispatch: AppDispatch) => {
dispatch(loadPluginHostSetting(settingsResult['pluginHost']));
}

if (settingsResult['workingHours'] !== undefined) {
dispatch(loadWorkingHoursSetting(settingsResult['workingHours']));
}

dispatch(settingsLoaded());
}
};
Expand Down

0 comments on commit 1fa5106

Please sign in to comment.