Skip to content
Merged
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
43 changes: 43 additions & 0 deletions CageUI/resources/queries/cageui/ghost_cages.query.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!--
~ /*
~ * Copyright (c) 2026 Board of Regents of the University of Wisconsin System
~ *
~ * Licensed under the Apache License, Version 2.0 (the "License");
~ * you may not use this file except in compliance with the License.
~ * You may obtain a copy of the License at
~ *
~ * http://www.apache.org/licenses/LICENSE-2.0
~ *
~ * Unless required by applicable law or agreed to in writing, software
~ * distributed under the License is distributed on an "AS IS" BASIS,
~ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ * See the License for the specific language governing permissions and
~ * limitations under the License.
~ */
-->

<query xmlns="http://labkey.org/data/xml/query">
<metadata>
<tables xmlns="http://labkey.org/data/xml">
<table tableName="ghost_cages" tableDbType="TABLE">
<tableTitle>Ghost Cages</tableTitle>
<columns>
<column columnName="rowid">
<isKeyField>true</isKeyField>
</column>
<column columnName="cage_objectid"/>
<column columnName="positionid"/>
<column columnName="rack_group"/>
<column columnName="rack_objectid"/>
<column columnName="group_rotation"/>
<column columnName="cage"/>
<column columnName="container"/>
<column columnName="createdby"/>
<column columnName="created"/>
<column columnName="modified"/>
<column columnName="modifiedby"/>
</columns>
</table>
</tables>
</metadata>
</query>
9 changes: 1 addition & 8 deletions CageUI/resources/queries/cageui/layout_history.query.xml

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure there are no UI (report/query, dropdowns, etc.) using these old lookups.

Seems like you replaced this with the rack_objectid and cage_objectid so this is correct, just wanted to make sure.

Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,7 @@
<isKeyField>true</isKeyField>
</column>
<column columnName="historyid"/>
<column columnName="cage">
<fk>
<fkDbSchema>cageui</fkDbSchema>
<fkTable>cages</fkTable>
<fkColumnName>objectid</fkColumnName>
<fkDisplayColumnName>cage_number</fkDisplayColumnName>
</fk>
</column>
<column columnName="cage"/>
<column columnName="extra_context"/>
<column columnName="object_type">
<datatype>integer</datatype>
Expand Down
16 changes: 16 additions & 0 deletions CageUI/resources/schemas/cageui.xml
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,20 @@
<column columnName="modifiedby"/>
</columns>
</table>
<table tableName="ghost_cages" tableDbType="TABLE">
<columns>
<column columnName="rowid"/>
<column columnName="cage_objectid"/>
<column columnName="positionid"/>
<column columnName="rack_group"/>
<column columnName="rack_objectid"/>
<column columnName="group_rotation"/>
<column columnName="cage"/>
<column columnName="container"/>
<column columnName="createdby"/>
<column columnName="created"/>
<column columnName="modified"/>
<column columnName="modifiedby"/>
</columns>
</table>
</tables>
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
*
* * Copyright (c) 2026 Board of Regents of the University of Wisconsin System
* *
* * Licensed under the Apache License, Version 2.0 (the "License");
* * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
* *
* * http://www.apache.org/licenses/LICENSE-2.0
* *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the License for the specific language governing permissions and
* * limitations under the License.
*
*/

DROP TABLE IF EXISTS cageui.ghost_cages;
CREATE TABLE cageui.ghost_cages
(
rowid SERIAL NOT NULL,
cage_objectid VARCHAR NOT NULL,
positionid INTEGER,
rack_group INTEGER NOT NULL,
rack_objectid VARCHAR NOT NULL,
group_rotation INTEGER NOT NULL,
cage INTEGER NOT NULL,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most places in your CageUI (like cageUi.cage_history) use VARCHAR for 'cage' and INTEGER for 'cage_number'. Not sure if this is a typo or intentional.

container entityid NOT NULL,
createdby userid,
created TIMESTAMP,
modifiedby userid,
modified TIMESTAMP,
CONSTRAINT PK_ghost_cages PRIMARY KEY (rowid),
CONSTRAINT FK_ghost_cages_container FOREIGN KEY (container) REFERENCES core.Containers (EntityId)
);

insert into ehr_lookups.lookups (set_name,container,value, category, title, description)
select setname, container, 8 as value, 'Caging' as category, 'Ghost Cage' as title, 4 as description from ehr_lookups.lookup_sets where setname='cageui_item_types';

