-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switched the KnowledgeDomain and Level context over to the string-map…
…-within-selective-context hook.
- Loading branch information
1 parent
d517e35
commit 3ee5df0
Showing
11 changed files
with
210 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
app/graphing/graph-types/work-task-types/assign-item-from-object-entries.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { StringMap } from '../../../contexts/string-map-context/string-map-reducer'; | ||
import { ColumnOne, ColumnsTwoToFour } from './rename-work-task-type'; | ||
import { Listbox } from '@headlessui/react'; | ||
import { | ||
NodeDetailsListBoxButton, | ||
NodeDetailsListBoxOption, | ||
NodeDetailsListBoxOptions | ||
} from '../organization/curriculum-delivery-details'; | ||
import React, { Fragment } from 'react'; | ||
import { isNotUndefined } from '../../../api/main'; | ||
|
||
export function AssignItemFromObjectEntries<T>({ | ||
itemDescriptor, | ||
currentAssignment, | ||
onChange, | ||
optionsMap, | ||
labelAccessor, | ||
idAccessor | ||
}: { | ||
itemDescriptor: string; | ||
currentAssignment: string; | ||
onChange: (value: string) => void; | ||
optionsMap: StringMap<T>; | ||
labelAccessor: (item: T) => string; | ||
idAccessor: (item: T) => string; | ||
}) { | ||
console.log(optionsMap); | ||
return ( | ||
<> | ||
<ColumnOne>{itemDescriptor}</ColumnOne> | ||
<ColumnsTwoToFour> | ||
<Listbox value={currentAssignment} onChange={onChange}> | ||
<Listbox.Button as={NodeDetailsListBoxButton}> | ||
{isNotUndefined(optionsMap[currentAssignment]) | ||
? labelAccessor(optionsMap[currentAssignment]) | ||
: 'Unassigned'} | ||
</Listbox.Button> | ||
<Listbox.Options as={NodeDetailsListBoxOptions} optionsWidth={'w-60'}> | ||
{Object.values(optionsMap) | ||
.filter(isNotUndefined) | ||
.map((option) => ( | ||
<Listbox.Option | ||
value={idAccessor(option)} | ||
key={`${itemDescriptor}-${idAccessor(option)}`} | ||
as={Fragment} | ||
> | ||
{({ selected, active }) => ( | ||
<NodeDetailsListBoxOption | ||
selected={selected} | ||
active={active} | ||
> | ||
{labelAccessor(option)} | ||
</NodeDetailsListBoxOption> | ||
)} | ||
</Listbox.Option> | ||
))} | ||
</Listbox.Options> | ||
</Listbox> | ||
</ColumnsTwoToFour> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
app/graphing/graph-types/work-task-types/use-string-map-context-controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { | ||
useSelectiveContextAnyController, | ||
useSelectiveContextGlobalListener | ||
} from '../../../selective-context/components/global/selective-context-manager-global'; | ||
import { | ||
getIdListContextKey, | ||
getNameSpacedKey | ||
} from '../../../selective-context/components/controllers/dto-id-list-controller'; | ||
import { useSelectiveContextListenerReadAll } from '../../../selective-context/components/base/generic-selective-context-creator'; | ||
import { SelectiveContextGlobal } from '../../../selective-context/components/global/selective-context-creator-global'; | ||
import { useMemo } from 'react'; | ||
import { getEntityNamespaceContextKey } from '../../../selective-context/hooks/dtoStores/use-dto-store'; | ||
import { EmptyArray, isNotUndefined } from '../../../api/main'; | ||
import { StringMap } from '../../../contexts/string-map-context/string-map-reducer'; | ||
import { KnowledgeDomainDto } from '../../../api/dtos/KnowledgeDomainDtoSchema'; | ||
|
||
export function useStringMapContextController<T, U extends string | number>( | ||
entityName: string, | ||
listenerKey: string | ||
) { | ||
const { currentState: idList } = useSelectiveContextGlobalListener<U[]>({ | ||
contextKey: getIdListContextKey(entityName), | ||
listenerKey: listenerKey, | ||
initialValue: EmptyArray | ||
}); | ||
|
||
const selectiveContextReadAll = useSelectiveContextListenerReadAll( | ||
SelectiveContextGlobal | ||
); | ||
|
||
const stringMap = useMemo(() => { | ||
return idList | ||
.map((id) => | ||
selectiveContextReadAll(getEntityNamespaceContextKey(entityName, id)) | ||
) | ||
.filter(isNotUndefined) | ||
.reduce((prev, curr) => { | ||
const next = { ...prev }; | ||
next[curr.id] = curr; | ||
return next; | ||
}, {}); | ||
}, [idList, selectiveContextReadAll, entityName]); | ||
|
||
const nameSpacedKey = getNameSpacedKey(entityName, 'stringMap'); | ||
console.log(nameSpacedKey, stringMap); | ||
return useSelectiveContextAnyController<StringMap<T>>({ | ||
contextKey: nameSpacedKey, | ||
listenerKey: listenerKey, | ||
initialValue: stringMap | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.