Skip to content

Commit

Permalink
Merge pull request #302 from bcgov/feature/api-list-schemas-with-cred…
Browse files Browse the repository at this point in the history
…defs

Return cred templates with schema template (optional)
  • Loading branch information
usingtechnology authored Oct 5, 2022
2 parents c8e4e5e + 5e54b82 commit c244f9f
Show file tree
Hide file tree
Showing 12 changed files with 321 additions and 348 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,9 @@ const toast = useToast();
const governanceStore = useGovernanceStore();
// use the loading state from the store to disable the button...
const {
loading,
schemaTemplates,
selectedSchemaTemplate,
schemaTemplateFilters,
} = storeToRefs(useGovernanceStore());
const { loading, schemaTemplates, selectedSchemaTemplate } = storeToRefs(
useGovernanceStore()
);
const loadTable = async () => {
governanceStore.listSchemaTemplates().catch((err) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const openModal = async () => {
Promise.all([
contactsStore.listContacts(),
governanceStore.listSchemaTemplates(),
governanceStore.listCredentialTemplates(),
]).catch((err) => {
console.error(err);
toast.error(
Expand Down
140 changes: 37 additions & 103 deletions services/tenant-ui/frontend/src/store/governanceStore.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { defineStore } from 'pinia';
import { computed, ref } from 'vue';
import { useTenantApi } from './tenantApi';
import { fetchList, filterMapSortList, sortByLabelAscending } from './utils';
import {
fetchItem,
fetchList,
filterMapSortList,
sortByLabelAscending,
} from './utils';

export const useGovernanceStore = defineStore('governance', () => {
// state
Expand Down Expand Up @@ -63,40 +68,18 @@ export const useGovernanceStore = defineStore('governance', () => {
async function listSchemaTemplates() {
selectedSchemaTemplate.value = null;
schemaTemplates.value = null;
//return fetchList('/tenant/v1/governance/schema_templates/', schemaTemplates, error, loading);

// this is a total hack for expedience, lets get cred templates at the same time...
// just so we can show it all in one grid, this should happen at the api level...
const schemas = ref();
await fetchList(
return fetchList(
'/tenant/v1/governance/schema_templates/',
schemas,
schemaTemplates,
error,
loading
);
await listCredentialTemplates();
schemaTemplates.value = await Promise.all(
schemas.value.map(async (item: any) => {
// find any credential templates...
const templates = ref();
await fetchList(
'/tenant/v1/governance/credential_templates/',
templates,
error,
loading,
{ schema_template_id: item.schema_template_id }
);
return {
...item,
credential_templates: templates,
};
})
loading,
{ credential_templates: true }
);
return schemaTemplates.value;
}

async function listCredentialTemplates() {
selectedCredentialTemplate.value = null;
credentialTemplates.value = null;
return fetchList(
'/tenant/v1/governance/credential_templates/',
credentialTemplates,
Expand Down Expand Up @@ -162,10 +145,13 @@ export const useGovernanceStore = defineStore('governance', () => {
console.log(
'credential template created. the store calls load automatically, but do we want this done "manually"?'
);
// TODO: for demo, we aren't separating schema/cred templates, so load the schema list (that has sub-list of cred templates.)
//listCredentialTemplates();
// load schemas for tables...
listSchemaTemplates();
})
.then(() => {
// reload this for pick lists...
listCredentialTemplates();
})
.catch((err) => {
error.value = err;
//console.log(error.value);
Expand Down Expand Up @@ -220,82 +206,30 @@ export const useGovernanceStore = defineStore('governance', () => {
return result;
}

async function getSchemaTemplate(id: String, params: any = {}) {
console.log('> governanceStore.getSchemaTemplate');
error.value = null;
loading.value = true;

let result = null;
await tenantApi
.getHttp(`/tenant/v1/governance/schema_templates/${id}`, params)
.then((res) => {
console.log(res);
result = res.data.item;
console.log(result);
return result;
})
.then((item) => {
// TODO: another hack, similar to list, move this to the API
const credtemplates = ref([]);
fetchList(
'/tenant/v1/governance/credential_templates/',
credtemplates,
error,
loading,
{ schema_template_id: item.schema_template_id }
);
result = {
...item,
credential_templates: credtemplates,
};
return result;
})
.catch((err) => {
error.value = err;
//console.log(error.value);
})
.finally(() => {
loading.value = false;
});
console.log('< governanceStore.getSchemaTemplate');

if (error.value != null) {
// throw error so $onAction.onError listeners can add their own handler
throw error.value;
async function getSchemaTemplate(id: string, params: any = {}) {
const getloading: any = ref(false);
if (!('credential_templates' in params)) {
// if we do not explicitly say not to get cred templates, get 'em.
params['credential_templates'] = true;
}
// return data so $onAction.after listeners can add their own handler
return result;
return fetchItem(
'/tenant/v1/governance/schema_templates/',
id,
error,
getloading,
params
);
}

async function getCredentialTemplate(id: String, params: any = {}) {
console.log('> governanceStore.getCredentialTemplate');
error.value = null;
loading.value = true;

let result = null;

await tenantApi
.getHttp(`/tenant/v1/governance/credential_templates/${id}`, params)
.then((res) => {
console.log(res);
result = res.data.item;
console.log(result);
})
.catch((err) => {
error.value = err;
//console.log(error.value);
})
.finally(() => {
loading.value = false;
});
console.log('< governanceStore.getCredentialTemplate');

if (error.value != null) {
// throw error so $onAction.onError listeners can add their own handler
throw error.value;
}
// return data so $onAction.after listeners can add their own handler
return result;
async function getCredentialTemplate(id: string, params: any = {}) {
const getloading: any = ref(false);
return fetchItem(
'/tenant/v1/governance/credential_templates/',
id,
error,
getloading,
params
);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions services/tenant-ui/frontend/src/store/utils/fetchList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ export async function fetchList(
list.value = null;
error.value = null;
loading.value = true;
console.log(params);
//console.log(params);
params = { ...params, page_num: 1, page_size: 100 };
console.log(params);
//console.log(params);
await tenantApi
.getHttp(url, params)
.then((res) => {
console.log(res);
//console.log(res);
list.value = res.data.items;
console.log(list.value);
//console.log(list.value);
})
.catch((err) => {
error.value = err;
Expand Down
1 change: 1 addition & 0 deletions services/tenant-ui/frontend/src/store/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export { fetchList } from './fetchList';
export { fetchItem } from './fetchItem';

/**
* Filter, Map and Sort a list.
Expand Down
Loading

0 comments on commit c244f9f

Please sign in to comment.