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

Add the hostApp to the state GET v3 result #1479

Merged
merged 3 commits into from
Jan 23, 2024
Merged

Conversation

thgreasi
Copy link
Member

@thgreasi thgreasi commented Nov 14, 2023

@thgreasi thgreasi force-pushed the state-get-v3-hostApp branch from 0a5c671 to c498245 Compare November 14, 2023 14:17
@thgreasi thgreasi force-pushed the state-get-v3-hostApp branch 2 times, most recently from dca2e2d to bc7fd4c Compare December 14, 2023 15:24
@pipex pipex force-pushed the state-get-v3-hostApp branch from bc7fd4c to dea3586 Compare December 14, 2023 18:17
@thgreasi thgreasi force-pushed the state-get-v3-hostApp branch 6 times, most recently from cabe9c5 to 40ca521 Compare December 20, 2023 07:50
@thgreasi thgreasi force-pushed the state-get-v3-hostApp branch from 40ca521 to 7dabc4d Compare January 5, 2024 13:23
@thgreasi thgreasi marked this pull request as ready for review January 5, 2024 13:57
@thgreasi thgreasi requested a review from Page- January 5, 2024 13:57
@thgreasi thgreasi force-pushed the state-get-v3-hostApp branch from 7dabc4d to 2070d1d Compare January 9, 2024 09:18
@flowzone-app flowzone-app bot enabled auto-merge January 9, 2024 09:20
const supervisorRelease = device.should_be_managed_by__release[0];
if (!supervisorRelease) {
return {};
const getSystemAppState = (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be merged with getUserAppState?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to do so, but felt it was a bit too aggressive. We could combine all 3 getSystemAppState, getUserAppState & getAppState to something like:

const getAppState = (
	device: AnyObject,
	targetReleaseField:
		| 'should_be_running__release'
		| 'should_be_managed_by__release'
		| 'should_be_operated_by__release',
	config: Dictionary<string>,
	defaultLabels?: Dictionary<string>,
): StateV3[string]['apps'] | null => {
	let application: AnyObject;
	let release: AnyObject | undefined;
	if (targetReleaseField === 'should_be_running__release') {
		application = device.belongs_to__application[0];
		release = getReleaseForDevice(device);
	} else {
		release = device[targetReleaseField][0];
		if (!release) {
			return null;
		}
		application = release.belongs_to__application[0];
	}

	return {
		[application.uuid]: {
			id: application.id,
			name: application.app_name,
			is_host: application.is_host,
			class: application.is_of__class,
			...(release != null && {
				releases: buildAppFromRelease(
					device,
					application,
					release,
					config,
					defaultLabels,
				),
			}),
		},
	};
};

What do you think?

@thgreasi thgreasi force-pushed the state-get-v3-hostApp branch from 7f21194 to 4c0a01c Compare January 9, 2024 13:26
@thgreasi thgreasi requested review from Page- and removed request for Page- January 9, 2024 13:53
@thgreasi thgreasi force-pushed the state-get-v3-hostApp branch from 4c0a01c to 792d33a Compare January 22, 2024 12:29
@thgreasi thgreasi force-pushed the state-get-v3-hostApp branch from 792d33a to 5cf3ced Compare January 23, 2024 15:32
@flowzone-app flowzone-app bot merged commit 758e3f8 into master Jan 23, 2024
47 checks passed
@flowzone-app flowzone-app bot deleted the state-get-v3-hostApp branch January 23, 2024 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants