Skip to content

Commit

Permalink
Revert "Fix oppia#18508: Improve the experience of adding concept car…
Browse files Browse the repository at this point in the history
…ds in the exploration editor. (oppia#19587)"

This reverts commit c4f4ce0.
  • Loading branch information
jnvtnguyen committed Feb 27, 2024
1 parent ccd96a2 commit 79d4e8d
Show file tree
Hide file tree
Showing 16 changed files with 57 additions and 183 deletions.
15 changes: 0 additions & 15 deletions assets/rich_text_components_definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export default {
"schema": {
"type": "unicode"
},
"default_value_obtainable_from_highlight": false,
"default_value": "Sample Header"
}, {
"name": "content",
Expand All @@ -46,7 +45,6 @@ export default {
"hide_complex_extensions": true
}
},
"default_value_obtainable_from_highlight": false,
"default_value": "You have opened the collapsible block."
}]
},
Expand All @@ -68,7 +66,6 @@ export default {
"type": "custom",
"obj_type": "Filepath"
},
"default_value_obtainable_from_highlight": false,
"default_value": ""
}, {
"name": "caption",
Expand All @@ -80,7 +77,6 @@ export default {
"max_value": 500
}]
},
"default_value_obtainable_from_highlight": false,
"default_value": ""
}, {
"name": "alt",
Expand All @@ -96,7 +92,6 @@ export default {
"rows": 3
}
},
"default_value_obtainable_from_highlight": false,
"default_value": ""
}]
},
Expand All @@ -118,15 +113,13 @@ export default {
"type": "custom",
"obj_type": "SanitizedUrl"
},
"default_value_obtainable_from_highlight": false,
"default_value": ""
}, {
"name": "text",
"description": "The link text. If left blank, the link URL will be used.",
"schema": {
"type": "unicode"
},
"default_value_obtainable_from_highlight": false,
"default_value": ""
}]
},
Expand All @@ -148,7 +141,6 @@ export default {
"type": "custom",
"obj_type": "MathExpressionContent"
},
"default_value_obtainable_from_highlight": false,
"default_value": {
"raw_latex": "",
"svg_filename": ""
Expand All @@ -175,7 +167,6 @@ export default {
"id": "is_nonempty"
}]
},
"default_value_obtainable_from_highlight": true,
"default_value": "concept card"
}, {
"name": "skill_id",
Expand All @@ -184,7 +175,6 @@ export default {
"type": "custom",
"obj_type": "SkillSelector"
},
"default_value_obtainable_from_highlight": false,
"default_value": ""
}]
},
Expand All @@ -206,7 +196,6 @@ export default {
"type": "custom",
"obj_type": "ListOfTabs"
},
"default_value_obtainable_from_highlight": false,
"default_value": [{
"title": "Hint introduction",
"content": "This set of tabs shows some hints. Click on the other tabs to display the relevant hints."
Expand All @@ -233,7 +222,6 @@ export default {
"schema": {
"type": "unicode"
},
"default_value_obtainable_from_highlight": false,
"default_value": ""
}, {
"name": "start",
Expand All @@ -245,7 +233,6 @@ export default {
"min_value": 0
}]
},
"default_value_obtainable_from_highlight": false,
"default_value": 0
}, {
"name": "end",
Expand All @@ -257,15 +244,13 @@ export default {
"min_value": 0
}]
},
"default_value_obtainable_from_highlight": false,
"default_value": 0
}, {
"name": "autoplay",
"description": "Autoplay this video once the question has loaded?",
"schema": {
"type": "bool"
},
"default_value_obtainable_from_highlight": false,
"default_value": false
}]
}
Expand Down
1 change: 0 additions & 1 deletion core/domain/rte_component_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class CustomizationArgSpecDict(TypedDict):
# Here we use type Any because values in schema dictionary can be of
# type str, List, Dict and other types too.
schema: Dict[str, Any]
default_value_obtainable_from_highlight: bool
default_value: Union[str, int, List[str], Dict[str, str]]


Expand Down
3 changes: 1 addition & 2 deletions core/domain/rte_component_registry_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ def _validate_customization_arg_specs(
"""Validates the given customization arg specs."""
for ca_spec in customization_arg_specs:
self.assertEqual(set(ca_spec.keys()), set([
'name', 'description', 'schema', 'default_value',
'default_value_obtainable_from_highlight']))
'name', 'description', 'schema', 'default_value']))

