diff --git a/ui/src/crud/commit.ts b/ui/src/crud/commit.ts index 8076da7..cb76c06 100644 --- a/ui/src/crud/commit.ts +++ b/ui/src/crud/commit.ts @@ -262,6 +262,23 @@ mutation($plan: PlanCreateParams!){ } ` +const UPDATE_PLAN = gql` +${SIMPLIFIED_PLAN_RETURN_FIELDS}, +mutation($plan: PlanUpdateParams!){ + updatePlan(plan: $plan) { + plan { + ...SimplifiedPlanReturnFields + } + } +} +` + +const DELETE_PLAN = gql` +mutation($revisionId: ID!){ + deletePlan(revisionId: $revisionId) +} +` + const CREATE_PROCESS = gql` ${PROCESS_RETURN_FIELDS}, mutation($process: ProcessCreateParams!){ @@ -273,6 +290,23 @@ mutation($process: ProcessCreateParams!){ } ` +const UPDATE_PROCESS = gql` +${PROCESS_RETURN_FIELDS}, +mutation($process: ProcessUpdateParams!){ + updateProcess(process: $process) { + process { + ...ProcessReturnFields + } + } +} +` + +const DELETE_PROCESS = gql` +mutation($revisionId: ID!){ + deleteProcess(revisionId: $revisionId) +} +` + const CREATE_RECIPE_FLOW = gql` ${RECIPE_FLOW_CORE_FIELDS}, mutation($recipeFlow: RecipeFlowCreateParams!){ @@ -608,6 +642,24 @@ export const createPlan = async (plan: any) => { }) } +export const updatePlan = async (plan: any) => { + return await client.mutate({ + mutation: UPDATE_PLAN, + variables: { + plan + } + }) +} + +export const deletePlan = async (revisionId: string) => { + return await client.mutate({ + mutation: DELETE_PLAN, + variables: { + revisionId + } + }) +} + export const createProcess = async (process: any) => { return await client.mutate({ mutation: CREATE_PROCESS, @@ -617,6 +669,24 @@ export const createProcess = async (process: any) => { }) } +export const updateProcess = async (process: any) => { + return await client.mutate({ + mutation: UPDATE_PROCESS, + variables: { + process + } + }) +} + +export const deleteProcess = async (revisionId: string) => { + return await client.mutate({ + mutation: DELETE_PROCESS, + variables: { + revisionId + } + }) +} + export const createRecipeFlow = async (recipeFlow: RecipeFlowCreateParams) => { return await client.mutate({ mutation: CREATE_RECIPE_FLOW, diff --git a/ui/src/crud/fetch.ts b/ui/src/crud/fetch.ts index 35b1069..d582afd 100644 --- a/ui/src/crud/fetch.ts +++ b/ui/src/crud/fetch.ts @@ -12,7 +12,7 @@ import { RESOURCE_SPECIFICATION_CORE_FIELDS, UNIT_CORE_FIELDS } from '$lib/graph import { PROCESS_SPECIFICATION_CORE_FIELDS } from '$lib/graphql/process_specification.fragments' import { RECIPE_RETURN_FIELDS, RECIPE_EXCHANGE_RETURN_FIELDS } from '$lib/graphql/recipe.fragments' import { addToFullPlans, setActions, clientStored, setAgents, updateAnAgent, setUnits, setResourceSpecifications, setProcessSpecifications, setProposals, setRecipes, setRecipeExchanges, - setHashChanges, setEconomicEvents, setEconomicResources, updateProcessInPlan, setFulfillments, setCommitments, setAgreements, addNonProcessCommitmentsToPlan } from './store' + setHashChanges, setEconomicEvents, setEconomicResources, updateProcessInPlan, setFulfillments, setCommitments, setAgreements, addNonProcessCommitmentsToPlan, setPlansList } from './store' import { WeaveClient, isWeContext, initializeHotReload, type WAL} from '@lightningrodlabs/we-applet'; import { appletServices } from '../../we'; import { decode } from '@msgpack/msgpack'; @@ -203,6 +203,20 @@ query GetPlan($id: ID!) { } ` +const GET_PLANS = gql` +${SIMPLIFIED_PLAN_RETURN_FIELDS} +query { + plans(last: 100000) { + edges { + cursor + node { + ...SimplifiedPlanReturnFields + } + } + } +} +` + const GET_NON_PROCESS_COMMITMENTS = gql` ${NON_PROCESS_COMMITMENT_RETURN_FIELDS} query GetPlan($id: ID!) { @@ -494,6 +508,15 @@ export const getPlan = async (id: string) => { return res.data.plan } +export const getAllPlans = async () => { + const res = await client.query({ + query: GET_PLANS, + fetchPolicy: 'no-cache' + }) + setPlansList(res.data.plans.edges.map((edge: any) => edge.node)) + return res +} + export const getNonProcessCommitments = async (id: string) => { const res = await client.query({ query: GET_NON_PROCESS_COMMITMENTS, diff --git a/ui/src/crud/store.ts b/ui/src/crud/store.ts index 4339855..a79fac8 100644 --- a/ui/src/crud/store.ts +++ b/ui/src/crud/store.ts @@ -13,6 +13,7 @@ export const allEconomicEvents = writable([]); export const allEconomicResources = writable([]); export const allActions = writable([]); export const fullPlans = writable({}); +export const plansList = writable([]); export const allFulfillments = writable([]); export const allCommitments = writable([]); export const allAgreements = writable([]); @@ -98,6 +99,10 @@ export function addToFullPlans(newPlan: any) { }); } +export function setPlansList(newPlans: any) { + plansList.update(v => newPlans); +} + export function addNonProcessCommitmentsToPlan(planId: string, commitments: any[]) { fullPlans.update(v => { let newPlan = v[planId] diff --git a/ui/src/lib/Initialize.svelte b/ui/src/lib/Initialize.svelte index 7525888..2c5ecda 100644 --- a/ui/src/lib/Initialize.svelte +++ b/ui/src/lib/Initialize.svelte @@ -208,6 +208,7 @@ action: actions.find(a => a.label === i.action.label.replaceAll("_", "-")).id, providerRole: i.provider_role, receiverRole: i.receiver_role, + instructions: i.instructions, resourceQuantity: { hasNumericalValue: Number(i.resourceQuantity.hasNumericalValue), hasUnit: units.find(u => u.label === i.resourceQuantity.hasUnit.label)?.id, @@ -229,6 +230,7 @@ action: actions.find(a => a.label === o.action.label.replaceAll("_", "-")).id, providerRole: o.provider_role, receiverRole: o.receiver_role, + instructions: o.instructions, resourceQuantity: { hasNumericalValue: Number(o.resourceQuantity.hasNumericalValue), hasUnit: units.find(u => u.label === o.resourceQuantity.hasUnit.label)?.id, diff --git a/ui/src/lib/graphql/plan.fragments.ts b/ui/src/lib/graphql/plan.fragments.ts index 4ab232d..e8b921f 100644 --- a/ui/src/lib/graphql/plan.fragments.ts +++ b/ui/src/lib/graphql/plan.fragments.ts @@ -6,45 +6,6 @@ export const SIMPLIFIED_PLAN_RETURN_FIELDS = gql` revisionId name note - meta { - retrievedRevision { - id - time - } - } - independentDemands { - id - revisionId - action { - id - label - } - receiverId - resourceQuantity { - hasNumericalValue - hasUnitId - } - resourceConformsTo { - id - name - defaultUnitOfResourceId - } - } - processes { - id - revisionId - name - meta { - retrievedRevision { - id - time - } - } - basedOn { - id - name - } - } } ` diff --git a/ui/src/lib/graphql/recipe.fragments.ts b/ui/src/lib/graphql/recipe.fragments.ts index 02e81a2..91b0003 100644 --- a/ui/src/lib/graphql/recipe.fragments.ts +++ b/ui/src/lib/graphql/recipe.fragments.ts @@ -41,6 +41,7 @@ export const RECIPE_RETURN_FIELDS = gql` note providerRole receiverRole + insructions stage { id name @@ -72,6 +73,7 @@ export const RECIPE_RETURN_FIELDS = gql` note providerRole receiverRole + instructions stage { id name diff --git a/ui/src/routes/+page.svelte b/ui/src/routes/+page.svelte index f5d2cba..05e5e89 100644 --- a/ui/src/routes/+page.svelte +++ b/ui/src/routes/+page.svelte @@ -2,32 +2,15 @@ import { browser } from '$app/environment' import { onMount } from 'svelte' import type { ComponentType } from 'svelte' - import { query } from 'svelte-apollo' - import type { ReadableQuery } from 'svelte-apollo' - import { gql } from 'graphql-tag' import type { AgentConnection, Agent, Proposal, ProposalConnection, ProposedIntent } from '@leosprograms/vf-graphql' import ErrorPage from './__error.svelte' import Search from '$lib/Search.svelte' import SidePanel from '$lib/SidePanel.svelte' - import { flattenRelayConnection } from '$lib/graphql/helpers' - import type { RelayConn } from '$lib/graphql/helpers' - import { AGENT_CORE_FIELDS, PERSON_CORE_FIELDS, ORGANIZATION_CORE_FIELDS } from '$lib/graphql/agent.fragments' - import { PROPOSAL_RETURN_FIELDS } from '$lib/graphql/proposal.fragments' - import { FACET_VALUE_CORE_FIELDS } from '$lib/graphql/facet.fragments' import type { AgentExtended } from '$lib/graphql/extension-schemas' import { getAllAgents, getAllProposals } from '../crud/fetch' import { allAgents, allProposals } from '../crud/store' import Loading from '$lib/Loading.svelte' - // import { AdminWebsocket } from '@holochain/client'; - const ENV_CONNECTION_URI = process.env.REACT_APP_HC_CONN_URL as string || '' - - // const appId = import.meta.env.VITE_APP_ID ? import.meta.env.VITE_APP_ID : 'acfn' - // const roleName = 'acfn' - // const appPort = import.meta.env.VITE_APP_PORT ? import.meta.env.VITE_APP_PORT : 8888 - // const adminPort = import.meta.env.VITE_ADMIN_PORT - // const url = `ws://localhost:${appPort}`; - - let loading = true; + let loading = false; let error: any; let agents: AgentExtended[]; let matchedAgents: AgentExtended[]; @@ -67,127 +50,9 @@ offersList = res }) - // query & data bindings - - // const GET_ALL_AGENTS = gql` - // ${AGENT_CORE_FIELDS} - // ${PERSON_CORE_FIELDS} - // ${ORGANIZATION_CORE_FIELDS} - // fragment FacetCoreFields on Facet { - // id - // name - // note - // image - // classifiedAs - // } - // query { - // agents(last: 100000) { - // edges { - // cursor - // node { - // ...AgentCoreFields - // ...PersonCoreFields - // ...OrganizationCoreFields - - // facets(last: 1000) { - // edges { - // node { - // ...FacetCoreFields - // } - // } - // } - // } - // } - // } - // } - // ` - - // const GET_ALL_AGENTS = gql` - // ${AGENT_CORE_FIELDS} - // ${PERSON_CORE_FIELDS} - // ${ORGANIZATION_CORE_FIELDS} - // ${FACET_VALUE_CORE_FIELDS} - // query { - // agents(last: 100000) { - // edges { - // cursor - // node { - // ...AgentCoreFields - // ...PersonCoreFields - // ...OrganizationCoreFields - // facets { - // ...FacetValueCoreFields - // } - // } - // } - // } - // } - // ` - - // interface QueryResponse { - // // agents: AgentConnection & RelayConn - // agents: AgentConnection & RelayConn - // } - - // map component state - - // async function fetchAgents() { - // // setInterval(function(){ - // await agentsQuery.getCurrentResult() - // await agentsQuery.refetch().then((r) => { - // agents = flattenRelayConnection(r.data?.agents).map((a) => { - // // @ts-ignore - // let iconUrl = roleImages[a.classifiedAs[2]] || 'mill.svg' - // return { - // ...a, - // "name": a.name, - // "imageUrl": a.image, - // "iconUrl": iconUrl, - // "latLng": {lat: a.classifiedAs[0], lon: a.classifiedAs[1]}, - // "address": a.note, - // "offers": offersList?.filter((o: Proposal) => (o.publishes || []) - // .filter((pi: ProposedIntent) => !pi.reciprocal && pi.publishes.provider?.id === a.id).length > 0) - // } - // }) - // }) - // // }, 20000) - // } - - // ===============GET OFFERS=============== - // const GET_All_PROPOSALS = gql` - // ${PROPOSAL_RETURN_FIELDS} - // query { - // proposals(last: 100000) { - // edges { - // cursor - // node { - // ...ProposalReturnFields - // } - // } - // } - // } - // ` - - // interface OffersQueryResponse { - // proposals: ProposalConnection & RelayConn - // } - - // let getOffers: ReadableQuery = query(GET_All_PROPOSALS) - - // async function fetchOffers() { - // await getOffers.getCurrentResult() - // await getOffers.refetch().then((r) => { - // if (r.data?.proposals.edges.length > 0) { - // offersList = flattenRelayConnection(r.data?.proposals) - // offersList = [...offersList] - // } - // }) - // } - // ===============GET OFFERS ENDS========== - onMount(async () => { + loading = agents.length === 0 await getAllProposals() - // await agentsQuery.getCurrentResult() await getAllAgents() loading = false // setInterval(function(){ @@ -200,25 +65,7 @@ } }) - // reactive data bindings - $: agents, offersList; - - - // set up zome call signing when run outside of launcher - // export const authorizeClient = async (appInfo: AppInfo) => { - // if (typeof window === "object" && !("__HC_LAUNCHER_ENV__" in window)) { - // if (!(CellType.Provisioned in appInfo.cell_info.mewsfeed[0])) { - // throw new Error("mewsfeed cell not provisioned"); - // } - // const { cell_id } = appInfo.cell_info.mewsfeed[0][CellType.Provisioned]; - // const adminWs = await AdminWebsocket.connect( - // new URL(`ws://localhost:${import.meta.env.VITE_HC_ADMIN_PORT}`) - // ); - // await adminWs.authorizeSigningCredentials(cell_id); - // console.log("Holochain app client authorized for zome calls"); - // } - // };
diff --git a/ui/src/routes/agents/+page.svelte b/ui/src/routes/agents/+page.svelte index 90decdd..4806030 100644 --- a/ui/src/routes/agents/+page.svelte +++ b/ui/src/routes/agents/+page.svelte @@ -1,7 +1,6 @@ +
+{#if loading} + +{/if} +
diff --git a/ui/src/routes/economic_events/+page.svelte b/ui/src/routes/economic_events/+page.svelte index ab5627d..34f16b5 100644 --- a/ui/src/routes/economic_events/+page.svelte +++ b/ui/src/routes/economic_events/+page.svelte @@ -5,10 +5,11 @@ import { getAllEconomicEvents, getAllEconomicResources, getAllResourceSpecifications, getAllUnits } from "../../crud/fetch"; import { allEconomicEvents, allEconomicResources, allFulfillments, allAgents, allUnits, allResourceSpecifications } from "../../crud/store"; import { importEconomicEvents } from '../../crud/import'; - import EconomicEventModal from '$lib/EconomicEventModal.svelte'; + import EconomicEventModal from './EconomicEventModal.svelte'; import Export from '$lib/Export.svelte'; import { createEconomicEvent, createEconomicEventWithResource } from '../../crud/commit' import EconomicEvent from '$lib/icons/EconomicEvent.svelte' + import Loading from '$lib/Loading.svelte'; let economicEvents: EconomicEvent[] = []; allEconomicEvents.subscribe(value => { @@ -41,14 +42,18 @@ }); let exportOpen = false; + let loading: boolean = false; let importing = false; let modalOpen = false; onMount(async () => { - await getAllEconomicEvents(); - await getAllEconomicResources(); - await getAllUnits(); - await getAllResourceSpecifications(); + loading = economicEvents.length === 0 || units.length === 0 || resourceSpecifications.length === 0; + console.log(economicEvents.length, units.length, resourceSpecifications.length) + await getAllEconomicEvents(); + await getAllEconomicResources(); + await getAllUnits(); + await getAllResourceSpecifications(); + loading = false; }); async function saveEconomicEvent(economicEvent: EconomicEventCreateParams) { @@ -107,6 +112,10 @@ }} /> +{#if loading} + +{/if} +
diff --git a/ui/src/lib/EconomicEventModal.svelte b/ui/src/routes/economic_events/EconomicEventModal.svelte similarity index 99% rename from ui/src/lib/EconomicEventModal.svelte rename to ui/src/routes/economic_events/EconomicEventModal.svelte index 3b87143..d6b6629 100644 --- a/ui/src/lib/EconomicEventModal.svelte +++ b/ui/src/routes/economic_events/EconomicEventModal.svelte @@ -1,5 +1,5 @@ @@ -60,6 +64,10 @@ }} /> +{#if loading} + +{/if} +
diff --git a/ui/src/lib/EconomicResourceModal.svelte b/ui/src/routes/economic_resources/EconomicResourceModal.svelte similarity index 98% rename from ui/src/lib/EconomicResourceModal.svelte rename to ui/src/routes/economic_resources/EconomicResourceModal.svelte index 83e982f..5074f2a 100644 --- a/ui/src/lib/EconomicResourceModal.svelte +++ b/ui/src/routes/economic_resources/EconomicResourceModal.svelte @@ -1,8 +1,8 @@ @@ -34,6 +39,10 @@ +{#if loading} + +{/if} +
diff --git a/ui/src/lib/RecipeExchangeModal.svelte b/ui/src/routes/recipe_exchanges/RecipeExchangeModal.svelte similarity index 98% rename from ui/src/lib/RecipeExchangeModal.svelte rename to ui/src/routes/recipe_exchanges/RecipeExchangeModal.svelte index b831333..76eb714 100644 --- a/ui/src/lib/RecipeExchangeModal.svelte +++ b/ui/src/routes/recipe_exchanges/RecipeExchangeModal.svelte @@ -1,8 +1,8 @@ @@ -100,6 +105,10 @@ +{#if loading} + +{/if} +
diff --git a/ui/src/lib/RecipeProcessModal.svelte b/ui/src/routes/recipes/RecipeProcessModal.svelte similarity index 97% rename from ui/src/lib/RecipeProcessModal.svelte rename to ui/src/routes/recipes/RecipeProcessModal.svelte index 8c9319b..285189c 100644 --- a/ui/src/lib/RecipeProcessModal.svelte +++ b/ui/src/routes/recipes/RecipeProcessModal.svelte @@ -1,8 +1,8 @@ @@ -29,6 +33,10 @@ onMount(async () => { getAllUnits() }} /> +{#if loading} + +{/if} +
diff --git a/ui/src/lib/UnitModal.svelte b/ui/src/routes/units/UnitModal.svelte similarity index 98% rename from ui/src/lib/UnitModal.svelte rename to ui/src/routes/units/UnitModal.svelte index c334e02..a00f022 100644 --- a/ui/src/lib/UnitModal.svelte +++ b/ui/src/routes/units/UnitModal.svelte @@ -1,8 +1,8 @@