Repository: hasura/graphql-engine
File: console/src/components/Services/Data/TableModify/ColumnEditorList.js (JavaScript)

Code before:
      isArrayDataType,
      isNullable: col.is_nullable === 'YES',
      isIdentity: col.is_identity === 'YES',
      pkConstraint: columnPKConstraints[colName],
      isUnique: isColumnUnique(tableSchema, colName),
      // uniqueConstraint: columnUniqueConstraints[colName],
      default: col.column_default || '',
      comment: col.comment || '',
      customFieldName: customColumnNames[colName] || '',
      isOnlyPrimaryKey: columnPKConstraints[colName] && pkLength === 1,
    };

    const onSubmit = toggleEditor => {
      dispatch(saveColumnChangesSql(colName, col, toggleEditor));
    };

    const onDelete = () => {
      let confirmMessage = `This will permanently delete the column "${colName}" from this table`;
      if (columnProperties.pkConstraint) {
        confirmMessage = DELETE_PK_WARNING;
      }

      const isOk = getConfirmation(confirmMessage, true, colName);
      if (isOk) {
        const pk = [];
        let flag = true;
        tableSchema.primary_key.columns.forEach(pkCol => {
          const currentPKCol = pkCol;
          tableSchema.columns.forEach((nonPKCol, colIndex) => {
            if (!nonPKCol.column_name.localeCompare(colName)) {
              flag = false;
            } else {
              if (flag && !currentPKCol.localeCompare(nonPKCol.column_name)) {
                pk.push(colIndex);
              } else if (!currentPKCol.localeCompare(nonPKCol.column_name)) {
                pk.push(colIndex - 1);
              }
            }
          });
          flag = true;
        });

        const pks = [...pk.sort(), ''];
        dispatch(setPrimaryKeys(pks));
        dispatch(deleteColumnSql(col, tableSchema));
      }
    };
    const gqlCompatibilityWarning = () => {
      return (
        <GqlCompatibilityWarning
          identifier={colName}

Review comment (suggestion):
You could perhaps change the name of this variable. Maybe something like `pkPresentFlag`? Also, adding a comment in the above line which would help others know why that flag variable is necessary would be awesome!

Code after:
      isNullable: col.is_nullable === 'YES',
      isIdentity: col.is_identity === 'YES',
      pkConstraint: columnPKConstraints[colName],
      isUnique: isColumnUnique(tableSchema, colName),
      // uniqueConstraint: columnUniqueConstraints[colName],
      default: col.column_default || '',
      comment: col.comment || '',
      customFieldName: customColumnNames[colName] || '',
      isOnlyPrimaryKey: columnPKConstraints[colName] && pkLength === 1,
    };

    const onSubmit = toggleEditor => {
      dispatch(saveColumnChangesSql(colName, col, toggleEditor));
    };

    const onDelete = () => {
      let confirmMessage = `This will permanently delete the column "${colName}" from this table`;
      if (columnProperties.pkConstraint) {
        confirmMessage = DELETE_PK_WARNING;
      }

      const isOk = getConfirmation(confirmMessage, true, colName);
      if (isOk) {
        dispatch(deleteColumnSql(col, tableSchema));
      }
    };
    const gqlCompatibilityWarning = () => {
      return (
        <GqlCompatibilityWarning
          identifier={colName}
          className={styles.add_mar_left_small}
        />
      );
    };

    const keyProperties = () => {
      const propertiesDisplay = [];

      const propertiesList = [];
      propertiesList.push(columnProperties.display_type_name);

      if (columnProperties.pkConstraint) {
        propertiesList.push('primary key');
      }

      if (columnProperties.isUnique || columnProperties.isOnlyPrimaryKey) {
        propertiesList.push('unique');
      }

      if (columnProperties.isIdentity) {
        propertiesList.push('identity');