self.assertTrue(
isinstance(ca_spec['name'], str))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export interface RteComponentSpecs {
backendId: string;
customizationArgSpecs: {
name: string; value: string; 'default_value': string;
'default_value_obtainable_from_highlight': boolean;
}[];
id: string;
iconDataUrl: string;
Expand All @@ -40,8 +39,8 @@ export interface RteHelperService {
getRichTextComponents: () => RteComponentSpecs[];
isInlineComponent: (string) => boolean;
openCustomizationModal: (
componentIsNewlyCreated, customizationArgSpecs, attrsCustomizationArgsDict,
onSubmitCallback, onDismissCallback
customizationArgSpecs, attrsCustomizationArgsDict, onSubmitCallback,
onDismissCallback
) => void;
}

Expand Down Expand Up @@ -108,13 +107,11 @@ export class CkEditorInitializerService {
var that = this;
var customizationArgs = {};
customizationArgSpecs.forEach(function(spec) {
customizationArgs[spec.name] = that.data[spec.name];
customizationArgs[spec.name] = that.data[spec.name] ||
spec.default_value;
});

const componentIsNewlyCreated: boolean = !that.isReady();

rteHelperService.openCustomizationModal(
componentIsNewlyCreated,
customizationArgSpecs,
customizationArgs,
function(customizationArgsDict) {
Expand All @@ -130,7 +127,7 @@ export class CkEditorInitializerService {
* has already been inserted into the RTE, we do not
* need to finalizeCreation again).
*/
if (componentIsNewlyCreated) {
if (!that.isReady()) {
// Actually create the widget, if we have not already.
editor.widgets.finalizeCreation(container);
}
Expand All @@ -154,38 +151,16 @@ export class CkEditorInitializerService {
},
function(widgetShouldBeRemoved) {
if (widgetShouldBeRemoved || that.data.isCopied) {
const defaultValueObtainableFromHighlight = (
customizationArgSpecs
.some(function(spec) {
return spec.default_value_obtainable_from_highlight;
}));

that.data.isCopied = false;
var newWidgetSelector = (
'[data-cke-widget-id="' + that.id + '"]');
if (newWidgetSelector === null) {
return;
}
var widgetElement = editor.editable().findOne(
newWidgetSelector);

if (!widgetElement) {
return;
}

/**
* If the component's default value was not obtained from
* a highlighted text or was not newly created, then
* simply remove the component. Otherwise, load the
* initial snapshot to revert back to the original text.
*/
if (!defaultValueObtainableFromHighlight ||
!componentIsNewlyCreated) {
widgetElement.remove();
editor.fire('change');
} else {
editor.loadSnapshot(that.initialSnapshot);
editor.fire('change');
if (newWidgetSelector !== null) {
var widgetElement = editor.editable().findOne(
newWidgetSelector);
if (widgetElement) {
widgetElement.remove();
editor.fire('change');
}
}
}
});
Expand Down Expand Up @@ -227,23 +202,6 @@ export class CkEditorInitializerService {
// eslint-disable-next-line max-len
index ? item.charAt(0).toUpperCase() + item.slice(1).toLowerCase() : item.toLowerCase()
);

/**
* If the component has not been initialized before with data,
* then set the default value or highlighted value as the
* component's data.
*/
const selection = that.editor.getSelection()
.getSelectedText();
if (!that.data[spec.name]) {
if (spec.default_value_obtainable_from_highlight &&
selection) {
that.setData(spec.name, selection);
} else {
that.setData(spec.name, spec.default_value);
}
}

capital.join('');
const customEl = that.element.getChild(0).$;
customEl[capital.join('') + 'WithValue'] = (
Expand All @@ -262,7 +220,6 @@ export class CkEditorInitializerService {
dontUpdate: true
});
var that = this;
that.initialSnapshot = editor.getSnapshot();
// On init, read values from component attributes and save them.
customizationArgSpecs.forEach(function(spec) {
var value = that.element.getChild(0).getAttribute(
Expand Down
2 changes: 1 addition & 1 deletion core/templates/services/rte-helper-modal.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ <h3>Customize This Component</h3>
<div class="modal-footer">
<button type="button"
class="btn btn-danger e2e-test-delete-button"
*ngIf="!componentIsNewlyCreated"
*ngIf="!defaultRTEComponent"
(click)="delete()">
Delete
</button>
Expand Down
37 changes: 32 additions & 5 deletions core/templates/services/rte-helper-modal.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ type CustomizationArgsNameAndValueArray = {
export class RteHelperModalComponent {
@Input() customizationArgSpecs: CustomizationArgsSpecsType;
@Input() attrsCustomizationArgsDict: CustomizationArgsForRteType;
@Input() componentIsNewlyCreated: boolean;
modalIsLoading: boolean = true;
currentRteIsMathExpressionEditor: boolean = false;
currentRteIsLinkEditor: boolean = false;
tmpCustomizationArgs: CustomizationArgsNameAndValueArray = [];
@ViewChild('schemaForm') schemaForm!: NgForm;
defaultRTEComponent: boolean;
public customizationArgsForm: FormGroup;

constructor(
Expand Down Expand Up @@ -198,6 +198,21 @@ export class RteHelperModalComponent {
this.currentRteIsLinkEditor = true;
}

// The 'defaultRTEComponent' variable controls whether the delete button
// needs to be shown. If the RTE component has default values, there is no
// need for a delete button as the 'Cancel' button would have
// the same functionality.
this.defaultRTEComponent = true;
for (let i = 0; i < this.customizationArgSpecs.length; i++) {
let caName = this.customizationArgSpecs[i].name;
let attrsCaDict = this.attrsCustomizationArgsDict;
if (
attrsCaDict.hasOwnProperty(caName) &&
attrsCaDict[caName] !== this.customizationArgSpecs[i].default_value
) {
this.defaultRTEComponent = false;
}
}
const formGroupControls = {};
this.customizationArgSpecs.forEach((_, index) => {
formGroupControls[index] = this.fb.control(
Expand All @@ -213,11 +228,23 @@ export class RteHelperModalComponent {
}

cancel(): void {
if (this.componentIsNewlyCreated) {
this.ngbActiveModal.dismiss(true);
} else {
this.ngbActiveModal.dismiss(false);
for (let i = 0; i < this.customizationArgSpecs.length; i++) {
let caName = this.customizationArgSpecs[i].name;
let attrsCaDict = this.attrsCustomizationArgsDict;
// If the RTE component contains only default ca values, we remove it
// from the editor on clicking cancel. When the
// uibModalInstance.dismiss method is called with true, the tag from
// the editor is removed and when called with false, the tag remains
// as-is.
if (
attrsCaDict.hasOwnProperty(caName) &&
attrsCaDict[caName] !== this.customizationArgSpecs[i].default_value
) {
this.ngbActiveModal.dismiss(false);
return;
}
}
this.ngbActiveModal.dismiss(true);
}

delete(): void {
Expand Down
Loading

0 comments on commit 79d4e8d

Please sign in to comment.