Skip to content

Commit

Permalink
change the default behavior of deleteRecord chaise-config property (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
RFSH authored Nov 21, 2024
1 parent 78f26cd commit a00aa8d
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 36 deletions.
21 changes: 7 additions & 14 deletions config/chaise-config-sample.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
// Configure deployment-specific data here
// for more info: https://github.com/informatics-isi-edu/chaise/blob/master/docs/user-docs/chaise-config.md

var chaiseConfig = {
name: "Sample",
defaultCatalog: "1",
resolverImplicitCatalog: "1",
allowErrorDismissal: true,
confirmDelete: true,
headTitle: 'Chaise',
customCSS: '/assets/css/chaise.css',
navbarBrand: '/',
navbarBrandImage: null,
logoutURL: '/image-annotation',
// signUpURL: '', The URL at a which a user can create a new account
dataBrowser: '',
shareCite: {
acls: {
show: ["*"], // [] <- hide
enable: ["*"] // [] <- disable
}
},
editRecord: true,
deleteRecord: true,
maxRecordsetRowHeight: 160,
navbarBanner: [
{
Expand Down Expand Up @@ -89,16 +82,16 @@ var chaiseConfig = {
footerMarkdown: "**Please check** [Privacy Policy](/privacy-policy/){target='_blank'}",
configRules: [
{
host: ["www.rebuildingakidney.org", "staging.rebuildingakidney.org", "dev.rebuildingakidney.org"], // array of host names
host: ["www.example.org", "staging.example.org", "dev.example.org"], // array of host names
config: {
headTitle: "RBK/GUDMAP",
navbarBrand: "/resources/"
headTitle: "Example",
navbarBrandText: "Example website"
}
}, {
host: ["www.gudmap.org", "staging.gudmap.org", "dev.gudmap.org"], // array of host names
host: ["www.example-2.org", "staging.examle-2.org", "dev.example-2.org"], // array of host names
config: {
headTitle: "GUDMAP/RBK",
navbarBrand: "/"
headTitle: "Example 2",
navbarBrandText: "Example 2 website"
}
}
],
Expand Down
10 changes: 5 additions & 5 deletions docs/user-docs/chaise-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -409,21 +409,21 @@ If a property appears in the same configuration twice, the property defined late
```
#### editRecord
If not present or equal to `true`, the recordedit page allows for inserting records and editing records. The record page will have an edit button for both of these cases as well. If equal to `false`, a dialog appears on recordedit that disallows use of the app for both create and edit, and the create/edit button does not appear in the record app.
If present and equal to `false`, the chaise pages will hide all the edit and create buttons regardless of user ACLs. Chaise will also disallow users from accessing recordedit app in this case.
- Type: Boolean
- Default behavior: Allows for inserting and editing records through the recordedit page
- Default behavior: Allows for inserting and editing records through the recordedit page if the user has proper ACLs.
- Sample syntax:
```
editRecord: false
```
#### deleteRecord
If present and equal to `true`, the recordedit page will show delete button if editRecord is also true, and record page will show delete button if this is true. Otherwise, hide delete buttons.
If present and equal to `false`, the chaise pages will hide all the delete buttons regardless of user ACLs. Otherwise chaise will consult the user ACL for conditonally hiding or showing delete buttons.
- Type: Boolean
- Default behavior: recordset and record page will not show a delete buttons
- Default behavior: Chaise pages display delete buttons based on user ACLs.
- Sample syntax:
```
deleteRecord: true
deleteRecord: false
```
#### allowErrorDismissal
Expand Down
2 changes: 1 addition & 1 deletion src/components/record/record.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ const RecordInner = ({

const canCreate = reference.canCreate && modifyRecord;
const canEdit = tuple.canUpdate && modifyRecord;
const canDelete = tuple.canDelete && modifyRecord && ConfigService.chaiseConfig.deleteRecord === true;
const canDelete = tuple.canDelete && ConfigService.chaiseConfig.deleteRecord !== false;

const copyRecord = () => {
const appLink = reference.contextualize.entryCreate.appLink;
Expand Down
4 changes: 2 additions & 2 deletions src/components/recordedit/recordedit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ const RecordeditInner = ({
delayError: undefined
});

const canShowBulkDelete = appMode === appModes.EDIT && ConfigService.chaiseConfig.deleteRecord === true;
const canShowBulkDelete = appMode === appModes.EDIT && ConfigService.chaiseConfig.deleteRecord !== false;
/**
* enable the button if at least one row can be deleted
*/
Expand Down Expand Up @@ -804,7 +804,7 @@ const RecordeditInner = ({
</p>
</div>
}
{/* Intersecting behaviour of scroll should be visible if there are multiple tables
{/* Intersecting behaviour of scroll should be visible if there are multiple tables
on one page which here seems to be the case when there are successful as well as failed records */}
<ResultsetTable page={resultsetProps.success.page} showSingleScrollbar={!!resultsetProps.failed}/>
</Accordion.Body>
Expand Down
6 changes: 2 additions & 4 deletions src/pages/recordset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,11 @@ const RecordsetApp = (): JSX.Element => {
}

const chaiseConfig = ConfigService.chaiseConfig;
const modifyEnabled = chaiseConfig.editRecord !== false;
const deleteEnabled = chaiseConfig.deleteRecord === true;

const recordsetConfig: RecordsetConfig = {
viewable: true,
editable: modifyEnabled,
deletable: modifyEnabled && deleteEnabled,
editable: chaiseConfig.editRecord !== false,
deletable: chaiseConfig.deleteRecord !== false,
sortable: true,
selectMode: RecordsetSelectMode.NO_SELECT,
disableFaceting: false,
Expand Down
3 changes: 2 additions & 1 deletion src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ export const DEFAULT_CHAISE_CONFIG = {
dataBrowser: '/',
maxRecordsetRowHeight: 160,
confirmDelete: true,
deleteRecord: false,
editRecord: true,
deleteRecord: true,
signUpURL: '',
allowErrorDismissal: false,
hideTableOfContents: false,
Expand Down
7 changes: 1 addition & 6 deletions src/utils/record-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,7 @@ export function canEditRelated(relatedRef: any): boolean {
* Whether we can delete instances of a related reference
*/
export function canDeleteRelated(relatedRef: any): boolean {
/**
* TODO this is replicating the Angularjs behavior but we should consider the following:
* - why do we need to check editRecord?
* - why deleteRecord check is backwards?
*/
if (ConfigService.chaiseConfig.editRecord === false || ConfigService.chaiseConfig.deleteRecord !== true) {
if (ConfigService.chaiseConfig.deleteRecord === false) {
return false;
}

Expand Down
24 changes: 22 additions & 2 deletions test/e2e/specs/default-config/record/links.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { test, expect, TestInfo, Page } from '@playwright/test';
import ModalLocators from '@isrd-isi-edu/chaise/test/e2e/locators/modal';
import NavbarLocators from '@isrd-isi-edu/chaise/test/e2e/locators/navbar';
import RecordLocators from '@isrd-isi-edu/chaise/test/e2e/locators/record';
import RecordeditLocators from '@isrd-isi-edu/chaise/test/e2e/locators/recordedit';
import RecordsetLocators from '@isrd-isi-edu/chaise/test/e2e/locators/recordset';

// utils
Expand Down Expand Up @@ -100,6 +101,27 @@ test('export button', async ({ page, baseURL }, testInfo) => {
await testExportDropdown(page, ['links-table.csv', `links-table_${ridValue}.zip`], APP_NAMES.RECORD);
});


test('default behavior of editRecord and deleteRecord chaise-config props', async ({page, baseURL}, testInfo) => {
await goToPage(page, baseURL, testInfo, testParams.table_name);

await test.step('delete button should be visible', async () => {
const deleteBtn = RecordLocators.getDeleteRecordButton(page);
await expect.soft(deleteBtn).toBeVisible();
// actual delete tests are done in other specs
});

// this must be the last step here as it will change the page location
await test.step('edit button should be visible', async () => {
const editBtn = RecordLocators.getEditRecordButton(page);
await expect.soft(editBtn).toBeVisible();
await editBtn.click();
await expect.soft(page).toHaveURL(/recordedit/);
await RecordeditLocators.waitForRecordeditPageReady(page);
// actual edit tests are done in other specs
});
});

test('hide_column_header support', async ({ page, baseURL }, testInfo) => {
await goToPage(page, baseURL, testInfo, testParams.table_name);

Expand All @@ -116,8 +138,6 @@ test('hide_column_header support', async ({ page, baseURL }, testInfo) => {
});




/********************** helper functions ************************/
const goToPage = async (page: Page, baseURL: string | undefined, testInfo: TestInfo, tableName: string, dontWrapAroundStep?: boolean) => {
const steps = async () => {
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/utils/page-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function generateChaiseURL(appName: APP_NAMES, schemaName: string, tableN
*
* Example:
*
* const newPage = await PageLocators.clickNewTabLink(someButton, context);
* const newPage = await clickNewTabLink(someButton, context);
*
* await newPage.waitForURL('someURL');
*
Expand Down

0 comments on commit a00aa8d

Please sign in to comment.