2024-07-16 08:12:23 +03:00
|
|
|
import {LitElement, css, html, nothing} from 'lit';
|
2022-09-07 03:35:35 +03:00
|
|
|
import {ref} from 'lit/directives/ref.js';
|
2024-04-17 07:52:17 +03:00
|
|
|
import {
|
2024-08-22 20:20:28 +03:00
|
|
|
getDisabledHelpText,
|
2024-04-17 07:52:17 +03:00
|
|
|
getStageValue,
|
|
|
|
flattenSections,
|
|
|
|
formatFeatureChanges,
|
|
|
|
showToastMessage,
|
2024-07-16 08:12:23 +03:00
|
|
|
FieldInfo,
|
2024-04-17 07:52:17 +03:00
|
|
|
} from './utils.js';
|
2022-09-07 03:35:35 +03:00
|
|
|
import './chromedash-form-field';
|
2022-08-23 03:41:12 +03:00
|
|
|
import './chromedash-form-table';
|
2024-04-17 07:52:17 +03:00
|
|
|
import {
|
|
|
|
formatFeatureForEdit,
|
2023-03-16 22:32:42 +03:00
|
|
|
VERIFY_ACCURACY_CONFIRMATION_FIELD,
|
|
|
|
VERIFY_ACCURACY_FORMS_BY_STAGE_TYPE,
|
|
|
|
VERIFY_ACCURACY_METADATA_FIELDS,
|
2024-04-17 07:52:17 +03:00
|
|
|
VERIFY_ACCURACY_TRIAL_EXTENSION_FIELDS,
|
|
|
|
} from './form-definition';
|
2023-04-28 00:55:26 +03:00
|
|
|
import {STAGE_SHORT_NAMES, STAGE_SPECIFIC_FIELDS} from './form-field-enums.js';
|
2023-07-20 16:23:03 +03:00
|
|
|
import {ALL_FIELDS} from './form-field-specs';
|
2023-05-10 20:34:35 +03:00
|
|
|
import {SHARED_STYLES} from '../css/shared-css.js';
|
|
|
|
import {FORM_STYLES} from '../css/forms-css.js';
|
2024-07-16 08:12:23 +03:00
|
|
|
import {property, state} from 'lit/decorators.js';
|
|
|
|
import {Feature} from '../js-src/cs-client.js';
|
2022-08-23 03:41:12 +03:00
|
|
|
|
|
|
|
export class ChromedashGuideVerifyAccuracyPage extends LitElement {
|
|
|
|
static get styles() {
|
2024-04-17 07:52:17 +03:00
|
|
|
return [...SHARED_STYLES, ...FORM_STYLES, css``];
|
2022-08-23 03:41:12 +03:00
|
|
|
}
|
2024-07-16 08:12:23 +03:00
|
|
|
@property({attribute: false})
|
|
|
|
featureId = 0;
|
|
|
|
@property({type: String})
|
|
|
|
appTitle = '';
|
|
|
|
@state()
|
|
|
|
feature = {} as Feature;
|
|
|
|
@state()
|
|
|
|
fieldValues: FieldInfo[] & {feature?: Feature} = [];
|
|
|
|
@state()
|
|
|
|
loading = true;
|
|
|
|
@state()
|
|
|
|
previousStageTypeRendered = 0;
|
|
|
|
@state()
|
|
|
|
sameTypeRendered = 0;
|
2022-08-23 03:41:12 +03:00
|
|
|
|
|
|
|
connectedCallback() {
|
|
|
|
super.connectedCallback();
|
|
|
|
this.fetchData();
|
|
|
|
}
|
|
|
|
|
|
|
|
fetchData() {
|
|
|
|
this.loading = true;
|
2024-04-17 07:52:17 +03:00
|
|
|
window.csClient
|
|
|
|
.getFeature(this.featureId)
|
|
|
|
.then(feature => {
|
|
|
|
this.feature = feature;
|
|
|
|
if (this.feature.name) {
|
|
|
|
document.title = `${this.feature.name} - ${this.appTitle}`;
|
|
|
|
}
|
|
|
|
this.loading = false;
|
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
showToastMessage(
|
|
|
|
'Some errors occurred. Please refresh the page or try again later.'
|
|
|
|
);
|
|
|
|
});
|
2022-08-23 03:41:12 +03:00
|
|
|
}
|
|
|
|
|
2022-09-13 23:19:55 +03:00
|
|
|
disconnectedCallback() {
|
|
|
|
super.disconnectedCallback();
|
|
|
|
document.title = this.appTitle;
|
|
|
|
}
|
|
|
|
|
2022-08-23 03:41:12 +03:00
|
|
|
/* Add the form's event listener after Shoelace event listeners are attached
|
|
|
|
* see more at https://github.com/GoogleChrome/chromium-dashboard/issues/2014 */
|
2022-09-07 03:35:35 +03:00
|
|
|
async registerFormSubmitHandler(el) {
|
|
|
|
if (!el) return;
|
|
|
|
|
|
|
|
await el.updateComplete;
|
2024-07-16 08:12:23 +03:00
|
|
|
const hiddenTokenField = this.renderRoot.querySelector(
|
|
|
|
'input[name=token]'
|
|
|
|
) as HTMLInputElement;
|
|
|
|
hiddenTokenField.form?.addEventListener('submit', event => {
|
2022-09-07 03:35:35 +03:00
|
|
|
this.handleFormSubmit(event, hiddenTokenField);
|
|
|
|
});
|
2022-08-23 03:41:12 +03:00
|
|
|
}
|
|
|
|
|
2023-07-20 16:23:03 +03:00
|
|
|
handleFormSubmit(e, hiddenTokenField) {
|
|
|
|
e.preventDefault();
|
|
|
|
const submitBody = formatFeatureChanges(this.fieldValues, this.featureId);
|
2022-08-23 03:41:12 +03:00
|
|
|
|
|
|
|
// get the XSRF token and update it if it's expired before submission
|
2024-04-17 07:52:17 +03:00
|
|
|
window.csClient
|
|
|
|
.ensureTokenIsValid()
|
|
|
|
.then(() => {
|
|
|
|
hiddenTokenField.value = window.csClient.token;
|
2024-07-16 08:12:23 +03:00
|
|
|
return window.csClient.updateFeature(submitBody);
|
2024-04-17 07:52:17 +03:00
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
window.location.href = `/feature/${this.featureId}`;
|
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
showToastMessage(
|
|
|
|
'Some errors occurred. Please refresh the page or try again later.'
|
|
|
|
);
|
|
|
|
});
|
2022-08-23 03:41:12 +03:00
|
|
|
}
|
|
|
|
|
2023-07-20 16:23:03 +03:00
|
|
|
// Handler to update form values when a field update event is fired.
|
|
|
|
handleFormFieldUpdate(event) {
|
|
|
|
const value = event.detail.value;
|
|
|
|
// Index represents which form was updated.
|
|
|
|
const index = event.detail.index;
|
|
|
|
if (index >= this.fieldValues.length) {
|
|
|
|
throw new Error('Out of bounds index when updating field values.');
|
|
|
|
}
|
|
|
|
// The field has been updated, so it is considered touched.
|
|
|
|
this.fieldValues[index].touched = true;
|
|
|
|
this.fieldValues[index].value = value;
|
2024-04-17 07:52:17 +03:00
|
|
|
}
|
2023-07-20 16:23:03 +03:00
|
|
|
|
2022-08-23 03:41:12 +03:00
|
|
|
handleCancelClick() {
|
2024-06-27 01:45:42 +03:00
|
|
|
window.location.href = `/feature/${this.featureId}`;
|
2022-08-23 03:41:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
renderSkeletons() {
|
|
|
|
return html`
|
|
|
|
<h3><sl-skeleton effect="sheen"></sl-skeleton></h3>
|
|
|
|
<section id="metadata">
|
|
|
|
<h3><sl-skeleton effect="sheen"></sl-skeleton></h3>
|
|
|
|
<p>
|
|
|
|
<sl-skeleton effect="sheen"></sl-skeleton>
|
|
|
|
<sl-skeleton effect="sheen"></sl-skeleton>
|
|
|
|
<sl-skeleton effect="sheen"></sl-skeleton>
|
|
|
|
<sl-skeleton effect="sheen"></sl-skeleton>
|
|
|
|
<sl-skeleton effect="sheen"></sl-skeleton>
|
|
|
|
<sl-skeleton effect="sheen"></sl-skeleton>
|
|
|
|
<sl-skeleton effect="sheen"></sl-skeleton>
|
|
|
|
<sl-skeleton effect="sheen"></sl-skeleton>
|
|
|
|
</p>
|
|
|
|
</section>
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
|
|
|
|
renderSubheader() {
|
|
|
|
return html`
|
|
|
|
<div id="subheader">
|
|
|
|
<h2 id="breadcrumbs">
|
2024-06-27 01:45:42 +03:00
|
|
|
<a href="/feature/${this.featureId}">
|
2022-08-23 03:41:12 +03:00
|
|
|
<iron-icon icon="chromestatus:arrow-back"></iron-icon>
|
|
|
|
Verify feature data for ${this.feature.name}
|
|
|
|
</a>
|
|
|
|
</h2>
|
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
|
2023-03-16 22:32:42 +03:00
|
|
|
getStageForm(stageType) {
|
|
|
|
return VERIFY_ACCURACY_FORMS_BY_STAGE_TYPE[stageType] || null;
|
|
|
|
}
|
|
|
|
|
|
|
|
renderStageSection(formattedFeature, name, feStage, stageFields) {
|
|
|
|
if (!stageFields) return nothing;
|
|
|
|
|
|
|
|
// Add a number differentiation if this stage type is the same as another stage.
|
|
|
|
let numberDifferentiation = '';
|
2024-04-17 07:52:17 +03:00
|
|
|
if (
|
|
|
|
this.previousStageTypeRendered &&
|
|
|
|
this.previousStageTypeRendered === feStage.stage_type
|
|
|
|
) {
|
2023-03-16 22:32:42 +03:00
|
|
|
this.sameTypeRendered += 1;
|
2023-03-31 20:14:15 +03:00
|
|
|
numberDifferentiation = ` ${this.sameTypeRendered}`;
|
2023-03-16 22:32:42 +03:00
|
|
|
} else {
|
|
|
|
this.previousStageTypeRendered = feStage.stage_type;
|
|
|
|
this.sameTypeRendered = 1;
|
|
|
|
}
|
2023-03-31 20:14:15 +03:00
|
|
|
let sectionName = `${name}${numberDifferentiation}`;
|
|
|
|
if (feStage.display_name) {
|
|
|
|
sectionName = `${name}: ${feStage.display_name}`;
|
|
|
|
}
|
2023-03-16 22:32:42 +03:00
|
|
|
|
|
|
|
const formFieldEls = stageFields.map(field => {
|
|
|
|
let value = formattedFeature[field];
|
2023-07-20 16:23:03 +03:00
|
|
|
const featureJSONKey = ALL_FIELDS[field].name || field;
|
|
|
|
|
2023-03-16 22:32:42 +03:00
|
|
|
if (STAGE_SPECIFIC_FIELDS.has(field)) {
|
2023-07-20 16:23:03 +03:00
|
|
|
value = getStageValue(feStage, featureJSONKey);
|
2023-03-16 22:32:42 +03:00
|
|
|
} else if (this.sameTypeRendered > 1) {
|
|
|
|
// Don't render fields that are not stage-specific if this is
|
|
|
|
// a stage type that is already being rendered.
|
|
|
|
// This is to avoid repeated fields on the edit-all page.
|
|
|
|
return nothing;
|
|
|
|
}
|
2023-07-20 16:23:03 +03:00
|
|
|
|
|
|
|
// Add the field to this component's stage before creating the field component.
|
|
|
|
const index = this.fieldValues.length;
|
2023-10-19 22:09:52 +03:00
|
|
|
let touched = false;
|
|
|
|
if (featureJSONKey === 'accurate_as_of') {
|
|
|
|
touched = true;
|
|
|
|
}
|
2023-07-20 16:23:03 +03:00
|
|
|
this.fieldValues.push({
|
|
|
|
name: featureJSONKey,
|
2023-10-19 22:09:52 +03:00
|
|
|
touched,
|
2023-07-20 16:23:03 +03:00
|
|
|
value,
|
|
|
|
stageId: feStage.id,
|
|
|
|
});
|
|
|
|
|
2023-03-16 22:32:42 +03:00
|
|
|
return html`
|
|
|
|
<chromedash-form-field
|
|
|
|
name=${field}
|
2023-07-20 16:23:03 +03:00
|
|
|
index=${index}
|
2023-03-31 02:37:14 +03:00
|
|
|
value=${value}
|
2024-08-22 20:20:28 +03:00
|
|
|
disabledReason="${getDisabledHelpText(field, feStage)}"
|
2023-11-01 00:07:57 +03:00
|
|
|
.fieldValues=${this.fieldValues}
|
2024-07-03 19:55:26 +03:00
|
|
|
.feature=${formattedFeature}
|
2023-07-20 16:23:03 +03:00
|
|
|
?forEnterprise=${formattedFeature.is_enterprise_feature}
|
2024-04-17 07:52:17 +03:00
|
|
|
@form-field-update="${this.handleFormFieldUpdate}"
|
|
|
|
>
|
2023-03-16 22:32:42 +03:00
|
|
|
</chromedash-form-field>
|
|
|
|
`;
|
|
|
|
});
|
2024-04-17 07:52:17 +03:00
|
|
|
const id =
|
|
|
|
`${STAGE_SHORT_NAMES[feStage.stage_type] || 'metadata'}${this.sameTypeRendered}`.toLowerCase();
|
2023-03-16 22:32:42 +03:00
|
|
|
return html`
|
2024-04-17 07:52:17 +03:00
|
|
|
<h3 id="${id}">${sectionName}</h3>
|
|
|
|
<section class="flat_form">${formFieldEls}</section>
|
2023-03-16 22:32:42 +03:00
|
|
|
`;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Builds the HTML elements for rendering the form sections.
|
|
|
|
* @param {Object} formattedFeature Object describing the feature.
|
|
|
|
* @param {Array} feStages List of stages associated with the feature.
|
|
|
|
*
|
|
|
|
* @return {Array} allFormFields, an array of strings representing all the field
|
|
|
|
* names that will exist on the page.
|
|
|
|
* @return {Array} formsToRender, All HTML elements to render in the form.
|
|
|
|
*/
|
|
|
|
getForms(formattedFeature, feStages) {
|
|
|
|
// All features display the metadata section.
|
|
|
|
let fieldsOnly = flattenSections(VERIFY_ACCURACY_METADATA_FIELDS);
|
|
|
|
const formsToRender = [
|
|
|
|
this.renderStageSection(
|
2024-04-17 07:52:17 +03:00
|
|
|
formattedFeature,
|
|
|
|
VERIFY_ACCURACY_METADATA_FIELDS.name,
|
|
|
|
{},
|
|
|
|
fieldsOnly
|
|
|
|
),
|
|
|
|
];
|
2023-03-16 22:32:42 +03:00
|
|
|
|
|
|
|
// Generate a single array with the name of every field that is displayed.
|
|
|
|
let allFormFields = [...fieldsOnly];
|
|
|
|
|
|
|
|
for (const feStage of feStages) {
|
|
|
|
const stageForm = this.getStageForm(feStage.stage_type);
|
|
|
|
if (!stageForm) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
fieldsOnly = flattenSections(stageForm);
|
2024-04-17 07:52:17 +03:00
|
|
|
formsToRender.push(
|
|
|
|
this.renderStageSection(
|
|
|
|
formattedFeature,
|
|
|
|
stageForm.name,
|
|
|
|
feStage,
|
|
|
|
fieldsOnly
|
|
|
|
)
|
|
|
|
);
|
2023-03-16 22:32:42 +03:00
|
|
|
allFormFields = [...allFormFields, ...fieldsOnly];
|
|
|
|
|
|
|
|
// If extension stages are associated with this stage,
|
|
|
|
// render them in a separate section as well.
|
|
|
|
const extensions = feStage.extensions || [];
|
|
|
|
extensions.forEach(extensionStage => {
|
|
|
|
fieldsOnly = flattenSections(VERIFY_ACCURACY_TRIAL_EXTENSION_FIELDS);
|
2023-03-31 20:14:15 +03:00
|
|
|
let sectionName = VERIFY_ACCURACY_TRIAL_EXTENSION_FIELDS.name;
|
|
|
|
if (feStage.display_name) {
|
|
|
|
sectionName = `${feStage.display_name} ${VERIFY_ACCURACY_TRIAL_EXTENSION_FIELDS.name}`;
|
|
|
|
}
|
2024-04-17 07:52:17 +03:00
|
|
|
formsToRender.push(
|
|
|
|
this.renderStageSection(
|
|
|
|
formattedFeature,
|
|
|
|
sectionName,
|
|
|
|
extensionStage,
|
|
|
|
fieldsOnly
|
|
|
|
)
|
|
|
|
);
|
2023-03-16 22:32:42 +03:00
|
|
|
allFormFields = [...allFormFields, ...fieldsOnly];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add the verify accuracy checkbox at the end of all forms.
|
|
|
|
fieldsOnly = flattenSections(VERIFY_ACCURACY_CONFIRMATION_FIELD);
|
2024-04-17 07:52:17 +03:00
|
|
|
formsToRender.push(
|
|
|
|
this.renderStageSection(
|
|
|
|
formattedFeature,
|
|
|
|
`${VERIFY_ACCURACY_CONFIRMATION_FIELD.name}`,
|
|
|
|
{},
|
|
|
|
fieldsOnly
|
|
|
|
)
|
|
|
|
);
|
2023-03-16 22:32:42 +03:00
|
|
|
allFormFields = [...allFormFields, ...fieldsOnly];
|
|
|
|
|
|
|
|
return [allFormFields, formsToRender];
|
|
|
|
}
|
|
|
|
|
|
|
|
getAllStageIds() {
|
2024-07-16 08:12:23 +03:00
|
|
|
const stageIds: number[] = [];
|
2023-03-16 22:32:42 +03:00
|
|
|
this.feature.stages.forEach(feStage => {
|
|
|
|
stageIds.push(feStage.id);
|
|
|
|
// Check if any trial extension exist, and collect their IDs as well.
|
|
|
|
const extensions = feStage.extensions || [];
|
|
|
|
extensions.forEach(extensionStage => stageIds.push(extensionStage.id));
|
|
|
|
});
|
|
|
|
return stageIds.join(',');
|
|
|
|
}
|
|
|
|
|
2022-08-23 03:41:12 +03:00
|
|
|
renderForm() {
|
2023-03-16 22:32:42 +03:00
|
|
|
const formattedFeature = formatFeatureForEdit(this.feature);
|
2024-01-29 21:39:12 +03:00
|
|
|
this.fieldValues.feature = this.feature;
|
2023-12-13 21:05:16 +03:00
|
|
|
|
2023-03-16 22:32:42 +03:00
|
|
|
const stageIds = this.getAllStageIds();
|
2024-04-17 07:52:17 +03:00
|
|
|
const [allFormFields, formsToRender] = this.getForms(
|
|
|
|
formattedFeature,
|
|
|
|
this.feature.stages
|
|
|
|
);
|
2023-03-16 22:32:42 +03:00
|
|
|
|
2024-04-17 07:52:17 +03:00
|
|
|
const title = this.feature.accurate_as_of
|
|
|
|
? `Accuracy last verified ${this.feature.accurate_as_of.split(' ')[0]}.`
|
|
|
|
: 'Accuracy last verified at time of creation.';
|
2022-09-07 03:35:35 +03:00
|
|
|
|
2022-08-23 03:41:12 +03:00
|
|
|
return html`
|
2024-08-23 00:31:56 +03:00
|
|
|
<form name="feature_form" method="post">
|
2024-04-17 07:52:17 +03:00
|
|
|
<input type="hidden" name="stages" value="${stageIds}" />
|
|
|
|
<input type="hidden" name="token" />
|
|
|
|
<input
|
|
|
|
type="hidden"
|
|
|
|
name="form_fields"
|
|
|
|
value=${allFormFields.join(',')}
|
|
|
|
/>
|
2022-09-07 03:35:35 +03:00
|
|
|
<h3>${title}</h3>
|
2023-03-16 22:32:42 +03:00
|
|
|
<chromedash-form-table ${ref(this.registerFormSubmitHandler)}>
|
|
|
|
${formsToRender}
|
|
|
|
</chromedash-form-table>
|
2022-08-23 03:41:12 +03:00
|
|
|
|
|
|
|
<section class="final_buttons">
|
2024-04-17 07:52:17 +03:00
|
|
|
<input class="button" type="submit" value="Submit" />
|
|
|
|
<button
|
|
|
|
id="cancel-button"
|
|
|
|
type="reset"
|
|
|
|
@click=${this.handleCancelClick}
|
|
|
|
>
|
|
|
|
Cancel
|
|
|
|
</button>
|
2022-08-23 03:41:12 +03:00
|
|
|
</section>
|
|
|
|
</form>
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return html`
|
|
|
|
${this.renderSubheader()}
|
|
|
|
${this.loading ? this.renderSkeletons() : this.renderForm()}
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-17 07:52:17 +03:00
|
|
|
customElements.define(
|
|
|
|
'chromedash-guide-verify-accuracy-page',
|
|
|
|
ChromedashGuideVerifyAccuracyPage
|
|
|
|
);
|