Skip to content

Commit

Permalink
use API from ermrestJS to generate ID for a row with linked data
Browse files Browse the repository at this point in the history
  • Loading branch information
jrchudy committed Sep 30, 2024
1 parent 3186b3d commit dfb5d49
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
26 changes: 10 additions & 16 deletions src/components/input-switch/foreignkey-field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ const ForeignkeyField = (props: ForeignkeyFieldProps): JSX.Element => {

const { setValue, getValues } = useFormContext();

const [inputSelectedRow, setInputSelectedRow] = useState<SelectedRow | null>(null);
const [recordsetModalProps, setRecordsetModalProps] = useState<RecordsetProps | null>(null);
const [showSpinner, setShowSpinner] = useState<boolean>(false);

Expand All @@ -100,8 +99,6 @@ const ForeignkeyField = (props: ForeignkeyFieldProps): JSX.Element => {
const onClear = () => {
const column = props.columnModel.column;

setInputSelectedRow(null);

if (props.foreignKeyCallbacks?.updateBulkForeignKeySelectedRows) {
props.foreignKeyCallbacks.updateBulkForeignKeySelectedRows(usedFormNumber);
}
Expand Down Expand Up @@ -152,17 +149,16 @@ const ForeignkeyField = (props: ForeignkeyFieldProps): JSX.Element => {
getValues
);

let currentSelectedRow = inputSelectedRow;
// there is a value in the input because of prefill showing an association picker on recordedit page load
// and the user selected a value in that modal that filled in the first form
if (!currentSelectedRow && getValues(props.name) && props.foreignKeyCallbacks?.bulkForeignKeySelectedRows) {
// find row in bulkForeignKeySelectedRows
currentSelectedRow = props.foreignKeyCallbacks.bulkForeignKeySelectedRows.filter((row: SelectedRow | null) => {
// if an input is empty, there won't be a row defined in `bulkForeignKeySelectedRows`
return row && row.displayname.value === getValues(props.name);
})[0];

setInputSelectedRow(currentSelectedRow);
let currentSelectedRow;
const inputFKData = props.foreignKeyData?.current[`c_${usedFormNumber}-${props.columnModel.column.RID}`];
if (inputFKData) {
currentSelectedRow = {
displayname: {
value: getValues(props.name),
isHTML: false
},
uniqueId: props.columnModel.column.generateUniqueId(inputFKData)
}
}

setRecordsetModalProps({
Expand Down Expand Up @@ -192,8 +188,6 @@ const ForeignkeyField = (props: ForeignkeyFieldProps): JSX.Element => {
const selectedRow = selectedRows[0];
const column = props.columnModel.column;

setInputSelectedRow(selectedRow);

// if the recordedit page's table is an association table with a unique key pair, track the selected rows
if (props.foreignKeyCallbacks?.updateBulkForeignKeySelectedRows) {
props.foreignKeyCallbacks.updateBulkForeignKeySelectedRows(usedFormNumber, selectedRow);
Expand Down
18 changes: 17 additions & 1 deletion test/e2e/utils/recordedit-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -607,8 +607,25 @@ const _testInputValidationAndExtraFeatures = async (

case RecordeditInputType.FK_POPUP:
const displayedValue = RecordeditLocators.getForeignKeyInputDisplay(page, displayname, formNumber);
const rsModal = ModalLocators.getForeignKeyPopup(page);

if (typeof existingValue === 'string') {
// before clearing the value, ensure the selected row has the right tooltip in the fk input modal first
await test.step('check the tooltip of the selected row in the modal before clearing the value', async () => {
await RecordeditLocators.getForeignKeyInputButton(page, displayname, formNumber).click();
await expect.soft(rsModal).toBeVisible();

// In the multi edit spec, we have 2 forms
// in the 1st form, the 1st row is selected
// in the 2nd form, the 3rd row is selected
const selectedRowIndex = formNumber === 1 ? 0 : 2;
await testTooltip(RecordsetLocators.getRowSelectButton(rsModal, selectedRowIndex), 'Selected', APP_NAMES.RECORDSET, true);

await ModalLocators.getCloseBtn(rsModal).click();
await expect.soft(rsModal).not.toBeAttached();
});

// value should be unchanged from previous test since the modal was closed with no selection made
await test.step('clicking the "x" should remove the value in the foreign key field.', async () => {
await expect.soft(displayedValue).toHaveText(existingValue);
await RecordeditLocators.getForeignKeyInputClear(page, displayname, formNumber).click();
Expand All @@ -617,7 +634,6 @@ const _testInputValidationAndExtraFeatures = async (
}

await test.step('popup selector', async () => {
const rsModal = ModalLocators.getForeignKeyPopup(page);
await test.step('should have the proper title.', async () => {
await RecordeditLocators.getForeignKeyInputButton(page, displayname, formNumber).click();
await expect.soft(rsModal).toBeVisible();
Expand Down

0 comments on commit dfb5d49

Please sign in to comment.