Skip to content

Instantly share code, notes, and snippets.

@philipnilsson
Created August 2, 2024 11:00
Show Gist options
  • Save philipnilsson/0508dda6ddb3e09844279449e8b27c20 to your computer and use it in GitHub Desktop.
Save philipnilsson/0508dda6ddb3e09844279449e8b27c20 to your computer and use it in GitHub Desktop.
type AdditiveSteps = {
orientStep: oqton.items.v1.action.types.SLMOrientStepData;
labelStep: Record<string, oqton.items.v1.action.types.SLMLabelStepData>;
supportStep: Record<string, oqton.items.v1.action.types.SLMSupportStepData>;
};
const $item = Optics.$root('partmodel');
const $partModel = $item.message;
const $actionModels = $partModel.routeModels.$each().actionDefinitions.$each().model.$resolve();
const $machineModels = $actionModels.message.locationModel.$resolve();
const $recoaterDirection = $machineModels.message.parameters.$oneKeyOf('slm', 'sla', 'sls', 'dlp').recoaterDirection;
// Look up the workflowname ...
export const $workflowName = $partModel.routeModels.$at(0).actionDefinitions.$at(0).uuid.text;
// ... use that to look up the workflow.
export const $workflow = $workflowName.$redirect(
name =>
$item.cache[`workflowFor${name}`] as Lens<
ItemRoot<oqton.items.v1.part.PartModel>,
oqton.services.items.CachedItemV1<AdditiveSteps>
>,
// here we need to do a bit of work in order to rewrite the mask for the data in the cache workflows
// as we don't properly support masking things off in the workflows unless we know their exact uuids
mask => constant(either(mask, path('cache.workflowFor*')))
);
// Look up the steps for each workflow we're interested in
export const $steps = $workflow.$redirect(wf => {
const id = Object.keys(wf?.value?.orientStep?.orientations || {})[0] || '0';
return Optics.$allOf({
orientStep: $workflow.value.orientStep,
labelStep: $workflow.value.labelStep[id],
supportStep: $workflow.value.supportStep[id]
});
});
const data = {
steps: $steps,
partModelName: $partModel.name.text,
machineModelName: $machineModels.message.name.text,
actionModelName: $actionModels.message.name.text,
routeModelNames: $partModel.routeModels.$each().routeTemplate.$resolve().message.name,
recoaterDirection: $recoaterDirection
};
export function usePartModel(urn: Urn<PartModel>): Promise<ItemWithLinks<PartModel>> {
const m = useMemo(() => {
return getRequestParamsFromPaths(
getAliasFromUrn(urn),
Object.values(data).flatMap(lens => paths(lens.$_mask))
);
}, []);
// get the links / mask / classmask from the lenses
return useGetAndSubscribeToItem(urn, m.links, m.mask, m.classMasks);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment