Skip to content

Commit

Permalink
#1304 - use category and status as db entity
Browse files Browse the repository at this point in the history
  • Loading branch information
petmongrels committed Aug 7, 2024
1 parent c86103c commit 8ed57c7
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 60 deletions.
16 changes: 4 additions & 12 deletions src/adminApp/DeploymentManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,8 @@ import {
AccountOrgAdminUserEdit,
AccountOrgAdminUserList
} from "./AccountOrgAdminUser";
import {
OrganisationCreate,
OrganisationDetails,
OrganisationEdit,
OrganisationList
} from "./Organisation";
import {
organisationGroupCreate,
organisationGroupEdit,
OrganisationGroupList,
OrganisationGroupShow
} from "./OrganisationGroup";
import { OrganisationCreate, OrganisationDetails, OrganisationEdit, OrganisationList } from "./Organisation";
import { organisationGroupCreate, organisationGroupEdit, OrganisationGroupList, OrganisationGroupShow } from "./OrganisationGroup";

class DeploymentManager extends Component {
static childContextTypes = {
Expand Down Expand Up @@ -82,6 +72,8 @@ class DeploymentManager extends Component {
show={OrganisationGroupShow}
edit={organisationGroupEdit}
/>
<Resource name={"organisationCategory"} />
<Resource name={"organisationStatus"} />
</Admin>
);
}
Expand Down
76 changes: 53 additions & 23 deletions src/adminApp/Organisation.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from "react";
import {
BooleanField,
Create,
Datagrid,
DisabledInput,
Expand All @@ -16,43 +17,27 @@ import {
SimpleShowLayout,
TextField,
TextInput,
Toolbar,
BooleanField,
SelectInput
Toolbar
} from "react-admin";
import { CustomSelectInput } from "./components/CustomSelectInput";
import { Title } from "./components/Title";
import OpenOrganisation from "./components/OpenOrganisation";
import ToggleAnalyticsButton from "./ToggleAnalyticsButton";
import OrganisationCategory from "./domain/OrganisationCategory";

export const OrganisationFilter = props => (
<Filter {...props} style={{ marginBottom: "2em" }}>
<TextInput label="Organisation Name" source="name" resettable alwaysOn />
</Filter>
);

const OrganisationCategoryInput = () => {
return (
<SelectInput
source="category"
validate={isRequired}
choices={[
{ id: OrganisationCategory.Production, name: OrganisationCategory.Production },
{ id: OrganisationCategory.UAT, name: OrganisationCategory.UAT },
{ id: OrganisationCategory.Prototype, name: OrganisationCategory.Prototype },
{ id: OrganisationCategory.Temporary, name: OrganisationCategory.Temporary }
]}
/>
);
};

export const OrganisationList = ({ history, ...props }) => {
return (
<List {...props} bulkActions={false} filter={{ searchURI: "find" }} filters={<OrganisationFilter />}>
<Datagrid>
<TextField source="name" label="Name" />
<TextField source="category" label="Category" />
<ReferenceField label="Category" source="categoryId" reference="organisationCategory" linkType={false}>
<TextField source="name" />
</ReferenceField>
<ReferenceField label="Parent organisation" source="parentOrganisationId" reference="organisation" linkType="show" allowEmpty>
<TextField source="name" />
</ReferenceField>
Expand All @@ -77,7 +62,18 @@ export const OrganisationDetails = props => {
<TextField source="schemaName" label="Schema Name" />
<TextField source="mediaDirectory" label="Media Directory" />
<TextField source="usernameSuffix" label="Username Suffix" />
<TextField source="category" label="Category" />
<ReferenceField
resource="organisationCategory"
source="categoryId"
reference="organisationCategory"
label="Category"
linkType={false}
>
<TextField source="name" />
</ReferenceField>
<ReferenceField resource="organisationStatus" source="statusId" reference="organisationStatus" label="Status" linkType={false}>
<TextField source="name" />
</ReferenceField>
<ReferenceField resource="account" source="accountId" reference="account" label="Account Name" linkType="show" allowEmpty>
<TextField source="name" />
</ReferenceField>
Expand Down Expand Up @@ -105,7 +101,24 @@ export const OrganisationEdit = props => {
<DisabledInput source="schemaName" validate={isRequired} />
<DisabledInput source="mediaDirectory" />
<TextInput source="usernameSuffix" validate={isRequired} />
<OrganisationCategoryInput />
<ReferenceInput
resource="organisationCategory"
source="categoryId"
reference="organisationCategory"
label="Organisation Category"
validate={required("Please select a category")}
>
<CustomSelectInput source="name" />
</ReferenceInput>
<ReferenceInput
resource="organisationStatus"
source="statusId"
reference="organisationStatus"
label="Organisation Status"
validate={required("Please select a status")}
>
<CustomSelectInput source="name" />
</ReferenceInput>
<BooleanField source="analyticsDataSyncActive" />
<ToggleAnalyticsButton />
<br />
Expand Down Expand Up @@ -139,7 +152,24 @@ export const OrganisationCreate = props => {
<TextInput source="schemaName" validate={isRequired} />
<TextInput source="mediaDirectory" validate={isRequired} />
<TextInput source="usernameSuffix" validate={isRequired} />
<OrganisationCategoryInput />
<ReferenceInput
resource="organisationCategory"
source="categoryId"
reference="organisationCategory"
label="Organisation Category"
validate={required("Please select a category")}
>
<CustomSelectInput source="name" />
</ReferenceInput>
<ReferenceInput
resource="organisationStatus"
source="statusId"
reference="organisationStatus"
label="Organisation Status"
validate={required("Please select a status")}
>
<CustomSelectInput source="name" />
</ReferenceInput>
<ReferenceInput
resource="account"
source="accountId"
Expand Down
3 changes: 0 additions & 3 deletions src/adminApp/domain/OrganisationCategory.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
class OrganisationCategory {
static Production = "Production";
static UAT = "UAT";
static Prototype = "Prototype";
static Temporary = "Temporary";
}

export default OrganisationCategory;
26 changes: 6 additions & 20 deletions src/adminApp/react-admin-config/dataProvider.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
import _ from "lodash";
import {
CREATE,
UPDATE,
DELETE_MANY,
GET_LIST,
GET_MANY,
GET_MANY_REFERENCE,
GET_ONE,
UPDATE_MANY,
DELETE
} from "react-admin";
import { CREATE, UPDATE, DELETE_MANY, GET_LIST, GET_MANY, GET_MANY_REFERENCE, GET_ONE, UPDATE_MANY, DELETE } from "react-admin";
import { UrlPartsGenerator } from "./requestUtils";
import SpringResponse from "./SpringResponse";
import { httpClient } from "../../common/utils/httpClient";
Expand Down Expand Up @@ -50,7 +40,9 @@ const urlMapping = {
relationship: "/web/relations",
individual: "subjects",
concept: "concept/answerConcepts",
group: "group"
group: "group",
organisationCategory: "organisationCategory",
organisationStatus: "organisationStatus"
};

const resourceSpecificProviders = {
Expand Down Expand Up @@ -98,11 +90,7 @@ export default apiUrl => {
default:
throw new Error(`Unsupported fetch action type ${type}`);
}
console.log(
`Data Provider Action ${type} | Url ${url} | Resource ${resource} | Params ${JSON.stringify(
params
)}`
);
console.log(`Data Provider Action ${type} | Url ${url} | Resource ${resource} | Params ${JSON.stringify(params)}`);
return { url, options };
};

Expand Down Expand Up @@ -163,9 +151,7 @@ export default apiUrl => {
}

const { url, options } = convertDataRequestToHTTP(type, resource, params);
const promise = httpClient
.fetchJson(url, options)
.then(response => convertHTTPResponse(response, type, resource, params));
const promise = httpClient.fetchJson(url, options).then(response => convertHTTPResponse(response, type, resource, params));
const resourceSpecificProvider = resourceSpecificProviders[resource];
if (resourceSpecificProvider && resourceSpecificProvider.supportsOperation(type))
return resourceSpecificProvider.execute(type, params, resource, promise);
Expand Down
2 changes: 1 addition & 1 deletion src/rootApp/ducks.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export default function(state = initialState, action) {
id: action.payload.organisationId,
name: action.payload.organisationName,
usernameSuffix: action.payload.usernameSuffix,
organisationCategory: action.payload.organisationCategory
organisationCategoryName: action.payload.organisationCategoryName
},
userInfo: action.payload
};
Expand Down
2 changes: 1 addition & 1 deletion src/rootApp/views/Homepage.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const Homepage = ({ userInfo, organisation }) => {
const showDataEntryApp = UserInfo.hasPrivilege(userInfo, Privilege.PrivilegeType.ViewEditEntitiesOnDataEntryApp);

return (
<ScreenWithAppBar appbarTitle={`Avni Web Console - ${organisation.organisationCategory}`}>
<ScreenWithAppBar appbarTitle={`Avni Web Console - ${organisation.organisationCategoryName}`}>
<Grid container justifyContent="center">
<HomePageCard
href={"/#/admin/user"}
Expand Down

0 comments on commit 8ed57c7

Please sign in to comment.