Skip to content

Commit

Permalink
fix(web): refresh service/order on ws reconnect
Browse files Browse the repository at this point in the history
* e.g. if you changed the config and restarted the service
  • Loading branch information
JosephKav committed Apr 8, 2024
1 parent 06e0927 commit 49c132c
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 15 deletions.
6 changes: 3 additions & 3 deletions web/ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions web/ui/react-app/src/components/generic/form-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,11 @@ const FormItem: FC<FormItemProps> = ({
const { getValues, register, setError, clearErrors } = useFormContext();
const error = useError(
name,
required || isNumber || isRegex || isURL || registerParams["validate"]
? true
: false
!!required ||
isNumber ||
isRegex ||
isURL ||
registerParams["validate"] !== undefined
);

const padding = formPadding({ col_xs, col_sm, position, positionXS });
Expand Down
6 changes: 3 additions & 3 deletions web/ui/react-app/src/contexts/modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interface ModalCtx {
}

/**
* The modal context, which provides modals to the application.
* Provides modals to the application.
*
* @param modalType - The type of modal to display
* @param service - The service to display in the modal
Expand All @@ -27,10 +27,10 @@ interface Props {
}

/**
* Returns the modal provider, which provides modals to the application.
* Provides modals to the application.
*
* @param props - The children to render
* @returns The modal provider, which provides modals to the application.
* @returns A Provider of modals to the application.
*/
const ModalProvider = (props: Props): ReactElement => {
const { modal, handleModal } = useModal();
Expand Down
6 changes: 3 additions & 3 deletions web/ui/react-app/src/contexts/notification.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ interface NotificationCtx {
}

/**
* The notification context, which provides notifications to the application.
* Provides notifications to the application and functions to add and remove them.
*
* @param notifications - The notifications to display
* @param addNotification - Function to add a notification
* @param removeNotification - Function to remove a notification
* @returns The notification context
* @returns A context to view, add, and remove notifications
*/
const NotificationContext = createContext<NotificationCtx>({
notifications: [],
Expand All @@ -33,7 +33,7 @@ const NotificationContext = createContext<NotificationCtx>({
});

/**
* @returns The notification provider, which provides notifications to the application.
* @returns A provider of notifications to the application.
*/
const NotificationProvider = () => {
const [notifications, setNotifications] = useState<NotificationType[]>([]);
Expand Down
7 changes: 5 additions & 2 deletions web/ui/react-app/src/contexts/websocket.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ interface WebSocketCtx {
}

/**
* The WebSocket context, which provides the WebSocket connection and monitor data.
* Provides the WebSocket connection and monitor data.
*
* @param ws - The WebSocket connection
* @param connected - Whether the WebSocket connection is established
Expand All @@ -57,7 +57,7 @@ interface Props {

const ws = new ReconnectingWebSocket(`${WS_ADDRESS}${getBasename()}/ws`);
/**
* @returns The WebSocket provider, which provides the WebSocket connection and monitor data.
* @returns The WebSocket connection and monitor data.
*/
export const WebSocketProvider = (props: Props) => {
const queryClient = useQueryClient();
Expand Down Expand Up @@ -108,6 +108,9 @@ export const WebSocketProvider = (props: Props) => {
}, [orderData]);

ws.onopen = () => {
queryClient.invalidateQueries({
queryKey: ["service/order"],
});
setConnected(true);
};

Expand Down
2 changes: 1 addition & 1 deletion web/ui/react-app/src/reducers/monitor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export default function reducerMonitor(
)
return state;

state.service[id].status = state.service[id].status || {};
state.service[id].status = state.service[id].status ?? {};

// latest_version
state.service[id].status!.latest_version =
Expand Down

0 comments on commit 49c132c

Please sign in to comment.