Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(macros): refactor gcode_macros getter #1889

Merged
merged 5 commits into from
Jun 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions src/store/printer/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,24 +141,31 @@ export const getters: GetterTree<PrinterState, RootState> = {

getMacros: (state) => {
const array: PrinterStateMacro[] = []
const config = state.configfile?.config ?? {}
const settings = state.configfile?.settings ?? null
const printerGcodes = state.gcode?.commands ?? {}

Object.keys(config)
.filter((prop) => prop.toLowerCase().startsWith('gcode_macro'))
const prefix = 'gcode_macro '
const prefixLength = prefix.length

Object.keys(state)
.filter((prop) => prop.toLowerCase().startsWith(prefix))
.forEach((prop) => {
const name = prop.replace('gcode_macro ', '')
const name = prop.slice(prefixLength)
const printerGcode = printerGcodes[name.toUpperCase()] ?? {}

// remove macros with a '_' as first char
if (name.startsWith('_')) return

// remove macros with rename_existing in the config
const propLower = prop.toLowerCase()
const propSettings = settings[propLower]
const propSettings = settings[propLower] ?? {}
if ('rename_existing' in propSettings) return

const variables = state[prop] ?? {}

array.push({
name,
description: settings[propLower].description ?? null,
description: printerGcode?.help ?? null,
prop: propSettings,
params: getMacroParams(propSettings),
variables,
Expand Down
Loading