8000 refactor:Get schema details from LocalStorage for view schema page by pranalidhanavade · Pull Request #241 · credebl/studio · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

refactor:Get schema details from LocalStorage for view schema page #241

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

< 8000 /div>
Merged
merged 3 commits into from
Sep 8, 2023
Merged
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
84 changes: 43 additions & 41 deletions src/components/Resources/Schema/ViewSchema.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,17 @@ interface Values {
revocable: boolean;
}

type SchemaData = {
schema: {
attrNames: string[];
name: string;
version: string;
issuerId: string;
};
interface SchemaData {
schemaName: string;
version: string;
issuerDid: string;
schemaId: string;
resolutionMetadata: Record<string, unknown>;
schemaMetadata: {
didIndyNamespace: string;
indyLedgerSeqNo: number;
};
attributes: string[];
createdDateTime: string;
};



const ViewSchemas = () => {
const [schemaDetails, setSchemaDetails] = useState<SchemaData>(null);
const [schemaDetails, setSchemaDetails] = useState<SchemaData | null >(null);
const [credDeffList, setCredDeffList] = useState<any>([]);
const [loading, setLoading] = useState<boolean>(true)
const [createloader, setCreateLoader] = useState<boolean>(false)
Expand All @@ -50,23 +42,34 @@ const ViewSchemas = () => {
const [orgId, setOrgId] = useState<number>(0)
const [credDefAuto, setCredDefAuto] = useState<string>('')

const getSchemaDetails = async (id: string, organizationId: number) => {
const getSchemaDetails = async () => {

try {
setLoading(true);
const SchemaDetails = await getSchemaById(id, organizationId);
const { data } = SchemaDetails as AxiosResponse;
const schemaDetails = await getFromLocalStorage(storageKeys.SCHEMA_ATTR)
const schemaId = await getFromLocalStorage(storageKeys.SCHEMA_ID)
const parts = schemaId.split(":");
const schemaName = parts[2];
const version = parts[3];
const schemaDidObject = JSON.parse(schemaDetails)
Copy link
Contributor

Choose a reason for hiding this comment

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

please remove logs

schemaDidObject.schema = schemaId;

if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) {
setSchemaDetails(data?.data);
setCredDefAuto(`${data?.data?.response?.schema?.name} ${nanoid(8)}`);
setLoading(false);
} else {
await setToLocalStorage(storageKeys.SCHEMA_ID, schemaId)
if (schemaDidObject) {
setLoading(false);
setSchemaDetailErr(SchemaDetails as unknown as string)
setSchemaDetails({
attributes: schemaDidObject.attribute,
schemaId: schemaId,
schemaName: schemaName,
version: version,
issuerDid: schemaDidObject.issuerDid,
createdDateTime: schemaDidObject.createdDateTime

})
}
setLoading(false);

} catch (error) {
setSchemaDetailErr('Error while fetching schema details')
console.error('Error while fetching schema details:', error);
setLoading(false);
}
};
Expand Down Expand Up @@ -100,11 +103,11 @@ const ViewSchemas = () => {
if (window?.location?.search) {
const str = window?.location?.search;
const schemaId = str.substring(str.indexOf('=') + 1);
await getSchemaDetails(schemaId, Number(organizationId));
await getSchemaDetails();
await getCredentialDefinitionList(schemaId, Number(organizationId));
}
};

getSchemaDetails();
fetchData();
}, []);

Expand All @@ -131,12 +134,11 @@ const ViewSchemas = () => {
}
getCredentialDefinitionList(schemaDetails?.schemaId, orgId)
}

const credDefSelectionCallback = async (schemaId: string, credentialDefinitionId: string) => {
await setToLocalStorage(storageKeys.CRED_DEF_ID, credentialDefinitionId)
window.location.href = `${pathRoutes.organizations.Issuance.connections}`
}

}
return (
<div className="px-4 pt-6">
<div className="mb-4 col-span-full xl:mb-2">
Expand Down Expand Up @@ -172,7 +174,7 @@ const ViewSchemas = () => {
<Card className='h-64 sm:w-1/2 p-2 mr-1 mb-1' id="viewSchemaDetailsCard">
{loading ? (
<div className="flex items-center justify-center mb-4">
<CustomSpinner/>
<CustomSpinner />
</div>
) : (
<div className='pt-4'>
Expand Down Expand Up @@ -207,19 +209,19 @@ const ViewSchemas = () => {
<div className="">
<div>
<p className='p-1 dark:text-white break-words'>
Name: {schemaDetails?.schema?.name}
Name: {schemaDetails?.schemaName}
</p>
</div>
<div>
<p className='p-1 dark:text-white break-words'>
Version: {schemaDetails?.schema?.version}
Version: {schemaDetails?.version}
</p>
</div>
<p className='p-1 dark:text-white break-all'>
Schema ID: {schemaDetails?.schemaId}
</p>
<p className='p-1 dark:text-white break-words'>
Issuer DID: {schemaDetails?.schema?.issuerId}
Issuer DID: {schemaDetails?.issuerDid}
</p>
</div>
<div className="flow-root overflow-y-auto">
Expand All @@ -228,9 +230,9 @@ const ViewSchemas = () => {
<div className="flex items-center space-x-4">
<div className="inline-flex items-center text-base font-semibold text-gray-900 dark:text-white flex-wrap p-1">
Attributes:
{schemaDetails?.schema?.attrNames && schemaDetails?.schema?.attrNames?.length > 0 &&
schemaDetails?.schema?.attrNames.map((element: string) => (
<span className='m-1 bg-blue-100 text-blue-800 text-sm font-medium mr-2 px-2.5 py-0.5 rounded dark:bg-blue-900 dark:text-blue-300'> {element}</span>
{schemaDetails?.attributes && schemaDetails?.attributes?.length > 0 &&
schemaDetails?.attributes.map((element: string) => (
<span className='m-1 bg-blue-100 text-blue-800 text-sm font-medium mr-2 px-2.5 py-0.5 rounded dark:bg-blue-900 dark:text-blue-300'>{element?.attributeName}</span>
))}
</div>
</div>
Expand Down Expand Up @@ -381,9 +383,9 @@ const ViewSchemas = () => {
Credential Definitions
</h5>

{loading ? (<div className="flex items-center justify-center mb-4">
<CustomSpinner/>
{credDeffloader ? (<div className="flex items-center justify-center mb-4">

<CustomSpinner />
</div>)
: credDeffList && credDeffList.length > 0 ? (
<div className='Flex-wrap' style={{ display: 'flex', flexDirection: 'column' }}>
Expand Down
0