Skip to content
This repository has been archived by the owner on Jan 7, 2022. It is now read-only.

#29 Nakadi SQL Query tab and server support added #30

Merged
merged 19 commits into from
Nov 16, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
#29 Nakadi SQL feature flag usage
  • Loading branch information
SergKam committed Nov 5, 2018
commit 5767357a892eb04890bd4f406068be2e230188a9
2 changes: 1 addition & 1 deletion client/Pages/EventTypeDetails/Models.elm
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ stringToTabs str =
Just PublishTab

"QueryTab" ->
Just SchemaTab
Just QueryTab

_ ->
Nothing
35 changes: 30 additions & 5 deletions client/Pages/EventTypeDetails/Update.elm
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ import User.Commands exposing (logoutIfExpired)
import Constants
import Http
import Config
import RemoteData exposing (RemoteData(NotAsked))
import RemoteData exposing (isFailure, RemoteData(Loading, Failure, NotAsked))
import User.Models exposing (Settings)


update : Msg -> Model -> ( Model, Cmd Msg, Route )
update message model =
update : Settings -> Msg -> Model -> ( Model, Cmd Msg, Route )
update settings message model =
let
deletePopup =
model.deletePopup
Expand Down Expand Up @@ -128,10 +129,34 @@ update message model =
( { model | eventTypeSchemasStore = subModel }, Cmd.map EventTypeSchemasStoreMsg msCmd )

LoadQuery id ->
( { model | loadQueryResponse = NotAsked }, loadQuery LoadQueryResponse id )
let
startLoadingQuery =
( { model | loadQueryResponse = Loading }
, loadQuery LoadQueryResponse id
)

switchTab =
( { model | loadQueryResponse = Failure Http.NetworkError }
, if model.tab == QueryTab then
dispatch (TabChange SchemaTab)
else
Cmd.none
)
in
if settings.showNakadiSql then
startLoadingQuery
else
switchTab

LoadQueryResponse resp ->
( { model | loadQueryResponse = resp }, Cmd.none )
let
switchTabOnFailure =
if isFailure resp && model.tab == QueryTab then
dispatch (TabChange SchemaTab)
else
Cmd.none
in
( { model | loadQueryResponse = resp }, switchTabOnFailure )

LoadPublishers ->
( model, dispatch (PublishersStoreMsg (loadSubStoreMsg model.name)) )
Expand Down
8 changes: 6 additions & 2 deletions client/Pages/EventTypeDetails/View.elm
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ detailsLayout typeName eventType model =
usersInfoUrl =
model.userStore.user.settings.usersInfoUrl

showNakadiSql =
model.userStore.user.settings.showNakadiSql

tab =
pageState.tab

Expand Down Expand Up @@ -216,11 +219,12 @@ detailsLayout typeName eventType model =
(Just tab)
<|
(\tabList ->
if isSuccess pageState.loadQueryResponse then
if showNakadiSql && isSuccess pageState.loadQueryResponse then
( QueryTab
, "SQL Query"
, queryTab pageState
):: tabList
)
:: tabList
else
tabList
)
Expand Down
4 changes: 0 additions & 4 deletions client/Stores/Query.elm
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ type alias Query =
{
id : String,
sql : String,
created: String,
modified: String,
status: String
}

Expand All @@ -18,6 +16,4 @@ queryDecoder =
decode Query
|> required "id" string
|> required "sql" string
|> required "created" string
|> required "modified" string
|> required "status" string
2 changes: 1 addition & 1 deletion client/Update.elm
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ updateComponents message model =
EventTypeDetailsMsg subMsg ->
let
( newModel, subCmd, newRoute ) =
PageEventTypeDetails.update subMsg model.eventTypeDetailsPage
PageEventTypeDetails.update model.userStore.user.settings subMsg model.eventTypeDetailsPage
in
( { model | eventTypeDetailsPage = newModel, newRoute = newRoute }, Cmd.map EventTypeDetailsMsg subCmd )

Expand Down
29 changes: 24 additions & 5 deletions tests/mocks/data/sqlquery.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,26 @@
{
"id":"sql-test",
"sql":"SELECT * FROM test-et",
"status":"active",
"created":"2018-01-01",
"modified":"2018-01-01"
"authorization": {
"admins": [
{
"data_type": "user",
"value": "lmontrieux"
}
],
"readers": [
{
"data_type": "user",
"value": "lmontrieux"
}
]
},
"created": "2018-10-31T09:41:21.274",
"id": "lm.sql.test1.output",
"output_event_type": {
"category": "data",
"name": "lm.sql.test1.output",
"owning_application": "stups_nakadi"
},
"sql": "select * from \"lm.sql.test1\" t1",
"status": "active",
"updated": "2018-10-31T09:41:21.274"
}
5 changes: 5 additions & 0 deletions tests/mocks/testNakadiSql.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ const express = require('express');
const http = require('http');
const app = express();
const query = require('./data/sqlquery');

app.get('/queries/ad.nakadi.sql.demo.et', (req, res, done) =>{
res.status(404).json({})
});

app.get('/queries/:id', (req, res, done) =>{
res.json(query)
});
Expand Down