Skip to content

Commit

Permalink
load reused data from planning page and import into modals
Browse files Browse the repository at this point in the history
  • Loading branch information
LeosPrograms committed Feb 19, 2024
1 parent ec8c343 commit 44f6781
Show file tree
Hide file tree
Showing 6 changed files with 635 additions and 324 deletions.
226 changes: 123 additions & 103 deletions ui/src/lib/CommitmentModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@
export let selectedCommitmentId: string | undefined
export let process: any[] | undefined;
export let commitments: any[]
export let agents: Agent[];
export let resourceSpecifications: any[];
export let units: any[];
const dispatch = createEventDispatcher();
let name = ''
let note = ''
let agents: Agent[];
let resourceSpecifications: any[];
let units: any[];
let saveCost: boolean = false;
let finished: boolean = false;
$: saveCost;
Expand All @@ -56,110 +58,110 @@
}
}
const GET_UNITS = gql`
query GetUnits {
units {
edges {
cursor
node {
id
label
symbol
}
}
}
}
`
const GET_ALL_AGENTS = gql`
query {
agents(last: 100000) {
edges {
cursor
node {
id
name
}
}
}
}
`
const GET_ALL_RESOURCE_SPECIFICATIONS = gql`
${RESOURCE_SPECIFICATION_CORE_FIELDS}
${UNIT_CORE_FIELDS}
query {
resourceSpecifications(last: 100000) {
edges {
cursor
node {
...ResourceSpecificationCoreFields
defaultUnitOfResource {
...UnitCoreFields
}
}
}
}
}
`
interface QueryResponse {
agents: AgentConnection & RelayConn<any>
}
interface RspecResponse {
resourceSpecifications: AgentConnection & RelayConn<any>
}
interface UnitsQueryResponse {
units: UnitConnection & RelayConn<any> //& RelayConn<unknown> | null | undefined
}
let getUnits: ReadableQuery<UnitsQueryResponse> = query(GET_UNITS)
// const GET_UNITS = gql`
// query GetUnits {
// units {
// edges {
// cursor
// node {
// id
// label
// symbol
// }
// }
// }
// }
// `
// const GET_ALL_AGENTS = gql`
// query {
// agents(last: 100000) {
// edges {
// cursor
// node {
// id
// name
// }
// }
// }
// }
// `
// const GET_ALL_RESOURCE_SPECIFICATIONS = gql`
// ${RESOURCE_SPECIFICATION_CORE_FIELDS}
// ${UNIT_CORE_FIELDS}
// query {
// resourceSpecifications(last: 100000) {
// edges {
// cursor
// node {
// ...ResourceSpecificationCoreFields
// defaultUnitOfResource {
// ...UnitCoreFields
// }
// }
// }
// }
// }
// `
// interface QueryResponse {
// agents: AgentConnection & RelayConn<any>
// }
// interface RspecResponse {
// resourceSpecifications: AgentConnection & RelayConn<any>
// }
// interface UnitsQueryResponse {
// units: UnitConnection & RelayConn<any> //& RelayConn<unknown> | null | undefined
// }
// let getUnits: ReadableQuery<UnitsQueryResponse> = query(GET_UNITS)
// map component state
let agentsQuery: ReadableQuery<QueryResponse> = query(GET_ALL_AGENTS)
let resourceSpecificationsQuery: ReadableQuery<RspecResponse> = query(GET_ALL_RESOURCE_SPECIFICATIONS)
async function fetchUnits() {
getUnits.getCurrentResult()
getUnits.refetch().then((r) => {
if (r.data?.units.edges.length > 0) {
units = flattenRelayConnection(r.data?.units)
}
})
}
async function fetchAgents() {
await agentsQuery.getCurrentResult()
const a = await agentsQuery.refetch()
agents = flattenRelayConnection(a.data?.agents).map((a) => {
return {
...a,
}
})
console.log(agents)
}
async function fetchResourceSpecifications() {
await resourceSpecificationsQuery.getCurrentResult()
let r = await resourceSpecificationsQuery.refetch()
resourceSpecifications = flattenRelayConnection(r.data?.resourceSpecifications).map((a) => {
return {
...a,
defaultUnitOfResourceId: a.defaultUnitOfResource?.id,
}
})
console.log(resourceSpecifications)
}
// // map component state
// let agentsQuery: ReadableQuery<QueryResponse> = query(GET_ALL_AGENTS)
// let resourceSpecificationsQuery: ReadableQuery<RspecResponse> = query(GET_ALL_RESOURCE_SPECIFICATIONS)
// async function fetchUnits() {
// getUnits.getCurrentResult()
// getUnits.refetch().then((r) => {
// if (r.data?.units.edges.length > 0) {
// units = flattenRelayConnection(r.data?.units)
// }
// })
// }
// async function fetchAgents() {
// await agentsQuery.getCurrentResult()
// const a = await agentsQuery.refetch()
// agents = flattenRelayConnection(a.data?.agents).map((a) => {
// return {
// ...a,
// }
// })
// console.log(agents)
// }
// async function fetchResourceSpecifications() {
// await resourceSpecificationsQuery.getCurrentResult()
// let r = await resourceSpecificationsQuery.refetch()
// resourceSpecifications = flattenRelayConnection(r.data?.resourceSpecifications).map((a) => {
// return {
// ...a,
// defaultUnitOfResourceId: a.defaultUnitOfResource?.id,
// }
// })
// console.log(resourceSpecifications)
// }
onMount(async() => {
window.addEventListener('keydown', checkKey)
await fetchUnits();
await fetchAgents();
await fetchResourceSpecifications();
// await fetchUnits();
// await fetchAgents();
// await fetchResourceSpecifications();
})
// let selectedCommitment: any;
Expand Down Expand Up @@ -539,6 +541,24 @@ const GET_ALL_RESOURCE_SPECIFICATIONS = gql`
{/if}
</div>

{#if selectedCommitmentId}
<div class="mt-4 flex items-center">
<input type="checkbox" id="finished"
on:change={(e) => {
selectedCommitment.finished = e.target.checked
console.log(selectedCommitment.finished)
}}
bind:checked={finished}
class="h-4 w-4 rounded border-gray-300 text-indigo-600 focus:ring-indigo-500"
>

<label
for="date"
class="block text-sm font-medium leading-6 text-gray-900"
>&nbsp;Commitment finished</label>
</div>
{/if}

<!-- save cost? checkbox -->
<div class="mt-4 flex items-center">
<input
Expand Down
Loading

0 comments on commit 44f6781

Please sign in to comment.