Skip to content

Commit

Permalink
[Fix] [WRS-1854] Default to default user interface when id not provided
Browse files Browse the repository at this point in the history
  • Loading branch information
abdelhalimkhouas committed Jun 10, 2024
1 parent 1d7e835 commit 7dfe8b9
Showing 1 changed file with 31 additions and 25 deletions.
56 changes: 31 additions & 25 deletions src/StudioProjectLoader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,31 +177,20 @@ export class StudioProjectLoader {
};

public onFetchOutputSettings = async (): Promise<UserInterfaceOutputSettings[] | null> => {
if (this.userInterfaceID) {
const outputSettings = await axios.get(`${this.graFxStudioEnvironmentApiBaseUrl}/output/settings`);

const fetchDefaultUserInterface = async (url: string) => {
try {
const res = await axios.get(url);
if (res.status === 200) {
return res.data.data.find((value: UserInterface) => value.default);
}
return res;
} catch (err) {
throw new Error(`${err}`);
const fetchDefaultUserInterface = async (url: string) => {
try {
const res = await axios.get(url);
if (res.status === 200) {
return res.data.data.find((value: UserInterface) => value.default);
}
};

const userInterface = await axios
.get(`${this.graFxStudioEnvironmentApiBaseUrl}/user-interfaces/${this.userInterfaceID}`)
.then((res) => res.data)
.catch(async (err) => {
if (err.response && err.response.status === 404) {
return fetchDefaultUserInterface(`${this.graFxStudioEnvironmentApiBaseUrl}/user-interfaces`);
}
throw new Error(`${err}`);
});
return res;
} catch (err) {
throw new Error(`${err}`);
}
};
const outputSettings = await axios.get(`${this.graFxStudioEnvironmentApiBaseUrl}/output/settings`);

const mapOutPutSettingsToLayoutIntent = (userInterface: UserInterface) => {
const mappedOutputSettings: UserInterfaceOutputSettings[] = [];

Object.keys(userInterface.outputSettings).forEach((outputSettingId) => {
Expand All @@ -216,9 +205,26 @@ export class StudioProjectLoader {
mappedOutputSettings.push(final);
}
});

return mappedOutputSettings;
};

if (this.userInterfaceID) {
const userInterface = await axios
.get(`${this.graFxStudioEnvironmentApiBaseUrl}/user-interfaces/${this.userInterfaceID}`)
.then((res) => res.data)
.catch(async (err) => {
if (err.response && err.response.status === 404) {
return fetchDefaultUserInterface(`${this.graFxStudioEnvironmentApiBaseUrl}/user-interfaces`);
}
throw new Error(`${err}`);
});

return mapOutPutSettingsToLayoutIntent(userInterface);
}
return null;
const defaultUserInterface = await fetchDefaultUserInterface(
`${this.graFxStudioEnvironmentApiBaseUrl}/user-interfaces`,
);

return mapOutPutSettingsToLayoutIntent(defaultUserInterface);
};
}

0 comments on commit 7dfe8b9

Please sign in to comment.