Skip to content
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

feat: support search functionality in issuance dropdown #760

Merged
merged 37 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
5dcc5c2
refactor: parameter name
bhavanakarwade Apr 15, 2024
635329a
Merge branch 'develop' of https://github.com/credebl/studio into fix/…
bhavanakarwade May 16, 2024
ac0a437
refactor: added query parameter
bhavanakarwade May 16, 2024
cfabd6a
fix: remove unnecessary code
bhavanakarwade May 16, 2024
caf8e60
fix: query param issue
bhavanakarwade May 17, 2024
03c8301
Merge branch 'develop' of https://github.com/credebl/studio into fix/…
bhavanakarwade May 24, 2024
75e6bdd
Merge branch 'develop' of https://github.com/credebl/studio into fix/…
bhavanakarwade May 24, 2024
3dab0f4
Merge branch 'develop' of https://github.com/credebl/studio into fix/…
bhavanakarwade Jun 18, 2024
f7103aa
fix: css issues
bhavanakarwade Jun 18, 2024
82cefd4
Merge branch 'develop' of https://github.com/credebl/studio into fix/…
bhavanakarwade Jun 21, 2024
67babdf
fix: create did button restrictions
bhavanakarwade Jun 21, 2024
6816754
Merge branch 'develop' of https://github.com/credebl/studio into fix/…
bhavanakarwade Jun 24, 2024
c46f1af
Merge branch 'develop' of https://github.com/credebl/studio into fix/…
bhavanakarwade Jul 11, 2024
d2575a6
fix: routes changes
bhavanakarwade Aug 26, 2024
806af77
Merge branch 'develop' of https://github.com/credebl/studio into fix/…
bhavanakarwade Aug 26, 2024
0d6eddc
Merge branch 'develop' of https://github.com/credebl/studio into fix/…
bhavanakarwade Aug 28, 2024
576b4b8
fix: popup card fixes
bhavanakarwade Aug 28, 2024
c7f7d66
Merge branch 'develop' of https://github.com/credebl/studio into fix/…
bhavanakarwade Aug 28, 2024
ac1358f
fix: remove click on card
bhavanakarwade Aug 28, 2024
bc0f693
fix: remove card click
bhavanakarwade Aug 28, 2024
8c2bf10
Merge branch 'develop' of https://github.com/credebl/studio into fix/…
bhavanakarwade Aug 28, 2024
b7472e2
fix: cred def details
bhavanakarwade Aug 28, 2024
8b33819
Merge branch 'develop' of https://github.com/credebl/studio into fix/…
bhavanakarwade Aug 28, 2024
c2aa3ed
fix: schema card click issue
bhavanakarwade Aug 29, 2024
014a3c9
fix: schema name is not visible in credentials list
bhavanakarwade Aug 29, 2024
09287ca
Merge branch 'develop' of https://github.com/credebl/studio into fix/…
bhavanakarwade Aug 29, 2024
168a19b
Merge branch 'develop' of https://github.com/credebl/studio into fix/…
bhavanakarwade Aug 30, 2024
c8aa02c
Merge branch 'develop' of https://github.com/credebl/studio into fix/…
bhavanakarwade Sep 2, 2024
eb91945
Merge branch 'develop' of https://github.com/credebl/studio into fix/…
bhavanakarwade Sep 3, 2024
05f5142
feat: applied search filter in issuance dropdown
bhavanakarwade Sep 3, 2024
2b58dac
fix: resolved conflicts
bhavanakarwade Sep 3, 2024
03bf24c
fix: resolved sonarlint checks
bhavanakarwade Sep 3, 2024
3e6d71f
fix: resolved sonarcloud issues
bhavanakarwade Sep 3, 2024
d0e13a6
refactor: serach functionality
bhavanakarwade Sep 4, 2024
45d6be3
refactor: search functionality for bulk issuance dropdown
bhavanakarwade Sep 4, 2024
d760e92
fix: remove unnecessary code
bhavanakarwade Sep 4, 2024
a18d58e
fix: remove unnecessary import
bhavanakarwade Sep 4, 2024
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
54 changes: 38 additions & 16 deletions src/components/Issuance/BulkIssuance.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Button, Card, Pagination } from 'flowbite-react';
import React, { useEffect, useState } from 'react';
import Select from 'react-select';
import Select, { type ActionMeta, type SingleValue } from 'react-select';
import {
DownloadCsvTemplate, getSchemaCredDef, getCsvFileData,
issueBulkCredential,
Expand Down Expand Up @@ -72,6 +72,20 @@ const BulkIssuance = () => {
};
const [currentPage, setCurrentPage] = useState(initialPageState);

const [searchValue, setSearchValue] = useState('');

const onInputChange = (inputValue: string) => {
setSearchValue(inputValue);
setSchemaListAPIParameters(prevParams => {
const updatedParams = {
...prevParams,
allSearch: inputValue,
};
getSchemaCredentials(updatedParams);
return updatedParams;
});
};

const getSchemaCredentials = async (schemaListAPIParameters: GetAllSchemaListParameter) => {
try {
setLoading(true);
Expand All @@ -95,6 +109,7 @@ const BulkIssuance = () => {
currentSchemaType = SchemaTypes.schema_INDY;
}

let dropDownOptions;
setSchemaType(currentSchemaType);
if ((currentSchemaType === SchemaTypes.schema_INDY && isAllSchema) || (currentSchemaType && orgId && !isAllSchema)) {
const response = await getSchemaCredDef(currentSchemaType);
Expand All @@ -103,7 +118,7 @@ const BulkIssuance = () => {
if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) {
const { data: credentialDefsData } = data;

const options = credentialDefsData.map(
dropDownOptions = credentialDefsData.map(
({
schemaName,
schemaVersion,
Expand All @@ -123,7 +138,7 @@ const BulkIssuance = () => {
}),
);

setCredentialOptionsData(options);
setCredentialOptionsData(dropDownOptions);
} else {
setUploadMessage({message: response as string, type: "failure"});
setSuccess(null)
Expand All @@ -142,7 +157,7 @@ const BulkIssuance = () => {
const credentialDefsData = data.data.data;


const options = credentialDefsData.map(({
dropDownOptions = credentialDefsData.map(({
name,
version,
schemaLedgerId,
Expand All @@ -157,7 +172,7 @@ const BulkIssuance = () => {
schemaIdentifier: schemaLedgerId,
attributes: Array.isArray(attributes) ? attributes : (attributes ? JSON.parse(attributes) : []),
}));
setCredentialOptionsData(options);
setCredentialOptionsData(dropDownOptions);
} else {
setUploadMessage({message: response as string, type: "failure"});
setSuccess(null)
Expand All @@ -166,12 +181,25 @@ const BulkIssuance = () => {
setLoading(false);
}
} catch (error) {
setUploadMessage({message: error as string, type: "failure"});
setUploadMessage({ message: (error as Error).message, type: "failure" });
setSuccess(null)
setFailure(null)
}
};


const onSelectChange = (newValue: SingleValue<ICredentials | undefined>) => {
const value = newValue as ICredentials | undefined;
if (schemaType === SchemaTypes.schema_INDY) {
setSelectedTemplate(value?.credentialDefinitionId);
setCredentialSelected(value ?? null);
} else if (schemaType === SchemaTypes.schema_W3C) {
setCredentialSelected(value ?? null);
setSelectedTemplate(value?.schemaIdentifier)
}
};


useEffect(() => {
getSchemaCredentials(schemaListAPIParameters);
}, [isAllSchema]);
Expand Down Expand Up @@ -586,15 +614,9 @@ const BulkIssuance = () => {
isSearchable={true}
name="color"
options={ credentialOptionsData}
onChange={(value: ICredentials | null) => {
if (schemaType === SchemaTypes.schema_INDY) {
setSelectedTemplate(value?.credentialDefinitionId);
setCredentialSelected(value ?? null);
} else if (schemaType === SchemaTypes.schema_W3C) {
setCredentialSelected(value ?? null);
setSelectedTemplate(value?.schemaIdentifier)
}
}}
onInputChange={onInputChange}
onChange={onSelectChange}
value={credentialOptionsData.find(option => option.value === searchValue)}
ref={selectInputRef}
/>:
null
Expand Down Expand Up @@ -959,4 +981,4 @@ const BulkIssuance = () => {
);
};

export default BulkIssuance;
export default BulkIssuance;
158 changes: 85 additions & 73 deletions src/components/Issuance/EmailIssuance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { pathRoutes } from '../../config/pathRoutes';
import BreadCrumbs from '../BreadCrumbs';
import BackButton from '../../commonComponents/backbutton';
import { Button, Card } from 'flowbite-react';
import Select from 'react-select';
import Select, { type SingleValue } from 'react-select';
import { AlertComponent } from '../AlertComponent';
import IssuancePopup from './IssuancePopup';
import type { AxiosResponse } from 'axios';
Expand Down Expand Up @@ -61,59 +61,71 @@ const EmailIssuance = () => {
const [schemasIdentifier, setSchemasIdentifier] = useState<string>();
const [schemaTypeValue, setSchemaTypeValue] = useState<SchemaTypeValue>();
const [isAllSchemaFlagSelected, setIsAllSchemaFlagSelected] = useState<boolean>();

const getSchemaCredentials = async (schemaListAPIParameter: GetAllSchemaListParameter) => {
const [searchValue, setSearchValue] = useState('');

const handleInputChange = (inputValue: string) => {
setSearchValue(inputValue);
setSchemaListAPIParameter(prevParams => {
const updatedParams = {
...prevParams,
allSearch: inputValue,
};
getSchemaCredentials(updatedParams);
return updatedParams;
});
};

const getSchemaCredentials = async (schemaListAPIParameter: GetAllSchemaListParameter) => {

try {
setLoading(true);
const orgId = await getFromLocalStorage(storageKeys.ORG_ID);
const orgDid = await getFromLocalStorage(storageKeys.ORG_DID);

const allSchemaSelectedFlag = await getFromLocalStorage(storageKeys.ALL_SCHEMAS)
if(allSchemaSelectedFlag === `false` || !allSchemaSelectedFlag){
if (allSchemaSelectedFlag === `false` || !allSchemaSelectedFlag) {
setIsAllSchemaFlagSelected(false)
}
else if(allSchemaSelectedFlag ==='true'){
setIsAllSchemaFlagSelected(true)

else if (allSchemaSelectedFlag === 'true') {
setIsAllSchemaFlagSelected(true)
}
let currentSchemaType = schemaType;

if (orgDid?.includes(DidMethod.POLYGON)) {
currentSchemaType = SchemaTypes.schema_W3C;
setSchemaTypeValue(SchemaTypeValue.POLYGON)
setCredentialType(CredentialType.JSONLD)
} else if ( orgDid?.includes(DidMethod.KEY) || orgDid?.includes(DidMethod.WEB)) {

} else if (orgDid?.includes(DidMethod.KEY) || orgDid?.includes(DidMethod.WEB)) {
currentSchemaType = SchemaTypes.schema_W3C;
setSchemaTypeValue(SchemaTypeValue.NO_LEDGER)

setCredentialType(CredentialType.JSONLD)
}
else if (orgDid?.includes(DidMethod.INDY)) {
else if (orgDid?.includes(DidMethod.INDY)) {
setCredentialType(CredentialType.INDY)
currentSchemaType = SchemaTypes.schema_INDY;
}
setSchemaType(currentSchemaType);
setSchemaType(currentSchemaType);

//FIXME: Logic of API call as per schema selection
if((currentSchemaType === SchemaTypes.schema_INDY && orgId && isAllSchemaFlagSelected ) || (currentSchemaType && !isAllSchemaFlagSelected)){
let options;

const response = await getSchemaCredDef(currentSchemaType);
const { data } = response as AxiosResponse;

if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) {
//FIXME: Logic of API call as per schema selection
if((currentSchemaType === SchemaTypes.schema_INDY && orgId
) || (currentSchemaType ===SchemaTypes.schema_W3C && isAllSchemaFlagSelected === false)){
const response = await getSchemaCredDef(currentSchemaType);
const { data } = response as AxiosResponse;
if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) {
const credentialDefs = data.data;
const options = credentialDefs.map(({

options = credentialDefs.map(({
schemaName,
schemaVersion,
credentialDefinition,
credentialDefinitionId,
schemaIdentifier,
schemaAttributes
} : ICredentials) => ({
value: schemaType===SchemaTypes.schema_INDY ? credentialDefinitionId : schemaVersion,
}: ICredentials) => ({
value: schemaType === SchemaTypes.schema_INDY ? credentialDefinitionId : schemaVersion,
label: `${schemaName} [${schemaVersion}]${currentSchemaType === SchemaTypes.schema_INDY ? ` - (${credentialDefinition})` : ''}`,
schemaName: schemaName,
schemaVersion: schemaVersion,
Expand All @@ -125,53 +137,67 @@ const EmailIssuance = () => {
typeof schemaAttributes === 'string' &&
JSON.parse(schemaAttributes),
}));

setCredentialOptions(options);
} else {
setSuccess(null);
setFailure(null);
}
setLoading(false);

setCredentialOptions(options);
} else {
setSuccess(null);
setFailure(null);
}
setLoading(false);
}

//FIXME: Logic of API call as per schema selection

else if (currentSchemaType === SchemaTypes.schema_W3C && orgId && allSchemaSelectedFlag) {
const response = await getAllSchemas(schemaListAPIParameter,currentSchemaType);
const { data } = response as AxiosResponse;

if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) {
else if ((currentSchemaType === SchemaTypes.schema_W3C) && (orgId) && (allSchemaSelectedFlag)) {
const response = await getAllSchemas(schemaListAPIParameter, currentSchemaType);
const { data } = response as AxiosResponse;

if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) {
const credentialDefs = data.data.data;

const options = credentialDefs.map(({
options = credentialDefs.map(({
name,
version,
schemaLedgerId,
attributes,
type
} : ICredentials) => ({
value: version,
}: ICredentials) => ({
value: version,
label: `${name} [${version}]`,
schemaName: name,
type:type,
type: type,
schemaVersion: version,
schemaIdentifier: schemaLedgerId,
attributes: Array.isArray(attributes) ? attributes : (attributes ? JSON.parse(attributes) : []),
}));
}));
setCredentialOptions(options);


} else {
setSuccess(null);
setFailure(null);
}
setLoading(false);
}

} catch (error) {
setSuccess(null);
setFailure(null);
}
};
} else {
setSuccess(null);
setFailure(null);
}
setLoading(false);
}


setCredentialOptions(options);
} catch (error) {
setSuccess(null);
setFailure(null);
}
};


const handleSelectChange = (newValue: SingleValue<ICredentials> | null) => {
const value = newValue as ICredentials | null;
setBatchName(value?.label ?? '');
if (schemaType === SchemaTypes.schema_INDY) {
setCredDefId(value?.credentialDefinitionId);
setCredentialSelected(value ?? null);
} else if (schemaType === SchemaTypes.schema_W3C) {
setCredentialSelected(value ?? null);
setSchemasIdentifier(value?.schemaIdentifier);
}
setAttributes(value?.schemaAttributes ?? value?.attributes ?? []);
};


useEffect(() => {

Expand Down Expand Up @@ -406,25 +432,11 @@ const EmailIssuance = () => {
isSearchable={true}
id="long-value-select"
instanceId="long-value-select"

name="color"
options={credentialOptions}
onChange={(value: ICredentials | null) => {
setBatchName(value?.label ?? '');

if (schemaType === SchemaTypes.schema_INDY) {

setCredDefId(value?.credentialDefinitionId);
setCredentialSelected(value ?? null);
} else if (schemaType === SchemaTypes.schema_W3C) {

setCredentialSelected(value ?? null);
setSchemasIdentifier(value?.schemaIdentifier)
}

setAttributes(value?.schemaAttributes ?? value?.attributes ?? []);

}}
onInputChange={handleInputChange}
onChange={handleSelectChange}
value={credentialOptions.find(option => option.value === searchValue)}
ref={selectInputRef}
/>
:
Expand Down Expand Up @@ -980,4 +992,4 @@ const EmailIssuance = () => {
);
};

export default EmailIssuance;
export default EmailIssuance;
2 changes: 1 addition & 1 deletion src/components/Issuance/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export interface ICredentials {
value?:String;
label?: string;
credentialDefinitionId?: string;
schemaCredDefName: string;
schemaCredDefName?: string;
schemaName: string;
schemaVersion: string;
schemaIdentifier: string;
Expand Down
Loading