insert into ehr_lookups.lookups (set_name,container,value, title)
select setname, container, 'ghostCage' as value, '/cageui/static/cage.svg' as title from ehr_lookups.lookup_sets where setname='cageui_svg_urls';
2 changes: 1 addition & 1 deletion CageUI/src/client/api/labkeyActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export function saveRoomLayout(room: Room, mods: CageMods[], prevRoomName: strin

export function createNewRoomFromRackChange(room: Room, newRackOption: RackSwitchOption, prevRack: Rack ): Promise<{
room: Room,
rack: string;
rack: string,
errors: any[]
}> {
return new Promise((resolve, reject) => {
Expand Down
31 changes: 30 additions & 1 deletion CageUI/src/client/api/popularQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import { Filter, Query } from '@labkey/api';
import { labkeyActionSelectWithPromise } from './labkeyActions';
import { EHRCageMods } from '../types/homeTypes';
import { CageData, CageHistoryData, RackData } from '../types/typings';
import { CageData, CageHistoryData, GhostCageData, RackData } from '../types/typings';

export const cageModLookup = async (columns: string[], filterArray: Filter.IFilter[]): Promise<EHRCageMods[]> => {
const config: Query.SelectRowsOptions = {
Expand Down Expand Up @@ -100,6 +100,35 @@ export const fetchCage = async (objectId: string): Promise<CageData> => {
}
};

export const fetchGhostCage = async (objectId: string): Promise<GhostCageData> => {
const config: Query.SelectRowsOptions = {
schemaName: 'cageui',
queryName: 'ghost_cages',
filterArray: [Filter.create('cage_objectid', objectId, Filter.Types.EQUAL)]
};

try {
const res = await labkeyActionSelectWithPromise(config);
if (res.rows.length === 1) {
return {
rowid: res.rows[0].rowid,
cageObjId: res.rows[0].cage_objectid,
positionId: res.rows[0].positionid,
rackGroup: res.rows[0].rack_group,
rack: 0,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks odd as the rest are imported from 'res.rows', but I assume this '0' assignment is the entire point of this fetchGhostCage function. If that's the case, this is good to go.

rackObjId: res.rows[0].rack_objectid,
groupRotation: res.rows[0].group_rotation,
cage: res.rows[0].cage,
};
} else {
throw new Error('Error fetching ghost cage data');
}
}
catch (e) {
throw new Error('Error fetching ghost cage data: ' + (e as Error).message);
}
};

export const fetchRack = async (objectId: string): Promise<RackData> => {
const config: Query.SelectRowsOptions = {
schemaName: 'cageui',
Expand Down
2 changes: 1 addition & 1 deletion CageUI/src/client/components/home/RoomList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export const RoomList: FC = () => {
} else {
tempRacks.push({
id: r.svgId,
name: `Rack-${r.itemId}`,
name: r.itemId === 0 ? 'Ghost Rack' : `Rack-${r.itemId}`,
cages: [{
name: c.cageNum,
id: c.svgId
Expand Down
13 changes: 11 additions & 2 deletions CageUI/src/client/components/home/rackView/ChangeRackPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { RackSwitchOption } from '../../../types/homeTypes';
import { LayoutErrors } from '../../LayoutErrors';
import { LoadingScreen } from '../../LoadingScreen';
import { useHomeNavigationContext } from '../../../context/HomeNavigationContextManager';
import { generateUUID } from '../../../utils/helpers';

interface ChangeRackPopupProps {
showChangeRackPopup: React.Dispatch<React.SetStateAction<boolean>>;
Expand Down Expand Up @@ -89,7 +90,7 @@ export const ChangeRackPopup: FC<ChangeRackPopupProps> = (props) => {
};
labkeyActionSelectWithPromise(racksConfig).then((racksResult) => {
if (racksResult.rowCount > 0) {
const options = racksResult.rows.reduce((acc, row) => {
let options = racksResult.rows.reduce((acc, row) => {
acc.push({
value: {
objectId: row.objectid,
Expand All @@ -100,6 +101,15 @@ export const ChangeRackPopup: FC<ChangeRackPopupProps> = (props) => {
});
return acc;
}, [] as RackSwitchOption[]);
const ghostCageOption: RackSwitchOption = {
value: {
objectId: generateUUID(),
rackId: 0,
typeRowId: 0
},
label: "Ghost Rack"
}
options = [ghostCageOption, ...options];
setRackOptions(options);
}
});
Expand Down Expand Up @@ -149,7 +159,6 @@ export const ChangeRackPopup: FC<ChangeRackPopupProps> = (props) => {
'home',
ActionURL.getContainer(),
{room: res.roomName, rack: res.rack});

} else {
setIsSaving(false);
if (res?.reason) {
Expand Down
2 changes: 2 additions & 0 deletions CageUI/src/client/context/LayoutEditorContextManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export const LayoutEditorContextProvider: FC<LayoutContextProps> = ({children, p
});
// loaded in and unchanged since start of layout editing
const [room, setRoom] = useState<Room>({
species: '',
name: 'new-layout',
rackGroups: [],
valid: false,
Expand All @@ -118,6 +119,7 @@ export const LayoutEditorContextProvider: FC<LayoutContextProps> = ({children, p
// All changes made to room reflect here. Use room state to compare to the start of room editing vs the changes made here
const [localRoom, setLocalRoom] = useState<Room>({
name: 'new-layout',
species: '',
rackGroups: [],
valid: false,
objects: [],
Expand Down
2 changes: 2 additions & 0 deletions CageUI/src/client/pages/layoutEditor/LayoutEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const LayoutEditor: FC<any> = () => {
const roomName: string = ActionURL.getParameter('room');
const [prevRoomData, setPrevRoomData] = useState<PrevRoom>({
name: null,
species: '',
cagingData: [],
layoutData: null,
isDefault: true
Expand Down Expand Up @@ -127,6 +128,7 @@ export const LayoutEditor: FC<any> = () => {
// Don't use template name instead treat the template as an empty room with objects already placed
newLocalRoom = {
name: isTemplate ? 'new-layout' : prevRoomData.name,
species: '',
rackGroups: [],
valid: false,
objects: [],
Expand Down
20 changes: 18 additions & 2 deletions CageUI/src/client/types/typings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ export enum RackTypes {
Cage = 4,
Pen = 5,
TempCage = 6,
PlayCage = 7
PlayCage = 7,
GhostCage = 8
}

// Like rack types enum but for room objects, start at 100 to give buffer room for rack types
Expand Down Expand Up @@ -235,13 +236,26 @@ export interface CageModificationsType {

export interface Room {
name: string;
species: string;
valid: boolean;
rackGroups: RackGroup[];
objects: RoomObject[];
layoutData: LayoutData;
mods?: RoomMods;
}


export interface GhostCageData {
rowid: number;
cageObjId: string;
positionId: number;
rackGroup: number;
rack: number;
rackObjId: string;
groupRotation: number;
cage: number;
}

export interface LayoutData {
scale: number;
borderWidth: number;
Expand Down Expand Up @@ -320,13 +334,14 @@ export interface AllHistoryData {
}

export interface FullObjectHistoryData {
isGhost: boolean;
objectType: RoomObjectTypes | RackTypes | DefaultRackTypes;
extraContext: string | null;
rackGroup?: number;
groupRotation?: GroupRotation;
// objectid of rack in racks table
rack?: RackData | number;
cage?: FullCageHistory | number;
cage?: FullCageHistory | GhostCageData | number;
xCoord: number;
yCoord: number;
}
Expand All @@ -346,6 +361,7 @@ export interface PrevRoom {
layoutData: LayoutData;
modData?: ModData[];
isDefault: boolean;
species: string;
name: string | null;
}

Expand Down
25 changes: 20 additions & 5 deletions CageUI/src/client/utils/LayoutEditorHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ import {
generateUUID,
getAdjLocation,
getDefaultMod,
getTypeClassFromElement, isRoomCreator, isRoomModifier, isTemplateCreator,
getTypeClassFromElement,
isRoomCreator,
isRoomModifier,
isTemplateCreator,
parseRoomItemType,
roomItemToString
} from './helpers';
Expand All @@ -35,7 +38,7 @@ import {
CageMods,
CageSvgId,
DefaultRackTypes,
FullObjectHistoryData,
FullObjectHistoryData, GhostCageData,
GroupId,
LayoutHistoryData,
LocationCoords,
Expand Down Expand Up @@ -64,12 +67,10 @@ import * as React from 'react';
import { MutableRefObject } from 'react';
import { Security } from '@labkey/api';
import { CELL_SIZE } from './constants';
import { fetchCage, fetchCageHistory, fetchRack } from '../api/popularQueries';
import { fetchCage, fetchCageHistory, fetchGhostCage, fetchRack } from '../api/popularQueries';
import { ConnectedCage, ConnectedRack } from '../types/homeTypes';




export const isTouchEvent = (event)=> {
return event.type.startsWith('touch');
}
Expand Down Expand Up @@ -136,16 +137,30 @@ export const processRealLayoutHistory = async (data: LayoutHistoryData[]): Promi
const processItem = async (item: LayoutHistoryData): Promise<FullObjectHistoryData> => {
if (item.cage === null) {
return {
isGhost: false,
extraContext: item.extraContext,
objectType: item.objectType,
xCoord: item.xCoord,
yCoord: item.yCoord
};
}else if(item.objectType === RackTypes.GhostCage){
const ghostCage: GhostCageData = await fetchGhostCage(item.cage);
return {
isGhost: true,
extraContext: item.extraContext,
objectType: item.objectType,
xCoord: item.xCoord,
yCoord: item.yCoord,
rackGroup: ghostCage.rackGroup,
groupRotation: ghostCage.groupRotation,
cage: ghostCage
};
} else {
const cageHistory: CageHistoryData = await fetchCageHistory(item.historyId, item.cage);
const cageData: CageData = await fetchCage(cageHistory.cage);
const rackData: RackData = await fetchRack(cageData.rack);
return {
isGhost: false,
extraContext: item.extraContext,
objectType: item.objectType,
xCoord: item.xCoord,
Expand Down
Loading
Loading