You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2019/10/30 03:10:36 UTC

[GitHub] [airflow-site] mik-laj commented on a change in pull request #96: Add integration search

mik-laj commented on a change in pull request #96: Add integration search
URL: https://github.com/apache/airflow-site/pull/96#discussion_r340414175
 
 

 ##########
 File path: landing-pages/src/js/integrationList.js
 ##########
 @@ -0,0 +1,153 @@
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import debounce from "lodash/debounce";
+import shuffle from "lodash/shuffle";
+
+const root = document.querySelector("#integrations");
+
+const templateText = root.querySelector("#integration-template").innerText;
+const templateElement = document.createElement("div");
+templateElement.innerHTML = templateText;
+
+const loadingIndicator = root.querySelector(".loading");
+const listItems = root.querySelector(".list-items");
+const searchBox = root.querySelector('[type="search"]');
+const moreButton = root.querySelector("#show-more-integration");
+
+let currentPage = 1;
+let currentQeury = "";
+function setIndicatorVisibility(visible) {
+  loadingIndicator.style.display = visible ? "" : "none";
+  listItems.style.display = visible ? "none" : "";
+}
+setIndicatorVisibility(false);
+function setMoreButtonVisibility(visible) {
+  moreButton.style.display = visible ? "" : "none";
+}
+setMoreButtonVisibility(true);
+
+const sortByLogoAvailability = (a, b) => {
+  const a_key = a.logo ? 1 : -1;
+  const b_key = b.logo ? 1 : -1;
+  return a_key - b_key;
+};
+
+const sortByName  = (a, b) => {
+  return a.name.toLowerCase().localeCompare(b.name.toLowerCase());
+};
+
+const sortByIndex = (a, b) => {
+  return a.index - b.index;
+};
+
+let fetchIntegrationRequest = null;
+
+function fetchIntegration() {
+  if (fetchIntegrationRequest) {
+    return fetchIntegrationRequest;
+  }
+  const request = Promise.all([
+    fetch("/integrations.json"),
+    () => {
+      setIndicatorVisibility(true);
+    }
+  ])
+    .then(([resp]) => resp.json())
+    .then((integrations) => {
+      setIndicatorVisibility(false);
+      return Promise.resolve(integrations);
+    })
+    .then((integrations) => {
+      integrations = shuffle(integrations);
+      integrations.forEach((i, index) => i.inddex = index);
+      integrations.sort(sortByLogoAvailability);
+      return Promise.resolve(integrations);
+    });
+  fetchIntegrationRequest = request;
+  return request;
+}
+
+function createElement(item) {
+  const element = templateElement.cloneNode(true);
+  element.querySelector('[data-name="name"]').innerText = item.name;
+  element.querySelector("a").href = item.url;
+  return element.firstElementChild;
+}
+
+function setItems(items) {
+  if (items.length === 0) {
+    listItems.innerText = "No items";
+  } else {
+    while (listItems.firstChild) {
+      listItems.removeChild(listItems.firstChild);
+    }
+    items.forEach((item) => {
+      const element = createElement(item);
+      listItems.append(element);
+    });
+  }
+}
+
+function showItems(keyword, page) {
+  const showMoreButtonIfNeeded = (integrations) => {
+    setMoreButtonVisibility(integrations.length > (page * 8));
+  };
+
+  const filterMatchingItems = (integrations) => {
+    if (!keyword) {
+      return Promise.resolve(integrations);
+    }
+    const selectedIntegration = integrations.filter(
+      (integration) => integration.name.indexOf(keyword) >= 0
+    );
+    return Promise.resolve(selectedIntegration);
+  };
+
+  const filterVisible = (integrations) => {
+    if (currentPage === 1) {
+      integrations.sort(sortByIndex);
+    } else {
+      integrations.sort(sortByName);
 
 Review comment:
   Viewing a long random list will be more confusing than reordering a few items after clicking, but I can change that and ask for feedback tomorrow.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services