Skip to content

Commit

Permalink
Use webdx feature api
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleJu committed Jan 25, 2025
1 parent 24bc89e commit 8833c9a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 551 deletions.
36 changes: 20 additions & 16 deletions client-src/elements/chromedash-form-field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
} from './utils.js';
import {Feature, StageDict} from '../js-src/cs-client';
import {FormattedFeature} from './form-definition';
import {WEB_FEATURES_CHOICES} from './web-feature-constants';

interface getFieldValue {
(fieldName: string, stageOrId: any): any;
Expand Down Expand Up @@ -85,25 +84,30 @@ export class ChromedashFormField extends LitElement {
}

if (this.name === 'blink_components') {
// get the choice values from API when the field is blink component select field
this.loading = true;
window.csClient
.getBlinkComponents()
.then(componentChoices => {
this.fetchedChoices = componentChoices;
this.loading = false;
})
.catch(() => {
showToastMessage(
'Some errors occurred. Please refresh the page or try again later.'
);
});
this.fetchChoices(
window.csClient.getBlinkComponents(),
'Error fetching Blink Components. Please refresh the page or try again later.'
);
} else if (this.name === 'web_feature') {
// TODO(kyleju): Create a web features API once a data ingestion pipeline is created.
this.fetchedChoices = WEB_FEATURES_CHOICES;
this.fetchChoices(
window.csClient.getWebdxFeatures(),
'Error fetching Webdx Features. Please refresh the page or try again later.'
);
}
}

fetchChoices(fetchPromise, errorMessage) {
this.loading = true;
fetchPromise
.then(choices => {
this.fetchedChoices = choices;
this.loading = false;
})
.catch(() => {
showToastMessage(errorMessage);
});
}

firstUpdated() {
this.initialValue = JSON.parse(JSON.stringify(this.value));
// We need to wait until the entire page is rendered, so later dependents
Expand Down
6 changes: 6 additions & 0 deletions client-src/elements/chromedash-form-field_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
STAGE_BLINK_ORIGIN_TRIAL,
STAGE_BLINK_SHIPPING,
} from './form-field-enums';
import {ChromeStatusClient} from '../js-src/cs-client';
import sinon from 'sinon';

describe('chromedash-form-field', () => {
it('renders a checkbox type of field', async () => {
Expand Down Expand Up @@ -66,6 +68,10 @@ describe('chromedash-form-field', () => {
});

it('renders Web Feature ID field with a link', async () => {
window.csClient = new ChromeStatusClient('fake_token', 1);
const webdxFeaturesStub = sinon.stub(window.csClient, 'getWebdxFeatures');
webdxFeaturesStub.returns(Promise.resolve({}));

const component = await fixture(
html` <chromedash-form-field name="web_feature" value="hwb">
</chromedash-form-field>`
Expand Down
Loading

0 comments on commit 8833c9a

Please sign in to comment.