Skip to content

Commit

Permalink
Merge pull request #129 from credebl/98-back-button-for-schema-cred-def
Browse files Browse the repository at this point in the history
feat: added get all schema list from platform on list schema page
  • Loading branch information
nishad-ayanworks authored Aug 22, 2023
2 parents 74e3817 + e8b2c9a commit 39dcd32
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 80 deletions.
28 changes: 24 additions & 4 deletions src/api/Schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,29 @@ import { apiRoutes } from "../config/apiRoutes";
import { getFromLocalStorage } from "./Auth";
import { storageKeys } from "../config/CommonConstant";

export const getAllSchemas = async ({ search, itemPerPage, sortBy, page }: GetAllSchemaListParameter, orgId: string) => {
export const getAllSchemas = async ({ search, itemPerPage, sortBy, page }: GetAllSchemaListParameter) => {
const token = await getFromLocalStorage(storageKeys.TOKEN)
const details = {
url: `${apiRoutes.schema.getAllSchemaFromPlatform}`,
config: {
headers: {
'Content-type': 'application/json',
'Authorization': `Bearer ${token}`,
},
},
};

try {
const response = await axiosGet(details)
return response
}
catch (error) {
const err = error as Error
return err?.message
}
}

export const getAllSchemasByOrgId = async ({ search, itemPerPage, sortBy, page }: GetAllSchemaListParameter, orgId: string) => {
const token = await getFromLocalStorage(storageKeys.TOKEN)
const details = {
url: `${apiRoutes.schema.getAll}?orgId=${orgId}&searchByText=${search}&page=${page}&items_per_page=${itemPerPage}&schemaSortBy=${sortBy}&items_per_page=${itemPerPage}&schemaSortBy=${sortBy}`,
Expand Down Expand Up @@ -116,6 +138,4 @@ export const getCredDeffById = async (id: string, orgId: number) => {
const err = error as Error
return err?.message
}
}


}
189 changes: 114 additions & 75 deletions src/components/Resources/Schema/SchemasList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { AxiosResponse } from 'axios';
import BreadCrumbs from '../../BreadCrumbs';
import SchemaCard from '../../../commonComponents/SchemaCard';
import SearchInput from '../../SearchInput';
import { getAllSchemas } from '../../../api/Schema';
import { getAllSchemasByOrgId, getAllSchemas } from '../../../api/Schema';
import { getFromLocalStorage } from '../../../api/Auth';
import { pathRoutes } from '../../../config/pathRoutes';
import { EmptyListMessage } from '../../EmptyListComponent';
Expand All @@ -18,6 +18,7 @@ const SchemaList = (props: { schemaSelectionCallback: (schemaId: string, schemaD
const [schemaList, setSchemaList] = useState([])
const [schemaListErr, setSchemaListErr] = useState<string | null>('')
const [loading, setLoading] = useState<boolean>(true)
const [allSchemaFlag, setAllSchemaFlag] = useState<boolean>(false)
const [orgId, setOrgId] = useState<string>('')
const [schemaListAPIParameter, setSchemaListAPIParameter] = useState({
itemPerPage: 9,
Expand All @@ -27,13 +28,25 @@ const SchemaList = (props: { schemaSelectionCallback: (schemaId: string, schemaD
sortingOrder: "DESC"
})

const getSchemaList = async (schemaListAPIParameter: GetAllSchemaListParameter) => {
const [allSchemaListAPIParameter, setAllSchemaListAPIParameter] = useState({
pageSize: 9,
pageNumber: 1,
searchByText: "",
sortByValue: "id",
sorting: "DESC"
})

const getSchemaList = async (schemaListAPIParameter: GetAllSchemaListParameter, flag: boolean) => {
try {
const organizationId = await getFromLocalStorage(storageKeys.ORG_ID);
setOrgId(organizationId);
setLoading(true);

const schemaList = await getAllSchemas(schemaListAPIParameter, organizationId);
let schemaList
if (allSchemaFlag) {
schemaList = await getAllSchemas(schemaListAPIParameter);
} else {
schemaList = await getAllSchemasByOrgId(schemaListAPIParameter, organizationId);
}
const { data } = schemaList as AxiosResponse;
if (schemaList === 'Schema records not found') {
setLoading(false);
Expand Down Expand Up @@ -72,13 +85,13 @@ const SchemaList = (props: { schemaSelectionCallback: (schemaId: string, schemaD


useEffect(() => {
getSchemaList(schemaListAPIParameter)
getSchemaList(schemaListAPIParameter, false)
}, []);

useEffect(() => {
getSchemaList(schemaListAPIParameter)
getSchemaList(schemaListAPIParameter, false)

}, [schemaListAPIParameter])
}, [schemaListAPIParameter, allSchemaFlag])

const onSearch = async (event: ChangeEvent<HTMLInputElement>): Promise<void> => {
event.preventDefault()
Expand All @@ -90,7 +103,7 @@ const SchemaList = (props: { schemaSelectionCallback: (schemaId: string, schemaD
getSchemaList({
...schemaListAPIParameter,
search: event.target.value
})
}, false)

}

Expand All @@ -103,7 +116,17 @@ const SchemaList = (props: { schemaSelectionCallback: (schemaId: string, schemaD
}
props.schemaSelectionCallback(schemaId, schemaDetails)
}
const options = ["All schemas"]

const handleFilter = (e: React.ChangeEvent<HTMLSelectElement>) => {
if (e.target.value === 'All schemas') {
setAllSchemaFlag(true)
}
else {
setAllSchemaFlag(false)
getSchemaList(schemaListAPIParameter, false)
}
};
return (
<div className="px-4 pt-6">
<div className="mb-4 col-span-full xl:mb-2">
Expand All @@ -122,80 +145,96 @@ const SchemaList = (props: { schemaSelectionCallback: (schemaId: string, schemaD
onInputChange={onSearch}
/>
</div>
<Button
id='createSchemaButton'
onClick={() => {
window.location.href = `${pathRoutes.organizations.createSchema}?OrgId=${orgId}`
}}
className='text-base font-medium text-center text-white bg-primary-700 rounded-lg hover:bg-primary-800 focus:ring-4 focus:ring-primary-300 sm:w-auto dark:bg-primary-600 dark:hover:bg-primary-700 dark:focus:ring-primary-800'
title='Create New Schema' // This is the tooltip text
>
<svg className="pr-2" xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="none" viewBox="0 0 24 24">
<path fill="#fff" d="M21.89 9.89h-7.78V2.11a2.11 2.11 0 1 0-4.22 0v7.78H2.11a2.11 2.11 0 1 0 0 4.22h7.78v7.78a2.11 2.11 0 1 0 4.22 0v-7.78h7.78a2.11 2.11 0 1 0 0-4.22Z" />
</svg>
Create
</Button>
</div>
{
schemaListErr &&
<Alert
color="failure"
onDismiss={() => setSchemaListErr(null)}
>
<span>
<p>
{schemaListErr}
</p>
</span>
</Alert>
}
{loading
? (<div className="flex items-center justify-center mb-4">
<Spinner
color="info"
/>
</div>)
:
schemaList && schemaList.length > 0 ? (
<div className='Flex-wrap' style={{ display: 'flex', flexDirection: 'column' }}>
<div className="mt-1 grid w-full grid-cols-1 gap-4 mt-0 mb-4 xl:grid-cols-2 2xl:grid-cols-3">
{schemaList && schemaList.length > 0 &&
schemaList.map((element, key) => (
<div className='p-2' key={key}>
<SchemaCard schemaName={element['name']} version={element['version']} schemaId={element['schemaLedgerId']} issuerDid={element['issuerId']} attributes={element['attributes']} created={element['createDateTime']}
onClickCallback={schemaSelectionCallback} />
</div>
))}
</div>
<div className="flex items-center justify-end mb-4" id="schemasPagination">

<Pagination
currentPage={1}
onPageChange={(page) => {
setSchemaListAPIParameter(prevState => ({
...prevState,
page: page
}));
}}
totalPages={0}
/>
</div>
</div>) : (<EmptyListMessage
message={'No Schemas'}
description={'Get started by creating a new Schema'}
buttonContent={'Create Schema'}
svgComponent={<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" fill="none" viewBox="0 0 24 24">
<path fill="#fff" d="M21.89 9.89h-7.78V2.11a2.11 2.11 0 1 0-4.22 0v7.78H2.11a2.11 2.11 0 1 0 0 4.22h7.78v7.78a2.11 2.11 0 1 0 4.22 0v-7.78h7.78a2.11 2.11 0 1 0 0-4.22Z" />
</svg>}
<div className='flex space-x-2'>
<select onChange={handleFilter} id="schamfilter" className="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500">
<option selected>Organization's schema</option>
{options.map((opt) => (
<option
key={opt}
className=""
value={opt}
>
{opt}
</option>
))}
</select>

<Button
id='createSchemaButton'
onClick={() => {
window.location.href = `${pathRoutes.organizations.createSchema}?OrgId=${orgId}`
}}
/>)
}
className='text-base font-medium text-center text-white bg-primary-700 rounded-lg hover:bg-primary-800 focus:ring-4 focus:ring-primary-300 sm:w-auto dark:bg-primary-600 dark:hover:bg-primary-700 dark:focus:ring-primary-800'
title='Create New Schema' // This is the tooltip text
>
<svg className="pr-2" xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="none" viewBox="0 0 24 24">
<path fill="#fff" d="M21.89 9.89h-7.78V2.11a2.11 2.11 0 1 0-4.22 0v7.78H2.11a2.11 2.11 0 1 0 0 4.22h7.78v7.78a2.11 2.11 0 1 0 4.22 0v-7.78h7.78a2.11 2.11 0 1 0 0-4.22Z" />
</svg>
Create
</Button>
</div>
</div>
</div>
{
schemaListErr &&
<Alert
color="failure"
onDismiss={() => setSchemaListErr(null)}
>
<span>
<p>
{schemaListErr}
</p>
</span>
</Alert>
}
{loading
? (<div className="flex items-center justify-center mb-4">
<Spinner
color="info"
/>
</div>)
:
schemaList && schemaList.length > 0 ? (
<div className='Flex-wrap' style={{ display: 'flex', flexDirection: 'column' }}>
<div className="mt-1 grid w-full grid-cols-1 gap-4 mt-0 mb-4 xl:grid-cols-2 2xl:grid-cols-3">
{schemaList && schemaList.length > 0 &&
schemaList.map((element, key) => (
<div className='p-2' key={key}>
<SchemaCard schemaName={element['name']} version={element['version']} schemaId={element['schemaLedgerId']} issuerDid={element['issuerId']} attributes={element['attributes']} created={element['createDateTime']}
onClickCallback={schemaSelectionCallback} />
</div>
))}
</div>
<div className="flex items-center justify-end mb-4" id="schemasPagination">

<Pagination
currentPage={1}
onPageChange={(page) => {
setSchemaListAPIParameter(prevState => ({
...prevState,
page: page
}));
}}
totalPages={0}
/>
</div>
</div>) : (<EmptyListMessage
message={'No Schemas'}
description={'Get started by creating a new Schema'}
buttonContent={'Create Schema'}
svgComponent={<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" fill="none" viewBox="0 0 24 24">
<path fill="#fff" d="M21.89 9.89h-7.78V2.11a2.11 2.11 0 1 0-4.22 0v7.78H2.11a2.11 2.11 0 1 0 0 4.22h7.78v7.78a2.11 2.11 0 1 0 4.22 0v-7.78h7.78a2.11 2.11 0 1 0 0-4.22Z" />
</svg>}
onClick={() => {
window.location.href = `${pathRoutes.organizations.createSchema}?OrgId=${orgId}`
}}
/>)
}
</div>
</div>


)
}

Expand Down
3 changes: 2 additions & 1 deletion src/config/apiRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ export const apiRoutes = {
getAll: '/schemas',
getSchemaById:'/schemas/id',
createCredentialDefinition: '/credential-definitions',
getCredDeffBySchemaId: '/schemas/credential-definitions'
getCredDeffBySchemaId: '/schemas/credential-definitions',
getAllSchemaFromPlatform: `/schemas/platform`
},
fido: {
generateRegistration: 'fido/generate-registration-options',
Expand Down

0 comments on commit 39dcd32

Please sign in to comment.