Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/ShiftSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const ShiftSelector: React.FC<PanelProps<TPropOptions>> = (props) => {
isShowDayLabel,
isShowTimeLabel,
isAutoSelectShift,
isAutoChangeEndToNow,
dayLabel,
rangeLabelType,
shiftOptionsLabelType,
Expand Down Expand Up @@ -193,6 +194,7 @@ const ShiftSelector: React.FC<PanelProps<TPropOptions>> = (props) => {
setShiftParams={setManualShiftParams}
shiftSelectHandler={shiftSelectHandler}
isAutoSelectShift={isAutoSelectShift}
isAutoChangeEndToNow={isAutoChangeEndToNow}
isOptionGroupLabelTrimmed={isOptionGroupLabelTrimmed}
autoSelectShiftGroup={autoSelectShiftGroup}
mappings={var_label_mapping}
Expand Down
1 change: 1 addition & 0 deletions src/components/inputWrappers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type TPropInputWrapperOptions = Omit<
| 'isDataSourceShifts'
| 'isOptionGroupLabelTrimmed'
| 'isAutoSelectShift'
| 'isAutoChangeEndToNow'
| 'autoSelectShiftGroup'
| 'isShowTimeLabel'
| 'shiftOptionsLabelType'
Expand Down
1 change: 1 addition & 0 deletions src/components/options.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export const ShiftOptions = ({
setShiftParams: (shift: ShiftI, isManualUpdate?: any) => void;
shiftSelectHandler: typeof utilShiftSelectHandler;
isAutoSelectShift: boolean;
isAutoChangeEndToNow: boolean;
isShowTimeLabel: boolean;
autoSelectShiftGroup: string | undefined;
mappings: string;
Expand Down
13 changes: 9 additions & 4 deletions src/hooks/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const useShiftSelectorHook = (props: PanelProps<TPropOptions>) => {
const { data: _data, width, height, timeRange, eventBus } = props;
const {
isAutoSelectShift,
isAutoChangeEndToNow,
isDataSourceShifts,
isOptionGroupLabelTrimmed,
var_query_map_dynamic,
Expand Down Expand Up @@ -140,7 +141,7 @@ export const useShiftSelectorHook = (props: PanelProps<TPropOptions>) => {
const { startDate, endDate } = shift || {};

const from = startDate.unix() * 1000;
const to = endDate.unix() * 1000;
const to = isAutoChangeEndToNow ? 'now' : endDate.unix() * 1000;

if (isAutoSelectShift && isManualUpdate) {
return setAlertHandler({
Expand All @@ -157,8 +158,9 @@ export const useShiftSelectorHook = (props: PanelProps<TPropOptions>) => {
uuid: shift.uuid,
}));
}
locationSrv.partial({[vars.varEndDate]: endDate.toISOString()}, false);
},
[isAutoSelectShift, setAlertHandler, setCustomTimeRange]
[isAutoSelectShift, setAlertHandler, setCustomTimeRange, isAutoChangeEndToNow, locationSrv]
);
const setManualShiftParams = useCallback(
(shift: TExtendedShift, productionDate: number) => {
Expand Down Expand Up @@ -357,15 +359,15 @@ ORDER by ??, ??

const query = {
from: isSwapDates ? to : from,
to: isSwapDates ? from : to,
to: isSwapDates ? from : (isAutoChangeEndToNow ? 'now' : to),
[vars.queryShiftsGroup]: autoSelectShiftGroup,
[vars.queryShiftsOptions]: uuid,
refresh: _refresh,
};

locationSrv.partial(query, false);
}
}, [locationSrv, customTimeRange, timeRange.to, timeRange.from, getRefreshRate, setInitDateRange, autoSelectShiftGroup, isAutoSelectShift]);
}, [locationSrv, customTimeRange, timeRange.to, timeRange.from, getRefreshRate, setInitDateRange, autoSelectShiftGroup, isAutoSelectShift, isAutoChangeEndToNow]);

useEffect(() => {
if (width < 400) {
Expand Down Expand Up @@ -460,6 +462,7 @@ ORDER by ??, ??
setShiftParams,
autoSelectShiftGroup,
isAutoSelectShift,
isAutoChangeEndToNow,
isOptionGroupLabelTrimmed,
shifts: {
options: shiftOptions.options,
Expand All @@ -477,6 +480,7 @@ ORDER by ??, ??
setShiftParams,
autoSelectShiftGroup,
isAutoSelectShift,
isAutoChangeEndToNow,
isOptionGroupLabelTrimmed,
shifts: {
options: shiftOptions.options,
Expand All @@ -499,6 +503,7 @@ ORDER by ??, ??
setShiftParams,
autoSelectShiftGroup,
isAutoSelectShift,
isAutoChangeEndToNow,
isOptionGroupLabelTrimmed,
shiftOptions,
shiftValues,
Expand Down
8 changes: 8 additions & 0 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ export const plugin = new PanelPlugin(ShiftSelector).setPanelOptions((builder) =
description: 'This gives you the ability to track the shifts in real-time',
defaultValue: false,
})
.addBooleanSwitch({
category: ['Behavior'],
path: 'isAutoChangeEndToNow',
showIf: (c: any) => c.isAutoSelectShift,
name: 'Change the end of time-range to now',
description: 'This will seek the current end of the time-range to now instead of ending shift time',
defaultValue: true,
})
.addTextInput({
category: ['Behavior'],
path: 'autoSelectShiftGroup',
Expand Down
3 changes: 3 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export type TPropOptions = {
isDataSourceShifts: boolean;
isOptionGroupLabelTrimmed: boolean;
isAutoSelectShift: boolean;
isAutoChangeEndToNow: boolean;
autoSelectShiftGroup: string;
isShowDayLabel: boolean;
isShowTimeLabel: boolean;
Expand Down Expand Up @@ -136,6 +137,7 @@ export enum vars {
varQueryMapper = 'var_query_map',
varDataModel = 'var_shifts_dataModel',
varShiftsValuesName = 'shifts_values',
varEndDate = 'var-end_date',
}

export type TMappings = {
Expand All @@ -146,6 +148,7 @@ export type TUpdateActiveShiftProps = {
setShiftParams: (shift: TExtendedShift, isManualUpdate?: any) => void;
autoSelectShiftGroup: string;
isAutoSelectShift: boolean;
isAutoChangeEndToNow: boolean;
isOptionGroupLabelTrimmed: boolean;
setProductionDate: React.Dispatch<number>;
productionDate: number;
Expand Down